about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2011-08-08 08:57:51 +0200
committerserpilliere <devnull@localhost>2011-08-08 08:57:51 +0200
commitb8b49c0635d7a96462dd58985d64cedfc1233b9e (patch)
treea79c2521e07e4c5a727af7ed6f12a809e9414de7
parent03ea86a64995c659f898d324fd364839fb392d08 (diff)
downloadmiasm-b8b49c0635d7a96462dd58985d64cedfc1233b9e.tar.gz
miasm-b8b49c0635d7a96462dd58985d64cedfc1233b9e.zip
fix 32/64 issue in pe helper
-rw-r--r--miasm/tools/emul_lib/libcodenat_interface.c4
-rw-r--r--miasm/tools/pe_helper.py7
2 files changed, 7 insertions, 4 deletions
diff --git a/miasm/tools/emul_lib/libcodenat_interface.c b/miasm/tools/emul_lib/libcodenat_interface.c
index 05c8a539..e8a66735 100644
--- a/miasm/tools/emul_lib/libcodenat_interface.c
+++ b/miasm/tools/emul_lib/libcodenat_interface.c
@@ -372,13 +372,15 @@ PyObject* _vm_set_mem(PyObject *addr, PyObject *item_str)
 	    RAISE(PyExc_TypeError,"arg1 must be int");
     }
 
-    printf("set addr: %X\n", val);
 
     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);
+
+    printf("set addr: %X (len %x)\n", val, length);
+
     mpn = get_memory_page_from_address(val);
     memcpy(mpn->ad_hp + (val-mpn->ad), buf_data, buf_size);
 
diff --git a/miasm/tools/pe_helper.py b/miasm/tools/pe_helper.py
index aba8d1b7..fe42b565 100644
--- a/miasm/tools/pe_helper.py
+++ b/miasm/tools/pe_helper.py
@@ -16,6 +16,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #
 from elfesteem import *
+from elfesteem import cstruct
 
 from miasm.arch.ia32_arch import *
 from miasm.tools.emul_helper import *
@@ -539,7 +540,7 @@ def preload_lib(e, patch_vm_imp = True, lib_base_ad = 0x77700000):
         libname_s = canon_libname_libfunc(libname, libfunc)
         dyn_funcs[libname_s] = ad_libfunc
         if patch_vm_imp:
-            to_c_helper.vm_set_mem(ad, struct.pack('L', ad_libfunc))
+            to_c_helper.vm_set_mem(ad, struct.pack(cstruct.size2type[e.wsize], ad_libfunc))
         
     return runtime_lib, dyn_funcs
 
@@ -558,7 +559,7 @@ def preload_elf(e, patch_vm_imp = True, lib_base_ad = 0x77700000):
         libname_s = canon_libname_libfunc(libname, libfunc)
         dyn_funcs[libname_s] = ad_libfunc
         if patch_vm_imp:
-            to_c_helper.vm_set_mem(ad, struct.pack('L', ad_libfunc))
+            to_c_helper.vm_set_mem(ad, struct.pack(cstruct.size2type[e.size], ad_libfunc))
         
     return runtime_lib, dyn_funcs
 
@@ -584,7 +585,7 @@ class find_call_xref:
     def next(self):
         while True:
             off_i = self.my_iter.next().start()
-            off = off_i + 5 + struct.unpack('l', self.e.content[off_i+1:off_i+5])[0]
+            off = off_i + 5 + struct.unpack('i', self.e.content[off_i+1:off_i+5])[0]
             if off == self.off:
                 return off_i
         raise StopIteration