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.x86.ira.ir_a_x86_64 Class Reference
+ Inheritance diagram for miasm2.arch.x86.ira.ir_a_x86_64:
+ Collaboration diagram for miasm2.arch.x86.ira.ir_a_x86_64:

Public Member Functions

def __init__
 
def call_effects
 
def sizeof_char
 
def sizeof_short
 
def sizeof_int
 
def sizeof_long
 
def sizeof_pointer
 
def mod_pc
 
def get_ir
 
def expr_fix_regs_for_mode
 
def expr_fix_regs_for_mode
 
def expraff_fix_regs_for_mode
 
def expraff_fix_regs_for_mode
 
def irbloc_fix_regs_for_mode
 
def irbloc_fix_regs_for_mode
 
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 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
 
def set_dead_regs
 
def get_out_regs
 
def add_unused_regs
 
def post_add_bloc
 
def get_ir
 
def expr_fix_regs_for_mode
 
def expr_fix_regs_for_mode
 
def expraff_fix_regs_for_mode
 
def expraff_fix_regs_for_mode
 
def irbloc_fix_regs_for_mode
 
def irbloc_fix_regs_for_mode
 
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 is_pc_written
 
def set_empty_dst_to_next
 
def gen_edges
 
def get_instr_label
 
def gen_label
 
def get_next_label
 
def simplify_blocs
 
def replace_expr_in_ir
 
def get_rw
 
def ExprIsLabel
 
def ira_regs_ids
 
def sort_dst
 
def dst_trackback
 
def gen_graph
 
def graph
 
def remove_dead_instr
 
def init_useful_instr
 
def remove_dead_code
 
def dump_bloc_state
 
def compute_reach_block
 
def compute_reach
 
def dead_simp
 
def gen_equations
 

Static Public Member Functions

def print_set
 

Public Attributes

 ret_reg
 
 do_stk_segm
 
 do_ds_segm
 
 do_str_segm
 
 do_all_segm
 
 pc
 
 sp
 
 IRDst
 
 symbol_pool
 
 blocs
 
 arch
 
 attrib
 
 symbol_pool
 
 blocs
 
 arch
 
 attrib
 
 g
 

Detailed Description

Definition at line 93 of file ira.py.

Constructor & Destructor Documentation

def miasm2.arch.x86.ira.ir_a_x86_64.__init__ (   self,
  symbol_pool = None 
)

Definition at line 95 of file ira.py.

95 
96  def __init__(self, symbol_pool=None):
97  ir_x86_64.__init__(self, symbol_pool)
98  self.ret_reg = self.arch.regs.RAX

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_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.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.arch.x86.ira.ir_a_x86_16.add_unused_regs (   self)
inherited

Definition at line 29 of file ira.py.

29 
30  def add_unused_regs(self):
31  leaves = [self.blocs[n] for n in self.g.leafs()]
32  for b in leaves:
33  self.set_dead_regs(b)

+ Here is the call graph for this function:

def miasm2.arch.x86.ira.ir_a_x86_64.call_effects (   self,
  ad 
)

Definition at line 99 of file ira.py.

99 
100  def call_effects(self, ad):
101  irs = [[ExprAff(self.ret_reg, ExprOp('call_func_ret', ad, self.sp,
102  self.arch.regs.RCX,
103  self.arch.regs.RDX,
104  self.arch.regs.R8,
105  self.arch.regs.R9,
106  )),
107  ExprAff(self.sp, ExprOp('call_func_stack', ad, self.sp)),
108  ]]
109  return irs
def miasm2.ir.analysis.ira.compute_reach (   self)
inherited
Compute reach, defout and kill sets until a fixed point is reached.

Source : Kennedy, K. (1979). A survey of data flow analysis techniques.
IBM Thomas J. Watson Research Division, page 43

PRE: gen_graph()

Definition at line 326 of file analysis.py.

327  def compute_reach(self):
328  """
329  Compute reach, defout and kill sets until a fixed point is reached.
330 
331  Source : Kennedy, K. (1979). A survey of data flow analysis techniques.
332  IBM Thomas J. Watson Research Division, page 43
333 
334  PRE: gen_graph()
335  """
336  fixed_point = False
337  log.debug('iteration...')
338  while not fixed_point:
339  for node in self.g.nodes():
340  if node in self.blocs:
341  self.compute_reach_block(self.blocs[node])
342  fixed_point = self._test_kill_reach_fix()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.analysis.ira.compute_reach_block (   self,
  irb 
)
inherited
Variable influence computation for a single block
@irb: irbloc instance
PRE: init_reach()

Definition at line 267 of file analysis.py.

268  def compute_reach_block(self, irb):
269  """Variable influence computation for a single block
270  @irb: irbloc instance
271  PRE: init_reach()
272  """
273 
274  reach_block = {key: value.copy()
275  for key, value in irb.cur_reach[0].iteritems()}
276 
277  # Compute reach from predecessors
278  for n_pred in self.g.predecessors(irb.label):
279  p_block = self.blocs[n_pred]
280 
281  # Handle each register definition
282  for c_reg in self.ira_regs_ids():
283  # REACH(n) = U[p in pred] DEFOUT(p) U REACH(p)\KILL(p)
284  pred_through = p_block.defout[-1][c_reg].union(
285  p_block.cur_reach[-1][c_reg].difference(
286  p_block.cur_kill[-1][c_reg]))
287  reach_block[c_reg].update(pred_through)
288 
289  # If a predecessor has changed
290  if reach_block != irb.cur_reach[0]:
291  irb.cur_reach[0] = reach_block
292  for c_reg in self.ira_regs_ids():
293  if irb.defout[0][c_reg]:
294  # KILL(n) = DEFOUT(n) ? REACH(n)\DEFOUT(n) : EMPTY
295  irb.cur_kill[0][c_reg].update(
296  reach_block[c_reg].difference(irb.defout[0][c_reg]))
297 
298  # Compute reach and kill for block's instructions
299  for i in xrange(1, len(irb.irs)):
300  for c_reg in self.ira_regs_ids():
301  # REACH(n) = U[p in pred] DEFOUT(p) U REACH(p)\KILL(p)
302  pred_through = irb.defout[i - 1][c_reg].union(
303  irb.cur_reach[i - 1][c_reg].difference(
304  irb.cur_kill[i - 1][c_reg]))
305  irb.cur_reach[i][c_reg].update(pred_through)
306  if irb.defout[i][c_reg]:
307  # KILL(n) = DEFOUT(n) ? REACH(n)\DEFOUT(n) : EMPTY
308  irb.cur_kill[i][c_reg].update(
309  irb.cur_reach[i][c_reg].difference(
310  irb.defout[i][c_reg]))

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.analysis.ira.dead_simp (   self)
inherited
This function is used to analyse relation of a * complete function *
This means the blocks under study represent a solid full function graph.

Source : Kennedy, K. (1979). A survey of data flow analysis techniques.
IBM Thomas J. Watson Research Division, page 43

PRE: gen_graph()

Definition at line 343 of file analysis.py.

344  def dead_simp(self):
345  """
346  This function is used to analyse relation of a * complete function *
347  This means the blocks under study represent a solid full function graph.
348 
349  Source : Kennedy, K. (1979). A survey of data flow analysis techniques.
350  IBM Thomas J. Watson Research Division, page 43
351 
352  PRE: gen_graph()
353  """
354  # Update r/w variables for all irblocs
355  self.get_rw(self.ira_regs_ids())
356  # Liveness step
357  self.compute_reach()
358  self.remove_dead_code()
359  # Simplify expressions
360  self.simplify_blocs()

+ Here is the call graph for this function:

def miasm2.ir.analysis.ira.dst_trackback (   self,
  b 
)
inherited

Definition at line 40 of file analysis.py.

40 
41  def dst_trackback(self, b):
42  dst = b.dst
43  todo = set([dst])
44  done = set()
45 
46  for irs in reversed(b.irs):
47  if len(todo) == 0:
48  break
49  out = self.sort_dst(todo, done)
50  found = set()
51  follow = set()
52  for i in irs:
53  if not out:
54  break
55  for o in out:
56  if i.dst == o:
57  follow.add(i.src)
58  found.add(o)
59  for o in found:
60  out.remove(o)
61 
62  for o in out:
63  if o not in found:
64  follow.add(o)
65  todo = follow
66 
67  return done

+ Here is the call graph for this function:

def miasm2.ir.analysis.ira.dump_bloc_state (   self,
  irb 
)
inherited

Definition at line 249 of file analysis.py.

250  def dump_bloc_state(self, irb):
251  print '*'*80
252  for k, irs in enumerate(irb.irs):
253  for i in xrange(len(irs)):
254  print 5*"-"
255  print 'instr', k, irs[i]
256  print 5*"-"
257  for v in self.ira_regs_ids():
258  if irb.cur_reach[k][v]:
259  print 'REACH[%d][%s]' % (k, v)
260  self.print_set(irb.cur_reach[k][v])
261  if irb.cur_kill[k][v]:
262  print 'KILL[%d][%s]' % (k, v)
263  self.print_set(irb.cur_kill[k][v])
264  if irb.defout[k][v]:
265  print 'DEFOUT[%d][%s]' % (k, v)
266  self.print_set(irb.defout[k][v])

+ 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.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.arch.x86.sem.ir_x86_16.expr_fix_regs_for_mode (   self,
  e,
  mode = 64 
)
inherited

Definition at line 3898 of file sem.py.

3899  def expr_fix_regs_for_mode(self, e, mode=64):
3900  return e.replace_expr(replace_regs[mode])

+ Here is the caller graph for this function:

def miasm2.arch.x86.sem.ir_x86_16.expr_fix_regs_for_mode (   self,
  e,
  mode = 64 
)
inherited

Definition at line 3898 of file sem.py.

3899  def expr_fix_regs_for_mode(self, e, mode=64):
3900  return e.replace_expr(replace_regs[mode])

+ Here is the caller graph for this function:

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.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.arch.x86.sem.ir_x86_16.expraff_fix_regs_for_mode (   self,
  e,
  mode = 64 
)
inherited

Definition at line 3901 of file sem.py.

3902  def expraff_fix_regs_for_mode(self, e, mode=64):
3903  dst = self.expr_fix_regs_for_mode(e.dst, mode)
3904  src = self.expr_fix_regs_for_mode(e.src, mode)
3905  return m2_expr.ExprAff(dst, src)

+ Here is the call graph for this function:

def miasm2.arch.x86.sem.ir_x86_16.expraff_fix_regs_for_mode (   self,
  e,
  mode = 64 
)
inherited

Definition at line 3901 of file sem.py.

3902  def expraff_fix_regs_for_mode(self, e, mode=64):
3903  dst = self.expr_fix_regs_for_mode(e.dst, mode)
3904  src = self.expr_fix_regs_for_mode(e.src, mode)
3905  return m2_expr.ExprAff(dst, src)

+ Here is the call graph for this function:

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.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_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.analysis.ira.gen_equations (   self)
inherited

Definition at line 361 of file analysis.py.

362  def gen_equations(self):
363  for irb in self.blocs.values():
364  symbols_init = {}
365  for r in self.arch.regs.all_regs_ids:
366  x = ExprId(r.name, r.size)
367  x.is_term = True
368  symbols_init[r] = x
369  sb = symbexec(self, dict(symbols_init))
370  sb.emulbloc(irb)
371  eqs = []
372  for n_w in sb.symbols:
373  v = sb.symbols[n_w]
374  if n_w in symbols_init and symbols_init[n_w] == v:
375  continue
376  eqs.append(ExprAff(n_w, v))
377  print '*' * 40
378  print irb
379  irb.irs = [eqs]
380  irb.lines = [None]
def miasm2.ir.analysis.ira.gen_graph (   self,
  link_all = True 
)
inherited
Gen irbloc digraph
@link_all: also gen edges to non present irblocs

Definition at line 68 of file analysis.py.

68 
69  def gen_graph(self, link_all = True):
70  """
71  Gen irbloc digraph
72  @link_all: also gen edges to non present irblocs
73  """
74  self.g = DiGraph()
75  for lbl, b in self.blocs.items():
76  # print 'add', lbl
77  self.g.add_node(lbl)
78  # dst = self.get_bloc_dst(b)
79  dst = self.dst_trackback(b)
80  # print "\tdst", dst
81  for d in dst:
82  if isinstance(d, ExprInt):
83  d = ExprId(
84  self.symbol_pool.getby_offset_create(int(d.arg)))
85  if self.ExprIsLabel(d):
86  if d.name in self.blocs or link_all is True:
87  self.g.add_edge(lbl, d.name)
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_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.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_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.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.x86.sem.ir_x86_16.get_ir (   self,
  instr 
)
inherited

Definition at line 3819 of file sem.py.

3820  def get_ir(self, instr):
3821  args = instr.args[:]
3822  args = [arg.replace_expr(float_replace) for arg in args]
3823  my_ss = None
3824  if self.do_ds_segm:
3825  my_ss = DS
3826  if self.do_all_segm and instr.additional_info.g2.value:
3827  my_ss = {1: CS, 2: SS, 3: DS, 4: ES, 5: FS, 6: GS}[
3828  instr.additional_info.g2.value]
3829  if my_ss is not None:
3830  for i, a in enumerate(args):
3831  if isinstance(a, m2_expr.ExprMem) and not a.is_op_segm():
3832  args[i] = m2_expr.ExprMem(m2_expr.ExprOp('segm', my_ss,
3833  a.arg), a.size)
3834 
3835  if not instr.name.lower() in mnemo_func:
3836  raise NotImplementedError("Mnemonic %s not implemented" % instr.name)
3837 
3838  instr_ir, extra_ir = mnemo_func[
3839  instr.name.lower()](self, instr, *args)
3840  self.mod_pc(instr, instr_ir, extra_ir)
3841 
3842  self.mod_pc(instr, instr_ir, extra_ir)
3843  instr.additional_info.except_on_instr = False
3844  if instr.additional_info.g1.value & 6 == 0 or \
3845  not instr.name in repeat_mn:
3846  return instr_ir, extra_ir
3847  if instr.name == "MOVSD" and len(instr.args) == 2:
3848  return instr_ir, extra_ir
3849 
3850  instr.additional_info.except_on_instr = True
3851  # get instruction size
3852  s = {"B": 8, "W": 16, "D": 32, 'Q': 64}[instr.name[-1]]
3853  size = instr.v_opmode()
3854  c_reg = mRCX[instr.mode][:size]
3855  out_ir = []
3856  zf_val = None
3857  # set if zf is tested (cmps, scas)
3858  for e in instr_ir: # +[updt_c]:
3859  if e.dst == zf:
3860  zf_val = e.src
3861 
3862  cond_dec = m2_expr.ExprCond(c_reg - m2_expr.ExprInt_from(c_reg, 1),
3863  m2_expr.ExprInt1(0), m2_expr.ExprInt1(1))
3864  # end condition
3865  if zf_val is None:
3866  c_cond = cond_dec
3867  elif instr.additional_info.g1.value & 2: # REPNE
3868  c_cond = cond_dec | zf
3869  elif instr.additional_info.g1.value & 4: # REP
3870  c_cond = cond_dec | (zf ^ m2_expr.ExprInt1(1))
3871 
3872  # gen while
3873  lbl_do = m2_expr.ExprId(self.gen_label(), instr.mode)
3874  lbl_end = m2_expr.ExprId(self.gen_label(), instr.mode)
3875  lbl_skip = m2_expr.ExprId(self.get_next_label(instr), instr.mode)
3876  lbl_next = m2_expr.ExprId(self.get_next_label(instr), instr.mode)
3877 
3878  for b in extra_ir:
3879  for ir in b.irs:
3880  for i, e in enumerate(ir):
3881  src = e.src.replace_expr({lbl_next: lbl_end})
3882  ir[i] = m2_expr.ExprAff(e.dst, src)
3883  cond_bloc = []
3884  cond_bloc.append(m2_expr.ExprAff(c_reg,
3885  c_reg - m2_expr.ExprInt_from(c_reg,
3886  1)))
3887  cond_bloc.append(m2_expr.ExprAff(self.IRDst, m2_expr.ExprCond(c_cond,
3888  lbl_skip,
3889  lbl_do)))
3890  cond_bloc = irbloc(lbl_end.name, [cond_bloc])
3891  e_do = instr_ir
3892 
3893  c = irbloc(lbl_do.name, [e_do])
3894  c.except_automod = False
3895  e_n = [m2_expr.ExprAff(self.IRDst, m2_expr.ExprCond(c_reg, lbl_do,
3896  lbl_skip))]
3897  return e_n, [cond_bloc, c] + extra_ir
def gen_label
Definition: ir.py:309
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.arch.x86.sem.ir_x86_16.get_ir (   self,
  instr 
)
inherited

Definition at line 3819 of file sem.py.

3820  def get_ir(self, instr):
3821  args = instr.args[:]
3822  args = [arg.replace_expr(float_replace) for arg in args]
3823  my_ss = None
3824  if self.do_ds_segm:
3825  my_ss = DS
3826  if self.do_all_segm and instr.additional_info.g2.value:
3827  my_ss = {1: CS, 2: SS, 3: DS, 4: ES, 5: FS, 6: GS}[
3828  instr.additional_info.g2.value]
3829  if my_ss is not None:
3830  for i, a in enumerate(args):
3831  if isinstance(a, m2_expr.ExprMem) and not a.is_op_segm():
3832  args[i] = m2_expr.ExprMem(m2_expr.ExprOp('segm', my_ss,
3833  a.arg), a.size)
3834 
3835  if not instr.name.lower() in mnemo_func:
3836  raise NotImplementedError("Mnemonic %s not implemented" % instr.name)
3837 
3838  instr_ir, extra_ir = mnemo_func[
3839  instr.name.lower()](self, instr, *args)
3840  self.mod_pc(instr, instr_ir, extra_ir)
3841 
3842  self.mod_pc(instr, instr_ir, extra_ir)
3843  instr.additional_info.except_on_instr = False
3844  if instr.additional_info.g1.value & 6 == 0 or \
3845  not instr.name in repeat_mn:
3846  return instr_ir, extra_ir
3847  if instr.name == "MOVSD" and len(instr.args) == 2:
3848  return instr_ir, extra_ir
3849 
3850  instr.additional_info.except_on_instr = True
3851  # get instruction size
3852  s = {"B": 8, "W": 16, "D": 32, 'Q': 64}[instr.name[-1]]
3853  size = instr.v_opmode()
3854  c_reg = mRCX[instr.mode][:size]
3855  out_ir = []
3856  zf_val = None
3857  # set if zf is tested (cmps, scas)
3858  for e in instr_ir: # +[updt_c]:
3859  if e.dst == zf:
3860  zf_val = e.src
3861 
3862  cond_dec = m2_expr.ExprCond(c_reg - m2_expr.ExprInt_from(c_reg, 1),
3863  m2_expr.ExprInt1(0), m2_expr.ExprInt1(1))
3864  # end condition
3865  if zf_val is None:
3866  c_cond = cond_dec
3867  elif instr.additional_info.g1.value & 2: # REPNE
3868  c_cond = cond_dec | zf
3869  elif instr.additional_info.g1.value & 4: # REP
3870  c_cond = cond_dec | (zf ^ m2_expr.ExprInt1(1))
3871 
3872  # gen while
3873  lbl_do = m2_expr.ExprId(self.gen_label(), instr.mode)
3874  lbl_end = m2_expr.ExprId(self.gen_label(), instr.mode)
3875  lbl_skip = m2_expr.ExprId(self.get_next_label(instr), instr.mode)
3876  lbl_next = m2_expr.ExprId(self.get_next_label(instr), instr.mode)
3877 
3878  for b in extra_ir:
3879  for ir in b.irs:
3880  for i, e in enumerate(ir):
3881  src = e.src.replace_expr({lbl_next: lbl_end})
3882  ir[i] = m2_expr.ExprAff(e.dst, src)
3883  cond_bloc = []
3884  cond_bloc.append(m2_expr.ExprAff(c_reg,
3885  c_reg - m2_expr.ExprInt_from(c_reg,
3886  1)))
3887  cond_bloc.append(m2_expr.ExprAff(self.IRDst, m2_expr.ExprCond(c_cond,
3888  lbl_skip,
3889  lbl_do)))
3890  cond_bloc = irbloc(lbl_end.name, [cond_bloc])
3891  e_do = instr_ir
3892 
3893  c = irbloc(lbl_do.name, [e_do])
3894  c.except_automod = False
3895  e_n = [m2_expr.ExprAff(self.IRDst, m2_expr.ExprCond(c_reg, lbl_do,
3896  lbl_skip))]
3897  return e_n, [cond_bloc, c] + extra_ir
def gen_label
Definition: ir.py:309
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.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_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_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.arch.x86.ira.ir_a_x86_16.get_out_regs (   self,
  b 
)
inherited

Definition at line 26 of file ira.py.

26 
27  def get_out_regs(self, b):
28  return set([self.ret_reg, self.sp])

+ 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.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.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.analysis.ira.graph (   self)
inherited
Output the graphviz script

Definition at line 88 of file analysis.py.

88 
89  def graph(self):
90  """Output the graphviz script"""
91  out = """
92  digraph asm_graph {
93  size="80,50";
94  node [
95  fontsize = "16",
96  shape = "box"
97  ];
98  """
99  all_lbls = {}
100  for lbl in self.g.nodes():
101  if lbl not in self.blocs:
102  continue
103  irb = self.blocs[lbl]
104  ir_txt = [str(lbl)]
105  for irs in irb.irs:
106  for l in irs:
107  ir_txt.append(str(l))
108  ir_txt.append("")
109  ir_txt.append("")
110  all_lbls[hash(lbl)] = "\l\\\n".join(ir_txt)
111  for l, v in all_lbls.items():
112  # print l, v
113  out += '%s [label="%s"];\n' % (l, v)
114 
115  for a, b in self.g.edges():
116  # print 'edge', a, b, hash(a), hash(b)
117  out += '%s -> %s;\n' % (hash(a), hash(b))
118  out += '}'
119  return out
def miasm2.ir.analysis.ira.init_useful_instr (   self)
inherited
Computes a set of triples (block, instruction number, instruction)
containing initially useful instructions :
  - Instructions affecting final value of return registers
  - Instructions affecting IRDst register
  - Instructions writing in memory
  - Function call instructions
Return set of intial useful instructions

Definition at line 140 of file analysis.py.

141  def init_useful_instr(self):
142  """Computes a set of triples (block, instruction number, instruction)
143  containing initially useful instructions :
144  - Instructions affecting final value of return registers
145  - Instructions affecting IRDst register
146  - Instructions writing in memory
147  - Function call instructions
148  Return set of intial useful instructions
149  """
150 
151  useful = set()
152 
153  for node in self.g.nodes():
154  if node not in self.blocs:
155  continue
156 
157  block = self.blocs[node]
158  successors = self.g.successors(node)
159  has_son = bool(successors)
160  for p_son in successors:
161  if p_son not in self.blocs:
162  # Leaf has lost its son: don't remove anything
163  # reaching this block
164  for r in self.ira_regs_ids():
165  useful.update(block.cur_reach[-1][r].union(
166  block.defout[-1][r]))
167 
168  # Function call, memory write or IRDst affectation
169  for k, ir in enumerate(block.irs):
170  for i_cur in ir:
171  if i_cur.src.is_function_call():
172  # /!\ never remove ir calls
173  useful.add((block.label, k, i_cur))
174  if isinstance(i_cur.dst, ExprMem):
175  useful.add((block.label, k, i_cur))
176  useful.update(block.defout[k][self.IRDst])
177 
178  # Affecting return registers
179  if not has_son:
180  for r in self.get_out_regs(block):
181  useful.update(block.defout[-1][r]
182  if block.defout[-1][r] else
183  block.cur_reach[-1][r])
184 
185  return useful

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.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.analysis.ira.ira_regs_ids (   self)
inherited
Returns ids of all registers used in the IR

Definition at line 19 of file analysis.py.

19 
20  def ira_regs_ids(self):
21  """Returns ids of all registers used in the IR"""
22  return self.arch.regs.all_regs_ids + [self.IRDst]

+ 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.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.arch.x86.sem.ir_x86_16.irbloc_fix_regs_for_mode (   self,
  irbloc,
  mode = 64 
)
inherited

Definition at line 3906 of file sem.py.

3907  def irbloc_fix_regs_for_mode(self, irbloc, mode=64):
3908  for irs in irbloc.irs:
3909  for i, e in enumerate(irs):
3910  """
3911  special case for 64 bits:
3912  if destination is a 32 bit reg, zero extend the 64 bit reg
3913  """
3914  if mode == 64:
3915  if (isinstance(e.dst, m2_expr.ExprId) and \
3916  e.dst.size == 32 and \
3917  e.dst in replace_regs[64]):
3918  src = self.expr_fix_regs_for_mode(e.src, mode)
3919  dst = replace_regs[64][e.dst].arg
3920  e = m2_expr.ExprAff(dst, src.zeroExtend(64))
3921  irs[i] = self.expr_fix_regs_for_mode(e, mode)
3922  irbloc.dst = self.expr_fix_regs_for_mode(irbloc.dst, mode)
3923 

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.arch.x86.sem.ir_x86_16.irbloc_fix_regs_for_mode (   self,
  irbloc,
  mode = 64 
)
inherited

Definition at line 3906 of file sem.py.

3907  def irbloc_fix_regs_for_mode(self, irbloc, mode=64):
3908  for irs in irbloc.irs:
3909  for i, e in enumerate(irs):
3910  """
3911  special case for 64 bits:
3912  if destination is a 32 bit reg, zero extend the 64 bit reg
3913  """
3914  if mode == 64:
3915  if (isinstance(e.dst, m2_expr.ExprId) and \
3916  e.dst.size == 32 and \
3917  e.dst in replace_regs[64]):
3918  src = self.expr_fix_regs_for_mode(e.src, mode)
3919  dst = replace_regs[64][e.dst].arg
3920  e = m2_expr.ExprAff(dst, src.zeroExtend(64))
3921  irs[i] = self.expr_fix_regs_for_mode(e, mode)
3922  irbloc.dst = self.expr_fix_regs_for_mode(irbloc.dst, mode)
3923 

+ Here is the call graph for this function:

+ 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.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.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.arch.x86.sem.ir_x86_64.mod_pc (   self,
  instr,
  instr_ir,
  extra_ir 
)
inherited

Definition at line 3949 of file sem.py.

3950  def mod_pc(self, instr, instr_ir, extra_ir):
3951  # fix RIP for 64 bit
3952  for i, expr in enumerate(instr_ir):
3953  dst, src = expr.dst, expr.src
3954  if dst != self.pc:
3955  dst = dst.replace_expr(
3956  {self.pc: m2_expr.ExprInt64(instr.offset + instr.l)})
3957  src = src.replace_expr(
3958  {self.pc: m2_expr.ExprInt64(instr.offset + instr.l)})
3959  instr_ir[i] = m2_expr.ExprAff(dst, src)
3960  for b in extra_ir:
3961  for irs in b.irs:
3962  for i, expr in enumerate(irs):
3963  dst, src = expr.dst, expr.src
3964  if dst != self.pc:
3965  new_pc = m2_expr.ExprInt64(instr.offset + instr.l)
3966  dst = dst.replace_expr({self.pc: new_pc})
3967  src = src.replace_expr(
3968  {self.pc: m2_expr.ExprInt64(instr.offset + instr.l)})
3969  irs[i] = m2_expr.ExprAff(dst, src)
def miasm2.arch.x86.ira.ir_a_x86_16.post_add_bloc (   self,
  bloc,
  ir_blocs 
)
inherited

Definition at line 40 of file ira.py.

40 
41  def post_add_bloc(self, bloc, ir_blocs):
42  ir.post_add_bloc(self, bloc, ir_blocs)
43  if not bloc.lines:
44  return
45  l = bloc.lines[-1]
46  sub_call_dst = None
47  if not l.is_subcall():
48  return
49  sub_call_dst = l.args[0]
50  if self.ExprIsLabel(sub_call_dst):
51  sub_call_dst = sub_call_dst.name
52  for b in ir_blocs:
53  l = b.lines[-1]
54  sub_call_dst = None
55  if not l.is_subcall():
56  continue
57  sub_call_dst = l.args[0]
58  if self.ExprIsLabel(sub_call_dst):
59  sub_call_dst = sub_call_dst.name
60  lbl = bloc.get_next()
61  new_lbl = self.gen_label()
62  irs = self.call_effects(l.args[0])
63  irs.append([ExprAff(self.IRDst, ExprId(lbl, size=self.pc.size))])
64 
65  nbloc = irbloc(new_lbl, irs)
66  nbloc.lines = [l]
67  self.blocs[new_lbl] = nbloc
68  b.dst = ExprId(new_lbl, size=self.pc.size)
69  return
70 
def ExprIsLabel
Definition: ir.py:337
def gen_label
Definition: ir.py:309

+ 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.analysis.ira.print_set (   v_set)
staticinherited
Print each triplet contained in a set
@v_set: set containing triplets elements

Definition at line 242 of file analysis.py.

243  def print_set(v_set):
244  """Print each triplet contained in a set
245  @v_set: set containing triplets elements
246  """
247  for p in v_set:
248  print ' (%s, %s, %s)' % p

+ Here is the caller graph for this function:

def miasm2.ir.analysis.ira.remove_dead_code (   self)
inherited
Remove dead instructions in each block of the graph using the reach
analysis .
Returns True if a block has been modified
PRE : compute_reach(self)

Definition at line 223 of file analysis.py.

224  def remove_dead_code(self):
225  """Remove dead instructions in each block of the graph using the reach
226  analysis .
227  Returns True if a block has been modified
228  PRE : compute_reach(self)
229  """
230  useful = self._mark_useful_code()
231  modified = False
232  for block in self.blocs.values():
233  modified |= self.remove_dead_instr(block, useful)
234  return modified

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def miasm2.ir.analysis.ira.remove_dead_instr (   self,
  irb,
  useful 
)
inherited
Remove dead affectations using previous reaches analysis
@irb: irbloc instance
@useful: useful statements from previous reach analysis
Return True iff the block state has changed
PRE: compute_reach(self)

Definition at line 120 of file analysis.py.

121  def remove_dead_instr(self, irb, useful):
122  """Remove dead affectations using previous reaches analysis
123  @irb: irbloc instance
124  @useful: useful statements from previous reach analysis
125  Return True iff the block state has changed
126  PRE: compute_reach(self)
127  """
128  modified = False
129  for k, ir in enumerate(irb.irs):
130  j = 0
131  while j < len(ir):
132  cur_instr = ir[j]
133  if (isinstance(cur_instr.dst, ExprId)
134  and (irb.label, k, cur_instr) not in useful):
135  del ir[j]
136  modified = True
137  else:
138  j += 1
139  return modified

+ 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.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.arch.x86.ira.ir_a_x86_16.set_dead_regs (   self,
  b 
)
inherited

Definition at line 18 of file ira.py.

18 
19  def set_dead_regs(self, b):
20  b.rw[-1][1].add(self.arch.regs.zf)
21  b.rw[-1][1].add(self.arch.regs.of)
22  b.rw[-1][1].add(self.arch.regs.pf)
23  b.rw[-1][1].add(self.arch.regs.cf)
24  b.rw[-1][1].add(self.arch.regs.nf)
25  b.rw[-1][1].add(self.arch.regs.af)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.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:

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:

def miasm2.arch.x86.ira.ir_a_x86_64.sizeof_char (   self)

Definition at line 110 of file ira.py.

111  def sizeof_char(self):
112  return 8
def miasm2.arch.x86.ira.ir_a_x86_64.sizeof_int (   self)

Definition at line 116 of file ira.py.

117  def sizeof_int(self):
118  return 32
def miasm2.arch.x86.ira.ir_a_x86_64.sizeof_long (   self)

Definition at line 119 of file ira.py.

120  def sizeof_long(self):
121  return 64
def miasm2.arch.x86.ira.ir_a_x86_64.sizeof_pointer (   self)

Definition at line 122 of file ira.py.

123  def sizeof_pointer(self):
124  return 64
def miasm2.arch.x86.ira.ir_a_x86_64.sizeof_short (   self)

Definition at line 113 of file ira.py.

114  def sizeof_short(self):
115  return 16
def miasm2.ir.analysis.ira.sort_dst (   self,
  todo,
  done 
)
inherited

Definition at line 23 of file analysis.py.

23 
24  def sort_dst(self, todo, done):
25  out = set()
26  while todo:
27  dst = todo.pop()
28  if self.ExprIsLabel(dst):
29  done.add(dst)
30  elif isinstance(dst, ExprMem) or isinstance(dst, ExprInt):
31  done.add(dst)
32  elif isinstance(dst, ExprCond):
33  todo.add(dst.src1)
34  todo.add(dst.src2)
35  elif isinstance(dst, ExprId):
36  out.add(dst)
37  else:
38  done.add(dst)
39  return out

+ Here is the call graph for this function:

+ 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.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.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.ir.ir.ir.blocs
inherited

Definition at line 128 of file ir.py.

miasm2.arch.x86.sem.ir_x86_64.do_all_segm
inherited

Definition at line 3944 of file sem.py.

miasm2.arch.x86.sem.ir_x86_64.do_ds_segm
inherited

Definition at line 3942 of file sem.py.

miasm2.arch.x86.sem.ir_x86_64.do_stk_segm
inherited

Definition at line 3941 of file sem.py.

miasm2.arch.x86.sem.ir_x86_64.do_str_segm
inherited

Definition at line 3943 of file sem.py.

miasm2.ir.analysis.ira.g
inherited

Definition at line 73 of file analysis.py.

miasm2.arch.x86.sem.ir_x86_64.IRDst
inherited

Definition at line 3947 of file sem.py.

miasm2.arch.x86.sem.ir_x86_64.pc
inherited

Definition at line 3945 of file sem.py.

miasm2.arch.x86.ira.ir_a_x86_64.ret_reg

Definition at line 97 of file ira.py.

miasm2.arch.x86.sem.ir_x86_64.sp
inherited

Definition at line 3946 of file sem.py.

miasm2.ir.ir.ir.symbol_pool
inherited

Definition at line 127 of file ir.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: