diff options
Diffstat (limited to '')
| -rw-r--r-- | miasm2/core/asmbloc.py | 30 | ||||
| -rw-r--r-- | miasm2/core/cpu.py | 4 | ||||
| -rw-r--r-- | miasm2/core/parse_asm.py | 10 |
3 files changed, 25 insertions, 19 deletions
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)) |