about summary refs log tree commit diff stats
path: root/miasm2/arch
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2/arch')
-rw-r--r--miasm2/arch/arm/jit.py27
-rw-r--r--miasm2/arch/x86/arch.py6
-rw-r--r--miasm2/arch/x86/jit.py58
-rw-r--r--miasm2/arch/x86/sem.py27
4 files changed, 23 insertions, 95 deletions
diff --git a/miasm2/arch/arm/jit.py b/miasm2/arch/arm/jit.py
index d089bafb..8803725e 100644
--- a/miasm2/arch/arm/jit.py
+++ b/miasm2/arch/arm/jit.py
@@ -58,33 +58,6 @@ class jitter_arml(jitter):
             arg = self.get_stack_arg(n-4)
         return arg
 
-    def add_lib_handler(self, libs, user_globals=None):
-        """Add a function to handle libs call with breakpoints
-        @libs: libimp instance
-        @user_globals: dictionnary for defined user function
-        """
-        if user_globals is None:
-            user_globals = {}
-
-        from miasm2.os_dep import linux_stdlib
-
-        def handle_lib(jitter):
-            fname = libs.fad2cname[jitter.pc]
-            if fname in user_globals:
-                f = user_globals[fname]
-            elif fname in linux_stdlib.__dict__:
-                f = linux_stdlib.__dict__[fname]
-            else:
-                log.debug('%s' % repr(fname))
-                raise ValueError('unknown api', hex(jitter.pop_uint32_t()), repr(fname))
-            f(jitter)
-            jitter.pc = getattr(jitter.cpu, jitter.ir_arch.pc.name)
-            return True
-
-        for f_addr in libs.fad2cname:
-            self.add_breakpoint(f_addr, handle_lib)
-
-
     def init_run(self, *args, **kwargs):
         jitter.init_run(self, *args, **kwargs)
         self.cpu.PC = self.pc
diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py
index 85356468..e75c22a9 100644
--- a/miasm2/arch/x86/arch.py
+++ b/miasm2/arch/x86/arch.py
@@ -20,8 +20,10 @@ conditional_branch = ["JO", "JNO", "JB", "JAE",
                       "JZ", "JNZ", "JBE", "JA",
                       "JS", "JNS", "JPE", "JNP",
                       #"L", "NL", "NG", "G"]
-                      "JL", "JGE", "JLE", "JG"]
-unconditional_branch = ['JMP']
+                      "JL", "JGE", "JLE", "JG",
+                      "JCXZ", "JECXZ", "JRCXZ"]
+
+unconditional_branch = ['JMP', 'JMPF']
 
 f_isad = "AD"
 f_s08 = "S08"
diff --git a/miasm2/arch/x86/jit.py b/miasm2/arch/x86/jit.py
index 36afcce5..08bac4db 100644
--- a/miasm2/arch/x86/jit.py
+++ b/miasm2/arch/x86/jit.py
@@ -106,32 +106,6 @@ class jitter_x86_32(jitter):
         self.cpu.EIP = ret_addr
         self.cpu.EAX = ret_value
 
-    def add_lib_handler(self, libs, user_globals=None):
-        """Add a function to handle libs call with breakpoints
-        @libs: libimp instance
-        @user_globals: dictionnary for defined user function
-        """
-        if user_globals is None:
-            user_globals = {}
-
-        from miasm2.os_dep import win_api_x86_32
-
-        def handle_lib(jitter):
-            fname = libs.fad2cname[jitter.pc]
-            if fname in user_globals:
-                f = user_globals[fname]
-            elif fname in win_api_x86_32.__dict__:
-                f = win_api_x86_32.__dict__[fname]
-            else:
-                log.debug('%s' % repr(fname))
-                raise ValueError('unknown api', hex(jitter.pop_uint32_t()), repr(fname))
-            f(jitter)
-            jitter.pc = getattr(jitter.cpu, jitter.ir_arch.pc.name)
-            return True
-
-        for f_addr in libs.fad2cname:
-            self.add_breakpoint(f_addr, handle_lib)
-
     def init_run(self, *args, **kwargs):
         jitter.init_run(self, *args, **kwargs)
         self.cpu.EIP = self.pc
@@ -165,10 +139,6 @@ class jitter_x86_64(jitter):
         x = upck64(self.vm.get_mem(self.cpu.RSP + 8 * n, 8))
         return x
 
-    def init_run(self, *args, **kwargs):
-        jitter.init_run(self, *args, **kwargs)
-        self.cpu.RIP = self.pc
-
     def func_args_stdcall(self, n_args):
         args_regs = ['RCX', 'RDX', 'R8', 'R9']
         ret_ad = self.pop_uint64_t()
@@ -207,28 +177,6 @@ class jitter_x86_64(jitter):
             self.cpu.RAX = ret_value
         return True
 
-    def add_lib_handler(self, libs, user_globals=None):
-        """Add a function to handle libs call with breakpoints
-        @libs: libimp instance
-        @user_globals: dictionnary for defined user function
-        """
-        if user_globals is None:
-            user_globals = {}
-
-        from miasm2.os_dep import win_api_x86_32
-
-        def handle_lib(jitter):
-            fname = libs.fad2cname[jitter.pc]
-            if fname in user_globals:
-                f = user_globals[fname]
-            elif fname in win_api_x86_32.__dict__:
-                f = win_api_x86_32.__dict__[fname]
-            else:
-                log.debug('%s' % repr(fname))
-                raise ValueError('unknown api', hex(jitter.pop_uint64_t()), repr(fname))
-            f(jitter)
-            jitter.pc = getattr(jitter.cpu, jitter.ir_arch.pc.name)
-            return True
-
-        for f_addr in libs.fad2cname:
-            self.add_breakpoint(f_addr, handle_lib)
+    def init_run(self, *args, **kwargs):
+        jitter.init_run(self, *args, **kwargs)
+        self.cpu.RIP = self.pc
diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py
index 22e8c276..36d8e618 100644
--- a/miasm2/arch/x86/sem.py
+++ b/miasm2/arch/x86/sem.py
@@ -635,7 +635,9 @@ def pop(ir, instr, a):
     if not s in [16, 32, 64]:
         raise ValueError('bad size stacker!')
     new_esp = mRSP[instr.mode][:s] + ExprInt_fromsize(s, off / 8)
-    e.append(ExprAff(mRSP[instr.mode][:s], new_esp))
+    # don't generate ESP incrementation on POP ESP
+    if a != ir.sp:
+        e.append(ExprAff(mRSP[instr.mode][:s], new_esp))
     # XXX FIX XXX for pop [esp]
     if isinstance(a, ExprMem):
         a = a.replace_expr({mRSP[instr.mode]: new_esp})
@@ -1821,16 +1823,16 @@ def fucomip(ir, instr, a, b):
 
 
 def fcomp(ir, instr, a, b = None):
-    dst, e, extra = fcom(ir, instr, a, b)
+    e, extra = fcom(ir, instr, a, b)
     e += float_pop()
     e += set_float_cs_eip(instr)
-    return dst, e, extra
+    return e, extra
 
 def ficomp(ir, instr, a, b = None):
-    dst, e, extra = ficom(ir, instr, a, b)
+    e, extra = ficom(ir, instr, a, b)
     e += float_pop()
     e += set_float_cs_eip(instr)
-    return dst, e, extra
+    return e, extra
 
 
 def fld(ir, instr, a):
@@ -1872,9 +1874,9 @@ def fst(ir, instr, a):
 
 
 def fstp(ir, instr, a):
-    dst, e, extra = fst(ir, instr, a)
+    e, extra = fst(ir, instr, a)
     e += float_pop(a)
-    return dst, e, extra
+    return e, extra
 
 
 def fist(ir, instr, a):
@@ -1885,9 +1887,9 @@ def fist(ir, instr, a):
     return e, []
 
 def fistp(ir, instr, a):
-    dst, e, extra = fist(ir, instr, a)
+    e, extra = fist(ir, instr, a)
     e += float_pop(a)
-    return dst, e, extra
+    return e, extra
 
 def fist(ir, instr, a):
     e = []
@@ -1910,9 +1912,9 @@ def fild(ir, instr, a):
     src = ExprOp('int_%.2d_to_double' % a.size, a)
     e = []
     e += set_float_cs_eip(instr)
-    dst, e_fld, extra = fld(ir, instr, src)
+    e_fld, extra = fld(ir, instr, src)
     e += e_fld
-    return dst, e, extra
+    return e, extra
 
 
 def fldz(ir, instr):
@@ -2003,6 +2005,9 @@ def fnstenv(ir, instr, a):
                                ])
 
     s = instr.mode
+    # The behaviour in 64bit is identical to 64 bit
+    # This will truncate addresses
+    s = min(32, s)
     ad = ExprMem(a.arg, size=16)
     e.append(ExprAff(ad, float_control))
     ad = ExprMem(a.arg + ExprInt_from(a.arg, s / 8 * 1), size=16)