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.aarch64.sem import ir_aarch64b, ir_aarch64l
7 
8 log = logging.getLogger('jit_aarch64')
9 hnd = logging.StreamHandler()
10 hnd.setFormatter(logging.Formatter("[%(levelname)s]: %(message)s"))
11 log.addHandler(hnd)
12 log.setLevel(logging.CRITICAL)
13 
14 
16  max_reg_arg = 8
17 
18  def __init__(self, *args, **kwargs):
19  sp = asmbloc.asm_symbol_pool()
20  jitter.__init__(self, ir_aarch64l(sp), *args, **kwargs)
21  self.vm.set_little_endian()
22  self.ir_arch.jit_pc = self.ir_arch.arch.regs.PC
23 
24  def push_uint64_t(self, v):
25  self.cpu.SP -= 8
26  self.vm.set_mem(self.cpu.SP, pck64(v))
27 
28  def pop_uint64_t(self):
29  x = upck32(self.vm.get_mem(self.cpu.SP, 8))
30  self.cpu.SP += 8
31  return x
32 
33  def get_stack_arg(self, n):
34  x = upck64(self.vm.get_mem(self.cpu.SP + 8 * n, 8))
35  return x
36 
37  # calling conventions
38 
39  @named_arguments
40  def func_args_stdcall(self, n_args):
41  args = []
42  for i in xrange(min(n_args, self.max_reg_arg)):
43  args.append(self.cpu.get_gpreg()['X%d' % i])
44  for i in xrange(max(0, n_args - self.max_reg_arg)):
45  args.append(self.get_stack_arg(i))
46  ret_ad = self.cpu.LR
47  return ret_ad, args
48 
49  def func_ret_stdcall(self, ret_addr, ret_value=None):
50  self.pc = self.cpu.PC = ret_addr
51  if ret_value is not None:
52  self.cpu.X0 = ret_value
53  return True
54 
55  def get_arg_n_stdcall(self, n):
56  if n < self.max_reg_arg:
57  arg = self.cpu.get_gpreg()['X%d' % n]
58  else:
59  arg = self.get_stack_arg(n - self.max_reg_arg)
60  return arg
61 
62  def init_run(self, *args, **kwargs):
63  jitter.init_run(self, *args, **kwargs)
64  self.cpu.PC = self.pc
65 
66 
68 
69  def __init__(self, *args, **kwargs):
70  sp = asmbloc.asm_symbol_pool()
71  jitter.__init__(self, ir_aarch64b(sp), *args, **kwargs)
72  self.vm.set_big_endian()
73  self.ir_arch.jit_pc = self.ir_arch.arch.regs.PC
tuple upck64
Definition: utils.py:9
tuple upck32
Definition: utils.py:8
tuple pck64
Definition: utils.py:13