def get_from_section(self, iaddr, address, size): if address.is_defined(): if self.has_patched_global(address): return self.get_patched_global(address) elfheader = self.app.get_elf_header() sectionindex = elfheader.get_elf_section_index( address.get_offset_value()) if sectionindex is None: memval = SV.mk_simvalue(0, size=size) self.simstate.add_logmsg('global memory', str(address) + ' uninitialized') return memval offset = address.get_offset_value() for i in range(offset, offset + size): byteval = self.app.get_elf_header().get_memory_value( i, sectionindex) if byteval is not None: self.set_byte(iaddr, i, SV.SimByteValue(byteval)) else: raise UF.CHBError('No value found for ' + hex(i) + ' in section ' + str(sectionindex)) memval = M.SimMemory.get(self, iaddr, address, size) if not memval.is_defined(): memval = mk_simvalue(0, size=size) self.simstate.add_logmsg('global memory', str(address) + ' uninitialized') self.accesses.setdefault(str(address), []) chrrep = ' (' + chr( memval.value) + ')' if memval.value < 128 else '' self.accesses[str(address)].append( str(iaddr) + ':' + str(memval) + chrrep) return memval
def get_rhs(self, iaddr, op, opsize=4): opkind = op.get_mips_opkind() if opkind.is_mips_register() or opkind.is_mips_special_register(): reg = opkind.get_mips_register() return self.get_regval(iaddr, reg, opsize) elif opkind.is_mips_immediate(): return SV.mk_simvalue(opsize, opkind.get_value()) elif opkind.is_mips_indirect_register(): reg = opkind.get_mips_register() offset = opkind.get_offset() regval = self.get_regval(iaddr, reg) if not regval.is_defined(): return SV.mk_undefined_simvalue(opsize) if regval.is_string_address() and opsize == 1: regstring = regval.get_string() if offset == len(regstring): return SV.SimByteValue(0) elif offset > len(regstring): print('Accessing string value out of bounds') exit(1) else: return SV.mk_simvalue(ord(regval.get_string()[offset]), size=1) if regval.is_symbol(): base = regval.get_name() if not base in self.basemem: self.basemem[base] = MM.MIPSimBaseMemory(self, base) address = SSV.mk_base_address(base, offset=offset) return self.get_memval(iaddr, address, opsize) elif regval.is_address(): address = regval.add_offset(offset) return self.get_memval(iaddr, address, opsize) elif (regval.is_literal() and self.instaticlib and regval.value > self.libimagebase.get_offset_value()): address = SSV.mk_global_address(regval.value + offset) return self.get_memval(iaddr, address, opsize) elif (regval.is_literal() and regval.value > self.imagebase.get_offset_value()): address = SSV.mk_global_address(regval.value + offset) return self.get_memval(iaddr, address, opsize) elif regval.is_literal( ) and regval.value <= self.imagebase.get_offset_value(): print('Invalid address: ' + str(regval)) return SV.mk_undefined_simvalue(opsize) elif regval.is_string_address(): s = regval.get_string() if offset < len(s): return SV.mk_simvalue(ord(s[0]), size=opsize) elif offset == len(s): return SV.mk_simvalue(0, size=opsize) # null terminator else: raise SU.CHBSimError( self, iaddr, 'string address: ' + s.get_string() + ' with offset: ' + str(offset)) elif regval.is_libc_table_address(): return SSV.mk_libc_table_value(regval.name) elif regval.is_libc_table_value(): return SSV.mk_libc_table_value_deref(regval.name, regval.offset) else: raise SU.CHBSimError( self, iaddr, 'register used in indirect register operand has no base: ' + str(regval) + ' (' + str(self.imagebase) + ')') else: raise SU.CHBSimError(self, iaddr, 'rhs-op not recognized(C): ' + str(op))