about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml21
-rw-r--r--miasm2/arch/mep/jit.py4
-rw-r--r--miasm2/arch/x86/jit.py8
-rw-r--r--miasm2/core/asmbloc.py10
-rw-r--r--miasm2/core/bin_stream_ida.py6
-rw-r--r--miasm2/jitter/arch/JitCore_aarch64.c8
-rw-r--r--miasm2/jitter/arch/JitCore_arm.c9
-rw-r--r--miasm2/jitter/arch/JitCore_mep.c9
-rw-r--r--miasm2/jitter/arch/JitCore_msp430.c7
-rw-r--r--miasm2/jitter/arch/JitCore_ppc32.c7
-rw-r--r--miasm2/jitter/arch/JitCore_x86.c28
-rw-r--r--miasm2/jitter/codegen.py10
-rw-r--r--miasm2/jitter/jitcore_python.py2
-rw-r--r--miasm2/jitter/llvmconvert.py16
-rwxr-xr-xtest/test_all.py5
15 files changed, 111 insertions, 39 deletions
diff --git a/.travis.yml b/.travis.yml
index 8253cb24..f5c55368 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,14 +11,17 @@ addons:
 env:
   global: CXX=g++-5 LLVM_CONFIG=llvm-config-6.0
   matrix:
-    - MIASM_TEST_TAG=regression
-    - MIASM_TEST_TAG=example
-    - MIASM_TEST_TAG=long
-    - MIASM_TEST_TAG=llvm
-    - MIASM_TEST_TAG=gcc
-    - MIASM_TEST_TAG=z3
-    - MIASM_TEST_TAG=qemu
-    - MIASM_TEST_TAG=cparser
+    - MIASM_TEST_EXTRA_ARG="-o regression -t long,python,llvm,gcc,z3,qemu,cparser"
+    - MIASM_TEST_EXTRA_ARG="-o example -t long,python,llvm,gcc,z3,qemu,cparser"
+    - MIASM_TEST_EXTRA_ARG="-o long"
+    - MIASM_TEST_EXTRA_ARG="-o qemu -t llvm,gcc"
+    - MIASM_TEST_EXTRA_ARG="-o qemu -t python,gcc"
+    - MIASM_TEST_EXTRA_ARG="-o qemu -t python,llvm"
+    - MIASM_TEST_EXTRA_ARG="-o llvm -t qemu,long"
+    - MIASM_TEST_EXTRA_ARG="-o gcc -t qemu,long"
+    - MIASM_TEST_EXTRA_ARG="-o python -t qemu,long"
+    - MIASM_TEST_EXTRA_ARG="-o z3"
+    - MIASM_TEST_EXTRA_ARG="-o cparser"
 before_script:
 - pip install -r optional_requirements.txt
 # codespell
@@ -28,4 +31,4 @@ before_script:
 # install
 - python setup.py build build_ext
 - python setup.py install
-script: cd test && python test_all.py -o=$MIASM_TEST_TAG && git ls-files -o --exclude-standard
+script: cd test && python test_all.py $MIASM_TEST_EXTRA_ARG && git ls-files -o --exclude-standard
diff --git a/miasm2/arch/mep/jit.py b/miasm2/arch/mep/jit.py
index 913d508f..6c0e6ff5 100644
--- a/miasm2/arch/mep/jit.py
+++ b/miasm2/arch/mep/jit.py
@@ -43,11 +43,11 @@ class mep_CGen(CGen):
 
         return out
 
-    def gen_post_code(self, attrib):
+    def gen_post_code(self, attrib, pc_value):
         """Generate C code inserted after the current bloc"""
 
         # Call the base class method
-        out = super(mep_CGen, self).gen_post_code(attrib)
+        out = super(mep_CGen, self).gen_post_code(attrib, pc_value)
 
         # Implement the *REPEAT instructions logics
         tmp = r"""
diff --git a/miasm2/arch/x86/jit.py b/miasm2/arch/x86/jit.py
index d775cff5..f0a9875e 100644
--- a/miasm2/arch/x86/jit.py
+++ b/miasm2/arch/x86/jit.py
@@ -20,16 +20,20 @@ class x86_32_CGen(CGen):
         self.translator = TranslatorC(self.ir_arch.loc_db)
         self.init_arch_C()
 
-    def gen_post_code(self, attrib):
+    def gen_post_code(self, attrib, pc_value):
         out = []
         if attrib.log_regs:
+            # Update PC for dump_gpregs
+            out.append("%s = %s;" % (self.C_PC, pc_value))
             out.append('dump_gpregs_32(jitcpu->cpu);')
         return out
 
 class x86_64_CGen(x86_32_CGen):
-    def gen_post_code(self, attrib):
+    def gen_post_code(self, attrib, pc_value):
         out = []
         if attrib.log_regs:
+            # Update PC for dump_gpregs
+            out.append("%s = %s;" % (self.C_PC, pc_value))
             out.append('dump_gpregs_64(jitcpu->cpu);')
         return out
 
diff --git a/miasm2/core/asmbloc.py b/miasm2/core/asmbloc.py
deleted file mode 100644
index 54760f4e..00000000
--- a/miasm2/core/asmbloc.py
+++ /dev/null
@@ -1,10 +0,0 @@
-"""
-This module will be removed in favour of asmblock.py
-Cause: French tipo.
-"""
-import warnings
-from miasm2.core.asmblock import *
-
-warnings.warn('DEPRECATION WARNING: use "asmblock" sub-module instead of "asmbloc"')
-
-log_asmbloc = log_asmblock
diff --git a/miasm2/core/bin_stream_ida.py b/miasm2/core/bin_stream_ida.py
index de7bc971..f63077bf 100644
--- a/miasm2/core/bin_stream_ida.py
+++ b/miasm2/core/bin_stream_ida.py
@@ -1,5 +1,6 @@
 from idc import Byte, SegEnd
 from idautils import Segments
+from idaapi import is_mapped
 
 from miasm2.core.bin_stream import bin_stream_str
 
@@ -14,7 +15,10 @@ class bin_stream_ida(bin_stream_str):
     def _getbytes(self, start, l=1):
         o = ""
         for ad in xrange(l):
-            o += chr(Byte(ad + start - self.shift))
+            offset = ad + start - self.shift
+            if not is_mapped(offset):
+                raise IOError("not enough bytes")
+            o += chr(Byte(offset))
         return o
 
     def readbs(self, l=1):
diff --git a/miasm2/jitter/arch/JitCore_aarch64.c b/miasm2/jitter/arch/JitCore_aarch64.c
index fc51848a..d8b6d0f9 100644
--- a/miasm2/jitter/arch/JitCore_aarch64.c
+++ b/miasm2/jitter/arch/JitCore_aarch64.c
@@ -194,6 +194,12 @@ PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args)
 }
 
 
+PyObject * cpu_dump_gpregs_with_attrib(JitCpu* self, PyObject* args)
+{
+	return cpu_dump_gpregs(self, args);
+}
+
+
 PyObject* cpu_set_exception(JitCpu* self, PyObject* args)
 {
 	PyObject *item1;
@@ -294,6 +300,8 @@ static PyMethodDef JitCpu_methods[] = {
 	 "X"},
 	{"dump_gpregs", (PyCFunction)cpu_dump_gpregs, METH_NOARGS,
 	 "X"},
+	{"dump_gpregs_with_attrib", (PyCFunction)cpu_dump_gpregs_with_attrib, METH_VARARGS,
+	 "X"},
 	{"get_gpreg", (PyCFunction)cpu_get_gpreg, METH_NOARGS,
 	 "X"},
 	{"set_gpreg", (PyCFunction)cpu_set_gpreg, METH_VARARGS,
diff --git a/miasm2/jitter/arch/JitCore_arm.c b/miasm2/jitter/arch/JitCore_arm.c
index 4f1fd254..dca341d3 100644
--- a/miasm2/jitter/arch/JitCore_arm.c
+++ b/miasm2/jitter/arch/JitCore_arm.c
@@ -157,6 +157,13 @@ PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args)
 }
 
 
+PyObject * cpu_dump_gpregs_with_attrib(JitCpu* self, PyObject* args)
+{
+	return cpu_dump_gpregs(self, args);
+}
+
+
+
 PyObject* cpu_set_exception(JitCpu* self, PyObject* args)
 {
 	PyObject *item1;
@@ -276,6 +283,8 @@ static PyMethodDef JitCpu_methods[] = {
 	 "X"},
 	{"dump_gpregs", (PyCFunction)cpu_dump_gpregs, METH_NOARGS,
 	 "X"},
+	{"dump_gpregs_with_attrib", (PyCFunction)cpu_dump_gpregs_with_attrib, METH_VARARGS,
+	 "X"},
 	{"get_gpreg", (PyCFunction)cpu_get_gpreg, METH_NOARGS,
 	 "X"},
 	{"set_gpreg", (PyCFunction)cpu_set_gpreg, METH_VARARGS,
diff --git a/miasm2/jitter/arch/JitCore_mep.c b/miasm2/jitter/arch/JitCore_mep.c
index 44f36290..a089e84f 100644
--- a/miasm2/jitter/arch/JitCore_mep.c
+++ b/miasm2/jitter/arch/JitCore_mep.c
@@ -223,6 +223,10 @@ PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args)
     return Py_None;
 }
 
+PyObject * cpu_dump_gpregs_with_attrib(JitCpu* self, PyObject* args)
+{
+	return cpu_dump_gpregs(self, args);
+}
 
 PyObject* cpu_set_exception(JitCpu* self, PyObject* args)
 {
@@ -244,10 +248,6 @@ PyObject* cpu_get_exception(JitCpu* self, PyObject* args)
     return PyLong_FromUnsignedLongLong((uint64_t)(((vm_cpu_t*)self->cpu)->exception_flags));
 }
 
-
-
-
-
 void check_automod(JitCpu* jitcpu, uint64_t addr, uint64_t size)
 {
     PyObject *result;
@@ -322,6 +322,7 @@ static PyMemberDef JitCpu_members[] = {
 static PyMethodDef JitCpu_methods[] = {
     {"init_regs", (PyCFunction)cpu_init_regs, METH_NOARGS, "X"},
     {"dump_gpregs", (PyCFunction)cpu_dump_gpregs, METH_NOARGS, "X"},
+    {"dump_gpregs_with_attrib", (PyCFunction)cpu_dump_gpregs_with_attrib, METH_VARARGS, "X"},
     {"get_gpreg", (PyCFunction)cpu_get_gpreg, METH_NOARGS, "X"},
     {"set_gpreg", (PyCFunction)cpu_set_gpreg, METH_VARARGS, "X"},
     {"get_exception", (PyCFunction)cpu_get_exception, METH_VARARGS, "X"},
diff --git a/miasm2/jitter/arch/JitCore_msp430.c b/miasm2/jitter/arch/JitCore_msp430.c
index 12a42782..69f179a4 100644
--- a/miasm2/jitter/arch/JitCore_msp430.c
+++ b/miasm2/jitter/arch/JitCore_msp430.c
@@ -158,6 +158,11 @@ PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args)
 	return Py_None;
 }
 
+PyObject * cpu_dump_gpregs_with_attrib(JitCpu* self, PyObject* args)
+{
+	return cpu_dump_gpregs(self, args);
+}
+
 
 PyObject* cpu_set_exception(JitCpu* self, PyObject* args)
 {
@@ -259,6 +264,8 @@ static PyMethodDef JitCpu_methods[] = {
 	 "X"},
 	{"dump_gpregs", (PyCFunction)cpu_dump_gpregs, METH_NOARGS,
 	 "X"},
+	{"dump_gpregs_with_attrib", (PyCFunction)cpu_dump_gpregs_with_attrib, METH_VARARGS,
+	 "X"},
 	{"get_gpreg", (PyCFunction)cpu_get_gpreg, METH_NOARGS,
 	 "X"},
 	{"set_gpreg", (PyCFunction)cpu_set_gpreg, METH_VARARGS,
diff --git a/miasm2/jitter/arch/JitCore_ppc32.c b/miasm2/jitter/arch/JitCore_ppc32.c
index dfc46c91..e1a3fcd5 100644
--- a/miasm2/jitter/arch/JitCore_ppc32.c
+++ b/miasm2/jitter/arch/JitCore_ppc32.c
@@ -109,6 +109,12 @@ cpu_dump_gpregs(JitCpu *self, PyObject *args) {
 }
 
 PyObject *
+cpu_dump_gpregs_with_attrib(JitCpu* self, PyObject* args)
+{
+	return cpu_dump_gpregs(self, args);
+}
+
+PyObject *
 cpu_set_exception(JitCpu *self, PyObject *args) {
     PyObject *item1;
     uint64_t i;
@@ -208,6 +214,7 @@ static PyMemberDef JitCpu_members[] = {
 static PyMethodDef JitCpu_methods[] = {
     {"init_regs", (PyCFunction)cpu_init_regs, METH_NOARGS, "X"},
     {"dump_gpregs", (PyCFunction)cpu_dump_gpregs, METH_NOARGS, "X"},
+    {"dump_gpregs_with_attrib", (PyCFunction)cpu_dump_gpregs_with_attrib, METH_VARARGS, "X"},
     {"get_gpreg", (PyCFunction)cpu_get_gpreg, METH_NOARGS, "X"},
     {"set_gpreg", (PyCFunction)cpu_set_gpreg, METH_VARARGS, "X"},
     {"get_exception", (PyCFunction)cpu_get_exception, METH_VARARGS, "X"},
diff --git a/miasm2/jitter/arch/JitCore_x86.c b/miasm2/jitter/arch/JitCore_x86.c
index b711f40b..fa47b324 100644
--- a/miasm2/jitter/arch/JitCore_x86.c
+++ b/miasm2/jitter/arch/JitCore_x86.c
@@ -349,6 +349,32 @@ PyObject * cpu_dump_gpregs(JitCpu* self, PyObject* args)
 }
 
 
+PyObject * cpu_dump_gpregs_with_attrib(JitCpu* self, PyObject* args)
+{
+	vm_cpu_t* vmcpu;
+	PyObject *item1;
+	uint64_t attrib;
+
+	if (!PyArg_ParseTuple(args, "O", &item1))
+		RAISE(PyExc_TypeError,"Cannot parse arguments");
+
+	PyGetInt(item1, attrib);
+
+	vmcpu = self->cpu;
+	if (attrib == 16 || attrib == 32)
+		dump_gpregs_32(vmcpu);
+	else if (attrib == 64)
+		dump_gpregs_64(vmcpu);
+	else {
+		RAISE(PyExc_TypeError,"Bad attrib");
+	}
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+
+
 PyObject* cpu_set_exception(JitCpu* self, PyObject* args)
 {
 	PyObject *item1;
@@ -484,6 +510,8 @@ static PyMethodDef JitCpu_methods[] = {
 	 "X"},
 	{"dump_gpregs", (PyCFunction)cpu_dump_gpregs, METH_NOARGS,
 	 "X"},
+	{"dump_gpregs_with_attrib", (PyCFunction)cpu_dump_gpregs_with_attrib, METH_VARARGS,
+	 "X"},
 	{"get_gpreg", (PyCFunction)cpu_get_gpreg, METH_NOARGS,
 	 "X"},
 	{"set_gpreg", (PyCFunction)cpu_set_gpreg, METH_VARARGS,
diff --git a/miasm2/jitter/codegen.py b/miasm2/jitter/codegen.py
index 32af29a2..a9405472 100644
--- a/miasm2/jitter/codegen.py
+++ b/miasm2/jitter/codegen.py
@@ -392,11 +392,13 @@ class CGen(object):
             )
         return out
 
-    def gen_post_code(self, attrib):
+    def gen_post_code(self, attrib, pc_value):
         """Callback to generate code AFTER the instruction execution
         @attrib: Attributes instance"""
         out = []
         if attrib.log_regs:
+            # Update PC for dump_gpregs
+            out.append("%s = %s;" % (self.C_PC, pc_value))
             out.append('dump_gpregs(jitcpu->cpu);')
         return out
 
@@ -408,7 +410,7 @@ class CGen(object):
 
         out = []
         if isinstance(dst, Expr):
-            out += self.gen_post_code(attrib)
+            out += self.gen_post_code(attrib, "DST_value")
             out.append('BlockDst->address = DST_value;')
             out += self.gen_post_instr_checks(attrib)
             out.append('\t\treturn JIT_RET_NO_EXCEPTION;')
@@ -423,11 +425,11 @@ class CGen(object):
             offset in instr_offsets):
             # Only generate goto for next instructions.
             # (consecutive instructions)
-            out += self.gen_post_code(attrib)
+            out += self.gen_post_code(attrib, "0x%x" % offset)
             out += self.gen_post_instr_checks(attrib)
             out.append('goto %s;' % dst)
         else:
-            out += self.gen_post_code(attrib)
+            out += self.gen_post_code(attrib, "0x%x" % offset)
             out.append('BlockDst->address = DST_value;')
             out += self.gen_post_instr_checks(attrib)
             out.append('\t\treturn JIT_RET_NO_EXCEPTION;')
diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py
index dd4c543e..0b1f5809 100644
--- a/miasm2/jitter/jitcore_python.py
+++ b/miasm2/jitter/jitcore_python.py
@@ -90,7 +90,7 @@ class JitCore_Python(jitcore.JitCore):
                         # Log registers values
                         if self.log_regs:
                             exec_engine.update_cpu_from_engine()
-                            exec_engine.cpu.dump_gpregs()
+                            exec_engine.cpu.dump_gpregs_with_attrib(self.ir_arch.attrib)
 
                         # Log instruction
                         if self.log_mn:
diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py
index 6f024c1e..37ce8d52 100644
--- a/miasm2/jitter/llvmconvert.py
+++ b/miasm2/jitter/llvmconvert.py
@@ -1292,8 +1292,14 @@ class LLVMFunction(object):
             self.printf("%.8X %s\n" % (instr_attrib.instr.offset,
                                        instr_attrib.instr.to_string(loc_db)))
 
-    def gen_post_code(self, attributes):
+    def gen_post_code(self, attributes, pc_value):
         if attributes.log_regs:
+            # Update PC for dump_gpregs
+            PC = self.llvm_context.PC
+            t_size = LLVMType.IntType(PC.size)
+            dst = self.builder.zext(t_size(pc_value), LLVMType.IntType(PC.size))
+            self.affect(dst, PC)
+
             fc_ptr = self.mod.get_global(self.llvm_context.logging_func)
             self.builder.call(fc_ptr, [self.local_vars["vmcpu"]])
 
@@ -1353,8 +1359,10 @@ class LLVMFunction(object):
         # We are no longer in the main stream, deactivate cache
         self.main_stream = False
 
+        offset = None
         if isinstance(dst, ExprInt):
-            loc_key = self.llvm_context.ir_arch.loc_db.get_or_create_offset_location(int(dst))
+            offset = int(dst)
+            loc_key = self.llvm_context.ir_arch.loc_db.get_or_create_offset_location(offset)
             dst = ExprLoc(loc_key, dst.size)
 
         if isinstance(dst, ExprLoc):
@@ -1371,7 +1379,7 @@ class LLVMFunction(object):
                 if (offset in instr_offsets and
                     offset > attrib.instr.offset):
                     # forward local jump (ie. next instruction)
-                    self.gen_post_code(attrib)
+                    self.gen_post_code(attrib, offset)
                     self.gen_post_instr_checks(attrib, offset)
                     self.builder.branch(bbl)
                     return
@@ -1389,7 +1397,7 @@ class LLVMFunction(object):
         if dst.type.width != PC.size:
             dst = self.builder.zext(dst, LLVMType.IntType(PC.size))
 
-        self.gen_post_code(attrib)
+        self.gen_post_code(attrib, offset)
         self.affect(dst, PC)
         self.gen_post_instr_checks(attrib, dst)
         self.affect(self.add_ir(ExprInt(0, 8)), ExprId("status", 32))
diff --git a/test/test_all.py b/test/test_all.py
index 4b97ffba..f3bcc477 100755
--- a/test/test_all.py
+++ b/test/test_all.py
@@ -21,6 +21,7 @@ TAGS = {"regression": "REGRESSION", # Regression tests
         "long": "LONG", # Very time consumming tests
         "llvm": "LLVM", # LLVM dependency is required
         "gcc": "GCC", # GCC based tests
+        "python": "PYTHON", # Python jitted tests
         "z3": "Z3", # Z3 dependency is needed
         "qemu": "QEMU", # QEMU tests (several tests)
         "cparser": "CPARSER", # pycparser is needed
@@ -109,7 +110,7 @@ for script in ["x86/sem.py",
             continue
         testset += ArchUnitTest(script, jitter, base_dir="arch", tags=tags)
 
-testset += ArchUnitTest("x86/unit/access_xmm.py", "python", base_dir="arch")
+testset += ArchUnitTest("x86/unit/access_xmm.py", "python", base_dir="arch", tags=[TAGS["python"]])
 
 ### QEMU regression tests
 class QEMUTest(RegressionTest):
@@ -750,7 +751,7 @@ class ExampleJitterNoPython(ExampleJitter):
 
 for jitter in ExampleJitter.jitter_engines:
     # Take 5 min on a Core i5
-    tags = {"python": [TAGS["long"]],
+    tags = {"python": [TAGS["long"], TAGS["python"]],
             "llvm": [TAGS["llvm"]],
             "gcc": [TAGS["gcc"]],
             }