Пример #1
0
PyObject* vm_add_memory_page(VmMngr* self, PyObject* args)
{
	PyObject *addr;
	PyObject *access;
	PyObject *item_str;
	PyObject *name=NULL;
	uint64_t buf_size;
	size_t buf_size_st;
	char* buf_data;
	Py_ssize_t length;
	uint64_t page_addr;
	uint64_t page_access;
	const char *name_ptr;

	struct memory_page_node * mpn;

	if (!PyArg_ParseTuple(args, "OOO|O", &addr, &access, &item_str, &name))
		RAISE(PyExc_TypeError,"Cannot parse arguments");

	PyGetInt_uint64_t(addr, page_addr);
	PyGetInt_uint64_t(access, page_access);

	if(!PyBytes_Check(item_str))
		RAISE(PyExc_TypeError,"arg must be bytes");

	buf_size = PyBytes_Size(item_str);
	PyBytes_AsStringAndSize(item_str, &buf_data, &length);

	if (name == NULL) {
		name_ptr = (char*)"";
	} else {
		PyGetStr(name_ptr, name);
	}
	mpn = create_memory_page_node(page_addr, (unsigned int)buf_size, (unsigned int)page_access, name_ptr);
	if (mpn == NULL)
		RAISE(PyExc_TypeError,"cannot create page");
	if (is_mpn_in_tab(&self->vm_mngr, mpn)) {
		free(mpn->ad_hp);
		free(mpn);
		RAISE(PyExc_TypeError,"known page in memory");
	}

	if (buf_size > SIZE_MAX) {
		      fprintf(stderr, "Size too big\n");
		      exit(EXIT_FAILURE);
	}
	buf_size_st = (size_t) buf_size;

	memcpy(mpn->ad_hp, buf_data, buf_size_st);
	add_memory_page(&self->vm_mngr, mpn);

	Py_INCREF(Py_None);
	return Py_None;
}
Пример #2
0
PyObject* vm_add_memory_page(VmMngr* self, PyObject* args)
{
	PyObject *addr;
	PyObject *access;
	PyObject *item_str;
	PyObject *name=NULL;
	uint64_t buf_size;
	char* buf_data;
	Py_ssize_t length;
	uint64_t ret = 0x1337beef;
	uint64_t page_addr;
	uint64_t page_access;
	char* name_ptr;

	struct memory_page_node * mpn;

	if (!PyArg_ParseTuple(args, "OOO|O", &addr, &access, &item_str, &name))
		return NULL;

	PyGetInt(addr, page_addr);
	PyGetInt(access, page_access);

	if(!PyString_Check(item_str))
		RAISE(PyExc_TypeError,"arg must be str");

	buf_size = PyString_Size(item_str);
	PyString_AsStringAndSize(item_str, &buf_data, &length);

	if (name == NULL) {
		name_ptr = (char*)"";
	} else {
		if (!PyString_Check(name))
			RAISE(PyExc_TypeError,"name must be str");
		name_ptr = PyString_AsString(name);
	}
	mpn = create_memory_page_node(page_addr, buf_size, page_access, name_ptr);
	if (mpn == NULL)
		RAISE(PyExc_TypeError,"cannot create page");
	if (is_mpn_in_tab(&self->vm_mngr, mpn)) {
		free(mpn->ad_hp);
		free(mpn);
		RAISE(PyExc_TypeError,"known page in memory");
	}

	memcpy(mpn->ad_hp, buf_data, buf_size);
	add_memory_page(&self->vm_mngr, mpn);

	return PyLong_FromUnsignedLongLong((uint64_t)ret);

}