diff options
Diffstat (limited to 'miasm2/arch/mips32/arch.py')
| -rw-r--r-- | miasm2/arch/mips32/arch.py | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/miasm2/arch/mips32/arch.py b/miasm2/arch/mips32/arch.py index 15c59cf0..974644dc 100644 --- a/miasm2/arch/mips32/arch.py +++ b/miasm2/arch/mips32/arch.py @@ -5,7 +5,7 @@ from collections import defaultdict from pyparsing import Literal, Group, Optional -from miasm2.expression.expression import ExprMem, ExprInt, ExprId, ExprOp +from miasm2.expression.expression import ExprMem, ExprInt, ExprId, ExprOp, ExprLoc from miasm2.core.bin_stream import bin_stream import miasm2.arch.mips32.regs as regs import miasm2.core.cpu as cpu @@ -60,11 +60,16 @@ class instruction_mips32(cpu.instruction): @staticmethod - def arg2str(e, pos = None): - if isinstance(e, ExprId) or isinstance(e, ExprInt): - return str(e) - assert(isinstance(e, ExprMem)) - arg = e.arg + def arg2str(expr, index=None, loc_db=None): + if expr.is_id() or expr.is_int(): + return str(expr) + elif expr.is_loc(): + if loc_db is not None: + return loc_db.pretty_str(expr.loc_key) + else: + return str(expr) + assert(isinstance(expr, ExprMem)) + arg = expr.arg if isinstance(arg, ExprId): return "(%s)"%arg assert(len(arg.args) == 2 and arg.op == '+') @@ -88,23 +93,22 @@ class instruction_mips32(cpu.instruction): raise NotImplementedError("TODO %s"%self) return i - def dstflow2label(self, symbol_pool): + def dstflow2label(self, loc_db): if self.name in ["J", 'JAL']: - e = self.args[0].arg - ad = (self.offset & (0xFFFFFFFF ^ ((1<< 28)-1))) + e - l = symbol_pool.getby_offset_create(ad) - self.args[0] = ExprId(l, e.size) + expr = self.args[0].arg + addr = (self.offset & (0xFFFFFFFF ^ ((1<< 28)-1))) + expr + loc_key = loc_db.get_or_create_offset_location(addr) + self.args[0] = ExprLoc(loc_key, expr.size) return ndx = self.get_dst_num() - e = self.args[ndx] + expr = self.args[ndx] - if not isinstance(e, ExprInt): + if not isinstance(expr, ExprInt): return - ad = e.arg + self.offset - l = symbol_pool.getby_offset_create(ad) - s = ExprId(l, e.size) - self.args[ndx] = s + addr = expr.arg + self.offset + loc_key = loc_db.get_or_create_offset_location(addr) + self.args[ndx] = ExprLoc(loc_key, expr.size) def breakflow(self): if self.name == 'BREAK': @@ -118,7 +122,7 @@ class instruction_mips32(cpu.instruction): return True return False - def getdstflow(self, symbol_pool): + def getdstflow(self, loc_db): if self.name in br_0: return [self.args[0]] elif self.name in br_1: @@ -143,7 +147,7 @@ class instruction_mips32(cpu.instruction): return True return False - def get_symbol_size(self, symbol, symbol_pool): + def get_symbol_size(self, symbol, loc_db): return 32 def fixDstOffset(self): @@ -255,23 +259,23 @@ def mips32op(name, fields, args=None, alias=False): #type(name, (mn_mips32b,), dct) class mips32_arg(cpu.m_arg): - def asm_ast_to_expr(self, arg, symbol_pool): + def asm_ast_to_expr(self, arg, loc_db): if isinstance(arg, AstId): if isinstance(arg.name, ExprId): return arg.name if arg.name in gpregs.str: return None - label = symbol_pool.getby_name_create(arg.name) - return ExprId(label, 32) + loc_key = loc_db.get_or_create_name_location(arg.name) + return ExprLoc(loc_key, 32) if isinstance(arg, AstOp): - args = [self.asm_ast_to_expr(tmp, symbol_pool) for tmp in arg.args] + args = [self.asm_ast_to_expr(tmp, loc_db) for tmp in arg.args] if None in args: return None return ExprOp(arg.op, *args) if isinstance(arg, AstInt): return ExprInt(arg.value, 32) if isinstance(arg, AstMem): - ptr = self.asm_ast_to_expr(arg.ptr, symbol_pool) + ptr = self.asm_ast_to_expr(arg.ptr, loc_db) if ptr is None: return None return ExprMem(ptr, arg.size) @@ -403,9 +407,9 @@ class mips32_dreg_imm(mips32_arg): return True @staticmethod - def arg2str(e): - assert(isinstance(e, ExprMem)) - arg = e.arg + def arg2str(expr, index=None): + assert(isinstance(expr, ExprMem)) + arg = expr.arg if isinstance(arg, ExprId): return "(%s)"%arg assert(len(arg.args) == 2 and arg.op == '+') |