Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
disasm.py
Go to the documentation of this file.
1 from miasm2.core.asmbloc import asm_constraint, asm_label, disasmEngine
2 from miasm2.expression.expression import ExprId
3 from miasm2.arch.x86.arch import mn_x86
4 
5 
6 def cb_x86_callpop(mn, attrib, pool_bin, cur_bloc, offsets_to_dis, symbol_pool):
7  """
8  1000: call 1005
9  1005: pop
10 
11  Will give:
12 
13  1000: push 1005
14  1005: pop
15 
16  """
17 
18  if len(cur_bloc.lines) < 1:
19  return
20  l = cur_bloc.lines[-1]
21  if l.name != 'CALL':
22  return
23  dst = l.args[0]
24  if not (isinstance(dst, ExprId) and isinstance(dst.name, asm_label)):
25  return
26  if dst.name.offset != l.offset + l.l:
27  return
28  l.name = 'PUSH'
29  cur_bloc.bto = set()
30  cur_bloc.add_cst(dst.name.offset, asm_constraint.c_next, symbol_pool)
31 
32 
33 cb_x86_funcs = [cb_x86_callpop]
34 
35 
36 def cb_x86_disasm(mn, attrib, pool_bin, cur_bloc, offsets_to_dis, symbol_pool):
37  for func in cb_x86_funcs:
38  func(mn, attrib, pool_bin, cur_bloc, offsets_to_dis, symbol_pool)
39 
40 
42  attrib = None
43 
44  def __init__(self, bs=None, **kwargs):
45  super(dis_x86, self).__init__(mn_x86, self.attrib, bs, **kwargs)
46  self.dis_bloc_callback = cb_x86_disasm
47 
48 
50  attrib = 16
51 
52 
54  attrib = 32
55 
56 
58  attrib = 64