Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
ira.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 
5 from miasm2.ir.ir import ir, irbloc
6 from miasm2.ir.analysis import ira
7 from miasm2.arch.arm.sem import ir_arml, ir_armtl, ir_armb, ir_armtb
8 from miasm2.arch.arm.regs import *
9 # from miasm2.core.graph import DiGraph
10 
11 
13  def __init__(self, symbol_pool=None):
14  ir_arml.__init__(self, symbol_pool)
15  self.ret_reg = self.arch.regs.R0
16 
18  def __init__(self, symbol_pool=None):
19  ir_armb.__init__(self, symbol_pool)
20  self.ret_reg = self.arch.regs.R0
21 
22 
24 
25  def __init__(self, symbol_pool=None):
26  ir_a_arml_base.__init__(self, symbol_pool)
27  self.ret_reg = self.arch.regs.R0
28 
29  # for test XXX TODO
30  def set_dead_regs(self, b):
31  b.rw[-1][1].add(self.arch.regs.zf)
32  b.rw[-1][1].add(self.arch.regs.nf)
33  b.rw[-1][1].add(self.arch.regs.of)
34  b.rw[-1][1].add(self.arch.regs.cf)
35 
36  def call_effects(self, ad):
37  irs = [[ExprAff(self.ret_reg, ExprOp('call_func_ret', ad, self.sp)),
38  ExprAff(self.sp, ExprOp('call_func_stack', ad, self.sp)),
39  ]]
40  return irs
41 
42  def post_add_bloc(self, bloc, ir_blocs):
43  ir.post_add_bloc(self, bloc, ir_blocs)
44  # flow_graph = DiGraph()
45  for irb in ir_blocs:
46  # print 'X'*40
47  # print irb
48  pc_val = None
49  lr_val = None
50  for exprs in irb.irs:
51  for e in exprs:
52  if e.dst == PC:
53  pc_val = e.src
54  if e.dst == LR:
55  lr_val = e.src
56  if pc_val is None or lr_val is None:
57  continue
58  if not isinstance(lr_val, ExprInt):
59  continue
60 
61  l = bloc.lines[-1]
62  if lr_val.arg != l.offset + l.l:
63  continue
64  # print 'IS CALL!'
65  lbl = bloc.get_next()
66  new_lbl = self.gen_label()
67  irs = self.call_effects(pc_val)
68  irs.append([ExprAff(self.IRDst, ExprId(lbl, size=self.pc.size))])
69  nbloc = irbloc(new_lbl, irs)
70  nbloc.lines = [l]*len(irs)
71  self.blocs[new_lbl] = nbloc
72  irb.dst = ExprId(new_lbl, size=self.pc.size)
73 
74  """
75  if not bloc.lines:
76  return
77  l = bloc.lines[-1]
78  sub_call_dst = None
79  if not l.is_subcall():
80  return
81  sub_call_dst = l.args[0]
82  if self.ExprIsLabel(sub_call_dst):
83  sub_call_dst = sub_call_dst.name
84  for b in ir_blocs:
85  l = b.lines[-1]
86  sub_call_dst_b = None
87  sub_call_dst_b = l.args[0]
88  #if self.ExprIsLabel(sub_call_dst_b):
89  # sub_call_dst_b = sub_call_dst.name
90  #if str(b.dst) == str(sub_call_dst_b):
91  # pass
92  if not l.is_subcall():
93  continue
94  if b.dst != sub_call_dst_b:
95  continue
96  sub_call_dst_b = l.args[0]
97  if self.ExprIsLabel(sub_call_dst_b):
98  sub_call_dst_b = sub_call_dst.name
99  lbl = bloc.get_next()
100  new_lbl = self.gen_label()
101  irs = self.call_effects(l.args[0])
102  nbloc = irbloc(new_lbl, ExprId(lbl, size=self.pc.size), irs)
103  nbloc.lines = [l]
104  self.blocs[new_lbl] = nbloc
105  b.dst = ExprId(new_lbl, size=self.pc.size)
106  return
107  """
108 
109  def get_out_regs(self, b):
110  return set([self.ret_reg, self.sp])
111 
112  def sizeof_char(self):
113  return 8
114 
115  def sizeof_short(self):
116  return 16
117 
118  def sizeof_int(self):
119  return 32
120 
121  def sizeof_long(self):
122  return 32
123 
124  def sizeof_pointer(self):
125  return 32
126 
128 
129  def __init__(self, symbol_pool=None):
130  ir_a_armb_base.__init__(self, symbol_pool)
131  self.ret_reg = self.arch.regs.R0
132 
133 
135  def __init__(self, symbol_pool):
136  ir_armtl.__init__(self, symbol_pool)
137  self.ret_reg = self.arch.regs.R0
138 
140  def __init__(self, symbol_pool):
141  ir_armtb.__init__(self, symbol_pool)
142  self.ret_reg = self.arch.regs.R0
def gen_label
Definition: ir.py:309