diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2018-03-04 01:43:18 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2018-03-04 02:44:17 +0100 |
| commit | 65e257294497e1ea573c469d637f5b9301b0ff74 (patch) | |
| tree | ba68fdee543a617749c2fe7b15ba807acf34de76 | |
| parent | 21604c8e0541ea03a38f15831eafaf5793396887 (diff) | |
| download | miasm-65e257294497e1ea573c469d637f5b9301b0ff74.tar.gz miasm-65e257294497e1ea573c469d637f5b9301b0ff74.zip | |
Jitter/python: support little endian
| -rw-r--r-- | miasm2/arch/ppc/sem.py | 1 | ||||
| -rw-r--r-- | miasm2/jitter/emulatedsymbexec.py | 9 | ||||
| -rw-r--r-- | miasm2/jitter/vm_mngr_py.c | 13 |
3 files changed, 21 insertions, 2 deletions
diff --git a/miasm2/arch/ppc/sem.py b/miasm2/arch/ppc/sem.py index 3c9d0e83..4434efa7 100644 --- a/miasm2/arch/ppc/sem.py +++ b/miasm2/arch/ppc/sem.py @@ -845,6 +845,7 @@ class ir_ppc32b(IntermediateRepresentation): self.pc = mn_ppc.getpc() self.sp = mn_ppc.getsp() self.IRDst = expr.ExprId('IRDst', 32) + self.addrsize = 32 def get_ir(self, instr): args = instr.args[:] diff --git a/miasm2/jitter/emulatedsymbexec.py b/miasm2/jitter/emulatedsymbexec.py index 97f038dc..4107dc75 100644 --- a/miasm2/jitter/emulatedsymbexec.py +++ b/miasm2/jitter/emulatedsymbexec.py @@ -44,9 +44,11 @@ class EmulatedSymbExec(SymbolicExecutionEngine): addr = expr_mem.arg.arg.arg size = expr_mem.size / 8 value = self.cpu.get_mem(addr, size) + if self.vm.is_little_endian(): + value = value[::-1] self.vm.add_mem_read(addr, size) - return m2_expr.ExprInt(int(value[::-1].encode("hex"), 16), + return m2_expr.ExprInt(int(value.encode("hex"), 16), expr_mem.size) def _func_write(self, symb_exec, dest, data): @@ -66,7 +68,10 @@ class EmulatedSymbExec(SymbolicExecutionEngine): size = data.size / 8 content = hex(to_write).replace("0x", "").replace("L", "") content = "0" * (size * 2 - len(content)) + content - content = content.decode("hex")[::-1] + content = content.decode("hex") + + if self.vm.is_little_endian(): + content = content[::-1] # Write in VmMngr context self.cpu.set_mem(addr, content) diff --git a/miasm2/jitter/vm_mngr_py.c b/miasm2/jitter/vm_mngr_py.c index 35633b7f..fa69fab5 100644 --- a/miasm2/jitter/vm_mngr_py.c +++ b/miasm2/jitter/vm_mngr_py.c @@ -564,6 +564,17 @@ vm_set_little_endian(VmMngr *self, PyObject *value, void *closure) } +static PyObject * +vm_is_little_endian(VmMngr *self, PyObject *value, void *closure) +{ + if (self->vm_mngr.sex == __BIG_ENDIAN) { + return PyLong_FromUnsignedLongLong(0); + } else { + return PyLong_FromUnsignedLongLong(1); + } +} + + static void VmMngr_dealloc(VmMngr* self) { @@ -649,6 +660,8 @@ static PyMethodDef VmMngr_methods[] = { "set_big_endian() -> Set the VmMngr to Big Endian"}, {"set_little_endian",(PyCFunction)vm_set_little_endian, METH_VARARGS, "set_little_endian() -> Set the VmMngr to Little Endian"}, + {"is_little_endian",(PyCFunction)vm_is_little_endian, METH_VARARGS, + "is_little_endian() -> Return True if the VmMngr is Little Endian"}, {"get_memory_read",(PyCFunction)vm_get_memory_read, METH_VARARGS, "get_memory_read() -> Retrieve last instruction READ access\n" "This function is only valid in a memory breakpoint callback." |