about summary refs log tree commit diff stats
path: root/miasm2/arch/x86/jit.py
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2017-04-24 17:40:37 +0200
committerAjax <commial@gmail.com>2017-04-24 17:40:37 +0200
commit001e2b61406702c7ace4785d63a6055899693705 (patch)
tree60c942a77ef3b9e247ea3fb9cf6cedc9fda6b763 /miasm2/arch/x86/jit.py
parent9b0f95d48250f41cdaa2da0a4ce86150a5751db4 (diff)
downloadmiasm-001e2b61406702c7ace4785d63a6055899693705.tar.gz
miasm-001e2b61406702c7ace4785d63a6055899693705.zip
x86_64: add stdcall ABI call prepare (for sb.call to work)
Diffstat (limited to 'miasm2/arch/x86/jit.py')
-rw-r--r--miasm2/arch/x86/jit.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/miasm2/arch/x86/jit.py b/miasm2/arch/x86/jit.py
index aa01359a..1329d7a4 100644
--- a/miasm2/arch/x86/jit.py
+++ b/miasm2/arch/x86/jit.py
@@ -171,6 +171,7 @@ class jitter_x86_64(jitter):
 
     C_Gen = x86_64_CGen
     args_regs_systemv = ['RDI', 'RSI', 'RDX', 'RCX', 'R8', 'R9']
+    args_regs_stdcall = ['RCX', 'RDX', 'R8', 'R9']
 
     def __init__(self, *args, **kwargs):
         sp = asmblock.AsmSymbolPool()
@@ -205,7 +206,7 @@ class jitter_x86_64(jitter):
     # stdcall
     @named_arguments
     def func_args_stdcall(self, n_args):
-        args_regs = ['RCX', 'RDX', 'R8', 'R9']
+        args_regs = self.args_regs_stdcall
         ret_ad = self.pop_uint64_t()
         args = []
         for i in xrange(min(n_args, 4)):
@@ -214,6 +215,15 @@ class jitter_x86_64(jitter):
             args.append(self.get_stack_arg(i))
         return ret_ad, args
 
+    def func_prepare_stdcall(self, ret_addr, *args):
+        args_regs = self.args_regs_stdcall
+        for i in xrange(min(len(args), len(args_regs))):
+            setattr(self.cpu, args_regs[i], args[i])
+        remaining_args = args[len(args_regs):]
+        for arg in reversed(remaining_args):
+            self.push_uint64_t(arg)
+        self.push_uint64_t(ret_addr)
+
     def func_ret_stdcall(self, ret_addr, ret_value=None):
         self.pc = self.cpu.RIP = ret_addr
         if ret_value is not None:
@@ -223,6 +233,7 @@ class jitter_x86_64(jitter):
     # cdecl
     func_args_cdecl = func_args_stdcall
     func_ret_cdecl = func_ret_stdcall
+    func_prepare_cdecl = func_prepare_stdcall
 
     # System V