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

Public Member Functions

def __init__
 
def get_ir
 
def instr2ir
 
def get_label
 
def get_bloc
 
def add_instr
 
def merge_multi_affect
 
def getby_offset
 
def gen_pc_update
 
def add_bloc
 
def expr_fix_regs_for_mode
 
def expraff_fix_regs_for_mode
 
def irbloc_fix_regs_for_mode
 
def is_pc_written
 
def set_empty_dst_to_next
 
def gen_edges
 
def post_add_bloc
 
def get_instr_label
 
def gen_label
 
def get_next_label
 
def simplify_blocs
 
def replace_expr_in_ir
 
def get_rw
 
def ExprIsLabel
 

Public Attributes

 pc
 
 sp
 
 IRDst
 
 symbol_pool
 
 blocs
 
 arch
 
 attrib
 

Detailed Description

Definition at line 1233 of file sem.py.

Constructor & Destructor Documentation

def miasm2.arch.arm.sem.ir_armtl.__init__ (   self,
  symbol_pool = None 
)

Definition at line 1234 of file sem.py.

1235  def __init__(self, symbol_pool=None):
1236  ir.__init__(self, mn_armt, "l", symbol_pool)
1237  self.pc = PC
1238  self.sp = SP
1239  self.IRDst = ExprId('IRDst', 32)

Member Function Documentation

def miasm2.ir.ir.ir.add_bloc (   self,
  bloc,
  gen_pc_updt = False 
)
inherited

Definition at line 235 of file ir.py.

236  def add_bloc(self, bloc, gen_pc_updt = False):
237  c = None
238  ir_blocs_all = []
239  for l in bloc.lines:
240  if c is None:
241  label = self.get_instr_label(l)
242  c = irbloc(label, [], [])
243  ir_blocs_all.append(c)
244  ir_bloc_cur, ir_blocs_extra = self.instr2ir(l)
245 
246  if gen_pc_updt is not False:
247  self.gen_pc_update(c, l)
248 
249  c.irs.append(ir_bloc_cur)
250  c.lines.append(l)
251 
252 
253  if ir_blocs_extra:
254  for b in ir_blocs_extra:
255  b.lines = [l] * len(b.irs)
256  ir_blocs_all += ir_blocs_extra
257  c = None
258  self.post_add_bloc(bloc, ir_blocs_all)
259  return ir_blocs_all
def get_instr_label
Definition: ir.py:303
def instr2ir
Definition: ir.py:134
def gen_pc_update
Definition: ir.py:230
def add_bloc
Definition: ir.py:235
def post_add_bloc
Definition: ir.py:289

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.add_instr (   self,
  l,
  ad = 0,
  gen_pc_updt = False 
)
inherited

Definition at line 160 of file ir.py.

161  def add_instr(self, l, ad=0, gen_pc_updt = False):
162  b = asmbloc.asm_bloc(l)
163  b.lines = [l]
164  self.add_bloc(b, gen_pc_updt)
def add_instr
Definition: ir.py:160
def add_bloc
Definition: ir.py:235

+ Here is the call graph for this function:

def miasm2.ir.ir.ir.expr_fix_regs_for_mode (   self,
  e,
  args,
  kwargs 
)
inherited

Definition at line 260 of file ir.py.

261  def expr_fix_regs_for_mode(self, e, *args, **kwargs):
262  return e
def expr_fix_regs_for_mode
Definition: ir.py:260
def miasm2.ir.ir.ir.expraff_fix_regs_for_mode (   self,
  e,
  args,
  kwargs 
)
inherited

Definition at line 263 of file ir.py.

264  def expraff_fix_regs_for_mode(self, e, *args, **kwargs):
265  return e
def expraff_fix_regs_for_mode
Definition: ir.py:263
def miasm2.ir.ir.ir.ExprIsLabel (   self,
  l 
)
inherited

Definition at line 337 of file ir.py.

338  def ExprIsLabel(self, l):
339  return isinstance(l, m2_expr.ExprId) and isinstance(l.name,
340  asmbloc.asm_label)
def ExprIsLabel
Definition: ir.py:337

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.gen_edges (   self,
  bloc,
  ir_blocs 
)
inherited

Definition at line 286 of file ir.py.

287  def gen_edges(self, bloc, ir_blocs):
288  pass
def gen_edges
Definition: ir.py:286

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.gen_label (   self)
inherited

Definition at line 309 of file ir.py.

310  def gen_label(self):
311  # TODO: fix hardcoded offset
312  l = self.symbol_pool.gen_label()
313  return l
def gen_label
Definition: ir.py:309

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.gen_pc_update (   self,
  c,
  l 
)
inherited

Definition at line 230 of file ir.py.

231  def gen_pc_update(self, c, l):
232  c.irs.append([m2_expr.ExprAff(self.pc, m2_expr.ExprInt_from(self.pc,
233  l.offset))])
234  c.lines.append(l)
def gen_pc_update
Definition: ir.py:230

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.get_bloc (   self,
  ad 
)
inherited
Returns the irbloc associated to an ExprId/ExprInt/label/int
@ad: an ExprId/ExprInt/label/int

Definition at line 153 of file ir.py.

154  def get_bloc(self, ad):
155  """Returns the irbloc associated to an ExprId/ExprInt/label/int
156  @ad: an ExprId/ExprInt/label/int"""
157 
158  label = self.get_label(ad)
159  return self.blocs.get(label, None)
def get_bloc
Definition: ir.py:153
def get_label
Definition: ir.py:138

+ Here is the call graph for this function:

def miasm2.ir.ir.ir.get_instr_label (   self,
  instr 
)
inherited
Returns the label associated to an instruction
@instr: current instruction

Definition at line 303 of file ir.py.

304  def get_instr_label(self, instr):
305  """Returns the label associated to an instruction
306  @instr: current instruction"""
307 
308  return self.symbol_pool.getby_offset_create(instr.offset)
def get_instr_label
Definition: ir.py:303

+ Here is the caller graph for this function:

def miasm2.arch.arm.sem.ir_armtl.get_ir (   self,
  instr 
)

Definition at line 1240 of file sem.py.

1241  def get_ir(self, instr):
1242  return get_mnemo_expr(self, instr, *instr.args)
def get_mnemo_expr
Definition: sem.py:1174

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.get_label (   self,
  ad 
)
inherited
Transforms an ExprId/ExprInt/label/int into a label
@ad: an ExprId/ExprInt/label/int

Definition at line 138 of file ir.py.

139  def get_label(self, ad):
140  """Transforms an ExprId/ExprInt/label/int into a label
141  @ad: an ExprId/ExprInt/label/int"""
142 
143  if (isinstance(ad, m2_expr.ExprId) and
144  isinstance(ad.name, asmbloc.asm_label)):
145  ad = ad.name
146  if isinstance(ad, m2_expr.ExprInt):
147  ad = int(ad.arg)
148  if type(ad) in [int, long]:
149  ad = self.symbol_pool.getby_offset_create(ad)
150  elif isinstance(ad, asmbloc.asm_label):
151  ad = self.symbol_pool.getby_name_create(ad.name)
152  return ad
def get_label
Definition: ir.py:138

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.get_next_label (   self,
  instr 
)
inherited

Definition at line 314 of file ir.py.

315  def get_next_label(self, instr):
316  l = self.symbol_pool.getby_offset_create(instr.offset + instr.l)
317  return l
def get_next_label
Definition: ir.py:314

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.get_rw (   self,
  regs_ids = [] 
)
inherited
Calls get_rw(irb) for each bloc
@regs_ids : ids of registers used in IR

Definition at line 329 of file ir.py.

330  def get_rw(self, regs_ids = []):
331  """
332  Calls get_rw(irb) for each bloc
333  @regs_ids : ids of registers used in IR
334  """
335  for b in self.blocs.values():
336  b.get_rw(regs_ids)
def get_rw
Definition: ir.py:329

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.getby_offset (   self,
  offset 
)
inherited

Definition at line 222 of file ir.py.

223  def getby_offset(self, offset):
224  out = set()
225  for irb in self.blocs.values():
226  for l in irb.lines:
227  if l.offset <= offset < l.offset + l.l:
228  out.add(irb)
229  return out
def getby_offset
Definition: ir.py:222
def miasm2.ir.ir.ir.instr2ir (   self,
  l 
)
inherited

Definition at line 134 of file ir.py.

135  def instr2ir(self, l):
136  ir_bloc_cur, ir_blocs_extra = self.get_ir(l)
137  return ir_bloc_cur, ir_blocs_extra
def instr2ir
Definition: ir.py:134

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.irbloc_fix_regs_for_mode (   self,
  irbloc,
  args,
  kwargs 
)
inherited

Definition at line 266 of file ir.py.

267  def irbloc_fix_regs_for_mode(self, irbloc, *args, **kwargs):
268  return
def irbloc_fix_regs_for_mode
Definition: ir.py:266

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.is_pc_written (   self,
  b 
)
inherited

Definition at line 269 of file ir.py.

270  def is_pc_written(self, b):
271  all_pc = self.arch.pc.values()
272  for irs in b.irs:
273  for ir in irs:
274  if ir.dst in all_pc:
275  return ir
276  return None
def is_pc_written
Definition: ir.py:269
def miasm2.ir.ir.ir.merge_multi_affect (   self,
  affect_list 
)
inherited
If multiple affection to a same ExprId are present in @affect_list,
merge them (in place).
For instance, XCGH AH, AL semantic is
[
    RAX = {RAX[0:8],0,8, RAX[0:8],8,16, RAX[16:64],16,64}
    RAX = {RAX[8:16],0,8, RAX[8:64],8,64}
]
This function will update @affect_list to replace previous ExprAff by
[
    RAX = {RAX[8:16],0,8, RAX[0:8],8,16, RAX[16:64],16,64}
]

Definition at line 165 of file ir.py.

166  def merge_multi_affect(self, affect_list):
167  """
168  If multiple affection to a same ExprId are present in @affect_list,
169  merge them (in place).
170  For instance, XCGH AH, AL semantic is
171  [
172  RAX = {RAX[0:8],0,8, RAX[0:8],8,16, RAX[16:64],16,64}
173  RAX = {RAX[8:16],0,8, RAX[8:64],8,64}
174  ]
175  This function will update @affect_list to replace previous ExprAff by
176  [
177  RAX = {RAX[8:16],0,8, RAX[0:8],8,16, RAX[16:64],16,64}
178  ]
179  """
180 
181  # Extract side effect
182  effect = {}
183  for expr in affect_list:
184  effect[expr.dst] = effect.get(expr.dst, []) + [expr]
185 
186  # Find candidates
187  for dst, expr_list in effect.items():
188  if len(expr_list) <= 1:
189  continue
190 
191  # Only treat ExprCompose list
192  if any(map(lambda e: not(isinstance(e.src, m2_expr.ExprCompose)),
193  expr_list)):
194  continue
195 
196  # Find collision
197  e_colision = reduce(lambda x, y: x.union(y),
198  (e.get_modified_slice() for e in expr_list),
199  set())
200  # Sort interval collision
201  known_intervals = sorted([(x[1], x[2]) for x in e_colision])
202 
203  # Fill with missing data
204  missing_i = get_missing_interval(known_intervals, 0, dst.size)
205 
206  remaining = ((m2_expr.ExprSlice(dst, *interval),
207  interval[0],
208  interval[1])
209  for interval in missing_i)
210 
211  # Build the merging expression
212  slices = sorted(e_colision.union(remaining), key=lambda x: x[1])
213  final_dst = m2_expr.ExprCompose(slices)
214 
215  # Remove unused expression
216  for expr in expr_list:
217  affect_list.remove(expr)
218 
219  # Add the merged one
220  affect_list.append(m2_expr.ExprAff(dst, final_dst))
221 
def merge_multi_affect
Definition: ir.py:165

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.post_add_bloc (   self,
  bloc,
  ir_blocs 
)
inherited

Definition at line 289 of file ir.py.

290  def post_add_bloc(self, bloc, ir_blocs):
291  self.set_empty_dst_to_next(bloc, ir_blocs)
292  self.gen_edges(bloc, ir_blocs)
293 
294  for irb in ir_blocs:
295  self.irbloc_fix_regs_for_mode(irb, self.attrib)
296 
297  # Detect multi-affectation
298  for affect_list in irb.irs:
299  self.merge_multi_affect(affect_list)
300 
301  self.blocs[irb.label] = irb
302 
def set_empty_dst_to_next
Definition: ir.py:277
def irbloc_fix_regs_for_mode
Definition: ir.py:266
def gen_edges
Definition: ir.py:286
def merge_multi_affect
Definition: ir.py:165
def post_add_bloc
Definition: ir.py:289

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.replace_expr_in_ir (   self,
  bloc,
  rep 
)
inherited

Definition at line 324 of file ir.py.

325  def replace_expr_in_ir(self, bloc, rep):
326  for irs in bloc.irs:
327  for i, l in enumerate(irs):
328  irs[i] = l.replace_expr(rep)
def replace_expr_in_ir
Definition: ir.py:324
def miasm2.ir.ir.ir.set_empty_dst_to_next (   self,
  bloc,
  ir_blocs 
)
inherited

Definition at line 277 of file ir.py.

278  def set_empty_dst_to_next(self, bloc, ir_blocs):
279  for b in ir_blocs:
280  if b.dst is not None:
281  continue
282  dst = m2_expr.ExprId(self.get_next_label(bloc.lines[-1]),
283  self.pc.size)
284  b.irs.append([m2_expr.ExprAff(self.IRDst, dst)])
285  b.lines.append(b.lines[-1])
def set_empty_dst_to_next
Definition: ir.py:277
def get_next_label
Definition: ir.py:314

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.ir.ir.simplify_blocs (   self)
inherited

Definition at line 318 of file ir.py.

319  def simplify_blocs(self):
320  for b in self.blocs.values():
321  for ir in b.irs:
322  for i, r in enumerate(ir):
323  ir[i] = m2_expr.ExprAff(expr_simp(r.dst), expr_simp(r.src))
def simplify_blocs
Definition: ir.py:318

+ Here is the caller graph for this function:

Member Data Documentation

miasm2.ir.ir.ir.arch
inherited

Definition at line 131 of file ir.py.

miasm2.ir.ir.ir.attrib
inherited

Definition at line 132 of file ir.py.

miasm2.ir.ir.ir.blocs
inherited

Definition at line 128 of file ir.py.

miasm2.arch.arm.sem.ir_armtl.IRDst

Definition at line 1238 of file sem.py.

miasm2.arch.arm.sem.ir_armtl.pc

Definition at line 1236 of file sem.py.

miasm2.arch.arm.sem.ir_armtl.sp

Definition at line 1237 of file sem.py.

miasm2.ir.ir.ir.symbol_pool
inherited

Definition at line 127 of file ir.py.


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