diff options
27 files changed, 99 insertions, 97 deletions
diff --git a/example/disasm/callback.py b/example/disasm/callback.py index 4a7507dd..f1b2d3c8 100644 --- a/example/disasm/callback.py +++ b/example/disasm/callback.py @@ -1,5 +1,5 @@ from miasm2.core.bin_stream import bin_stream_str -from miasm2.core.asmbloc import asm_label, asm_constraint, expr_is_label +from miasm2.core.asmbloc import AsmLabel, asm_constraint, expr_is_label from miasm2.arch.x86.disasm import dis_x86_32, cb_x86_funcs diff --git a/example/disasm/full.py b/example/disasm/full.py index 5fc9008a..f28decbb 100644 --- a/example/disasm/full.py +++ b/example/disasm/full.py @@ -4,7 +4,7 @@ from argparse import ArgumentParser from pdb import pm from miasm2.analysis.binary import Container -from miasm2.core.asmbloc import log_asmbloc, asm_label, AsmCFG +from miasm2.core.asmbloc import log_asmbloc, AsmLabel, AsmCFG from miasm2.expression.expression import ExprId from miasm2.core.interval import interval from miasm2.analysis.machine import Machine @@ -139,7 +139,7 @@ while not finish and todo: if not isntr: continue for dest in instr.getdstflow(mdis.symbol_pool): - if not (isinstance(dest, ExprId) and isinstance(dest.name, asm_label)): + if not (isinstance(dest, ExprId) and isinstance(dest.name, AsmLabel)): continue todo.append((mdis, instr, dest.name.offset)) diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py index 5d3ebc59..fb227345 100644 --- a/example/expression/solve_condition_stp.py +++ b/example/expression/solve_condition_stp.py @@ -36,7 +36,7 @@ if not args: def get_block(ir_arch, mdis, ad): - if isinstance(ad, asmbloc.asm_label): + if isinstance(ad, asmbloc.AsmLabel): l = ad else: l = mdis.symbol_pool.getby_offset_create(ad) @@ -87,8 +87,8 @@ def emul_symb(ir_arch, mdis, states_todo, states_done): p2[ad.cond] = ExprInt(1, ad.cond.size) ad1 = expr_simp(sb.eval_expr(ad.replace_expr(c1), {})) ad2 = expr_simp(sb.eval_expr(ad.replace_expr(c2), {})) - if not (isinstance(ad1, ExprInt) or (isinstance(ad1, ExprId) and isinstance(ad1.name, asmbloc.asm_label)) and - isinstance(ad2, ExprInt) or (isinstance(ad2, ExprId) and isinstance(ad2.name, asmbloc.asm_label))): + if not (isinstance(ad1, ExprInt) or (isinstance(ad1, ExprId) and isinstance(ad1.name, asmbloc.AsmLabel)) and + isinstance(ad2, ExprInt) or (isinstance(ad2, ExprId) and isinstance(ad2.name, asmbloc.AsmLabel))): print str(ad1), str(ad2) raise ValueError("zarb condition") conds1 = list(conds) + c1.items() @@ -106,7 +106,7 @@ def emul_symb(ir_arch, mdis, states_todo, states_done): elif isinstance(ad, ExprInt): ad = int(ad.arg) states_todo.add((ad, sb.symbols.copy(), tuple(conds))) - elif isinstance(ad, ExprId) and isinstance(ad.name, asmbloc.asm_label): + elif isinstance(ad, ExprId) and isinstance(ad.name, asmbloc.AsmLabel): if isinstance(ad, ExprId): ad = ad.name states_todo.add((ad, sb.symbols.copy(), tuple(conds))) diff --git a/miasm2/analysis/depgraph.py b/miasm2/analysis/depgraph.py index 214cf819..f500a736 100644 --- a/miasm2/analysis/depgraph.py +++ b/miasm2/analysis/depgraph.py @@ -2,7 +2,7 @@ import miasm2.expression.expression as m2_expr from miasm2.core.graph import DiGraph -from miasm2.core.asmbloc import asm_label, expr_is_int_or_label, expr_is_label +from miasm2.core.asmbloc import AsmLabel, expr_is_int_or_label, expr_is_label from miasm2.expression.simplifications import expr_simp from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.ir.ir import IRBlock, AssignBlock @@ -28,7 +28,7 @@ class DependencyNode(object): def __init__(self, label, element, line_nb): """Create a dependency node with: - @label: asm_label instance + @label: AsmLabel instance @element: Expr instance @line_nb: int """ @@ -107,7 +107,7 @@ class DependencyState(object): def extend(self, label): """Return a copy of itself, with itself in history - @label: asm_label instance for the new DependencyState's label + @label: AsmLabel instance for the new DependencyState's label """ new_state = self.__class__(label, self.pending) new_state.links = set(self.links) @@ -297,7 +297,7 @@ class DependencyResult(DependencyState): line_nb).irs # Eval the block - temp_label = asm_label("Temp") + temp_label = AsmLabel("Temp") symb_exec = SymbolicExecutionEngine(self._ira, ctx_init) symb_exec.emulbloc(IRBlock(temp_label, assignblks), step=step) @@ -416,7 +416,7 @@ class FollowExpr(object): """Build a set of FollowExpr(DependencyNode) from the @follow_exprs set of FollowExpr @follow_exprs: set of FollowExpr - @label: asm_label instance + @label: AsmLabel instance @line: integer """ dependencies = set() @@ -590,10 +590,10 @@ class DependencyGraph(object): """Compute the dependencies of @elements at line number @line_nb in the block named @label in the current IRA, before the execution of this line. Dependency check stop if one of @heads is reached - @label: asm_label instance + @label: AsmLabel instance @element: set of Expr instances @line_nb: int - @heads: set of asm_label instances + @heads: set of AsmLabel instances Return an iterator on DiGraph(DependencyNode) """ # Init the algorithm @@ -630,7 +630,7 @@ class DependencyGraph(object): argument. PRE: Labels and lines of depnodes have to be equals @depnodes: set of DependencyNode instances - @heads: set of asm_label instances + @heads: set of AsmLabel instances """ lead = list(depnodes)[0] elements = set(depnode.element for depnode in depnodes) diff --git a/miasm2/arch/aarch64/arch.py b/miasm2/arch/aarch64/arch.py index 460c134e..f352f547 100644 --- a/miasm2/arch/aarch64/arch.py +++ b/miasm2/arch/aarch64/arch.py @@ -8,7 +8,7 @@ from collections import defaultdict from miasm2.core.bin_stream import bin_stream import regs as regs_module from regs import * -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmbloc import AsmLabel from miasm2.core.cpu import log as log_cpu from miasm2.expression.modint import uint32, uint64 import math @@ -207,7 +207,7 @@ simdregs_h_zero = (simd32_info.parser | def ast_id2expr(t): if not t in mn_aarch64.regs.all_regs_ids_byname: - r = m2_expr.ExprId(asm_label(t)) + r = m2_expr.ExprId(AsmLabel(t)) else: r = mn_aarch64.regs.all_regs_ids_byname[t] return r diff --git a/miasm2/arch/arm/arch.py b/miasm2/arch/arm/arch.py index d9bf42ba..54a168af 100644 --- a/miasm2/arch/arm/arch.py +++ b/miasm2/arch/arm/arch.py @@ -8,7 +8,6 @@ from collections import defaultdict from miasm2.core.bin_stream import bin_stream import miasm2.arch.arm.regs as regs_module from miasm2.arch.arm.regs import * -from miasm2.core.asmbloc import asm_label # A1 encoding diff --git a/miasm2/arch/mips32/arch.py b/miasm2/arch/mips32/arch.py index 79176205..f11c6e3a 100644 --- a/miasm2/arch/mips32/arch.py +++ b/miasm2/arch/mips32/arch.py @@ -9,7 +9,6 @@ from miasm2.expression.expression import ExprMem, ExprInt, ExprInt32, ExprId from miasm2.core.bin_stream import bin_stream import miasm2.arch.mips32.regs as regs import miasm2.core.cpu as cpu -from miasm2.core.asmbloc import asm_label log = logging.getLogger("mips32dis") console_handler = logging.StreamHandler() diff --git a/miasm2/arch/msp430/arch.py b/miasm2/arch/msp430/arch.py index d7463f3d..07ba3019 100644 --- a/miasm2/arch/msp430/arch.py +++ b/miasm2/arch/msp430/arch.py @@ -8,7 +8,6 @@ from collections import defaultdict from miasm2.core.bin_stream import bin_stream import miasm2.arch.msp430.regs as regs_module from miasm2.arch.msp430.regs import * -from miasm2.core.asmbloc import asm_label log = logging.getLogger("msp430dis") console_handler = logging.StreamHandler() diff --git a/miasm2/arch/sh4/arch.py b/miasm2/arch/sh4/arch.py index ae96fef1..634cbf43 100644 --- a/miasm2/arch/sh4/arch.py +++ b/miasm2/arch/sh4/arch.py @@ -6,7 +6,6 @@ from miasm2.expression.expression import * from collections import defaultdict import miasm2.arch.sh4.regs as regs_module from miasm2.arch.sh4.regs import * -from miasm2.core.asmbloc import asm_label jra = ExprId('jra') jrb = ExprId('jrb') diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py index 8ae6cd31..55775a1a 100644 --- a/miasm2/arch/x86/arch.py +++ b/miasm2/arch/x86/arch.py @@ -7,7 +7,7 @@ from miasm2.core.cpu import * from collections import defaultdict import miasm2.arch.x86.regs as regs_module from miasm2.arch.x86.regs import * -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmbloc import AsmLabel log = logging.getLogger("x86_arch") console_handler = logging.StreamHandler() @@ -489,7 +489,7 @@ class instruction_x86(instruction): return expr = self.args[0] if isinstance(expr, ExprId): - if not isinstance(expr.name, asm_label) and expr not in all_regs_ids: + if not isinstance(expr.name, AsmLabel) and expr not in all_regs_ids: raise ValueError("ExprId must be a label or a register") elif isinstance(expr, ExprInt): ad = expr.arg + int(self.offset) diff --git a/miasm2/core/asmbloc.py b/miasm2/core/asmbloc.py index a0dd64f0..97f94821 100644 --- a/miasm2/core/asmbloc.py +++ b/miasm2/core/asmbloc.py @@ -26,15 +26,15 @@ def is_int(a): def expr_is_label(e): - return isinstance(e, m2_expr.ExprId) and isinstance(e.name, asm_label) + return isinstance(e, m2_expr.ExprId) and isinstance(e.name, AsmLabel) def expr_is_int_or_label(e): return isinstance(e, m2_expr.ExprInt) or \ - (isinstance(e, m2_expr.ExprId) and isinstance(e.name, asm_label)) + (isinstance(e, m2_expr.ExprId) and isinstance(e.name, AsmLabel)) -class asm_label: +class AsmLabel(object): "Stand for an assembly label" @@ -56,13 +56,19 @@ class asm_label: return "%s:%s" % (self.name, str(self.offset)) def __repr__(self): - rep = '<asmlabel ' + rep = '<%s ' % self.__class__.__name__ if self.name: rep += repr(self.name) + ' ' rep += '>' return rep +class asm_label(AsmLabel): + + def __init__(self, name="", offset=None): + warnings.warn('DEPRECATION WARNING: use "AsmLabel" instead of "asm_label"') + super(asm_label, self).__init__(name, offset) + class asm_raw: def __init__(self, raw=""): @@ -78,7 +84,7 @@ class asm_constraint(object): def __init__(self, label, c_t=c_to): # Sanity check - assert isinstance(label, asm_label) + assert isinstance(label, AsmLabel) self.label = label self.c_t = c_t @@ -104,7 +110,7 @@ class asm_constraint_to(asm_constraint): class AsmBlock(object): def __init__(self, label, alignment=1): - assert isinstance(label, asm_label) + assert isinstance(label, AsmLabel) self.bto = set() self.lines = [] self.label = label @@ -181,7 +187,7 @@ class AsmBlock(object): l = symbol_pool.getby_offset_create(offset) elif isinstance(offset, str): l = symbol_pool.getby_name_create(offset) - elif isinstance(offset, asm_label): + elif isinstance(offset, AsmLabel): l = offset else: raise ValueError('unknown offset type %r' % offset) @@ -314,7 +320,7 @@ class asm_symbol_pool: @name: label's name @offset: (optional) label's offset """ - label = asm_label(name, offset) + label = AsmLabel(name, offset) # Test for collisions if (label.offset in self._offset2label and @@ -445,7 +451,7 @@ class AsmCFG(DiGraph): super(AsmCFG, self).__init__(*args, **kwargs) # Edges -> constraint self.edges2constraint = {} - # Expected asm_label -> set( (src, dst), constraint ) + # Expected AsmLabel -> set( (src, dst), constraint ) self._pendings = {} # Label2block built on the fly self._label2block = {} @@ -614,7 +620,7 @@ class AsmCFG(DiGraph): def label2block(self, label): """Return the block corresponding to label @label - @label: asm_label instance or ExprId(asm_label) instance""" + @label: AsmLabel instance or ExprId(AsmLabel) instance""" return self._label2block[label] def rebuild_edges(self): @@ -1134,7 +1140,7 @@ def resolve_symbol(blockChains, symbol_pool, dst_interval=None): def filter_exprid_label(exprs): """Extract labels from list of ExprId @exprs""" - return set(expr.name for expr in exprs if isinstance(expr.name, asm_label)) + return set(expr.name for expr in exprs if isinstance(expr.name, AsmLabel)) def get_block_labels(block): @@ -1442,7 +1448,7 @@ class disasmEngine(object): dstn = [] for d in dst: if isinstance(d, m2_expr.ExprId) and \ - isinstance(d.name, asm_label): + isinstance(d.name, AsmLabel): dstn.append(d.name) if d.name.offset in self.dont_dis_retcall_funcs: add_next_offset = False diff --git a/miasm2/core/cpu.py b/miasm2/core/cpu.py index 1beeeff0..41ae822d 100644 --- a/miasm2/core/cpu.py +++ b/miasm2/core/cpu.py @@ -232,7 +232,7 @@ class ParseAst(object): if size is None: size = self.default_size assert value is not None - return m2_expr.ExprId(asmbloc.asm_label(value), size) + return m2_expr.ExprId(asmbloc.AsmLabel(value), size) def ast_to_expr(self, size, ast): """Transform a typed ast into a Miasm expression @@ -974,7 +974,7 @@ class instruction(object): ids = m2_expr.get_expr_ids(e) fixed_ids = {} for x in ids: - if isinstance(x.name, asmbloc.asm_label): + if isinstance(x.name, asmbloc.AsmLabel): name = x.name.name # special symbol $ if name == '$': diff --git a/miasm2/core/parse_asm.py b/miasm2/core/parse_asm.py index ce982b48..e51a2412 100644 --- a/miasm2/core/parse_asm.py +++ b/miasm2/core/parse_asm.py @@ -73,11 +73,11 @@ def guess_next_new_label(symbol_pool): def replace_expr_labels(expr, symbol_pool, replace_id): - """Create asm_label of the expression @expr in the @symbol_pool + """Create AsmLabel of the expression @expr in the @symbol_pool Update @replace_id""" if not (isinstance(expr, m2_expr.ExprId) and - isinstance(expr.name, asmbloc.asm_label)): + isinstance(expr.name, asmbloc.AsmLabel)): return expr old_lbl = expr.name @@ -218,7 +218,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None): line = line.strip(' ').strip('\t') instr = mnemo.fromstring(line, attrib) - # replace orphan asm_label with labels from symbol_pool + # replace orphan AsmLabel with labels from symbol_pool replace_orphan_labels(instr, symbol_pool) if instr.dstflow(): @@ -250,7 +250,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None): block_to_nlink = None i += 1 continue - elif not isinstance(line, asmbloc.asm_label): + elif not isinstance(line, asmbloc.AsmLabel): # First line must be a label. If it's not the case, generate # it. label = guess_next_new_label(symbol_pool) @@ -281,7 +281,7 @@ def parse_txt(mnemo, attrib, txt, symbol_pool=None): elif isinstance(line, asmbloc.asm_raw): cur_block.addline(line) block_to_nlink = cur_block - elif isinstance(line, asmbloc.asm_label): + elif isinstance(line, asmbloc.AsmLabel): if block_to_nlink: cur_block.addto( asmbloc.asm_constraint(line, C_NEXT)) diff --git a/miasm2/ir/ir.py b/miasm2/ir/ir.py index c2e63132..30c33b9c 100644 --- a/miasm2/ir/ir.py +++ b/miasm2/ir/ir.py @@ -24,7 +24,7 @@ from itertools import chain import miasm2.expression.expression as m2_expr from miasm2.expression.expression_helper import get_missing_interval from miasm2.expression.simplifications import expr_simp -from miasm2.core.asmbloc import asm_symbol_pool, expr_is_label, asm_label, \ +from miasm2.core.asmbloc import asm_symbol_pool, expr_is_label, AsmLabel, \ AsmBlock from miasm2.core.graph import DiGraph @@ -170,12 +170,12 @@ class IRBlock(object): def __init__(self, label, irs, lines=None): """ - @label: asm_label of the IR basic block + @label: AsmLabel of the IR basic block @irs: list of AssignBlock @lines: list of native instructions """ - assert isinstance(label, asm_label) + assert isinstance(label, AsmLabel) if lines is None: lines = [] self.label = label @@ -359,13 +359,13 @@ class IntermediateRepresentation(object): @ad: an ExprId/ExprInt/label/int""" if (isinstance(ad, m2_expr.ExprId) and - isinstance(ad.name, asm_label)): + isinstance(ad.name, AsmLabel)): ad = ad.name if isinstance(ad, m2_expr.ExprInt): ad = int(ad) if isinstance(ad, (int, long)): ad = self.symbol_pool.getby_offset_create(ad) - elif isinstance(ad, asm_label): + elif isinstance(ad, AsmLabel): ad = self.symbol_pool.getby_name_create(ad.name) return ad diff --git a/miasm2/ir/symbexec.py b/miasm2/ir/symbexec.py index d6a4c196..b5c43a4e 100644 --- a/miasm2/ir/symbexec.py +++ b/miasm2/ir/symbexec.py @@ -205,7 +205,7 @@ class SymbolicExecutionEngine(object): elif isinstance(expr, m2_expr.ExprInt): return expr elif isinstance(expr, m2_expr.ExprId): - if isinstance(expr.name, asmbloc.asm_label) and expr.name.offset is not None: + if isinstance(expr.name, asmbloc.AsmLabel) and expr.name.offset is not None: ret = m2_expr.ExprInt(expr.name.offset, expr.size) else: ret = state.get(expr, expr) diff --git a/miasm2/ir/translators/C.py b/miasm2/ir/translators/C.py index c7913ea8..4a6bbb37 100644 --- a/miasm2/ir/translators/C.py +++ b/miasm2/ir/translators/C.py @@ -23,7 +23,7 @@ class TranslatorC(Translator): def from_ExprId(self, expr): - if isinstance(expr.name, asmbloc.asm_label): + if isinstance(expr.name, asmbloc.AsmLabel): return "0x%x" % expr.name.offset return str(expr) diff --git a/miasm2/ir/translators/smt2.py b/miasm2/ir/translators/smt2.py index 5d5fb26b..7a3e342e 100644 --- a/miasm2/ir/translators/smt2.py +++ b/miasm2/ir/translators/smt2.py @@ -1,7 +1,7 @@ import logging import operator -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmbloc import AsmLabel from miasm2.ir.translators.translator import Translator from miasm2.expression.smt2_helper import * @@ -134,7 +134,7 @@ class TranslatorSMT2(Translator): return bit_vec_val(expr.arg.arg, expr.size) def from_ExprId(self, expr): - if isinstance(expr.name, asm_label): + if isinstance(expr.name, AsmLabel): if expr.name.offset is not None: return bit_vec_val(str(expr.name.offset), expr.size) else: diff --git a/miasm2/ir/translators/z3_ir.py b/miasm2/ir/translators/z3_ir.py index ccb14b4f..32c7637a 100644 --- a/miasm2/ir/translators/z3_ir.py +++ b/miasm2/ir/translators/z3_ir.py @@ -3,7 +3,7 @@ import operator import z3 -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmbloc import AsmLabel from miasm2.ir.translators.translator import Translator log = logging.getLogger("translator_z3") @@ -121,7 +121,7 @@ class TranslatorZ3(Translator): return z3.BitVecVal(expr.arg.arg, expr.size) def from_ExprId(self, expr): - if isinstance(expr.name, asm_label) and expr.name.offset is not None: + if isinstance(expr.name, AsmLabel) and expr.name.offset is not None: return z3.BitVecVal(expr.name.offset, expr.size) else: return z3.BitVec(str(expr), expr.size) diff --git a/miasm2/jitter/codegen.py b/miasm2/jitter/codegen.py index e9907071..09383f54 100644 --- a/miasm2/jitter/codegen.py +++ b/miasm2/jitter/codegen.py @@ -1,7 +1,7 @@ import miasm2.expression.expression as m2_expr from miasm2.ir.ir import IRBlock from miasm2.ir.translators import Translator -from miasm2.core.asmbloc import expr_is_label, AsmBlockBad, asm_label +from miasm2.core.asmbloc import expr_is_label, AsmBlockBad, AsmLabel # Miasm to C translator translator = Translator.to_language("C") @@ -324,11 +324,11 @@ class CGen(object): return out def gen_goto_code(self, attrib, instr_offsets, dst): - if isinstance(dst, asm_label) and dst.offset is None: + if isinstance(dst, AsmLabel) and dst.offset is None: # Generate goto for local labels return ['goto %s;' % dst.name] offset = None - if isinstance(dst, asm_label) and dst.offset is not None: + if isinstance(dst, AsmLabel) and dst.offset is not None: offset = dst.offset elif isinstance(dst, (int, long)): offset = dst diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py index ecf55bd5..b0f911eb 100644 --- a/miasm2/jitter/jitcore.py +++ b/miasm2/jitter/jitcore.py @@ -128,12 +128,12 @@ class JitCore(object): def disbloc(self, addr, vm): """Disassemble a new block and JiT it - @addr: address of the block to disassemble (asm_label or int) + @addr: address of the block to disassemble (AsmLabel or int) @vm: VmMngr instance """ # Get the block - if isinstance(addr, asmbloc.asm_label): + if isinstance(addr, asmbloc.AsmLabel): addr = addr.offset # Prepare disassembler diff --git a/miasm2/jitter/jitcore_cc_base.py b/miasm2/jitter/jitcore_cc_base.py index 2c2d3d52..9d41d06c 100644 --- a/miasm2/jitter/jitcore_cc_base.py +++ b/miasm2/jitter/jitcore_cc_base.py @@ -88,14 +88,14 @@ class JitCore_Cc_Base(JitCore): def label2fname(self, label): """ Generate function name from @label - @label: asm_label instance + @label: AsmLabel instance """ return "block_%s" % label.name def gen_c_code(self, label, block): """ Return the C code corresponding to the @irblocks - @label: asm_label of the block to jit + @label: AsmLabel of the block to jit @irblocks: list of irblocks """ f_name = self.label2fname(label) diff --git a/miasm2/jitter/llvmconvert.py b/miasm2/jitter/llvmconvert.py index 6d8cdc18..e98d2133 100644 --- a/miasm2/jitter/llvmconvert.py +++ b/miasm2/jitter/llvmconvert.py @@ -508,7 +508,7 @@ class LLVMFunction(): @label: str or asmlabel instance""" if isinstance(label, str): return label - elif isinstance(label, m2_asmbloc.asm_label): + elif isinstance(label, m2_asmbloc.AsmLabel): return "label_%s" % label.name elif m2_asmbloc.expr_is_label(label): return "label_%s" % label.name.name diff --git a/test/analysis/depgraph.py b/test/analysis/depgraph.py index 429f7dc8..f84f19cc 100644 --- a/test/analysis/depgraph.py +++ b/test/analysis/depgraph.py @@ -1,7 +1,7 @@ """Regression test module for DependencyGraph""" from miasm2.expression.expression import ExprId, ExprInt32, ExprAff, ExprCond, \ ExprInt -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmbloc import AsmLabel from miasm2.ir.analysis import ira from miasm2.ir.ir import IRBlock, AssignBlock from miasm2.core.graph import DiGraph @@ -42,13 +42,13 @@ CST33 = ExprInt32(0x33) CST35 = ExprInt32(0x35) CST37 = ExprInt32(0x37) -LBL0 = asm_label("lbl0") -LBL1 = asm_label("lbl1") -LBL2 = asm_label("lbl2") -LBL3 = asm_label("lbl3") -LBL4 = asm_label("lbl4") -LBL5 = asm_label("lbl5") -LBL6 = asm_label("lbl6") +LBL0 = AsmLabel("lbl0") +LBL1 = AsmLabel("lbl1") +LBL2 = AsmLabel("lbl2") +LBL3 = AsmLabel("lbl3") +LBL4 = AsmLabel("lbl4") +LBL5 = AsmLabel("lbl5") +LBL6 = AsmLabel("lbl6") def gen_irblock(label, exprs_list): """ Returns an IRBlock with empty lines. @@ -114,7 +114,7 @@ def bloc2graph(irgraph, label=False, lines=True): # Generate basic blocks out_blocks = [] for label in irgraph.graph.nodes(): - if isinstance(label, asm_label): + if isinstance(label, AsmLabel): label_name = label.name else: label_name = str(label) @@ -123,7 +123,7 @@ def bloc2graph(irgraph, label=False, lines=True): irblock = irgraph.blocks[label] else: irblock = None - if isinstance(label, asm_label): + if isinstance(label, AsmLabel): out_block = '%s [\n' % label.name else: out_block = '%s [\n' % label @@ -154,11 +154,11 @@ def bloc2graph(irgraph, label=False, lines=True): out += out_blocks # Generate links for src, dst in irgraph.graph.edges(): - if isinstance(src, asm_label): + if isinstance(src, AsmLabel): src_name = src.name else: src_name = str(src) - if isinstance(dst, asm_label): + if isinstance(dst, AsmLabel): dst_name = dst.name else: dst_name = str(dst) diff --git a/test/core/asmbloc.py b/test/core/asmbloc.py index ef68b5db..4b6947d6 100644 --- a/test/core/asmbloc.py +++ b/test/core/asmbloc.py @@ -3,7 +3,7 @@ from pdb import pm from miasm2.arch.x86.disasm import dis_x86_32 from miasm2.analysis.binary import Container from miasm2.core.asmbloc import AsmCFG, asm_constraint, AsmBlock, \ - asm_label, AsmBlockBad, asm_constraint_to, asm_constraint_next, \ + AsmLabel, AsmBlockBad, asm_constraint_to, asm_constraint_next, \ bbl_simplifier from miasm2.core.graph import DiGraphSimplifier, MatchGraphJoker from miasm2.expression.expression import ExprId @@ -98,7 +98,7 @@ open("graph2.dot", "w").write(blocks.dot()) # Test helper methods ## Label2block should always be updated assert blocks.label2block(first_block.label) == first_block -my_block = AsmBlock(asm_label("testlabel")) +my_block = AsmBlock(AsmLabel("testlabel")) blocks.add_node(my_block) assert len(blocks) == 3 assert blocks.label2block(first_block.label) == first_block @@ -108,7 +108,7 @@ assert blocks.label2block(my_block.label) == my_block assert len(list(blocks.get_bad_blocks())) == 0 assert len(list(blocks.get_bad_blocks_predecessors())) == 0 ### Add a bad block, not linked -my_bad_block = AsmBlockBad(asm_label("testlabel_bad")) +my_bad_block = AsmBlockBad(AsmLabel("testlabel_bad")) blocks.add_node(my_bad_block) assert list(blocks.get_bad_blocks()) == [my_bad_block] assert len(list(blocks.get_bad_blocks_predecessors())) == 0 @@ -126,7 +126,7 @@ assert len(list(blocks.get_bad_blocks_predecessors(strict=True))) == 0 ## Sanity check blocks.sanity_check() ### Next on itself -my_block_ni = AsmBlock(asm_label("testlabel_nextitself")) +my_block_ni = AsmBlock(AsmLabel("testlabel_nextitself")) my_block_ni.bto.add(asm_constraint_next(my_block_ni.label)) blocks.add_node(my_block_ni) error_raised = False @@ -139,10 +139,10 @@ assert error_raised blocks.del_node(my_block_ni) blocks.sanity_check() ### Multiple next on the same node -my_block_target = AsmBlock(asm_label("testlabel_target")) +my_block_target = AsmBlock(AsmLabel("testlabel_target")) blocks.add_node(my_block_target) -my_block_src1 = AsmBlock(asm_label("testlabel_src1")) -my_block_src2 = AsmBlock(asm_label("testlabel_src2")) +my_block_src1 = AsmBlock(AsmLabel("testlabel_src1")) +my_block_src2 = AsmBlock(AsmLabel("testlabel_src2")) my_block_src1.bto.add(asm_constraint_next(my_block_target.label)) blocks.add_node(my_block_src1) ### OK for now @@ -171,8 +171,8 @@ assert blocks.label2block(my_block_src1.label).max_size == 0 ## Check pendings ### Create a pending element -my_block_src = AsmBlock(asm_label("testlabel_pend_src")) -my_block_dst = AsmBlock(asm_label("testlabel_pend_dst")) +my_block_src = AsmBlock(AsmLabel("testlabel_pend_src")) +my_block_dst = AsmBlock(AsmLabel("testlabel_pend_dst")) my_block_src.bto.add(asm_constraint_to(my_block_dst.label)) blocks.add_node(my_block_src) ### Check resulting state diff --git a/test/core/sembuilder.py b/test/core/sembuilder.py index 3a575727..d0109092 100644 --- a/test/core/sembuilder.py +++ b/test/core/sembuilder.py @@ -3,7 +3,7 @@ from pdb import pm from miasm2.core.sembuilder import SemBuilder import miasm2.expression.expression as m2_expr -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmbloc import AsmLabel # Test classes class IR(object): @@ -11,13 +11,13 @@ class IR(object): IRDst = m2_expr.ExprId("IRDst") def get_next_instr(self, _): - return asm_label("NEXT") + return AsmLabel("NEXT") def get_next_label(self, _): - return asm_label("NEXT") + return AsmLabel("NEXT") def gen_label(self): - return asm_label("GEN") + return AsmLabel("GEN") class Instr(object): mode = 32 diff --git a/test/ir/analysis.py b/test/ir/analysis.py index 2446b5ba..0350fb23 100644 --- a/test/ir/analysis.py +++ b/test/ir/analysis.py @@ -1,6 +1,6 @@ """ Test cases for dead code elimination""" from miasm2.expression.expression import ExprId, ExprInt32, ExprAff, ExprMem -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmbloc import AsmLabel from miasm2.ir.analysis import ira from miasm2.ir.ir import IRBlock, AssignBlock @@ -23,13 +23,13 @@ CST1 = ExprInt32(0x11) CST2 = ExprInt32(0x12) CST3 = ExprInt32(0x13) -LBL0 = asm_label("lbl0") -LBL1 = asm_label("lbl1") -LBL2 = asm_label("lbl2") -LBL3 = asm_label("lbl3") -LBL4 = asm_label("lbl4") -LBL5 = asm_label("lbl5") -LBL6 = asm_label("lbl6") +LBL0 = AsmLabel("lbl0") +LBL1 = AsmLabel("lbl1") +LBL2 = AsmLabel("lbl2") +LBL3 = AsmLabel("lbl3") +LBL4 = AsmLabel("lbl4") +LBL5 = AsmLabel("lbl5") +LBL6 = AsmLabel("lbl6") diff --git a/test/ir/translators/z3_ir.py b/test/ir/translators/z3_ir.py index 5fcfe25e..9a75a320 100644 --- a/test/ir/translators/z3_ir.py +++ b/test/ir/translators/z3_ir.py @@ -1,6 +1,6 @@ import z3 -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmbloc import AsmLabel from miasm2.expression.expression import * from miasm2.ir.translators.translator import Translator from miasm2.ir.translators.z3_ir import Z3Mem @@ -139,13 +139,13 @@ for miasm_int, res in [(five, -5), (four, -4)]: assert equiv(ez3, z3_e6) # -------------------------------------------------------------------------- -e7 = ExprId(asm_label("label_histoire", 0xdeadbeef), 32) +e7 = ExprId(AsmLabel("label_histoire", 0xdeadbeef), 32) ez3 = Translator.to_language('z3').from_expr(e7) z3_e7 = z3.BitVecVal(0xdeadbeef, 32) assert equiv(ez3, z3_e7) # Should just not throw anything to pass -e8 = ExprId(asm_label("label_jambe"), 32) +e8 = ExprId(AsmLabel("label_jambe"), 32) ez3 = Translator.to_language('z3').from_expr(e8) assert not equiv(ez3, z3_e7) |