about summary refs log tree commit diff stats
path: root/example/ida/depgraph.py
diff options
context:
space:
mode:
Diffstat (limited to 'example/ida/depgraph.py')
-rw-r--r--example/ida/depgraph.py67
1 files changed, 35 insertions, 32 deletions
diff --git a/example/ida/depgraph.py b/example/ida/depgraph.py
index 5342313a..297877a1 100644
--- a/example/ida/depgraph.py
+++ b/example/ida/depgraph.py
@@ -19,16 +19,18 @@ from utils import guess_machine
 
 class depGraphSettingsForm(ida_kernwin.Form):
 
-    def __init__(self, ira):
+    def __init__(self, ira, ircfg):
 
         self.ira = ira
+        self.ircfg = ircfg
         self.stk_args = {'ARG%d' % i:i for i in xrange(10)}
         self.stk_unalias_force = False
 
         self.address = idc.ScreenEA()
         cur_block = None
-        for block in ira.getby_offset(self.address):
-            if block.label.offset is not None:
+        for block in ircfg.getby_offset(self.address):
+            offset = self.ircfg.loc_db.get_location_offset(block.loc_key)
+            if offset is not None:
                 # Only one block non-generated
                 assert cur_block is None
                 cur_block = block
@@ -38,8 +40,8 @@ class depGraphSettingsForm(ida_kernwin.Form):
             if assignblk.instr.offset == self.address:
                 break
         assert line_nb is not None
-        cur_label = str(cur_block.label)
-        labels = sorted(map(str, ira.blocks.keys()))
+        cur_loc_key = str(cur_block.loc_key)
+        loc_keys = sorted(map(str, ircfg.blocks.keys()))
         regs = sorted(ira.arch.regs.all_regs_ids_byname.keys())
         regs += self.stk_args.keys()
         reg_default = regs[0]
@@ -85,21 +87,21 @@ Method to use:
                 tp=ida_kernwin.Form.FT_RAWHEX,
                 value=line_nb),
             'cbBBL': ida_kernwin.Form.DropdownListControl(
-                    items=labels,
+                    items=loc_keys,
                     readonly=False,
-                    selval=cur_label),
+                    selval=cur_loc_key),
             'cColor': ida_kernwin.Form.ColorInput(value=0xc0c020),
         })
 
         self.Compile()
 
     @property
-    def label(self):
+    def loc_key(self):
         value = self.cbBBL.value
-        for real_label in self.ira.blocks:
-            if str(real_label) == value:
-                return real_label
-        raise ValueError("Bad label")
+        for real_loc_key in self.ircfg.blocks:
+            if str(real_loc_key) == value:
+                return real_loc_key
+        raise ValueError("Bad loc_key")
 
     @property
     def line_nb(self):
@@ -110,13 +112,13 @@ Method to use:
         elif mode == 1:
             return value + 1
         else:
-            return len(self.ira.blocks[self.label])
+            return len(self.ircfg.blocks[self.loc_key])
 
     @property
     def elements(self):
         value = self.cbReg.value
         if value in self.stk_args:
-            line = self.ira.blocks[self.label][self.line_nb].instr
+            line = self.ircfg.blocks[self.loc_key][self.line_nb].instr
             arg_num = self.stk_args[value]
             stk_high = m2_expr.ExprInt(idc.GetSpd(line.offset), ir_arch.sp.size)
             stk_off = m2_expr.ExprInt(self.ira.sp.size/8 * arg_num, ir_arch.sp.size)
@@ -134,7 +136,7 @@ Method to use:
     @property
     def depgraph(self):
         value = self.cMethod.value
-        return DependencyGraph(self.ira,
+        return DependencyGraph(self.ircfg,
                                implicit=value & 4,
                                follow_mem=value & 1,
                                follow_call=value & 2)
@@ -174,7 +176,7 @@ def treat_element():
 
     for node in graph.relevant_nodes:
         try:
-            offset = ir_arch.blocks[node.label][node.line_nb].instr.offset
+            offset = ir_arch.blocks[node.loc_key][node.line_nb].instr.offset
         except IndexError:
             print "Unable to highlight %s" % node
             continue
@@ -184,7 +186,7 @@ def treat_element():
     if graph.has_loop:
         print 'Graph has dependency loop: symbolic execution is inexact'
     else:
-        print "Possible value: %s" % graph.emul().values()[0]
+        print "Possible value: %s" % graph.emul(self.ira).values()[0]
 
     for offset, elements in comments.iteritems():
         idc.MakeComm(offset, ", ".join(map(str, elements)))
@@ -197,38 +199,39 @@ def next_element():
 
 def launch_depgraph():
     global graphs, comments, sol_nb, settings, addr, ir_arch
+    # Get the current function
+    addr = idc.ScreenEA()
+    func = ida_funcs.get_func(addr)
+
     # Init
-    machine = guess_machine()
+    machine = guess_machine(addr=func.startEA)
     mn, dis_engine, ira = machine.mn, machine.dis_engine, machine.ira
 
     bs = bin_stream_ida()
     mdis = dis_engine(bs, dont_dis_nulstart_bloc=True)
-    ir_arch = ira(mdis.symbol_pool)
+    ir_arch = ira(mdis.loc_db)
 
     # Populate symbols with ida names
     for ad, name in idautils.Names():
         if name is None:
             continue
-        mdis.symbol_pool.add_label(name, ad)
+        mdis.loc_db.add_location(name, ad)
 
-    # Get the current function
-    addr = idc.ScreenEA()
-    func = ida_funcs.get_func(addr)
-    blocks = mdis.dis_multiblock(func.startEA)
+    asmcfg = mdis.dis_multiblock(func.startEA)
 
     # Generate IR
-    for block in blocks:
-        ir_arch.add_block(block)
+    ircfg = ir_arch.new_ircfg_from_asmcfg(asmcfg)
 
     # Get settings
-    settings = depGraphSettingsForm(ir_arch)
+    settings = depGraphSettingsForm(ir_arch, ircfg)
     settings.Execute()
 
-    label, elements, line_nb = settings.label, settings.elements, settings.line_nb
+    loc_key, elements, line_nb = settings.loc_key, settings.elements, settings.line_nb
     # Simplify affectations
     for irb in ir_arch.blocks.values():
         irs = []
-        fix_stack = irb.label.offset is not None and settings.unalias_stack
+        offset = ir_arch.loc_db.get_location_offset(irb.loc_key)
+        fix_stack = offset is not None and settings.unalias_stack
         for assignblk in irb:
             if fix_stack:
                 stk_high = m2_expr.ExprInt(idc.GetSpd(assignblk.instr.offset), ir_arch.sp.size)
@@ -243,12 +246,12 @@ def launch_depgraph():
                 dst, src = expr_simp(dst), expr_simp(src)
                 new_assignblk[dst] = src
             irs.append(AssignBlock(new_assignblk, instr=assignblk.instr))
-        ir_arch.blocks[irb.label] = IRBlock(irb.label, irs)
+        ir_arch.blocks[irb.loc_key] = IRBlock(irb.loc_key, irs)
 
     # Get dependency graphs
     dg = settings.depgraph
-    graphs = dg.get(label, elements, line_nb,
-                    set([ir_arch.symbol_pool.getby_offset(func.startEA)]))
+    graphs = dg.get(loc_key, elements, line_nb,
+                    set([ir_arch.loc_db.get_offset_location(func.startEA)]))
 
     # Display the result
     comments = {}