1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <cstddef>
#include <vector>
#include <hwd.h>
static PyObject * memory_write(PyObject * self, PyObject * args)
{
Py_ssize_t offset;
Py_buffer data;
if (!PyArg_ParseTuple(args, "y*n", &data, &offset))
return NULL;
hwd::memory::write(
std::vector<char> {static_cast<char *>(data.buf), static_cast<char *>(data.buf) + data.len},
static_cast<std::size_t>(offset));
Py_RETURN_NONE;
}
static PyMethodDef memory_methods[] = {
{"write", memory_write, METH_VARARGS, "mem_write(data, offset)\n--\n\nWrites *data* to memory at *offset*."},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef memory_module = {
PyModuleDef_HEAD_INIT,
"memory",
NULL,
-1,
memory_methods
};
PyMODINIT_FUNC PyInit_memory(void)
{
return PyModule_Create(&memory_module);
}
|