def OnBlockSelected(self, event): self.BlocksItems.DeleteAllItems() item_id = self.Blocks.GetFirstSelected() item = self.Blocks.GetItem(item_id, 0) index = item.GetText() #wx.MessageBox("index: %d" % int(index), "index") reloc_dir = pedata.getRelocDirectory(self.__pe) items_index = 1 entries = pedata.getRelocDataEntry( reloc_dir[int(index) - 1]) # -1 because index starts in 1 for entry in entries: index = self.BlocksItems.InsertStringItem(sys.maxint, str(items_index)) entry_rva = entry.rva entry_type = entry.type if entry_type >= 0: entry_far_address = self.__pe.get_dword_at_rva(entry_rva) entry_offset = self.__pe.get_offset_from_rva(entry_rva) entry_rva_data = entry_far_address - self.__pe.OPTIONAL_HEADER.ImageBase try: entry_data = self.__pe.get_data(entry_rva_data, 10) bytes = get_hex_bytes(entry_data) if not bytes: bytes = "-" except pefile.PEFormatError: bytes = "-" self.BlocksItems.SetStringItem(index, 5, "%s" % bytes) if entry_type == 0: # ABSOLUTE self.BlocksItems.SetStringItem(index, 0, str(items_index)) self.BlocksItems.SetStringItem(index, 1, "-") self.BlocksItems.SetStringItem(index, 2, "-") self.BlocksItems.SetStringItem( index, 3, "%s (%d)" % (reloc_types[entry_type], entry_type)) self.BlocksItems.SetStringItem(index, 4, "-") else: self.BlocksItems.SetStringItem(index, 0, str(items_index)) self.BlocksItems.SetStringItem(index, 1, hex_up(entry_rva)) self.BlocksItems.SetStringItem(index, 2, hex_up(entry_offset)) self.BlocksItems.SetStringItem( index, 3, "%s (%d)" % (reloc_types[entry_type], entry_type)) self.BlocksItems.SetStringItem(index, 4, hex_up(entry_far_address)) items_index += 1
def OnBlockSelected(self, event): self.BlocksItems.DeleteAllItems() item_id = self.Blocks.GetFirstSelected() item = self.Blocks.GetItem(item_id, 0) index = item.GetText() #wx.MessageBox("index: %d" % int(index), "index") reloc_dir = pedata.getRelocDirectory(self.__pe) items_index = 1 entries = pedata.getRelocDataEntry(reloc_dir[int(index) - 1]) # -1 because index starts in 1 for entry in entries: index = self.BlocksItems.InsertStringItem(sys.maxint, str(items_index)) entry_rva = entry.rva entry_type = entry.type if entry_type >= 0: entry_far_address = self.__pe.get_dword_at_rva(entry_rva) entry_offset = self.__pe.get_offset_from_rva(entry_rva) entry_rva_data = entry_far_address - self.__pe.OPTIONAL_HEADER.ImageBase try: entry_data = self.__pe.get_data(entry_rva_data, 10) bytes = get_hex_bytes(entry_data) if not bytes: bytes = "-" except pefile.PEFormatError: bytes = "-" self.BlocksItems.SetStringItem(index, 5, "%s" % bytes) if entry_type == 0: # ABSOLUTE self.BlocksItems.SetStringItem(index, 0, str(items_index)) self.BlocksItems.SetStringItem(index, 1, "-") self.BlocksItems.SetStringItem(index, 2, "-") self.BlocksItems.SetStringItem(index, 3, "%s (%d)" % (reloc_types[entry_type], entry_type)) self.BlocksItems.SetStringItem(index, 4, "-") else: self.BlocksItems.SetStringItem(index, 0, str(items_index)) self.BlocksItems.SetStringItem(index, 1, hex_up(entry_rva)) self.BlocksItems.SetStringItem(index, 2, hex_up(entry_offset)) self.BlocksItems.SetStringItem(index, 3, "%s (%d)" % (reloc_types[entry_type], entry_type)) self.BlocksItems.SetStringItem(index, 4, hex_up(entry_far_address)) items_index += 1
def loadRelocsInfo(self): reloc_dir = pedata.getRelocDirectory(self.__pe) block_index = 1 for entry in reloc_dir: index = self.Blocks.InsertStringItem(sys.maxint, str(block_index)) entry_rva = entry.struct.VirtualAddress entry_size_of_block = entry.struct.SizeOfBlock entry_len = len(entry.entries) entry_section = self.__pe.sections[pedata.guess_section_from_rva(self.__pe, entry_rva)].Name self.Blocks.SetStringItem(index, 0, str(block_index)) self.Blocks.SetStringItem(index, 1, entry_section) self.Blocks.SetStringItem(index, 2, hex_up(entry_rva)) self.Blocks.SetStringItem(index, 3, hex_up(entry_size_of_block, 4)) self.Blocks.SetStringItem(index, 4, "%sh / %sd" % (hex_up(len(entry.entries), 4), len(entry.entries))) block_index += 1
def loadRelocsInfo(self): reloc_dir = pedata.getRelocDirectory(self.__pe) block_index = 1 for entry in reloc_dir: index = self.Blocks.InsertStringItem(sys.maxint, str(block_index)) entry_rva = entry.struct.VirtualAddress entry_size_of_block = entry.struct.SizeOfBlock entry_len = len(entry.entries) entry_section = self.__pe.sections[pedata.guess_section_from_rva( self.__pe, entry_rva)].Name self.Blocks.SetStringItem(index, 0, str(block_index)) self.Blocks.SetStringItem(index, 1, entry_section) self.Blocks.SetStringItem(index, 2, hex_up(entry_rva)) self.Blocks.SetStringItem(index, 3, hex_up(entry_size_of_block, 4)) self.Blocks.SetStringItem( index, 4, "%sh / %sd" % (hex_up(len(entry.entries), 4), len(entry.entries))) block_index += 1