Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
jit.py
Go to the documentation of this file.
1 import logging
2 
3 from miasm2.jitter.jitload import jitter, named_arguments
4 from miasm2.core import asmbloc
5 from miasm2.core.utils import *
6 from miasm2.arch.arm.sem import ir_armb, ir_arml
7 
8 log = logging.getLogger('jit_arm')
9 hnd = logging.StreamHandler()
10 hnd.setFormatter(logging.Formatter("[%(levelname)s]: %(message)s"))
11 log.addHandler(hnd)
12 log.setLevel(logging.CRITICAL)
13 
15 
16  def __init__(self, *args, **kwargs):
17  sp = asmbloc.asm_symbol_pool()
18  jitter.__init__(self, ir_arml(sp), *args, **kwargs)
19  self.vm.set_little_endian()
20  self.ir_arch.jit_pc = self.ir_arch.arch.regs.PC
21 
22  def push_uint32_t(self, v):
23  self.cpu.SP -= 4
24  self.vm.set_mem(self.cpu.SP, pck32(v))
25 
26  def pop_uint32_t(self):
27  x = upck32(self.vm.get_mem(self.cpu.SP, 4))
28  self.cpu.SP += 4
29  return x
30 
31  def get_stack_arg(self, n):
32  x = upck32(self.vm.get_mem(self.cpu.SP + 4 * n, 4))
33  return x
34 
35  # calling conventions
36 
37  @named_arguments
38  def func_args_stdcall(self, n_args):
39  args = []
40  for i in xrange(min(n_args, 4)):
41  args.append(self.cpu.get_gpreg()['R%d' % i])
42  for i in xrange(max(0, n_args - 4)):
43  args.append(self.get_stack_arg(i))
44  ret_ad = self.cpu.LR
45  return ret_ad, args
46 
47  def func_ret_stdcall(self, ret_addr, ret_value=None):
48  self.pc = self.cpu.PC = ret_addr
49  if ret_value is not None:
50  self.cpu.R0 = ret_value
51  return True
52 
53  def get_arg_n_stdcall(self, n):
54  if n < 4:
55  arg = self.cpu.get_gpreg()['R%d' % n]
56  else:
57  arg = self.get_stack_arg(n-4)
58  return arg
59 
60  def init_run(self, *args, **kwargs):
61  jitter.init_run(self, *args, **kwargs)
62  self.cpu.PC = self.pc
63 
65 
66  def __init__(self, *args, **kwargs):
67  sp = asmbloc.asm_symbol_pool()
68  jitter.__init__(self, ir_armb(sp), *args, **kwargs)
69  self.vm.set_big_endian()
70  self.ir_arch.jit_pc = self.ir_arch.arch.regs.PC
tuple upck32
Definition: utils.py:8
tuple pck32
Definition: utils.py:12