Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
miasm2.arch.arm.jit.jitter_arml Class Reference
+ Inheritance diagram for miasm2.arch.arm.jit.jitter_arml:
+ Collaboration diagram for miasm2.arch.arm.jit.jitter_arml:

Public Member Functions

def __init__
 
def push_uint32_t
 
def pop_uint32_t
 
def get_stack_arg
 
def func_args_stdcall
 
def func_ret_stdcall
 
def get_arg_n_stdcall
 
def init_run
 
def init_exceptions_handler
 
def add_breakpoint
 
def set_breakpoint
 
def remove_breakpoints_by_callback
 
def add_exception_handler
 
def runbloc
 
def runiter_once
 
def init_run
 
def continue_run
 
def init_stack
 
def get_exception
 
def get_str_ansi
 
def get_str_unic
 
def set_str_ansi
 
def set_str_unic
 
def handle_function
 
def add_lib_handler
 

Static Public Member Functions

def handle_lib
 

Public Attributes

 pc
 
 arch
 
 attrib
 
 vm
 
 cpu
 
 bs
 
 ir_arch
 
 jit
 
 stack_size
 
 stack_base
 
 breakpoints_handler
 
 exceptions_handler
 
 exec_cb
 
 run_iterator
 
 run
 
 libs
 
 user_globals
 

Detailed Description

Definition at line 14 of file jit.py.

Constructor & Destructor Documentation

def miasm2.arch.arm.jit.jitter_arml.__init__ (   self,
  args,
  kwargs 
)

Definition at line 16 of file jit.py.

16 
17  def __init__(self, *args, **kwargs):
18  sp = asmbloc.asm_symbol_pool()
19  jitter.__init__(self, ir_arml(sp), *args, **kwargs)
20  self.vm.set_little_endian()
21  self.ir_arch.jit_pc = self.ir_arch.arch.regs.PC

Member Function Documentation

def miasm2.jitter.jitload.jitter.add_breakpoint (   self,
  addr,
  callback 
)
inherited
Add a callback associated with addr.
@addr: breakpoint address
@callback: function with definition (jitter instance)

Definition at line 257 of file jitload.py.

258  def add_breakpoint(self, addr, callback):
259  """Add a callback associated with addr.
260  @addr: breakpoint address
261  @callback: function with definition (jitter instance)
262  """
263  self.breakpoints_handler.add_callback(addr, callback)
264  self.jit.add_disassembly_splits(addr)

+ Here is the caller graph for this function:

def miasm2.jitter.jitload.jitter.add_exception_handler (   self,
  flag,
  callback 
)
inherited
Add a callback associated with an exception flag.
@flag: bitflag
@callback: function with definition (jitter instance)

Definition at line 281 of file jitload.py.

282  def add_exception_handler(self, flag, callback):
283  """Add a callback associated with an exception flag.
284  @flag: bitflag
285  @callback: function with definition (jitter instance)
286  """
287  self.exceptions_handler.add_callback(flag, callback)

+ Here is the caller graph for this function:

def miasm2.jitter.jitload.jitter.add_lib_handler (   self,
  libs,
  user_globals = None 
)
inherited
Add a function to handle libs call with breakpoints
@libs: libimp instance
@user_globals: dictionnary for defined user function

Definition at line 424 of file jitload.py.

425  def add_lib_handler(self, libs, user_globals=None):
426  """Add a function to handle libs call with breakpoints
427  @libs: libimp instance
428  @user_globals: dictionnary for defined user function
429  """
430  if user_globals is None:
431  user_globals = {}
433  self.libs = libs
434  self.user_globals = user_globals
435 
436  for f_addr in libs.fad2cname:
437  self.handle_function(f_addr)
def miasm2.jitter.jitload.jitter.continue_run (   self,
  step = False 
)
inherited
PRE: init_run.
Continue the run of the current session until iterator returns or run is
set to False.
If step is True, run only one time.
Return the iterator value

Definition at line 336 of file jitload.py.

337  def continue_run(self, step=False):
338  """PRE: init_run.
339  Continue the run of the current session until iterator returns or run is
340  set to False.
341  If step is True, run only one time.
342  Return the iterator value"""
343 
344  while self.run:
345  try:
346  return self.run_iterator.next()
347  except StopIteration:
348  pass
349 
350  self.run_iterator = self.runiter_once(self.pc)
351 
352  if step is True:
353  return None
354 
355  return None

+ Here is the call graph for this function:

def miasm2.arch.arm.jit.jitter_arml.func_args_stdcall (   self,
  n_args 
)

Definition at line 38 of file jit.py.

38 
39  def func_args_stdcall(self, n_args):
40  args = []
41  for i in xrange(min(n_args, 4)):
42  args.append(self.cpu.get_gpreg()['R%d' % i])
43  for i in xrange(max(0, n_args - 4)):
44  args.append(self.get_stack_arg(i))
45  ret_ad = self.cpu.LR
46  return ret_ad, args

+ Here is the call graph for this function:

def miasm2.arch.arm.jit.jitter_arml.func_ret_stdcall (   self,
  ret_addr,
  ret_value = None 
)

Definition at line 47 of file jit.py.

47 
48  def func_ret_stdcall(self, ret_addr, ret_value=None):
49  self.pc = self.cpu.PC = ret_addr
50  if ret_value is not None:
51  self.cpu.R0 = ret_value
52  return True
def miasm2.arch.arm.jit.jitter_arml.get_arg_n_stdcall (   self,
  n 
)

Definition at line 53 of file jit.py.

53 
54  def get_arg_n_stdcall(self, n):
55  if n < 4:
56  arg = self.cpu.get_gpreg()['R%d' % n]
57  else:
58  arg = self.get_stack_arg(n-4)
59  return arg

+ Here is the call graph for this function:

def miasm2.jitter.jitload.jitter.get_exception (   self)
inherited

Definition at line 365 of file jitload.py.

366  def get_exception(self):
367  return self.cpu.get_exception() | self.vm.get_exception()
def miasm2.arch.arm.jit.jitter_arml.get_stack_arg (   self,
  n 
)

Definition at line 31 of file jit.py.

31 
32  def get_stack_arg(self, n):
33  x = upck32(self.vm.get_mem(self.cpu.SP + 4 * n, 4))
34  return x
tuple upck32
Definition: utils.py:8

+ Here is the caller graph for this function:

def miasm2.jitter.jitload.jitter.get_str_ansi (   self,
  addr,
  max_char = None 
)
inherited
Get ansi str from vm.
@addr: address in memory
@max_char: maximum len

Definition at line 369 of file jitload.py.

370  def get_str_ansi(self, addr, max_char=None):
371  """Get ansi str from vm.
372  @addr: address in memory
373  @max_char: maximum len"""
374  l = 0
375  tmp = addr
376  while ((max_char is None or l < max_char) and
377  self.vm.get_mem(tmp, 1) != "\x00"):
378  tmp += 1
379  l += 1
380  return self.vm.get_mem(addr, l)
def miasm2.jitter.jitload.jitter.get_str_unic (   self,
  addr,
  max_char = None 
)
inherited
Get unicode str from vm.
@addr: address in memory
@max_char: maximum len

Definition at line 381 of file jitload.py.

382  def get_str_unic(self, addr, max_char=None):
383  """Get unicode str from vm.
384  @addr: address in memory
385  @max_char: maximum len"""
386  l = 0
387  tmp = addr
388  while ((max_char is None or l < max_char) and
389  self.vm.get_mem(tmp, 2) != "\x00\x00"):
390  tmp += 2
391  l += 2
392  s = self.vm.get_mem(addr, l)
393  s = s[::2] # TODO: real unicode decoding
394  return s
def miasm2.jitter.jitload.jitter.handle_function (   self,
  f_addr 
)
inherited
Add a brakpoint which will trigger the function handler

Definition at line 420 of file jitload.py.

421  def handle_function(self, f_addr):
422  """Add a brakpoint which will trigger the function handler"""
423  self.add_breakpoint(f_addr, self.handle_lib)

+ Here is the call graph for this function:

def miasm2.jitter.jitload.jitter.handle_lib (   jitter)
staticinherited
Resolve the name of the function which cause the handler call. Then
call the corresponding handler from users callback.

Definition at line 406 of file jitload.py.

407  def handle_lib(jitter):
408  """Resolve the name of the function which cause the handler call. Then
409  call the corresponding handler from users callback.
410  """
411  fname = jitter.libs.fad2cname[jitter.pc]
412  if fname in jitter.user_globals:
413  func = jitter.user_globals[fname]
414  else:
415  log.debug('%r', fname)
416  raise ValueError('unknown api', hex(jitter.pc), repr(fname))
417  func(jitter)
418  jitter.pc = getattr(jitter.cpu, jitter.ir_arch.pc.name)
419  return True

+ Here is the caller graph for this function:

def miasm2.jitter.jitload.jitter.init_exceptions_handler (   self)
inherited

Definition at line 238 of file jitload.py.

239  def init_exceptions_handler(self):
240  "Add common exceptions handlers"
241 
242  def exception_automod(jitter):
243  "Tell the JiT backend to update blocs modified"
244 
245  self.jit.updt_automod_code(jitter.vm)
246  self.vm.set_exception(0)
247 
248  return True
249 
250  def exception_memory_breakpoint(jitter):
251  "Stop the execution and return an identifier"
252  return ExceptionHandle.memoryBreakpoint()
253 
254  self.add_exception_handler(EXCEPT_CODE_AUTOMOD, exception_automod)
255  self.add_exception_handler(EXCEPT_BREAKPOINT_INTERN,
256  exception_memory_breakpoint)

+ Here is the call graph for this function:

def miasm2.arch.arm.jit.jitter_arml.init_run (   self,
  args,
  kwargs 
)

Definition at line 60 of file jit.py.

60 
61  def init_run(self, *args, **kwargs):
62  jitter.init_run(self, *args, **kwargs)
63  self.cpu.PC = self.pc
def miasm2.jitter.jitload.jitter.init_run (   self,
  pc 
)
inherited
Create an iterator on pc with runiter.
@pc: address of code to run

Definition at line 328 of file jitload.py.

329  def init_run(self, pc):
330  """Create an iterator on pc with runiter.
331  @pc: address of code to run
332  """
333  self.run_iterator = self.runiter_once(pc)
334  self.pc = pc
335  self.run = True
def miasm2.jitter.jitload.jitter.init_stack (   self)
inherited

Definition at line 356 of file jitload.py.

357  def init_stack(self):
358  self.vm.add_memory_page(
359  self.stack_base, PAGE_READ | PAGE_WRITE, "\x00" * self.stack_size)
360  sp = self.arch.getsp(self.attrib)
361  setattr(self.cpu, sp.name, self.stack_base + self.stack_size)
362  # regs = self.cpu.get_gpreg()
363  # regs[sp.name] = self.stack_base+self.stack_size
364  # self.cpu.set_gpreg(regs)
def miasm2.arch.arm.jit.jitter_arml.pop_uint32_t (   self)

Definition at line 26 of file jit.py.

26 
27  def pop_uint32_t(self):
28  x = upck32(self.vm.get_mem(self.cpu.SP, 4))
29  self.cpu.SP += 4
30  return x
tuple upck32
Definition: utils.py:8

+ Here is the caller graph for this function:

def miasm2.arch.arm.jit.jitter_arml.push_uint32_t (   self,
  v 
)

Definition at line 22 of file jit.py.

22 
23  def push_uint32_t(self, v):
24  self.cpu.SP -= 4
25  self.vm.set_mem(self.cpu.SP, pck32(v))
tuple pck32
Definition: utils.py:12
def miasm2.jitter.jitload.jitter.remove_breakpoints_by_callback (   self,
  callback 
)
inherited
Remove callbacks associated with breakpoint.
@callback: callback to remove

Definition at line 273 of file jitload.py.

274  def remove_breakpoints_by_callback(self, callback):
275  """Remove callbacks associated with breakpoint.
276  @callback: callback to remove
277  """
278  empty_keys = self.breakpoints_handler.remove_callback(callback)
279  for key in empty_keys:
280  self.jit.remove_disassembly_splits(key)
def miasm2.jitter.jitload.jitter.runbloc (   self,
  pc 
)
inherited
Wrapper on JiT backend. Run the code at PC and return the next PC.
@pc: address of code to run

Definition at line 288 of file jitload.py.

289  def runbloc(self, pc):
290  """Wrapper on JiT backend. Run the code at PC and return the next PC.
291  @pc: address of code to run"""
292 
293  return self.jit.runbloc(self.cpu, self.vm, pc, self.breakpoints_handler.callbacks)
def miasm2.jitter.jitload.jitter.runiter_once (   self,
  pc 
)
inherited
Iterator on callbacks results on code running from PC.
Check exceptions before breakpoints.

Definition at line 294 of file jitload.py.

295  def runiter_once(self, pc):
296  """Iterator on callbacks results on code running from PC.
297  Check exceptions before breakpoints."""
299  self.pc = pc
300 
301  # Callback called before exec
302  if self.exec_cb is not None:
303  res = self.exec_cb(self)
304  if res is not True:
305  yield res
306 
307  # Check breakpoints
308  old_pc = self.pc
309  for res in self.breakpoints_handler.call_callbacks(self.pc, self):
310  if res is not True:
311  yield res
312 
313  # If a callback changed pc, re call every callback
314  if old_pc != self.pc:
315  return
316 
317  # Exceptions should never be activated before run
318  assert(self.get_exception() == 0)
319 
320  # Run the bloc at PC
321  self.pc = self.runbloc(self.pc)
322 
323  # Check exceptions
324  exception_flag = self.get_exception()
325  for res in self.exceptions_handler(exception_flag, self):
326  if res is not True:
327  yield res

+ Here is the caller graph for this function:

def miasm2.jitter.jitload.jitter.set_breakpoint (   self,
  addr,
  args 
)
inherited
Set callbacks associated with addr.
@addr: breakpoint address
@args: functions with definition (jitter instance)

Definition at line 265 of file jitload.py.

266  def set_breakpoint(self, addr, *args):
267  """Set callbacks associated with addr.
268  @addr: breakpoint address
269  @args: functions with definition (jitter instance)
270  """
271  self.breakpoints_handler.set_callback(addr, *args)
272  self.jit.add_disassembly_splits(addr)
def miasm2.jitter.jitload.jitter.set_str_ansi (   self,
  addr,
  s 
)
inherited
Set an ansi string in memory

Definition at line 395 of file jitload.py.

396  def set_str_ansi(self, addr, s):
397  """Set an ansi string in memory"""
398  s = s + "\x00"
399  self.vm.set_mem(addr, s)
def miasm2.jitter.jitload.jitter.set_str_unic (   self,
  addr,
  s 
)
inherited
Set an unicode string in memory

Definition at line 400 of file jitload.py.

401  def set_str_unic(self, addr, s):
402  """Set an unicode string in memory"""
403  s = "\x00".join(list(s)) + '\x00' * 3
404  self.vm.set_mem(addr, s)

Member Data Documentation

miasm2.jitter.jitload.jitter.arch
inherited

Definition at line 186 of file jitload.py.

miasm2.jitter.jitload.jitter.attrib
inherited

Definition at line 187 of file jitload.py.

miasm2.jitter.jitload.jitter.breakpoints_handler
inherited

Definition at line 233 of file jitload.py.

miasm2.jitter.jitload.jitter.bs
inherited

Definition at line 205 of file jitload.py.

miasm2.jitter.jitload.jitter.cpu
inherited

Definition at line 203 of file jitload.py.

miasm2.jitter.jitload.jitter.exceptions_handler
inherited

Definition at line 234 of file jitload.py.

miasm2.jitter.jitload.jitter.exec_cb
inherited

Definition at line 236 of file jitload.py.

miasm2.jitter.jitload.jitter.ir_arch
inherited

Definition at line 206 of file jitload.py.

miasm2.jitter.jitload.jitter.jit
inherited

Definition at line 210 of file jitload.py.

miasm2.jitter.jitload.jitter.libs
inherited

Definition at line 432 of file jitload.py.

miasm2.arch.arm.jit.jitter_arml.pc

Definition at line 48 of file jit.py.

miasm2.jitter.jitload.jitter.run
inherited

Definition at line 334 of file jitload.py.

miasm2.jitter.jitload.jitter.run_iterator
inherited

Definition at line 332 of file jitload.py.

miasm2.jitter.jitload.jitter.stack_base
inherited

Definition at line 229 of file jitload.py.

miasm2.jitter.jitload.jitter.stack_size
inherited

Definition at line 228 of file jitload.py.

miasm2.jitter.jitload.jitter.user_globals
inherited

Definition at line 433 of file jitload.py.

miasm2.jitter.jitload.jitter.vm
inherited

Definition at line 202 of file jitload.py.


The documentation for this class was generated from the following file: