about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2012-07-31 12:57:20 +0200
committerserpilliere <devnull@localhost>2012-07-31 12:57:20 +0200
commitae66cd9178f210bd6d5e198e8fc20698d0feb924 (patch)
tree9b0d4c9b4f0bb37e82d7eb9696f0a8bc0ab46737
parent753e230cec8b4070ce6ffcdfadc5daa05abb0f5d (diff)
parentac28bc813ab39c8a56d65feacd952ece59ae7eac (diff)
downloadmiasm-ae66cd9178f210bd6d5e198e8fc20698d0feb924.tar.gz
miasm-ae66cd9178f210bd6d5e198e8fc20698d0feb924.zip
merge
-rw-r--r--miasm/tools/emul_lib/libcodenat_interface.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/miasm/tools/emul_lib/libcodenat_interface.c b/miasm/tools/emul_lib/libcodenat_interface.c
index e0307d37..a0eeb4b3 100644
--- a/miasm/tools/emul_lib/libcodenat_interface.c
+++ b/miasm/tools/emul_lib/libcodenat_interface.c
@@ -677,6 +677,7 @@ PyObject* _vm_set_mem(PyObject *addr, PyObject *item_str)
     Py_ssize_t length;
     int ret = 0x1337;
     unsigned int val;
+    unsigned int l;
 
     struct memory_page_node * mpn;
 
@@ -690,15 +691,25 @@ PyObject* _vm_set_mem(PyObject *addr, PyObject *item_str)
 	    RAISE(PyExc_TypeError,"arg1 must be int");
     }
 
-
     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);
 
-    mpn = get_memory_page_from_address(val);
-    memcpy(mpn->ad_hp + (val-mpn->ad), buf_data, buf_size);
+    /* read is multiple page wide */
+    while (buf_size){
+	    mpn = get_memory_page_from_address(val);
+	    if (!mpn){
+		    PyErr_SetString(PyExc_RuntimeError, "cannot find address");
+		    return 0;
+	    }
+	    l = MIN(buf_size, mpn->size - (val-mpn->ad));
+	    memcpy(mpn->ad_hp + (val-mpn->ad), buf_data, l);
+	    buf_data += l;
+	    val += l;
+	    buf_size -= l;
+    }
 
     return PyInt_FromLong((long)ret);
 }