From d8cbc059655bd275b5e178b2339b931d9f0b126a Mon Sep 17 00:00:00 2001 From: Fabrice Desclaux Date: Tue, 14 Feb 2017 15:33:17 +0100 Subject: IR/Symbexec: rename symbexec to SymbolicExecutionEngine --- example/expression/graph_dataflow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'example/expression/graph_dataflow.py') diff --git a/example/expression/graph_dataflow.py b/example/expression/graph_dataflow.py index 64801e52..16dbcbb6 100644 --- a/example/expression/graph_dataflow.py +++ b/example/expression/graph_dataflow.py @@ -7,7 +7,7 @@ from miasm2.arch.x86.ira import ir_a_x86_32 from miasm2.arch.x86.disasm import dis_x86_32 from miasm2.analysis.data_analysis import intra_bloc_flow_raw, inter_bloc_flow from miasm2.core.graph import DiGraph -from miasm2.ir.symbexec import symbexec +from miasm2.ir.symbexec import SymbolicExecutionEngine parser = ArgumentParser("Simple expression use for generating dataflow graph") @@ -51,7 +51,7 @@ def get_modified_symbols(sb): def intra_bloc_flow_symb(ir_arch, flow_graph, irbloc): symbols_init = ir_arch.arch.regs.regs_init.copy() - sb = symbexec(ir_arch, symbols_init) + sb = SymbolicExecutionEngine(ir_arch, symbols_init) sb.emulbloc(irbloc) print '*' * 40 print irbloc -- cgit 1.4.1 From c3940991f2461278fdb3c7faff8b270320585556 Mon Sep 17 00:00:00 2001 From: Fabrice Desclaux Date: Wed, 15 Feb 2017 07:20:23 +0100 Subject: IR: rename blocs to blocks --- example/disasm/full.py | 18 ++--- example/expression/asm_to_ir.py | 10 +-- example/expression/get_read_write.py | 2 +- example/expression/graph_dataflow.py | 40 +++++----- example/expression/solve_condition_stp.py | 6 +- example/ida/depgraph.py | 14 ++-- example/ida/graph_ir.py | 16 ++-- miasm2/analysis/data_analysis.py | 12 +-- miasm2/analysis/depgraph.py | 6 +- miasm2/analysis/disasm_cb.py | 6 +- miasm2/arch/mips32/ira.py | 2 +- miasm2/arch/x86/ira.py | 2 +- miasm2/ir/analysis.py | 24 +++--- miasm2/ir/ir.py | 30 ++++--- miasm2/jitter/jitcore.py | 14 ++-- test/analysis/depgraph.py | 54 ++++++------- test/ir/analysis.py | 126 +++++++++++++++--------------- 17 files changed, 193 insertions(+), 189 deletions(-) (limited to 'example/expression/graph_dataflow.py') diff --git a/example/disasm/full.py b/example/disasm/full.py index f15b59eb..6bea91cd 100644 --- a/example/disasm/full.py +++ b/example/disasm/full.py @@ -188,23 +188,23 @@ if args.gen_ir: ir_arch = ir(mdis.symbol_pool) ir_arch_a = ira(mdis.symbol_pool) - ir_arch.blocs = {} - ir_arch_a.blocs = {} - for ad, all_bloc in all_funcs_blocs.items(): + ir_arch.blocks = {} + ir_arch_a.blocks = {} + for ad, all_block in all_funcs_blocks.items(): log.info("generating IR... %x" % ad) for b in all_bloc: ir_arch_a.add_bloc(b) ir_arch.add_bloc(b) - log.info("Print blocs (without analyse)") - for label, bloc in ir_arch.blocs.iteritems(): - print bloc + log.info("Print blocks (without analyse)") + for label, block in ir_arch.blocks.iteritems(): + print block log.info("Gen Graph... %x" % ad) - log.info("Print blocs (with analyse)") - for label, bloc in ir_arch_a.blocs.iteritems(): - print bloc + log.info("Print blocks (with analyse)") + for label, block in ir_arch_a.blocks.iteritems(): + print block if args.simplify: ir_arch_a.dead_simp() diff --git a/example/expression/asm_to_ir.py b/example/expression/asm_to_ir.py index 2f8999a4..552ddd36 100644 --- a/example/expression/asm_to_ir.py +++ b/example/expression/asm_to_ir.py @@ -41,8 +41,8 @@ for b in blocs: ir_arch.add_bloc(b) # Display IR -for lbl, b in ir_arch.blocs.items(): - print b +for lbl, irblock in ir_arch.blocks.items(): + print irblock # Dead propagation open('graph.dot', 'w').write(ir_arch.graph.dot()) @@ -51,6 +51,6 @@ ir_arch.dead_simp() open('graph2.dot', 'w').write(ir_arch.graph.dot()) # Display new IR -print 'new ir blocs' -for lbl, b in ir_arch.blocs.items(): - print b +print 'new ir blocks' +for lbl, irblock in ir_arch.blocks.items(): + print irblock diff --git a/example/expression/get_read_write.py b/example/expression/get_read_write.py index cb9e0900..f4dde4b5 100644 --- a/example/expression/get_read_write.py +++ b/example/expression/get_read_write.py @@ -16,7 +16,7 @@ l.offset, l.l = 0, 15 ir_arch.add_instr(l) print '*' * 80 -for lbl, b in ir_arch.blocs.items(): +for lbl, b in ir_arch.blocks.items(): print b for irs in b.irs: o_r, o_w = get_rw(irs) diff --git a/example/expression/graph_dataflow.py b/example/expression/graph_dataflow.py index 16dbcbb6..0b01956f 100644 --- a/example/expression/graph_dataflow.py +++ b/example/expression/graph_dataflow.py @@ -110,28 +110,28 @@ def node2str(self, node): return out -def gen_bloc_data_flow_graph(ir_arch, ad, block_flow_cb): - for irbloc in ir_arch.blocs.values(): - print irbloc +def gen_block_data_flow_graph(ir_arch, ad, block_flow_cb): + for irblock in ir_arch.blocks.values(): + print irblock ir_arch.dead_simp() - irbloc_0 = None - for irbloc in ir_arch.blocs.values(): - if irbloc.label.offset == ad: - irbloc_0 = irbloc + irblock_0 = None + for irblock in ir_arch.blocks.values(): + if irblock.label.offset == ad: + irblock_0 = irblock break assert(irbloc_0 is not None) flow_graph = DiGraph() flow_graph.node2str = lambda n: node2str(flow_graph, n) - for irbloc in ir_arch.blocs.values(): - block_flow_cb(ir_arch, flow_graph, irbloc) + for irblock in ir_arch.blocks.values(): + block_flow_cb(ir_arch, flow_graph, irblock) - for irbloc in ir_arch.blocs.values(): - print irbloc - print 'IN', [str(x) for x in irbloc.in_nodes] - print 'OUT', [str(x) for x in irbloc.out_nodes] + for irblock in ir_arch.blocks.values(): + print irblock + print 'IN', [str(x) for x in irblock.in_nodes] + print 'OUT', [str(x) for x in irblock.out_nodes] print '*' * 20, 'interbloc', '*' * 20 inter_bloc_flow(ir_arch, flow_graph, irbloc_0.label) @@ -154,13 +154,13 @@ print 'ok' print 'generating dataflow graph for:' ir_arch = ir_a_x86_32(mdis.symbol_pool) -blocs = ab -for bloc in blocs: - print bloc - ir_arch.add_bloc(bloc) -for irbloc in ir_arch.blocs.values(): - print irbloc - if irbloc.label.offset != 0: +blocks = ab +for block in blocks: + print block + ir_arch.add_bloc(block) +for irblock in ir_arch.blocks.values(): + print irblock + if irblock.label.offset != 0: continue diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py index 841081b4..1f0f2967 100644 --- a/example/expression/solve_condition_stp.py +++ b/example/expression/solve_condition_stp.py @@ -40,7 +40,7 @@ def get_bloc(ir_arch, mdis, ad): l = ad else: l = mdis.symbol_pool.getby_offset_create(ad) - if not l in ir_arch.blocs: + if not l in ir_arch.blocks: ad = l.offset b = mdis.dis_bloc(ad) ir_arch.add_bloc(b) @@ -178,8 +178,8 @@ if __name__ == '__main__': sb.emulbloc(irb) sb.dump_mem() - # reset ir_arch blocs - ir_arch.blocs = {} + # reset ir_arch blocks + ir_arch.blocks = {} states_todo = set() states_done = set() diff --git a/example/ida/depgraph.py b/example/ida/depgraph.py index 002075ee..9024f2af 100644 --- a/example/ida/depgraph.py +++ b/example/ida/depgraph.py @@ -25,8 +25,8 @@ class depGraphSettingsForm(Form): for line_nb, l in enumerate(cur_bloc.lines): if l.offset == self.address: break - cur_label = str(cur_bloc.label) - labels = sorted(map(str, ira.blocs.keys())) + cur_label = str(cur_block.label) + labels = sorted(map(str, ira.blocks.keys())) regs = sorted(ir_arch.arch.regs.all_regs_ids_byname.keys()) regs += self.stk_args.keys() reg_default = regs[0] @@ -82,7 +82,7 @@ Method to use: @property def label(self): value = self.cbBBL.value - for real_label in self.ira.blocs: + for real_label in self.ira.blocks: if str(real_label) == value: return real_label raise ValueError("Bad label") @@ -96,13 +96,13 @@ Method to use: elif mode == 1: return value + 1 else: - return len(self.ira.blocs[self.label].irs) + return len(self.ira.blocks[self.label].irs) @property def elements(self): value = self.cbReg.value if value in self.stk_args: - line = self.ira.blocs[self.label].lines[self.line_nb] + line = self.ira.blocks[self.label].lines[self.line_nb] arg_num = self.stk_args[value] stk_high = m2_expr.ExprInt(GetSpd(line.offset), ir_arch.sp.size) stk_off = m2_expr.ExprInt(self.ira.sp.size/8 * arg_num, ir_arch.sp.size) @@ -163,7 +163,7 @@ settings.Execute() label, elements, line_nb = settings.label, settings.elements, settings.line_nb # Simplify affectations -for irb in ir_arch.blocs.values(): +for irb in ir_arch.blocks.values(): fix_stack = irb.label.offset is not None and settings.unalias_stack for i, assignblk in enumerate(irb.irs): if fix_stack: @@ -215,7 +215,7 @@ def treat_element(): for node in graph.relevant_nodes: try: - offset = ir_arch.blocs[node.label].lines[node.line_nb].offset + offset = ir_arch.blocks[node.label].lines[node.line_nb].offset except IndexError: print "Unable to highlight %s" % node continue diff --git a/example/ida/graph_ir.py b/example/ida/graph_ir.py index 188c8fa6..252dc612 100644 --- a/example/ida/graph_ir.py +++ b/example/ida/graph_ir.py @@ -48,11 +48,11 @@ class GraphMiasmIR(GraphViewer): print 'refresh' self.Clear() addr_id = {} - for irbloc in self.ir_arch.blocs.values(): + for irbloc in self.ir_arch.blocks.values(): id_irbloc = self.AddNode(color_irbloc(irbloc)) addr_id[irbloc] = id_irbloc - for irbloc in self.ir_arch.blocs.values(): + for irbloc in self.ir_arch.blocks.values(): if not irbloc: continue dst = ir_arch.dst_trackback(irbloc) @@ -61,9 +61,9 @@ class GraphMiasmIR(GraphViewer): continue d = d.name - if not d in self.ir_arch.blocs: + if not d in self.ir_arch.blocks: continue - b = self.ir_arch.blocs[d] + b = self.ir_arch.blocks[d] node1 = addr_id[irbloc] node2 = addr_id[b] self.AddEdge(node1, node2) @@ -133,7 +133,7 @@ for b in ab: print "IR ok... %x" % ad -for irb in ir_arch.blocs.values(): +for irb in ir_arch.blocks.values(): for assignblk in irb.irs: for dst, src in assignblk.items(): del(assignblk[dst]) @@ -201,7 +201,7 @@ def gen_bloc_data_flow_graph(ir_arch, in_str, ad): # arch, attrib, pool_bin, bl # ir_arch.dead_simp() irbloc_0 = None - for irbloc in ir_arch.blocs.values(): + for irbloc in ir_arch.blocks.values(): if irbloc.label.offset == ad: irbloc_0 = irbloc break @@ -212,11 +212,11 @@ def gen_bloc_data_flow_graph(ir_arch, in_str, ad): # arch, attrib, pool_bin, bl bloc2w = {} - for irbloc in ir_arch.blocs.values(): + for irbloc in ir_arch.blocks.values(): intra_bloc_flow_symbexec(ir_arch, flow_graph, irbloc) # intra_bloc_flow_symb(ir_arch, flow_graph, irbloc) - for irbloc in ir_arch.blocs.values(): + for irbloc in ir_arch.blocks.values(): print irbloc print 'IN', [str(x) for x in irbloc.in_nodes] print 'OUT', [str(x) for x in irbloc.out_nodes] diff --git a/miasm2/analysis/data_analysis.py b/miasm2/analysis/data_analysis.py index 8582f2f7..8703c0cd 100644 --- a/miasm2/analysis/data_analysis.py +++ b/miasm2/analysis/data_analysis.py @@ -116,10 +116,10 @@ def inter_bloc_flow_link(ir_arch, flow_graph, todo, link_exec_to_data): current_nodes = dict(current_nodes) # link current nodes to bloc in_nodes - if not lbl in ir_arch.blocs: + if not lbl in ir_arch.blocks: print "cannot find bloc!!", lbl return set() - irb = ir_arch.blocs[lbl] + irb = ir_arch.blocks[lbl] # pp(('IN', lbl, [(str(x[0]), str(x[1])) for x in current_nodes.items()])) to_del = set() for n_r, node_n_r in irb.in_nodes.items(): @@ -159,15 +159,15 @@ def create_implicit_flow(ir_arch, flow_graph): # first fix IN/OUT # If a son read a node which in not in OUT, add it - todo = set(ir_arch.blocs.keys()) + todo = set(ir_arch.blocks.keys()) while todo: lbl = todo.pop() - irb = ir_arch.blocs[lbl] + irb = ir_arch.blocks[lbl] for lbl_son in ir_arch.graph.successors(irb.label): - if not lbl_son in ir_arch.blocs: + if not lbl_son in ir_arch.blocks: print "cannot find bloc!!", lbl continue - irb_son = ir_arch.blocs[lbl_son] + irb_son = ir_arch.blocks[lbl_son] for n_r in irb_son.in_nodes: if n_r in irb.out_nodes: continue diff --git a/miasm2/analysis/depgraph.py b/miasm2/analysis/depgraph.py index f2e87c41..214cf819 100644 --- a/miasm2/analysis/depgraph.py +++ b/miasm2/analysis/depgraph.py @@ -293,7 +293,7 @@ class DependencyResult(DependencyState): line_nb = self.initial_state.line_nb else: line_nb = None - assignblks += self.irblock_slice(self._ira.blocs[label], + assignblks += self.irblock_slice(self._ira.blocks[label], line_nb).irs # Eval the block @@ -365,7 +365,7 @@ class DependencyResultImplicit(DependencyResult): line_nb = self.initial_state.line_nb else: line_nb = None - irb = self.irblock_slice(self._ira.blocs[label], line_nb) + irb = self.irblock_slice(self._ira.blocks[label], line_nb) # Emul the block and get back destination dst = symb_exec.emulbloc(irb, step=step) @@ -580,7 +580,7 @@ class DependencyGraph(object): """Follow dependencies tracked in @state in the current irbloc @state: instance of DependencyState""" - irb = self._ira.blocs[state.label] + irb = self._ira.blocks[state.label] line_nb = len(irb.irs) if state.line_nb is None else state.line_nb for cur_line_nb, assignblk in reversed(list(enumerate(irb.irs[:line_nb]))): diff --git a/miasm2/analysis/disasm_cb.py b/miasm2/analysis/disasm_cb.py index f1f23377..e2fa54cf 100644 --- a/miasm2/analysis/disasm_cb.py +++ b/miasm2/analysis/disasm_cb.py @@ -31,7 +31,7 @@ def arm_guess_subcall( print cur_bloc ir_arch.add_bloc(cur_bloc) - ir_blocs = ir_arch.blocs.values() + ir_blocks = ir_arch.blocks.values() # flow_graph = DiGraph() to_add = set() for irb in ir_blocs: @@ -78,8 +78,8 @@ def arm_guess_jump_table( ir_arch = ira(sp) ir_arch.add_bloc(cur_bloc) - ir_blocs = ir_arch.blocs.values() - for irb in ir_blocs: + ir_blocks = ir_arch.blocks.values() + for irblock in ir_blocks: # print 'X'*40 # print irb pc_val = None diff --git a/miasm2/arch/mips32/ira.py b/miasm2/arch/mips32/ira.py index bb51c055..630daa56 100644 --- a/miasm2/arch/mips32/ira.py +++ b/miasm2/arch/mips32/ira.py @@ -43,7 +43,7 @@ class ir_a_mips32l(ir_mips32l, ira): ExprId(lbl, size=self.pc.size))])) nblock = IRBlock(new_lbl, irs) nblock.lines = [line] * len(irs) - self.blocs[new_lbl] = nblock + self.blocks[new_lbl] = nblock irb.dst = ExprId(new_lbl, size=self.pc.size) def get_out_regs(self, _): diff --git a/miasm2/arch/x86/ira.py b/miasm2/arch/x86/ira.py index 1ff4cbe8..74aa0203 100644 --- a/miasm2/arch/x86/ira.py +++ b/miasm2/arch/x86/ira.py @@ -25,7 +25,7 @@ class ir_a_x86_16(ir_x86_16, ira): return set([self.ret_reg, self.sp]) def add_unused_regs(self): - leaves = [self.blocs[label] for label in self.g.leafs()] + leaves = [self.blocks[label] for label in self.g.leafs()] for irblock in leaves: self.set_dead_regs(irblock) diff --git a/miasm2/ir/analysis.py b/miasm2/ir/analysis.py index 2108cc53..6eb226ed 100644 --- a/miasm2/ir/analysis.py +++ b/miasm2/ir/analysis.py @@ -87,14 +87,14 @@ class ira(IntermediateRepresentation): useful = set() for node in self.graph.nodes(): - if node not in self.blocs: + if node not in self.blocks: continue - block = self.blocs[node] + block = self.blocks[node] successors = self.graph.successors(node) has_son = bool(successors) for p_son in successors: - if p_son not in self.blocs: + if p_son not in self.blocks: # Leaf has lost its son: don't remove anything # reaching this block for r in self.ira_regs_ids(): @@ -139,7 +139,7 @@ class ira(IntermediateRepresentation): useful.add(elem) irb_label, irs_ind, dst = elem - assignblk = self.blocs[irb_label].irs[irs_ind] + assignblk = self.blocks[irb_label].irs[irs_ind] ins = assignblk.dst2ExprAff(dst) # Handle dependencies of used variables in ins @@ -164,8 +164,8 @@ class ira(IntermediateRepresentation): """ useful = self._mark_useful_code() modified = False - for block in self.blocs.values(): - modified |= self.remove_dead_instr(block, useful) + for irblock in self.blocks.values(): + modified |= self.remove_dead_instr(irblock, useful) # Remove useless structures for assignblk in block.irs: del assignblk._cur_kill @@ -217,7 +217,7 @@ class ira(IntermediateRepresentation): # Compute reach from predecessors for n_pred in self.graph.predecessors(irb.label): - p_block = self.blocs[n_pred] + p_block = self.blocks[n_pred] # Handle each register definition for c_reg in self.ira_regs_ids(): @@ -256,8 +256,8 @@ class ira(IntermediateRepresentation): fixed = True for node in self.graph.nodes(): - if node in self.blocs: - irb = self.blocs[node] + if node in self.blocks: + irb = self.blocks[node] for assignblk in irb.irs: if (assignblk._cur_reach != assignblk._prev_reach or assignblk._cur_kill != assignblk._prev_kill): @@ -279,8 +279,8 @@ class ira(IntermediateRepresentation): log.debug('iteration...') while not fixed_point: for node in self.graph.nodes(): - if node in self.blocs: - self.compute_reach_block(self.blocs[node]) + if node in self.blocks: + self.compute_reach_block(self.blocks[node]) fixed_point = self._test_kill_reach_fix() def dead_simp(self): @@ -300,7 +300,7 @@ class ira(IntermediateRepresentation): self.simplify_blocs() def gen_equations(self): - for irb in self.blocs.values(): + for irb in self.blocks.values(): symbols_init = dict(self.arch.regs.all_regs_ids_init) sb = SymbolicExecutionEngine(self, dict(symbols_init)) diff --git a/miasm2/ir/ir.py b/miasm2/ir/ir.py index b993c356..a7076e2a 100644 --- a/miasm2/ir/ir.py +++ b/miasm2/ir/ir.py @@ -331,7 +331,7 @@ class IntermediateRepresentation(object): if symbol_pool is None: symbol_pool = asm_symbol_pool() self.symbol_pool = symbol_pool - self.blocs = {} + self.blocks = {} self.pc = arch.getpc(attrib) self.sp = arch.getsp(attrib) self.arch = arch @@ -339,6 +339,11 @@ class IntermediateRepresentation(object): # Lazy structure self._graph = None + @property + def get_blocs(self): + warnings.warn('DEPRECATION WARNING: use ".blocks" instead of ".blocs"') + return self.blocks + def get_ir(self, instr): raise NotImplementedError("Abstract Method") @@ -369,7 +374,7 @@ class IntermediateRepresentation(object): @ad: an ExprId/ExprInt/label/int""" label = self.get_label(ad) - return self.blocs.get(label, None) + return self.blocks.get(label, None) def add_instr(self, l, ad=0, gen_pc_updt=False): b = asm_bloc(self.gen_label()) @@ -378,7 +383,7 @@ class IntermediateRepresentation(object): def getby_offset(self, offset): out = set() - for irb in self.blocs.values(): + for irb in self.blocks.values(): for l in irb.lines: if l.offset <= offset < l.offset + l.l: out.add(irb) @@ -494,10 +499,9 @@ class IntermediateRepresentation(object): def post_add_bloc(self, bloc, ir_blocs): self.set_empty_dst_to_next(bloc, ir_blocs) - for irb in ir_blocs: - self.irbloc_fix_regs_for_mode(irb, self.attrib) - - self.blocs[irb.label] = irb + for irblock in ir_blocks: + self.irbloc_fix_regs_for_mode(irblock, self.attrib) + self.blocks[irblock.label] = irblock # Forget graph if any self._graph = None @@ -518,8 +522,8 @@ class IntermediateRepresentation(object): return l def simplify_blocs(self): - for irb in self.blocs.values(): - for assignblk in irb.irs: + for irblock in self.blocks.values(): + for assignblk in irblock.irs: for dst, src in assignblk.items(): del assignblk[dst] assignblk[expr_simp(dst)] = expr_simp(src) @@ -537,8 +541,8 @@ class IntermediateRepresentation(object): """ if regs_ids is None: regs_ids = [] - for b in self.blocs.values(): - b.get_rw(regs_ids) + for irblock in self.blocks.values(): + irblock.get_rw(regs_ids) def _extract_dst(self, todo, done): """ @@ -589,8 +593,8 @@ class IntermediateRepresentation(object): """ Gen irbloc digraph """ - self._graph = DiGraphIR(self.blocs) - for lbl, b in self.blocs.iteritems(): + self._graph = DiGraphIR(self.blocks) + for lbl, b in self.blocks.iteritems(): self._graph.add_node(lbl) dst = self.dst_trackback(b) for d in dst: diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py index 7e831280..651b71e3 100644 --- a/miasm2/jitter/jitcore.py +++ b/miasm2/jitter/jitcore.py @@ -117,14 +117,14 @@ class JitCore(object): raise NotImplementedError("Abstract class") - def add_bloc(self, b): - """Add a bloc to JiT and JiT it. - @b: the bloc to add + def add_bloc(self, block): + """Add a block to JiT and JiT it. + @block: asm_bloc to add """ - irblocs = self.ir_arch.add_bloc(b, gen_pc_updt = True) - b.irblocs = irblocs - self.jitirblocs(b.label, irblocs) + irblocks = self.ir_arch.add_bloc(block, gen_pc_updt = True) + b.blocks = irblocks + self.jitirblocs(block.label, irblocks) def disbloc(self, addr, vm): """Disassemble a new bloc and JiT it @@ -234,7 +234,7 @@ class JitCore(object): # Remove modified blocs for b in modified_blocs: try: - for irbloc in b.irblocs: + for irblock in block.blocks: # Remove offset -> jitted bloc link if irbloc.label.offset in self.lbl2jitbloc: diff --git a/test/analysis/depgraph.py b/test/analysis/depgraph.py index b5065722..429f7dc8 100644 --- a/test/analysis/depgraph.py +++ b/test/analysis/depgraph.py @@ -119,8 +119,8 @@ def bloc2graph(irgraph, label=False, lines=True): else: label_name = str(label) - if hasattr(irgraph, 'blocs'): - irblock = irgraph.blocs[label] + if hasattr(irgraph, 'blocks'): + irblock = irgraph.blocks[label] else: irblock = None if isinstance(label, asm_label): @@ -239,7 +239,7 @@ G1_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B)]]) G1_IRA.graph.add_uniq_edge(G1_IRB0.label, G1_IRB1.label) G1_IRA.graph.add_uniq_edge(G1_IRB1.label, G1_IRB2.label) -G1_IRA.blocs = dict([(irb.label, irb) for irb in [G1_IRB0, G1_IRB1, G1_IRB2]]) +G1_IRA.blocks = dict([(irb.label, irb) for irb in [G1_IRB0, G1_IRB1, G1_IRB2]]) # graph 2 @@ -252,7 +252,7 @@ G2_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B + C)]]) G2_IRA.graph.add_uniq_edge(G2_IRB0.label, G2_IRB1.label) G2_IRA.graph.add_uniq_edge(G2_IRB1.label, G2_IRB2.label) -G2_IRA.blocs = dict([(irb.label, irb) for irb in [G2_IRB0, G2_IRB1, G2_IRB2]]) +G2_IRA.blocks = dict([(irb.label, irb) for irb in [G2_IRB0, G2_IRB1, G2_IRB2]]) # graph 3 @@ -269,8 +269,8 @@ G3_IRA.graph.add_uniq_edge(G3_IRB0.label, G3_IRB2.label) G3_IRA.graph.add_uniq_edge(G3_IRB1.label, G3_IRB3.label) G3_IRA.graph.add_uniq_edge(G3_IRB2.label, G3_IRB3.label) -G3_IRA.blocs = dict([(irb.label, irb) for irb in [G3_IRB0, G3_IRB1, - G3_IRB2, G3_IRB3]]) +G3_IRA.blocks = dict([(irb.label, irb) for irb in [G3_IRB0, G3_IRB1, + G3_IRB2, G3_IRB3]]) # graph 4 @@ -288,7 +288,7 @@ G4_IRA.graph.add_uniq_edge(G4_IRB0.label, G4_IRB1.label) G4_IRA.graph.add_uniq_edge(G4_IRB1.label, G4_IRB2.label) G4_IRA.graph.add_uniq_edge(G4_IRB1.label, G4_IRB1.label) -G4_IRA.blocs = dict([(irb.label, irb) for irb in [G4_IRB0, G4_IRB1, G4_IRB2]]) +G4_IRA.blocks = dict([(irb.label, irb) for irb in [G4_IRB0, G4_IRB1, G4_IRB2]]) # graph 5 @@ -307,7 +307,7 @@ G5_IRA.graph.add_uniq_edge(G5_IRB0.label, G5_IRB1.label) G5_IRA.graph.add_uniq_edge(G5_IRB1.label, G5_IRB2.label) G5_IRA.graph.add_uniq_edge(G5_IRB1.label, G5_IRB1.label) -G5_IRA.blocs = dict([(irb.label, irb) for irb in [G5_IRB0, G5_IRB1, G5_IRB2]]) +G5_IRA.blocks = dict([(irb.label, irb) for irb in [G5_IRB0, G5_IRB1, G5_IRB2]]) # graph 6 @@ -319,7 +319,7 @@ G6_IRB1 = gen_irblock(LBL1, [[ExprAff(A, B)]]) G6_IRA.graph.add_uniq_edge(G6_IRB0.label, G6_IRB1.label) G6_IRA.graph.add_uniq_edge(G6_IRB1.label, G6_IRB1.label) -G6_IRA.blocs = dict([(irb.label, irb) for irb in [G6_IRB0, G6_IRB1]]) +G6_IRA.blocks = dict([(irb.label, irb) for irb in [G6_IRB0, G6_IRB1]]) # graph 7 @@ -333,7 +333,7 @@ G7_IRA.graph.add_uniq_edge(G7_IRB0.label, G7_IRB1.label) G7_IRA.graph.add_uniq_edge(G7_IRB1.label, G7_IRB1.label) G7_IRA.graph.add_uniq_edge(G7_IRB1.label, G7_IRB2.label) -G7_IRA.blocs = dict([(irb.label, irb) for irb in [G7_IRB0, G7_IRB1, G7_IRB2]]) +G7_IRA.blocks = dict([(irb.label, irb) for irb in [G7_IRB0, G7_IRB1, G7_IRB2]]) # graph 8 @@ -347,7 +347,7 @@ G8_IRA.graph.add_uniq_edge(G8_IRB0.label, G8_IRB1.label) G8_IRA.graph.add_uniq_edge(G8_IRB1.label, G8_IRB1.label) G8_IRA.graph.add_uniq_edge(G8_IRB1.label, G8_IRB2.label) -G8_IRA.blocs = dict([(irb.label, irb) for irb in [G8_IRB0, G8_IRB1, G8_IRB2]]) +G8_IRA.blocks = dict([(irb.label, irb) for irb in [G8_IRB0, G8_IRB1, G8_IRB2]]) # graph 9 is graph 8 @@ -361,7 +361,7 @@ G10_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B)]]) G10_IRA.graph.add_uniq_edge(G10_IRB1.label, G10_IRB2.label) G10_IRA.graph.add_uniq_edge(G10_IRB1.label, G10_IRB1.label) -G10_IRA.blocs = dict([(irb.label, irb) for irb in [G10_IRB1, G10_IRB2]]) +G10_IRA.blocks = dict([(irb.label, irb) for irb in [G10_IRB1, G10_IRB2]]) # graph 11 @@ -376,8 +376,8 @@ G11_IRB2 = gen_irblock(LBL2, [[ExprAff(A, A - B)]]) G11_IRA.graph.add_uniq_edge(G11_IRB0.label, G11_IRB1.label) G11_IRA.graph.add_uniq_edge(G11_IRB1.label, G11_IRB2.label) -G11_IRA.blocs = dict([(irb.label, irb) - for irb in [G11_IRB0, G11_IRB1, G11_IRB2]]) +G11_IRA.blocks = dict([(irb.label, irb) + for irb in [G11_IRB0, G11_IRB1, G11_IRB2]]) # graph 12 @@ -391,8 +391,8 @@ G12_IRA.graph.add_uniq_edge(G12_IRB0.label, G12_IRB1.label) G12_IRA.graph.add_uniq_edge(G12_IRB1.label, G12_IRB2.label) G12_IRA.graph.add_uniq_edge(G12_IRB1.label, G12_IRB1.label) -G12_IRA.blocs = dict([(irb.label, irb) for irb in [G12_IRB0, G12_IRB1, - G12_IRB2]]) +G12_IRA.blocks = dict([(irb.label, irb) for irb in [G12_IRB0, G12_IRB1, + G12_IRB2]]) # graph 13 @@ -420,8 +420,8 @@ G13_IRA.graph.add_uniq_edge(G13_IRB1.label, G13_IRB2.label) G13_IRA.graph.add_uniq_edge(G13_IRB2.label, G13_IRB1.label) G13_IRA.graph.add_uniq_edge(G13_IRB1.label, G13_IRB3.label) -G13_IRA.blocs = dict([(irb.label, irb) for irb in [G13_IRB0, G13_IRB1, - G13_IRB2, G13_IRB3]]) +G13_IRA.blocks = dict([(irb.label, irb) for irb in [G13_IRB0, G13_IRB1, + G13_IRB2, G13_IRB3]]) # graph 14 @@ -450,8 +450,8 @@ G14_IRA.graph.add_uniq_edge(G14_IRB1.label, G14_IRB2.label) G14_IRA.graph.add_uniq_edge(G14_IRB2.label, G14_IRB1.label) G14_IRA.graph.add_uniq_edge(G14_IRB1.label, G14_IRB3.label) -G14_IRA.blocs = dict([(irb.label, irb) for irb in [G14_IRB0, G14_IRB1, - G14_IRB2, G14_IRB3]]) +G14_IRA.blocks = dict([(irb.label, irb) for irb in [G14_IRB0, G14_IRB1, + G14_IRB2, G14_IRB3]]) # graph 16 @@ -467,8 +467,8 @@ G15_IRA.graph.add_uniq_edge(G15_IRB0.label, G15_IRB1.label) G15_IRA.graph.add_uniq_edge(G15_IRB1.label, G15_IRB2.label) G15_IRA.graph.add_uniq_edge(G15_IRB1.label, G15_IRB1.label) -G15_IRA.blocs = dict([(irb.label, irb) for irb in [G15_IRB0, G15_IRB1, - G15_IRB2]]) +G15_IRA.blocks = dict([(irb.label, irb) for irb in [G15_IRB0, G15_IRB1, + G15_IRB2]]) # graph 16 @@ -490,9 +490,9 @@ G16_IRA.graph.add_uniq_edge(G16_IRB1.label, G16_IRB4.label) G16_IRA.graph.add_uniq_edge(G16_IRB4.label, G16_IRB1.label) G16_IRA.graph.add_uniq_edge(G16_IRB1.label, G16_IRB5.label) -G16_IRA.blocs = dict([(irb.label, irb) for irb in [G16_IRB0, G16_IRB1, - G16_IRB2, G16_IRB3, - G16_IRB4, G16_IRB5]]) +G16_IRA.blocks = dict([(irb.label, irb) for irb in [G16_IRB0, G16_IRB1, + G16_IRB2, G16_IRB3, + G16_IRB4, G16_IRB5]]) # graph 17 @@ -507,8 +507,8 @@ G17_IRB2 = gen_irblock(LBL2, [[ExprAff(A, A - B)]]) G17_IRA.graph.add_uniq_edge(G17_IRB0.label, G17_IRB1.label) G17_IRA.graph.add_uniq_edge(G17_IRB1.label, G17_IRB2.label) -G17_IRA.blocs = dict([(irb.label, irb) for irb in [G17_IRB0, G17_IRB1, - G17_IRB2]]) +G17_IRA.blocks = dict([(irb.label, irb) for irb in [G17_IRB0, G17_IRB1, + G17_IRB2]]) # Test graph 1 G1_TEST1_DN1 = DependencyNode( diff --git a/test/ir/analysis.py b/test/ir/analysis.py index 788586a0..2446b5ba 100644 --- a/test/ir/analysis.py +++ b/test/ir/analysis.py @@ -83,7 +83,7 @@ G1_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) G1_IRA.graph.add_uniq_edge(G1_IRB0.label, G1_IRB1.label) G1_IRA.graph.add_uniq_edge(G1_IRB1.label, G1_IRB2.label) -G1_IRA.blocs = {irb.label : irb for irb in [G1_IRB0, G1_IRB1, G1_IRB2]} +G1_IRA.blocks = {irb.label : irb for irb in [G1_IRB0, G1_IRB1, G1_IRB2]} # Expected output for graph 1 G1_EXP_IRA = IRATest() @@ -92,8 +92,8 @@ G1_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(b, CST2)]]) G1_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(a, b)]]) G1_EXP_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) -G1_EXP_IRA.blocs = {irb.label : irb for irb in [G1_EXP_IRB0, G1_EXP_IRB1, - G1_EXP_IRB2]} +G1_EXP_IRA.blocks = {irb.label : irb for irb in [G1_EXP_IRB0, G1_EXP_IRB1, + G1_EXP_IRB2]} # graph 2 : Natural loop with dead variable @@ -107,7 +107,7 @@ G2_IRA.graph.add_uniq_edge(G2_IRB0.label, G2_IRB1.label) G2_IRA.graph.add_uniq_edge(G2_IRB1.label, G2_IRB2.label) G2_IRA.graph.add_uniq_edge(G2_IRB1.label, G2_IRB1.label) -G2_IRA.blocs = {irb.label : irb for irb in [G2_IRB0, G2_IRB1, G2_IRB2]} +G2_IRA.blocks = {irb.label : irb for irb in [G2_IRB0, G2_IRB1, G2_IRB2]} # Expected output for graph 2 G2_EXP_IRA = IRATest() @@ -116,8 +116,8 @@ G2_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(r, CST1)]]) G2_EXP_IRB1 = gen_irblock(LBL1, [[]]) G2_EXP_IRB2 = gen_irblock(LBL2, [[]]) -G2_EXP_IRA.blocs = {irb.label : irb for irb in [G2_EXP_IRB0, G2_EXP_IRB1, - G2_EXP_IRB2]} +G2_EXP_IRA.blocks = {irb.label : irb for irb in [G2_EXP_IRB0, G2_EXP_IRB1, + G2_EXP_IRB2]} # graph 3 : Natural loop with alive variables @@ -131,7 +131,7 @@ G3_IRA.graph.add_uniq_edge(G3_IRB0.label, G3_IRB1.label) G3_IRA.graph.add_uniq_edge(G3_IRB1.label, G3_IRB2.label) G3_IRA.graph.add_uniq_edge(G3_IRB1.label, G3_IRB1.label) -G3_IRA.blocs = {irb.label : irb for irb in [G3_IRB0, G3_IRB1, G3_IRB2]} +G3_IRA.blocks = {irb.label : irb for irb in [G3_IRB0, G3_IRB1, G3_IRB2]} # Expected output for graph 3 G3_EXP_IRA = IRATest() @@ -140,8 +140,8 @@ G3_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]]) G3_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]]) G3_EXP_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) -G3_EXP_IRA.blocs = {irb.label : irb for irb in [G3_EXP_IRB0, G3_EXP_IRB1, - G3_EXP_IRB2]} +G3_EXP_IRA.blocks = {irb.label : irb for irb in [G3_EXP_IRB0, G3_EXP_IRB1, + G3_EXP_IRB2]} # graph 4 : If/else with dead variables @@ -157,8 +157,8 @@ G4_IRA.graph.add_uniq_edge(G4_IRB0.label, G4_IRB2.label) G4_IRA.graph.add_uniq_edge(G4_IRB1.label, G4_IRB3.label) G4_IRA.graph.add_uniq_edge(G4_IRB2.label, G4_IRB3.label) -G4_IRA.blocs = {irb.label : irb for irb in [G4_IRB0, G4_IRB1, G4_IRB2, - G4_IRB3]} +G4_IRA.blocks = {irb.label : irb for irb in [G4_IRB0, G4_IRB1, G4_IRB2, + G4_IRB3]} # Expected output for graph 4 G4_EXP_IRA = IRATest() @@ -168,8 +168,8 @@ G4_EXP_IRB1 = gen_irblock(LBL1, [[]]) G4_EXP_IRB2 = gen_irblock(LBL2, [[]]) G4_EXP_IRB3 = gen_irblock(LBL3, [[ExprAff(a, CST3)], [ExprAff(r, a)]]) -G4_EXP_IRA.blocs = {irb.label : irb for irb in [G4_EXP_IRB0, G4_EXP_IRB1, - G4_EXP_IRB2, G4_EXP_IRB3]} +G4_EXP_IRA.blocks = {irb.label : irb for irb in [G4_EXP_IRB0, G4_EXP_IRB1, + G4_EXP_IRB2, G4_EXP_IRB3]} # graph 5 : Loop and If/else with dead variables @@ -190,8 +190,8 @@ G5_IRA.graph.add_uniq_edge(G5_IRB3.label, G5_IRB4.label) G5_IRA.graph.add_uniq_edge(G5_IRB4.label, G5_IRB5.label) G5_IRA.graph.add_uniq_edge(G5_IRB4.label, G5_IRB1.label) -G5_IRA.blocs = {irb.label : irb for irb in [G5_IRB0, G5_IRB1, G5_IRB2, G5_IRB3, - G5_IRB4, G5_IRB5]} +G5_IRA.blocks = {irb.label : irb for irb in [G5_IRB0, G5_IRB1, G5_IRB2, G5_IRB3, + G5_IRB4, G5_IRB5]} # Expected output for graph 5 G5_EXP_IRA = IRATest() @@ -203,9 +203,9 @@ G5_EXP_IRB3 = gen_irblock(LBL3, [[]]) G5_EXP_IRB4 = gen_irblock(LBL4, [[]]) G5_EXP_IRB5 = gen_irblock(LBL5, [[]]) -G5_EXP_IRA.blocs = {irb.label : irb for irb in [G5_EXP_IRB0, G5_EXP_IRB1, - G5_EXP_IRB2, G5_EXP_IRB3, - G5_EXP_IRB4, G5_EXP_IRB5]} +G5_EXP_IRA.blocks = {irb.label : irb for irb in [G5_EXP_IRB0, G5_EXP_IRB1, + G5_EXP_IRB2, G5_EXP_IRB3, + G5_EXP_IRB4, G5_EXP_IRB5]} # graph 6 : Natural loop with dead variables symetric affectation # (a = b <-> b = a ) @@ -223,8 +223,8 @@ G6_IRA.graph.add_uniq_edge(G6_IRB1.label, G6_IRB2.label) G6_IRA.graph.add_uniq_edge(G6_IRB2.label, G6_IRB1.label) G6_IRA.graph.add_uniq_edge(G6_IRB2.label, G6_IRB3.label) -G6_IRA.blocs = {irb.label : irb for irb in [G6_IRB0, G6_IRB1, G6_IRB2, - G6_IRB3]} +G6_IRA.blocks = {irb.label : irb for irb in [G6_IRB0, G6_IRB1, G6_IRB2, + G6_IRB3]} # Expected output for graph 6 G6_EXP_IRA = IRATest() @@ -234,8 +234,8 @@ G6_EXP_IRB1 = gen_irblock(LBL1, [[]]) G6_EXP_IRB2 = gen_irblock(LBL2, [[]]) G6_EXP_IRB3 = gen_irblock(LBL3, [[ExprAff(r, CST2)]]) -G6_EXP_IRA.blocs = {irb.label : irb for irb in [G6_EXP_IRB0, G6_EXP_IRB1, - G6_EXP_IRB2, G6_EXP_IRB3]} +G6_EXP_IRA.blocks = {irb.label : irb for irb in [G6_EXP_IRB0, G6_EXP_IRB1, + G6_EXP_IRB2, G6_EXP_IRB3]} # graph 7 : Double entry loop with dead variables @@ -254,8 +254,8 @@ G7_IRA.graph.add_uniq_edge(G7_IRB2.label, G7_IRB3.label) G7_IRA.graph.add_uniq_edge(G7_IRB0.label, G7_IRB2.label) -G7_IRA.blocs = {irb.label : irb for irb in [G7_IRB0, G7_IRB1, G7_IRB2, - G7_IRB3]} +G7_IRA.blocks = {irb.label : irb for irb in [G7_IRB0, G7_IRB1, G7_IRB2, + G7_IRB3]} # Expected output for graph 7 G7_EXP_IRA = IRATest() @@ -265,8 +265,8 @@ G7_EXP_IRB1 = gen_irblock(LBL1, [[]]) G7_EXP_IRB2 = gen_irblock(LBL2, [[]]) G7_EXP_IRB3 = gen_irblock(LBL3, [[]]) -G7_EXP_IRA.blocs = {irb.label : irb for irb in [G7_EXP_IRB0, G7_EXP_IRB1, - G7_EXP_IRB2, G7_EXP_IRB3]} +G7_EXP_IRA.blocks = {irb.label : irb for irb in [G7_EXP_IRB0, G7_EXP_IRB1, + G7_EXP_IRB2, G7_EXP_IRB3]} # graph 8 : Nested loops with dead variables @@ -285,8 +285,8 @@ G8_IRA.graph.add_uniq_edge(G8_IRB2.label, G8_IRB3.label) G8_IRA.graph.add_uniq_edge(G8_IRB3.label, G8_IRB2.label) -G8_IRA.blocs = {irb.label : irb for irb in [G8_IRB0, G8_IRB1, G8_IRB2, - G8_IRB3]} +G8_IRA.blocks = {irb.label : irb for irb in [G8_IRB0, G8_IRB1, G8_IRB2, + G8_IRB3]} # Expected output for graph 8 @@ -297,8 +297,8 @@ G8_EXP_IRB1 = gen_irblock(LBL1, [[]]) G8_EXP_IRB2 = gen_irblock(LBL2, [[]]) G8_EXP_IRB3 = gen_irblock(LBL3, [[]]) -G8_EXP_IRA.blocs = {irb.label : irb for irb in [G8_EXP_IRB0, G8_EXP_IRB1, - G8_EXP_IRB2, G8_EXP_IRB3]} +G8_EXP_IRA.blocks = {irb.label : irb for irb in [G8_EXP_IRB0, G8_EXP_IRB1, + G8_EXP_IRB2, G8_EXP_IRB3]} # graph 9 : Miultiple-exits loops with dead variables @@ -321,8 +321,8 @@ G9_IRA.graph.add_uniq_edge(G9_IRB2.label, G9_IRB3.label) G9_IRA.graph.add_uniq_edge(G9_IRB3.label, G9_IRB4.label) -G9_IRA.blocs = {irb.label : irb for irb in [G9_IRB0, G9_IRB1, G9_IRB2, - G9_IRB3, G9_IRB4]} +G9_IRA.blocks = {irb.label : irb for irb in [G9_IRB0, G9_IRB1, G9_IRB2, + G9_IRB3, G9_IRB4]} # Expected output for graph 9 @@ -334,9 +334,9 @@ G9_EXP_IRB2 = gen_irblock(LBL2, [[], [ExprAff(b, b+CST2)]]) G9_EXP_IRB3 = gen_irblock(LBL3, [[]]) G9_EXP_IRB4 = gen_irblock(LBL4, [[], [ExprAff(r, b)]]) -G9_EXP_IRA.blocs = {irb.label : irb for irb in [G9_EXP_IRB0, G9_EXP_IRB1, - G9_EXP_IRB2, G9_EXP_IRB3, - G9_EXP_IRB4]} +G9_EXP_IRA.blocks = {irb.label : irb for irb in [G9_EXP_IRB0, G9_EXP_IRB1, + G9_EXP_IRB2, G9_EXP_IRB3, + G9_EXP_IRB4]} # graph 10 : Natural loop with alive variables symetric affectation # (a = b <-> b = a ) @@ -354,8 +354,8 @@ G10_IRA.graph.add_uniq_edge(G10_IRB1.label, G10_IRB2.label) G10_IRA.graph.add_uniq_edge(G10_IRB2.label, G10_IRB1.label) G10_IRA.graph.add_uniq_edge(G10_IRB2.label, G10_IRB3.label) -G10_IRA.blocs = {irb.label : irb for irb in [G10_IRB0, G10_IRB1, - G10_IRB2, G10_IRB3]} +G10_IRA.blocks = {irb.label : irb for irb in [G10_IRB0, G10_IRB1, + G10_IRB2, G10_IRB3]} # Expected output for graph 10 G10_EXP_IRA = IRATest() @@ -365,8 +365,8 @@ G10_EXP_IRB1 = gen_irblock(LBL1, [[]]) G10_EXP_IRB2 = gen_irblock(LBL2, [[]]) G10_EXP_IRB3 = gen_irblock(LBL3, [[ExprAff(r, CST1)]]) -G10_EXP_IRA.blocs = {irb.label : irb for irb in [G10_EXP_IRB0, G10_EXP_IRB1, - G10_EXP_IRB2, G10_EXP_IRB3]} +G10_EXP_IRA.blocks = {irb.label : irb for irb in [G10_EXP_IRB0, G10_EXP_IRB1, + G10_EXP_IRB2, G10_EXP_IRB3]} # graph 11 : If/Else conditions with alive variables @@ -385,7 +385,7 @@ G11_IRA.graph.add_uniq_edge(G11_IRB1.label, G11_IRB0.label) #G11_IRA.graph.add_uniq_edge(G11_IRB4.label, G11_IRB0.label) G11_IRA.graph.add_uniq_edge(G11_IRB1.label, G11_IRB2.label) -G11_IRA.blocs = {irb.label : irb for irb in [G11_IRB0, G11_IRB1, G11_IRB2]} +G11_IRA.blocks = {irb.label : irb for irb in [G11_IRB0, G11_IRB1, G11_IRB2]} # Expected output for graph 11 G11_EXP_IRA = IRATest() @@ -396,8 +396,8 @@ G11_EXP_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) #G11_EXP_IRB3 = gen_irblock(LBL3, [[ExprAff(a, a+CST1)]]) #G11_EXP_IRB4 = gen_irblock(LBL4, [[ExprAff(b, b+CST1)]]) -G11_EXP_IRA.blocs = {irb.label : irb for irb in [G11_EXP_IRB0, G11_EXP_IRB1, - G11_EXP_IRB2]} +G11_EXP_IRA.blocks = {irb.label : irb for irb in [G11_EXP_IRB0, G11_EXP_IRB1, + G11_EXP_IRB2]} # graph 12 : Graph with multiple out points and useless definitions # of return register @@ -417,8 +417,8 @@ G12_IRA.graph.add_uniq_edge(G12_IRB2.label, G12_IRB3.label) G12_IRA.graph.add_uniq_edge(G12_IRB2.label, G12_IRB4.label) G12_IRA.graph.add_uniq_edge(G12_IRB4.label, G12_IRB5.label) -G12_IRA.blocs = {irb.label : irb for irb in [G12_IRB0, G12_IRB1, G12_IRB2, - G12_IRB3, G12_IRB4, G12_IRB5]} +G12_IRA.blocks = {irb.label : irb for irb in [G12_IRB0, G12_IRB1, G12_IRB2, + G12_IRB3, G12_IRB4, G12_IRB5]} # Expected output for graph 12 G12_EXP_IRA = IRATest() @@ -431,9 +431,9 @@ G12_EXP_IRB4 = gen_irblock(LBL4, [[]]) G12_EXP_IRB5 = gen_irblock(LBL5, [[ExprAff(r, b)]]) -G12_EXP_IRA.blocs = {irb.label : irb for irb in [G12_EXP_IRB0, G12_EXP_IRB1, - G12_EXP_IRB2, G12_EXP_IRB3, - G12_EXP_IRB4, G12_EXP_IRB5]} +G12_EXP_IRA.blocks = {irb.label : irb for irb in [G12_EXP_IRB0, G12_EXP_IRB1, + G12_EXP_IRB2, G12_EXP_IRB3, + G12_EXP_IRB4, G12_EXP_IRB5]} # graph 13 : Graph where a leaf has lost its son @@ -451,8 +451,8 @@ G13_IRA.graph.add_uniq_edge(G13_IRB0.label, G13_IRB4.label) G13_IRA.graph.add_uniq_edge(G13_IRB2.label, G13_IRB3.label) G13_IRA.graph.add_uniq_edge(G13_IRB4.label, G13_IRB2.label) -G13_IRA.blocs = {irb.label : irb for irb in [G13_IRB0, G13_IRB1, G13_IRB2, - G13_IRB4]} +G13_IRA.blocks = {irb.label : irb for irb in [G13_IRB0, G13_IRB1, G13_IRB2, + G13_IRB4]} # Expected output for graph 13 G13_EXP_IRA = IRATest() @@ -464,8 +464,8 @@ G13_EXP_IRB2 = gen_irblock(LBL2, [[ExprAff(d, CST2)], [ExprAff(a, b+CST1), G13_EXP_IRB3 = gen_irblock(LBL3, [[]]) G13_EXP_IRB4 = gen_irblock(LBL4, [[ExprAff(b, CST2)]]) -G13_EXP_IRA.blocs = {irb.label: irb for irb in [G13_EXP_IRB0, G13_EXP_IRB1, - G13_EXP_IRB2, G13_EXP_IRB4]} +G13_EXP_IRA.blocks = {irb.label: irb for irb in [G13_EXP_IRB0, G13_EXP_IRB1, + G13_EXP_IRB2, G13_EXP_IRB4]} #G13_EXP_IRA = G13_IRA @@ -480,7 +480,7 @@ G14_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a+c)]]) G14_IRA.graph.add_uniq_edge(G14_IRB0.label, G14_IRB1.label) -G14_IRA.blocs = {irb.label : irb for irb in [G14_IRB0, G14_IRB1]} +G14_IRA.blocks = {irb.label : irb for irb in [G14_IRB0, G14_IRB1]} # Expected output for graph 1 G14_EXP_IRA = IRATest() @@ -489,7 +489,7 @@ G14_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(c, a)], [ExprAff(a, CST2)]]) G14_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a+c)]]) -G14_EXP_IRA.blocs = {irb.label: irb for irb in [G14_EXP_IRB0, G14_EXP_IRB1]} +G14_EXP_IRA.blocks = {irb.label: irb for irb in [G14_EXP_IRB0, G14_EXP_IRB1]} # graph 15 : Graph where variable assigned multiple and read at the same time, # but useless @@ -503,7 +503,7 @@ G15_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a)]]) G15_IRA.graph.add_uniq_edge(G15_IRB0.label, G15_IRB1.label) -G15_IRA.blocs = {irb.label : irb for irb in [G15_IRB0, G15_IRB1]} +G15_IRA.blocks = {irb.label : irb for irb in [G15_IRB0, G15_IRB1]} # Expected output for graph 1 G15_EXP_IRA = IRATest() @@ -511,7 +511,7 @@ G15_EXP_IRA = IRATest() G15_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(a, CST1)]]) G15_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a)]]) -G15_EXP_IRA.blocs = {irb.label: irb for irb in [G15_EXP_IRB0, G15_EXP_IRB1]} +G15_EXP_IRA.blocks = {irb.label: irb for irb in [G15_EXP_IRB0, G15_EXP_IRB1]} # graph 16 : Graph where variable assigned multiple times in the same bloc @@ -526,7 +526,7 @@ G16_IRB2 = gen_irblock(LBL2, [[]]) G16_IRA.graph.add_uniq_edge(G16_IRB0.label, G16_IRB1.label) G16_IRA.graph.add_uniq_edge(G16_IRB1.label, G16_IRB2.label) -G16_IRA.blocs = {irb.label : irb for irb in [G16_IRB0, G16_IRB1]} +G16_IRA.blocks = {irb.label : irb for irb in [G16_IRB0, G16_IRB1]} # Expected output for graph 1 G16_EXP_IRA = IRATest() @@ -535,7 +535,7 @@ G16_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(c, CST3)], [ExprAff(a, c + CST1), ExprAff(b, c + CST2)]]) G16_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a+b)], [ExprAff(r, c+r)]]) -G16_EXP_IRA.blocs = {irb.label: irb for irb in [G16_EXP_IRB0, G16_EXP_IRB1]} +G16_EXP_IRA.blocks = {irb.label: irb for irb in [G16_EXP_IRB0, G16_EXP_IRB1]} # graph 17 : parallel ir @@ -595,7 +595,7 @@ G17_IRB0 = gen_irblock(LBL0, [[ExprAff(a, a*b), ]) -G17_IRA.blocs = {irb.label : irb for irb in [G17_IRB0]} +G17_IRA.blocks = {irb.label : irb for irb in [G17_IRB0]} G17_IRA.graph.add_node(G17_IRB0.label) @@ -637,7 +637,7 @@ G17_EXP_IRB0 = gen_irblock(LBL0, [[], # Trick because a+b+c != ((a+b)+c) ]) -G17_EXP_IRA.blocs = {irb.label : irb for irb in [G17_EXP_IRB0]} +G17_EXP_IRA.blocks = {irb.label : irb for irb in [G17_EXP_IRB0]} # Begining of tests @@ -674,8 +674,8 @@ for test_nb, test in enumerate([(G1_IRA, G1_EXP_IRA), open("simp_graph_%02d.dot" % (test_nb+1), "w").write(g_ira.graph.dot()) # Same number of blocks - assert len(g_ira.blocs) == len(g_exp_ira.blocs) - # Check that each expr in the blocs are the same - for lbl, irb in g_ira.blocs.iteritems(): - exp_irb = g_exp_ira.blocs[lbl] + assert len(g_ira.blocks) == len(g_exp_ira.blocks) + # Check that each expr in the blocks are the same + for lbl, irb in g_ira.blocks.iteritems(): + exp_irb = g_exp_ira.blocks[lbl] assert exp_irb.irs == irb.irs -- cgit 1.4.1 From 287cb1bb182112ad8b476a9631f0099163041fdc Mon Sep 17 00:00:00 2001 From: Fabrice Desclaux Date: Wed, 15 Feb 2017 08:20:45 +0100 Subject: All: rename vars bloc -> block --- example/asm/shellcode.py | 12 +-- example/asm/simple.py | 10 +-- example/disasm/full.py | 36 ++++----- example/expression/asm_to_ir.py | 16 ++-- example/expression/graph_dataflow.py | 26 +++---- example/expression/solve_condition_stp.py | 22 +++--- example/ida/depgraph.py | 10 +-- example/ida/graph_ir.py | 6 +- example/ida/symbol_exec.py | 6 +- miasm2/analysis/data_analysis.py | 4 +- miasm2/analysis/disasm_cb.py | 10 +-- miasm2/arch/aarch64/sem.py | 10 +-- miasm2/arch/arm/sem.py | 4 +- miasm2/arch/mips32/sem.py | 47 +----------- miasm2/arch/x86/sem.py | 8 +- miasm2/ir/analysis.py | 4 +- miasm2/ir/ir.py | 28 +++---- miasm2/jitter/jitcore.py | 121 +++++++++++++++--------------- miasm2/jitter/jitcore_python.py | 16 ++-- miasm2/jitter/jitload.py | 2 +- test/arch/aarch64/unit/asm_test.py | 6 +- test/arch/mips32/unit/asm_test.py | 6 +- test/arch/x86/sem.py | 6 +- test/arch/x86/unit/asm_test.py | 6 +- 24 files changed, 191 insertions(+), 231 deletions(-) (limited to 'example/expression/graph_dataflow.py') diff --git a/example/asm/shellcode.py b/example/asm/shellcode.py index 3ff11489..20fa02d8 100755 --- a/example/asm/shellcode.py +++ b/example/asm/shellcode.py @@ -64,7 +64,7 @@ else: with open(args.source) as fstream: source = fstream.read() -blocs, symbol_pool = parse_asm.parse_txt(machine.mn, attrib, source) +blocks, symbol_pool = parse_asm.parse_txt(machine.mn, attrib, source) # Fix shellcode addrs symbol_pool.set_offset(symbol_pool.getby_name("main"), addr_main) @@ -73,14 +73,14 @@ if args.PE: symbol_pool.set_offset(symbol_pool.getby_name_create("MessageBoxA"), pe.DirImport.get_funcvirt('USER32.dll', 'MessageBoxA')) -# Print and graph firsts blocs before patching it -for bloc in blocs: - print bloc -open("graph.dot", "w").write(blocs.dot()) +# Print and graph firsts blocks before patching it +for block in blocks: + print block +open("graph.dot", "w").write(blocks.dot()) # Apply patches patches = asmbloc.asm_resolve_final(machine.mn, - blocs, + blocks, symbol_pool, dst_interval) if args.encrypt: diff --git a/example/asm/simple.py b/example/asm/simple.py index d7623908..7ab403f4 100644 --- a/example/asm/simple.py +++ b/example/asm/simple.py @@ -6,7 +6,7 @@ from miasm2.core import parse_asm, asmbloc # Assemble code -blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' +blocks, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' main: MOV EAX, 1 MOV EBX, 2 @@ -25,11 +25,11 @@ loop: symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) # Spread information and resolve instructions offset -patches = asmbloc.asm_resolve_final(mn_x86, blocs, symbol_pool) +patches = asmbloc.asm_resolve_final(mn_x86, blocks, symbol_pool) -# Show resolved blocs -for bloc in blocs: - print bloc +# Show resolved blocks +for block in blocks: + print block # Print offset -> bytes pprint(patches) diff --git a/example/disasm/full.py b/example/disasm/full.py index 6bea91cd..5fc9008a 100644 --- a/example/disasm/full.py +++ b/example/disasm/full.py @@ -108,7 +108,7 @@ for ad in addrs: done = set() all_funcs = set() -all_funcs_blocs = {} +all_funcs_blocks = {} done_interval = interval() @@ -121,27 +121,27 @@ while not finish and todo: if ad in done: continue done.add(ad) - ab = mdis.dis_multibloc(ad) + allblocks = mdis.dis_multibloc(ad) log.info('func ok %.16x (%d)' % (ad, len(all_funcs))) all_funcs.add(ad) - all_funcs_blocs[ad] = ab - for b in ab: - for l in b.lines: + all_funcs_blocks[ad] = allblocks + for block in allblocks: + for l in block.lines: done_interval += interval([(l.offset, l.offset + l.l)]) if args.funcswatchdog is not None: args.funcswatchdog -= 1 if args.recurfunctions: - for b in ab: - i = b.get_subcall_instr() - if not i: + for block in allblocks: + instr = block.get_subcall_instr() + if not isntr: continue - for d in i.getdstflow(mdis.symbol_pool): - if not (isinstance(d, ExprId) and isinstance(d.name, asm_label)): + for dest in instr.getdstflow(mdis.symbol_pool): + if not (isinstance(dest, ExprId) and isinstance(dest.name, asm_label)): continue - todo.append((mdis, i, d.name.offset)) + todo.append((mdis, instr, dest.name.offset)) if args.funcswatchdog is not None and args.funcswatchdog <= 0: finish = True @@ -155,13 +155,13 @@ while not finish and todo: # Generate dotty graph -all_blocs = AsmCFG() -for blocs in all_funcs_blocs.values(): - all_blocs += blocs +all_blocks = AsmCFG() +for blocks in all_funcs_blocks.values(): + all_blocks += blocks log.info('generate graph file') -open('graph_execflow.dot', 'w').write(all_blocs.dot(offset=True)) +open('graph_execflow.dot', 'w').write(all_blocks.dot(offset=True)) log.info('generate intervals') @@ -192,9 +192,9 @@ if args.gen_ir: ir_arch_a.blocks = {} for ad, all_block in all_funcs_blocks.items(): log.info("generating IR... %x" % ad) - for b in all_bloc: - ir_arch_a.add_bloc(b) - ir_arch.add_bloc(b) + for block in all_block: + ir_arch_a.add_bloc(block) + ir_arch.add_bloc(block) log.info("Print blocks (without analyse)") for label, block in ir_arch.blocks.iteritems(): diff --git a/example/expression/asm_to_ir.py b/example/expression/asm_to_ir.py index 552ddd36..4193f31d 100644 --- a/example/expression/asm_to_ir.py +++ b/example/expression/asm_to_ir.py @@ -8,7 +8,7 @@ from miasm2.arch.x86.ira import ir_a_x86_32 # First, asm code -blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' +blocks, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' main: MOV EAX, 1 MOV EBX, 2 @@ -25,20 +25,20 @@ loop: symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) -for b in blocs: - print b +for block in blocks: + print block print "symbols:" print symbol_pool -patches = asmbloc.asm_resolve_final(mn_x86, blocs, symbol_pool) +patches = asmbloc.asm_resolve_final(mn_x86, blocks, symbol_pool) # Translate to IR ir_arch = ir_a_x86_32(symbol_pool) -for b in blocs: - print 'add bloc' - print b - ir_arch.add_bloc(b) +for block in blocks: + print 'add block' + print block + ir_arch.add_bloc(block) # Display IR for lbl, irblock in ir_arch.blocks.items(): diff --git a/example/expression/graph_dataflow.py b/example/expression/graph_dataflow.py index 0b01956f..bd767165 100644 --- a/example/expression/graph_dataflow.py +++ b/example/expression/graph_dataflow.py @@ -49,12 +49,12 @@ def get_modified_symbols(sb): return out -def intra_bloc_flow_symb(ir_arch, flow_graph, irbloc): +def intra_bloc_flow_symb(ir_arch, flow_graph, irblock): symbols_init = ir_arch.arch.regs.regs_init.copy() sb = SymbolicExecutionEngine(ir_arch, symbols_init) - sb.emulbloc(irbloc) + sb.emulbloc(irblock) print '*' * 40 - print irbloc + print irblock in_nodes = {} out_nodes = {} @@ -68,7 +68,7 @@ def intra_bloc_flow_symb(ir_arch, flow_graph, irbloc): all_mems.update(get_expr_mem(n)) for n in all_mems: - node_n_w = get_node_name(irbloc.label, 0, n) + node_n_w = get_node_name(irblock.label, 0, n) if not n == src: continue o_r = n.arg.get_r(mem_read=False, cst_read=True) @@ -76,7 +76,7 @@ def intra_bloc_flow_symb(ir_arch, flow_graph, irbloc): if n_r in current_nodes: node_n_r = current_nodes[n_r] else: - node_n_r = get_node_name(irbloc.label, i, n_r) + node_n_r = get_node_name(irblock.label, i, n_r) if not n_r in in_nodes: in_nodes[n_r] = node_n_r flow_graph.add_uniq_edge(node_n_r, node_n_w) @@ -89,20 +89,20 @@ def intra_bloc_flow_symb(ir_arch, flow_graph, irbloc): if n_r in current_nodes: node_n_r = current_nodes[n_r] else: - node_n_r = get_node_name(irbloc.label, 0, n_r) + node_n_r = get_node_name(irblock.label, 0, n_r) if not n_r in in_nodes: in_nodes[n_r] = node_n_r flow_graph.add_node(node_n_r) for n_w in nodes_w: - node_n_w = get_node_name(irbloc.label, 1, n_w) + node_n_w = get_node_name(irblock.label, 1, n_w) out_nodes[n_w] = node_n_w flow_graph.add_node(node_n_w) flow_graph.add_uniq_edge(node_n_r, node_n_w) - irbloc.in_nodes = in_nodes - irbloc.out_nodes = out_nodes + irblock.in_nodes = in_nodes + irblock.out_nodes = out_nodes def node2str(self, node): @@ -121,7 +121,7 @@ def gen_block_data_flow_graph(ir_arch, ad, block_flow_cb): if irblock.label.offset == ad: irblock_0 = irblock break - assert(irbloc_0 is not None) + assert(irblock_0 is not None) flow_graph = DiGraph() flow_graph.node2str = lambda n: node2str(flow_graph, n) @@ -133,8 +133,8 @@ def gen_block_data_flow_graph(ir_arch, ad, block_flow_cb): print 'IN', [str(x) for x in irblock.in_nodes] print 'OUT', [str(x) for x in irblock.out_nodes] - print '*' * 20, 'interbloc', '*' * 20 - inter_bloc_flow(ir_arch, flow_graph, irbloc_0.label) + print '*' * 20, 'interblock', '*' * 20 + inter_bloc_flow(ir_arch, flow_graph, irblock_0.label) # from graph_qt import graph_qt # graph_qt(flow_graph) @@ -169,7 +169,7 @@ if args.symb: else: block_flow_cb = intra_bloc_flow_raw -gen_bloc_data_flow_graph(ir_arch, ad, block_flow_cb) +gen_block_data_flow_graph(ir_arch, ad, block_flow_cb) print '*' * 40 print """ diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py index 1f0f2967..5d3ebc59 100644 --- a/example/expression/solve_condition_stp.py +++ b/example/expression/solve_condition_stp.py @@ -35,7 +35,7 @@ if not args: sys.exit(0) -def get_bloc(ir_arch, mdis, ad): +def get_block(ir_arch, mdis, ad): if isinstance(ad, asmbloc.asm_label): l = ad else: @@ -46,7 +46,7 @@ def get_bloc(ir_arch, mdis, ad): ir_arch.add_bloc(b) b = ir_arch.get_bloc(l) if b is None: - raise LookupError('no bloc found at that address: %s' % l) + raise LookupError('no block found at that address: %s' % l) return b @@ -62,11 +62,11 @@ def emul_symb(ir_arch, mdis, states_todo, states_done): sb.symbols = symbols.copy() if ir_arch.pc in sb.symbols: del(sb.symbols[ir_arch.pc]) - b = get_bloc(ir_arch, mdis, ad) + b = get_block(ir_arch, mdis, ad) - print 'run bloc' + print 'run block' print b - # print blocs[ad] + # print blocks[ad] ad = sb.emulbloc(b) print 'final state' sb.dump_id() @@ -161,20 +161,20 @@ if __name__ == '__main__': sb = SymbolicExecutionEngine(ir_arch, symbols_init) - blocs, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' + blocks, symbol_pool = parse_asm.parse_txt(mn_x86, 32, ''' PUSH argv PUSH argc PUSH ret_addr ''') - b = list(blocs)[0] + b = list(blocks)[0] print b # add fake address and len to parsed instructions - for i, l in enumerate(b.lines): - l.offset, l.l = i, 1 + for i, line in enumerate(b.lines): + line.offset, line.l = i, 1 ir_arch.add_bloc(b) - irb = get_bloc(ir_arch, mdis, 0) + irb = get_block(ir_arch, mdis, 0) sb.emulbloc(irb) sb.dump_mem() @@ -185,7 +185,7 @@ if __name__ == '__main__': states_done = set() states_todo.add((uint32(ad), sb.symbols, ())) - # emul blocs, propagate states + # emul blocks, propagate states emul_symb(ir_arch, mdis, states_todo, states_done) all_info = [] diff --git a/example/ida/depgraph.py b/example/ida/depgraph.py index 9024f2af..50c73a54 100644 --- a/example/ida/depgraph.py +++ b/example/ida/depgraph.py @@ -21,8 +21,8 @@ class depGraphSettingsForm(Form): self.stk_unalias_force = False self.address = ScreenEA() - cur_bloc = list(ira.getby_offset(self.address))[0] - for line_nb, l in enumerate(cur_bloc.lines): + cur_block = list(ira.getby_offset(self.address))[0] + for line_nb, l in enumerate(cur_block.lines): if l.offset == self.address: break cur_label = str(cur_block.label) @@ -151,11 +151,11 @@ for ad, name in Names(): # Get the current function addr = ScreenEA() func = idaapi.get_func(addr) -blocs = mdis.dis_multibloc(func.startEA) +blocks = mdis.dis_multibloc(func.startEA) # Generate IR -for bloc in blocs: - ir_arch.add_bloc(bloc) +for block in blocks: + ir_arch.add_bloc(block) # Get settings settings = depGraphSettingsForm(ir_arch) diff --git a/example/ida/graph_ir.py b/example/ida/graph_ir.py index 252dc612..250eebfc 100644 --- a/example/ida/graph_ir.py +++ b/example/ida/graph_ir.py @@ -125,10 +125,10 @@ open('asm_flow.dot', 'w').write(ab.dot()) print "generating IR... %x" % ad -for b in ab: +for block in ab: print 'ADD' - print b - ir_arch.add_bloc(b) + print block + ir_arch.add_bloc(block) print "IR ok... %x" % ad diff --git a/example/ida/symbol_exec.py b/example/ida/symbol_exec.py index edb6287b..70e1cfc1 100644 --- a/example/ida/symbol_exec.py +++ b/example/ida/symbol_exec.py @@ -87,10 +87,10 @@ def symbolic_exec(): start, end = SelStart(), SelEnd() mdis.dont_dis = [end] - blocs = mdis.dis_multibloc(start) + blocks = mdis.dis_multibloc(start) ira = machine.ira() - for bloc in blocs: - ira.add_bloc(bloc) + for block in blocks: + ira.add_bloc(block) print "Run symbolic execution..." sb = SymbolicExecutionEngine(ira, machine.mn.regs.regs_init) diff --git a/miasm2/analysis/data_analysis.py b/miasm2/analysis/data_analysis.py index 8703c0cd..c67c4509 100644 --- a/miasm2/analysis/data_analysis.py +++ b/miasm2/analysis/data_analysis.py @@ -211,8 +211,8 @@ class symb_exec_func: """ This algorithm will do symbolic execution on a function, trying to propagate - states between basic blocs in order to extract inter-blocs dataflow. The - algorithm tries to merge states from blocs with multiple parents. + states between basic blocks in order to extract inter-blocs dataflow. The + algorithm tries to merge states from blocks with multiple parents. There is no real magic here, loops and complex merging will certainly fail. """ diff --git a/miasm2/analysis/disasm_cb.py b/miasm2/analysis/disasm_cb.py index e2fa54cf..95a2b49b 100644 --- a/miasm2/analysis/disasm_cb.py +++ b/miasm2/analysis/disasm_cb.py @@ -34,12 +34,12 @@ def arm_guess_subcall( ir_blocks = ir_arch.blocks.values() # flow_graph = DiGraph() to_add = set() - for irb in ir_blocs: + for irblock in ir_blocks: # print 'X'*40 - # print irb + # print irblock pc_val = None lr_val = None - for exprs in irb.irs: + for exprs in irblock.irs: for e in exprs: if e.dst == ir_arch.pc: pc_val = e.src @@ -81,10 +81,10 @@ def arm_guess_jump_table( ir_blocks = ir_arch.blocks.values() for irblock in ir_blocks: # print 'X'*40 - # print irb + # print irblock pc_val = None # lr_val = None - for exprs in irb.irs: + for exprs in irblock.irs: for e in exprs: if e.dst == ir_arch.pc: pc_val = e.src diff --git a/miasm2/arch/aarch64/sem.py b/miasm2/arch/aarch64/sem.py index 1d2ff4f1..792a4984 100644 --- a/miasm2/arch/aarch64/sem.py +++ b/miasm2/arch/aarch64/sem.py @@ -804,8 +804,8 @@ class ir_aarch64l(IntermediateRepresentation): dst = dst.replace_expr({self.pc: cur_offset}) src = src.replace_expr({self.pc: cur_offset}) instr_ir[i] = m2_expr.ExprAff(dst, src) - for b in extra_ir: - for irs in b.irs: + for irblock in extra_ir: + for irs in irblock.irs: for i, expr in enumerate(irs): dst, src = expr.dst, expr.src if dst != self.pc: @@ -819,9 +819,9 @@ class ir_aarch64l(IntermediateRepresentation): regs_to_fix = [WZR, XZR] instr_ir = [expr for expr in instr_ir if expr.dst not in regs_to_fix] - for b in extra_ir: - for i, irs in enumerate(b.irs): - b.irs[i] = [expr for expr in irs if expr.dst not in regs_to_fix] + for irblock in extra_ir: + for i, irs in enumerate(irblock.irs): + irblock.irs[i] = [expr for expr in irs if expr.dst not in regs_to_fix] return instr_ir, extra_ir diff --git a/miasm2/arch/arm/sem.py b/miasm2/arch/arm/sem.py index 0ec02907..8c74aa76 100644 --- a/miasm2/arch/arm/sem.py +++ b/miasm2/arch/arm/sem.py @@ -1252,8 +1252,8 @@ class ir_arml(IntermediateRepresentation): x = ExprAff(x.dst, x.src.replace_expr( {self.pc: ExprInt32(instr.offset + 8)})) instr_ir[i] = x - for b in extra_ir: - for irs in b.irs: + for irblock in extra_ir: + for irs in irblock.irs: for i, x in enumerate(irs): x = ExprAff(x.dst, x.src.replace_expr( {self.pc: ExprInt32(instr.offset + 8)})) diff --git a/miasm2/arch/mips32/sem.py b/miasm2/arch/mips32/sem.py index cf760307..d982f033 100644 --- a/miasm2/arch/mips32/sem.py +++ b/miasm2/arch/mips32/sem.py @@ -445,8 +445,8 @@ class ir_mips32l(IntermediateRepresentation): x = m2_expr.ExprAff(x.dst, x.src.replace_expr( {self.pc: m2_expr.ExprInt32(instr.offset + 4)})) instr_ir[i] = x - for b in extra_ir: - for irs in b.irs: + for irblock in extra_ir: + for irs in irblock.irs: for i, x in enumerate(irs): x = m2_expr.ExprAff(x.dst, x.src.replace_expr( {self.pc: m2_expr.ExprInt32(instr.offset + 4)})) @@ -454,49 +454,10 @@ class ir_mips32l(IntermediateRepresentation): return instr_ir, extra_ir def get_next_instr(self, instr): - l = self.symbol_pool.getby_offset_create(instr.offset + 4) - return l + return self.symbol_pool.getby_offset_create(instr.offset + 4) def get_next_break_label(self, instr): - l = self.symbol_pool.getby_offset_create(instr.offset + 8) - return l - """ - def add_bloc(self, bloc, gen_pc_updt = False): - c = None - ir_blocs_all = [] - for l in bloc.lines: - if c is None: - # print 'new c' - label = self.get_label(l) - c = IRBlock(label, [], []) - ir_blocs_all.append(c) - bloc_dst = None - # print 'Translate', l - dst, ir_bloc_cur, ir_blocs_extra = self.instr2ir(l) - # print ir_bloc_cur - # for xxx in ir_bloc_cur: - # print "\t", xxx - assert((dst is None) or (bloc_dst is None)) - bloc_dst = dst - #if bloc_dst is not None: - # c.dst = bloc_dst - if dst is not None: - ir_bloc_cur.append(m2_expr.ExprAff(PC_FETCH, dst)) - c.dst = PC_FETCH - if gen_pc_updt is not False: - self.gen_pc_update(c, l) - - c.irs.append(ir_bloc_cur) - c.lines.append(l) - if ir_blocs_extra: - # print 'split' - for b in ir_blocs_extra: - b.lines = [l] * len(b.irs) - ir_blocs_all += ir_blocs_extra - c = None - self.post_add_bloc(bloc, ir_blocs_all) - return ir_blocs_all - """ + return self.symbol_pool.getby_offset_create(instr.offset + 8) class ir_mips32b(ir_mips32l): def __init__(self, symbol_pool=None): diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py index 24b9487a..729806b5 100644 --- a/miasm2/arch/x86/sem.py +++ b/miasm2/arch/x86/sem.py @@ -4571,8 +4571,8 @@ class ir_x86_16(IntermediateRepresentation): lbl_skip = m2_expr.ExprId(self.get_next_label(instr), self.IRDst.size) lbl_next = m2_expr.ExprId(self.get_next_label(instr), self.IRDst.size) - for b in extra_ir: - for ir in b.irs: + for irblock in extra_ir: + for ir in irblock.irs: for i, e in enumerate(ir): src = e.src.replace_expr({lbl_next: lbl_end}) ir[i] = m2_expr.ExprAff(e.dst, src) @@ -4656,8 +4656,8 @@ class ir_x86_64(ir_x86_16): src = src.replace_expr( {self.pc: m2_expr.ExprInt64(instr.offset + instr.l)}) instr_ir[i] = m2_expr.ExprAff(dst, src) - for b in extra_ir: - for irs in b.irs: + for irblock in extra_ir: + for irs in irblock.irs: for i, expr in enumerate(irs): dst, src = expr.dst, expr.src if dst != self.pc: diff --git a/miasm2/ir/analysis.py b/miasm2/ir/analysis.py index 6eb226ed..4f7b321f 100644 --- a/miasm2/ir/analysis.py +++ b/miasm2/ir/analysis.py @@ -167,7 +167,7 @@ class ira(IntermediateRepresentation): for irblock in self.blocks.values(): modified |= self.remove_dead_instr(irblock, useful) # Remove useless structures - for assignblk in block.irs: + for assignblk in irblock.irs: del assignblk._cur_kill del assignblk._prev_kill del assignblk._cur_reach @@ -291,7 +291,7 @@ class ira(IntermediateRepresentation): Source : Kennedy, K. (1979). A survey of data flow analysis techniques. IBM Thomas J. Watson Research Division, page 43 """ - # Update r/w variables for all irblocs + # Update r/w variables for all irblocks self.get_rw(self.ira_regs_ids()) # Liveness step self.compute_reach() diff --git a/miasm2/ir/ir.py b/miasm2/ir/ir.py index a7076e2a..7f1b00d6 100644 --- a/miasm2/ir/ir.py +++ b/miasm2/ir/ir.py @@ -431,7 +431,7 @@ class IntermediateRepresentation(object): if irb_cur is None: return None - assignblk, ir_blocs_extra = self.instr2ir(instr) + assignblk, ir_blocks_extra = self.instr2ir(instr) if gen_pc_updt is not False: self.gen_pc_update(irb_cur, instr) @@ -439,10 +439,10 @@ class IntermediateRepresentation(object): irb_cur.irs.append(assignblk) irb_cur.lines.append(instr) - if ir_blocs_extra: - for b in ir_blocs_extra: - b.lines = [instr] * len(b.irs) - ir_blocks_all += ir_blocs_extra + if ir_blocks_extra: + for irblock in ir_blocks_extra: + irblock.lines = [instr] * len(irblock.irs) + ir_blocks_all += ir_blocks_extra irb_cur = None return irb_cur @@ -482,22 +482,22 @@ class IntermediateRepresentation(object): return ir return None - def set_empty_dst_to_next(self, bloc, ir_blocs): - for b in ir_blocs: - if b.dst is not None: + def set_empty_dst_to_next(self, block, ir_blocks): + for irblock in ir_blocks: + if irblock.dst is not None: continue - next_lbl = bloc.get_next() + next_lbl = block.get_next() if next_lbl is None: - dst = m2_expr.ExprId(self.get_next_label(bloc.lines[-1]), + dst = m2_expr.ExprId(self.get_next_label(block.lines[-1]), self.pc.size) else: dst = m2_expr.ExprId(next_lbl, self.pc.size) - b.irs.append(AssignBlock([m2_expr.ExprAff(self.IRDst, dst)])) - b.lines.append(b.lines[-1]) + irblock.irs.append(AssignBlock([m2_expr.ExprAff(self.IRDst, dst)])) + irblock.lines.append(irblock.lines[-1]) - def post_add_bloc(self, bloc, ir_blocs): - self.set_empty_dst_to_next(bloc, ir_blocs) + def post_add_bloc(self, block, ir_blocks): + self.set_empty_dst_to_next(block, ir_blocks) for irblock in ir_blocks: self.irbloc_fix_regs_for_mode(irblock, self.attrib) diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py index 651b71e3..60fb3f2c 100644 --- a/miasm2/jitter/jitcore.py +++ b/miasm2/jitter/jitcore.py @@ -88,31 +88,31 @@ class JitCore(object): "Initialise the Jitter" raise NotImplementedError("Abstract class") - def get_bloc_min_max(self, cur_bloc): - "Update cur_bloc to set min/max address" + def get_bloc_min_max(self, cur_block): + "Update cur_block to set min/max address" - if cur_bloc.lines: - cur_bloc.ad_min = cur_bloc.lines[0].offset - cur_bloc.ad_max = cur_bloc.lines[-1].offset + cur_bloc.lines[-1].l + if cur_block.lines: + cur_block.ad_min = cur_block.lines[0].offset + cur_block.ad_max = cur_block.lines[-1].offset + cur_block.lines[-1].l else: # 1 byte block for unknown mnemonic - cur_bloc.ad_min = cur_bloc.label.offset - cur_bloc.ad_max = cur_bloc.label.offset+1 + cur_block.ad_min = cur_block.label.offset + cur_block.ad_max = cur_block.label.offset+1 - def add_bloc_to_mem_interval(self, vm, bloc): - "Update vm to include bloc addresses in its memory range" + def add_bloc_to_mem_interval(self, vm, block): + "Update vm to include block addresses in its memory range" - self.blocs_mem_interval += interval([(bloc.ad_min, bloc.ad_max - 1)]) + self.blocs_mem_interval += interval([(block.ad_min, block.ad_max - 1)]) vm.reset_code_bloc_pool() for a, b in self.blocs_mem_interval: vm.add_code_bloc(a, b + 1) - def jitirblocs(self, label, irblocs): - """JiT a group of irblocs. - @label: the label of the irblocs - @irblocs: a gorup of irblocs + def jitirblocs(self, label, irblocks): + """JiT a group of irblocks. + @label: the label of the irblocks + @irblocks: a gorup of irblocks """ raise NotImplementedError("Abstract class") @@ -123,16 +123,16 @@ class JitCore(object): """ irblocks = self.ir_arch.add_bloc(block, gen_pc_updt = True) - b.blocks = irblocks + block.blocks = irblocks self.jitirblocs(block.label, irblocks) def disbloc(self, addr, vm): - """Disassemble a new bloc and JiT it + """Disassemble a new block and JiT it @addr: address of the block to disassemble (asm_label or int) @vm: VmMngr instance """ - # Get the bloc + # Get the block if isinstance(addr, asmbloc.asm_label): addr = addr.offset @@ -143,30 +143,30 @@ class JitCore(object): # Disassemble it try: - cur_bloc = self.mdis.dis_bloc(addr) + cur_block = self.mdis.dis_bloc(addr) except IOError: # vm_exception_flag is set label = self.ir_arch.symbol_pool.getby_offset_create(addr) - cur_bloc = asmbloc.asm_block_bad(label) + cur_block = asmbloc.asm_block_bad(label) # Logging if self.log_newbloc: - print cur_bloc + print cur_block - # Update label -> bloc - self.lbl2bloc[cur_bloc.label] = cur_bloc + # Update label -> block + self.lbl2bloc[cur_block.label] = cur_block - # Store min/max bloc address needed in jit automod code - self.get_bloc_min_max(cur_bloc) + # Store min/max block address needed in jit automod code + self.get_bloc_min_max(cur_block) # JiT it - self.add_bloc(cur_bloc) + self.add_bloc(cur_block) # Update jitcode mem range - self.add_bloc_to_mem_interval(vm, cur_bloc) + self.add_bloc_to_mem_interval(vm, cur_block) def runbloc(self, cpu, lbl, breakpoints): - """Run the bloc starting at lbl. + """Run the block starting at lbl. @cpu: JitCpu instance @lbl: target label """ @@ -175,80 +175,79 @@ class JitCore(object): lbl = getattr(cpu, self.ir_arch.pc.name) if not lbl in self.lbl2jitbloc: - # Need to JiT the bloc + # Need to JiT the block self.disbloc(lbl, cpu.vmmngr) - # Run the bloc and update cpu/vmmngr state + # Run the block and update cpu/vmmngr state return self.exec_wrapper(lbl, cpu, self.lbl2jitbloc.data, breakpoints, self.options["max_exec_per_call"]) - def blocs2memrange(self, blocs): - """Return an interval instance standing for blocs addresses - @blocs: list of asm_bloc instances + def blocs2memrange(self, blocks): + """Return an interval instance standing for blocks addresses + @blocks: list of asm_bloc instances """ mem_range = interval() - for b in blocs: - mem_range += interval([(b.ad_min, b.ad_max - 1)]) + for block in blocks: + mem_range += interval([(block.ad_min, block.ad_max - 1)]) return mem_range def __updt_jitcode_mem_range(self, vm): - """Rebuild the VM blocs address memory range + """Rebuild the VM blocks address memory range @vm: VmMngr instance """ # Reset the current pool vm.reset_code_bloc_pool() - # Add blocs in the pool - for a, b in self.blocs_mem_interval: - vm.add_code_bloc(a, b + 1) + # Add blocks in the pool + for start, stop in self.blocs_mem_interval: + vm.add_code_bloc(start, stop + 1) def del_bloc_in_range(self, ad1, ad2): - """Find and remove jitted bloc in range [ad1, ad2]. - Return the list of bloc removed. + """Find and remove jitted block in range [ad1, ad2]. + Return the list of block removed. @ad1: First address @ad2: Last address """ - # Find concerned blocs - modified_blocs = set() - for b in self.lbl2bloc.values(): - if not b.lines: + # Find concerned blocks + modified_blocks = set() + for block in self.lbl2bloc.values(): + if not block.lines: continue - if b.ad_max <= ad1 or b.ad_min >= ad2: - # Bloc not modified + if block.ad_max <= ad1 or block.ad_min >= ad2: + # Block not modified pass else: - # Modified blocs - modified_blocs.add(b) + # Modified blocks + modified_blocks.add(block) # Generate interval to delete - del_interval = self.blocs2memrange(modified_blocs) + del_interval = self.blocs2memrange(modified_blocks) # Remove interval from monitored interval list self.blocs_mem_interval -= del_interval - # Remove modified blocs - for b in modified_blocs: + # Remove modified blocks + for block in modified_blocks: try: for irblock in block.blocks: - - # Remove offset -> jitted bloc link - if irbloc.label.offset in self.lbl2jitbloc: - del(self.lbl2jitbloc[irbloc.label.offset]) + # Remove offset -> jitted block link + if irblock.label.offset in self.lbl2jitbloc: + del(self.lbl2jitbloc[irblock.label.offset]) except AttributeError: - # The bloc has never been translated in IR - if b.label.offset in self.lbl2jitbloc: - del(self.lbl2jitbloc[b.label.offset]) + # The block has never been translated in IR + if block.label.offset in self.lbl2jitbloc: + del(self.lbl2jitbloc[block.label.offset]) - # Remove label -> bloc link - del(self.lbl2bloc[b.label]) + # Remove label -> block link + del(self.lbl2bloc[block.label]) - return modified_blocs + return modified_blocks def updt_automod_code_range(self, vm, mem_range): """Remove jitted code in range @mem_range diff --git a/miasm2/jitter/jitcore_python.py b/miasm2/jitter/jitcore_python.py index a8ecc3d6..cbd582ab 100644 --- a/miasm2/jitter/jitcore_python.py +++ b/miasm2/jitter/jitcore_python.py @@ -34,10 +34,10 @@ class JitCore_Python(jitcore.JitCore): "Preload symbols according to current architecture" self.symbexec.reset_regs() - def jitirblocs(self, label, irblocs): - """Create a python function corresponding to an irblocs' group. - @label: the label of the irblocs - @irblocs: a gorup of irblocs + def jitirblocs(self, label, irblocks): + """Create a python function corresponding to an irblocks' group. + @label: the label of the irblocks + @irblocks: a gorup of irblocks """ def myfunc(cpu): @@ -47,7 +47,7 @@ class JitCore_Python(jitcore.JitCore): # Get virtual memory handler vmmngr = cpu.vmmngr - # Keep current location in irblocs + # Keep current location in irblocks cur_label = label # Required to detect new instructions @@ -57,15 +57,15 @@ class JitCore_Python(jitcore.JitCore): exec_engine = self.symbexec expr_simp = exec_engine.expr_simp - # For each irbloc inside irblocs + # For each irbloc inside irblocks while True: # Get the current bloc - for irb in irblocs: + for irb in irblocks: if irb.label == cur_label: break else: - raise RuntimeError("Irblocs must end with returning an " + raise RuntimeError("Irblocks must end with returning an " "ExprInt instance") # Refresh CPU values according to @cpu instance diff --git a/miasm2/jitter/jitload.py b/miasm2/jitter/jitload.py index eaeae89a..693dd224 100644 --- a/miasm2/jitter/jitload.py +++ b/miasm2/jitter/jitload.py @@ -242,7 +242,7 @@ class jitter: "Add common exceptions handlers" def exception_automod(jitter): - "Tell the JiT backend to update blocs modified" + "Tell the JiT backend to update blocks modified" self.jit.updt_automod_code(jitter.vm) self.vm.set_exception(0) diff --git a/test/arch/aarch64/unit/asm_test.py b/test/arch/aarch64/unit/asm_test.py index 54ab476d..d8639ce7 100644 --- a/test/arch/aarch64/unit/asm_test.py +++ b/test/arch/aarch64/unit/asm_test.py @@ -28,12 +28,12 @@ class Asm_Test(object): def asm(self): - blocs, symbol_pool = parse_asm.parse_txt(mn_aarch64, 'l', self.TXT, - symbol_pool = self.myjit.ir_arch.symbol_pool) + blocks, symbol_pool = parse_asm.parse_txt(mn_aarch64, 'l', self.TXT, + symbol_pool = self.myjit.ir_arch.symbol_pool) # fix shellcode addr symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) s = StrPatchwork() - patches = asmbloc.asm_resolve_final(mn_aarch64, blocs, symbol_pool) + patches = asmbloc.asm_resolve_final(mn_aarch64, blocks, symbol_pool) for offset, raw in patches.items(): s[offset] = raw diff --git a/test/arch/mips32/unit/asm_test.py b/test/arch/mips32/unit/asm_test.py index 4425bb65..4edcaf84 100644 --- a/test/arch/mips32/unit/asm_test.py +++ b/test/arch/mips32/unit/asm_test.py @@ -28,12 +28,12 @@ class Asm_Test(object): self.check() def asm(self): - blocs, symbol_pool = parse_asm.parse_txt(mn_mips32, 'l', self.TXT, - symbol_pool=self.myjit.ir_arch.symbol_pool) + blocks, symbol_pool = parse_asm.parse_txt(mn_mips32, 'l', self.TXT, + symbol_pool=self.myjit.ir_arch.symbol_pool) # fix shellcode addr symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) s = StrPatchwork() - patches = asmbloc.asm_resolve_final(mn_mips32, blocs, symbol_pool) + patches = asmbloc.asm_resolve_final(mn_mips32, blocks, symbol_pool) for offset, raw in patches.items(): s[offset] = raw diff --git a/test/arch/x86/sem.py b/test/arch/x86/sem.py index 676dfeed..40988e61 100755 --- a/test/arch/x86/sem.py +++ b/test/arch/x86/sem.py @@ -45,11 +45,11 @@ def compute(ir, mode, asm, inputstate={}, debug=False): def compute_txt(ir, mode, txt, inputstate={}, debug=False): - blocs, symbol_pool = parse_asm.parse_txt(mn, mode, txt) + blocks, symbol_pool = parse_asm.parse_txt(mn, mode, txt) symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) - patches = asmbloc.asm_resolve_final(mn, blocs, symbol_pool) + patches = asmbloc.asm_resolve_final(mn, blocks, symbol_pool) interm = ir(symbol_pool) - for bbl in blocs: + for bbl in blocks: interm.add_bloc(bbl) return symb_exec(interm, inputstate, debug) diff --git a/test/arch/x86/unit/asm_test.py b/test/arch/x86/unit/asm_test.py index 524791ce..ebe7612d 100644 --- a/test/arch/x86/unit/asm_test.py +++ b/test/arch/x86/unit/asm_test.py @@ -44,12 +44,12 @@ class Asm_Test(object): assert(self.myjit.pc == self.ret_addr) def asm(self): - blocs, symbol_pool = parse_asm.parse_txt(mn_x86, self.arch_attrib, self.TXT, - symbol_pool = self.myjit.ir_arch.symbol_pool) + blocks, symbol_pool = parse_asm.parse_txt(mn_x86, self.arch_attrib, self.TXT, + symbol_pool = self.myjit.ir_arch.symbol_pool) # fix shellcode addr symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) s = StrPatchwork() - patches = asmbloc.asm_resolve_final(mn_x86, blocs, symbol_pool) + patches = asmbloc.asm_resolve_final(mn_x86, blocks, symbol_pool) for offset, raw in patches.items(): s[offset] = raw -- cgit 1.4.1