def update_memory_view(self): if self.adapter == None: raise Exception('missing adapter') if self.memory_view == None: raise Exception('missing memory_view') for symbol in self.old_symbols: # Symbols are immutable so just destroy the old one self.memory_view.undefine_auto_symbol(symbol) for dv in self.old_dvs: self.memory_view.undefine_data_var(dv) self.old_symbols = [] self.old_dvs = set() new_dvs = set() for (reg, addr) in self.registers: bits = self.registers.bits(reg) symbol_name = '$' + reg self.memory_view.define_auto_symbol( Symbol(SymbolType.ExternalSymbol, addr, symbol_name, namespace=symbol_name)) self.old_symbols.append( self.memory_view.get_symbol_by_raw_name(symbol_name, namespace=symbol_name)) self.memory_view.define_data_var(addr, Type.int(bits // 8, sign=False)) self.old_dvs.add(addr) # Special struct for stack frame if self.remote_arch.name == 'x86_64': width = self.registers['rbp'] - self.registers[ 'rsp'] + self.remote_arch.address_size if width > 0: if width > 0x1000: width = 0x1000 struct = Structure() struct.type = StructureType.StructStructureType struct.width = width for i in range(0, width, self.remote_arch.address_size): var_name = "var_{:x}".format(width - i) struct.insert(i, Type.pointer(self.remote_arch, Type.void()), var_name) self.memory_view.define_data_var(self.registers['rsp'], Type.structure_type(struct)) self.memory_view.define_auto_symbol( Symbol(SymbolType.ExternalSymbol, self.registers['rsp'], "$stack_frame", raw_name="$stack_frame")) self.old_symbols.append( self.memory_view.get_symbol_by_raw_name("$stack_frame")) self.old_dvs.add(self.registers['rsp']) else: pass
def update_memory_view(self): if self.adapter == None: raise Exception('missing adapter') if self.memory_view == None: raise Exception('missing memory_view') addr_regs = {} reg_addrs = {} for reg in self.adapter.reg_list(): addr = self.adapter.reg_read(reg) reg_symbol_name = '$' + reg if addr not in addr_regs.keys(): addr_regs[addr] = [reg_symbol_name] else: addr_regs[addr].append(reg_symbol_name) reg_addrs[reg] = addr for symbol in self.old_symbols: # Symbols are immutable so just destroy the old one self.memory_view.undefine_auto_symbol(symbol) for dv in self.old_dvs: self.memory_view.undefine_data_var(dv) self.old_symbols = [] self.old_dvs = set() new_dvs = set() for (reg, addr) in reg_addrs.items(): symbol_name = '$' + reg self.memory_view.define_auto_symbol(Symbol(SymbolType.ExternalSymbol, addr, symbol_name, namespace=symbol_name)) self.old_symbols.append(self.memory_view.get_symbol_by_raw_name(symbol_name, namespace=symbol_name)) new_dvs.add(addr) for new_dv in new_dvs: self.memory_view.define_data_var(new_dv, Type.int(8)) self.old_dvs.add(new_dv) # Special struct for stack frame if self.bv.arch.name == 'x86_64': width = reg_addrs['rbp'] - reg_addrs['rsp'] + self.bv.arch.address_size if width > 0: if width > 0x1000: width = 0x1000 struct = Structure() struct.type = StructureType.StructStructureType struct.width = width for i in range(0, width, self.bv.arch.address_size): var_name = "var_{:x}".format(width - i) struct.insert(i, Type.pointer(self.bv.arch, Type.void()), var_name) self.memory_view.define_data_var(reg_addrs['rsp'], Type.structure_type(struct)) self.memory_view.define_auto_symbol(Symbol(SymbolType.ExternalSymbol, reg_addrs['rsp'], "$stack_frame", raw_name="$stack_frame")) self.old_symbols.append(self.memory_view.get_symbol_by_raw_name("$stack_frame")) self.old_dvs.add(reg_addrs['rsp']) else: raise NotImplementedError('only x86_64 so far')
def define_type(self): structure = Structure() structure.type = StructureType.ClassStructureType structure.width = self.vtable.instanceSize structure.insert(0, Type.pointer(self._view.arch, Type.void()), 'isa') classes = [self] current_superclass = self.superclass while current_superclass: classes.append(current_superclass) current_superclass = current_superclass.superclass while classes: current_class = classes.pop() if current_class.vtable.ivars is None: continue ivar_list = current_class.vtable.ivars for name, ivar in ivar_list.ivars.items(): structure.insert(ivar.offset, ivar.type, name) self._view.define_user_type(self.vtable.name, Type.structure_type(structure))