def OnSaveButton(self, event): rva = toInt(self._rva.GetValue()) name_ordinal = toInt(self._name_ordinal.GetValue()) func_name = self._function_name.GetValue() name_rva = toInt(self._name_rva.GetValue()) old_ordinal = self.parent.getCurrentItemData()["Ordinal"] f = self.parent.getPeInstance( ).DIRECTORY_ENTRY_EXPORT.symbols[old_ordinal] f.name = func_name f.ordinal = name_ordinal f.rva = rva data = self.parent.getCurrentItemData() p = self.parent.getPeInstance() e = p.DIRECTORY_ENTRY_EXPORT.struct raw_data = p.get_data(e.AddressOfNames, 4 * e.NumberOfNames) addr_of_names = list() for i in range(0, len(raw_data), 4): addr_of_names.append(unpack("<L", raw_data[i:i + 4])[0]) p.set_dword_at_rva(addr_of_names[data["Ordinal"]], name_rva) try: self.parent.getPeInstance().write(self.parent.getFp()) except IOError, e: wx.MessageBox("%s" % e.strerror, "IOError", wx.ICON_ERROR)
def OnSaveButton(self, event): rva = toInt(self._rva.GetValue()) name_ordinal = toInt(self._name_ordinal.GetValue()) func_name = self._function_name.GetValue() name_rva = toInt(self._name_rva.GetValue()) old_ordinal = self.parent.getCurrentItemData()["Ordinal"] f = self.parent.getPeInstance().DIRECTORY_ENTRY_EXPORT.symbols[old_ordinal] f.name = func_name f.ordinal = name_ordinal f.rva = rva data = self.parent.getCurrentItemData() p = self.parent.getPeInstance() e = p.DIRECTORY_ENTRY_EXPORT.struct raw_data = p.get_data(e.AddressOfNames, 4 * e.NumberOfNames) addr_of_names = list() for i in range(0, len(raw_data), 4): addr_of_names.append(unpack("<L", raw_data[i:i+4])[0]) p.set_dword_at_rva(addr_of_names[data["Ordinal"]], name_rva) try: self.parent.getPeInstance().write(self.parent.getFp()) except IOError, e: wx.MessageBox("%s" % e.strerror, "IOError", wx.ICON_ERROR)
def OnEditSectionHeader(self, event): if self.current_item != None: self.hdr_data["SectionName"] = self.sectionList.GetItem(self.current_item, 0).GetText() self.hdr_data["VirtualSize"] = toInt(self.sectionList.GetItem(self.current_item, 1).GetText()) self.hdr_data["VirtualOffset"] = toInt(self.sectionList.GetItem(self.current_item, 2).GetText()) self.hdr_data["RawSize"] = toInt(self.sectionList.GetItem(self.current_item, 3).GetText()) self.hdr_data["RawOffset"] = toInt(self.sectionList.GetItem(self.current_item, 4).GetText()) self.hdr_data["Characteristics"] = toInt(self.sectionList.GetItem(self.current_item, 5).GetText()) secHdrDlg = edit_section_hdr.create(self) secHdrDlg.Show() self.Hide() else: wx.MessageBox("Error getting currentItem from list", "Error", wx.ICON_ERROR)
def OnExportsEdit(self, event): if self.currentItem != None: item_ordinal = self.exports_list.GetItem(self.currentItem, 0) ordinal = toInt(item_ordinal.GetText()) item_rva = self.exports_list.GetItem(self.currentItem, 1) rva = toInt(item_rva.GetText()) item_offset = self.exports_list.GetItem(self.currentItem, 2) offset = toInt(item_offset.GetText()) item_function_name = self.exports_list.GetItem(self.currentItem, 3) function_name = item_function_name.GetText() self.__exp_data["Ordinal"] = ordinal - toInt(self._base.GetValue()) self.__exp_data["RVA"] = rva self.__exp_data["Offset"] = offset self.__exp_data["Name"] = function_name editItemDlg = edit_exports.create(self) editItemDlg.ShowModal() else: wx.MessageBox("Error getting currentItem from the list", "Error", wx.ICON_ERROR)
def OnEditSectionHeader(self, event): if self.current_item != None: self.hdr_data["SectionName"] = self.sectionList.GetItem( self.current_item, 0).GetText() self.hdr_data["VirtualSize"] = toInt( self.sectionList.GetItem(self.current_item, 1).GetText()) self.hdr_data["VirtualOffset"] = toInt( self.sectionList.GetItem(self.current_item, 2).GetText()) self.hdr_data["RawSize"] = toInt( self.sectionList.GetItem(self.current_item, 3).GetText()) self.hdr_data["RawOffset"] = toInt( self.sectionList.GetItem(self.current_item, 4).GetText()) self.hdr_data["Characteristics"] = toInt( self.sectionList.GetItem(self.current_item, 5).GetText()) secHdrDlg = edit_section_hdr.create(self) secHdrDlg.Show() self.Hide() else: wx.MessageBox("Error getting currentItem from list", "Error", wx.ICON_ERROR)
def OnSaveButton(self, event): cs = pedata.getDirectoryEntryExport(self.__pe).struct new_dll_name = self._name_string.GetValue() end = self.__pe.get_data(cs.Name).find("\x00") + 1 old_dll_name = self.__pe.get_data(cs.Name, end) if len(old_dll_name) == len(new_dll_name): result = self.__pe.set_bytes_at_rva(cs.Name, new_dll_name) if not result: wx.MessageBox("Error saving the dll name", "Error", wx.ICON_ERROR) else: wx.MessageBox("The len of the dll name must be equal to the one in the file: %d" % len(old_dll_name), "Error in length", wx.ICON_ERROR) return False offset_to_et = toInt(self._offset_to_export_table.GetValue()) self.__pe.OPTIONAL_HEADER.DATA_DIRECTORY[0].VirtualAddress = offset_to_et cs.Characteristics = toInt(self._characteristics.GetValue()) cs.Base = toInt(self._base.GetValue()) cs.Name = toInt(self._name.GetValue()) cs.AddressOfFunctions = toInt(self._address_of_functions.GetValue()) cs.AddressOfNames = toInt(self._address_of_names.GetValue()) cs.NumberOfFunctions = toInt(self._number_of_functions.GetValue()) cs.NumberOfNames = toInt(self._number_of_names.GetValue()) cs.AddressOfNameOrdinals = toInt(self._address_of_name_ordinals.GetValue()) cs.TimeDateStamp = toInt(self._time_date_stamp.GetValue()) cs.MinorVersion = self._minor_version.GetValue() cs.MajorVersion = self._major_version.GetValue() try: self.__pe.write(self.__fp) except IOError, e: raise str(e)
def OnSave(self, event): # function name is an unicode string function_name = self._name.GetValue() vs = toInt(self._virtual_size.GetValue()) vo = toInt(self._virtual_address.GetValue()) rs = toInt(self._raw_size.GetValue()) ro = toInt(self._raw_offset.GetValue()) flags = toInt(self._flags.GetValue()) p = self.parent.get_pe_instance() section = p.sections[self.parent.get_section_index()] section.Characteristics = flags section.Name = str(function_name) section.Misc_VirtualSize = vs section.VirtualAddress = vo section.SizeOfRawData = rs section.PointerToRawData = ro try: p.write(self.parent.getFp()) except IOError, e: wx.MessageBox("%s" % e.strerror, "IOError", wx.ICON_ERROR)
def OnApplyChangesButton(self, event): oh = self.peInstance.OPTIONAL_HEADER fh = self.peInstance.FILE_HEADER oh.AddressOfEntryPoint = toInt(self.entrypoint.GetValue()) oh.ImageBase = toInt(self.imagebase.GetValue()) oh.BaseOfCode = toInt(self.baseofcode.GetValue()) if self.isx86: oh.BaseOfData = toInt(self.baseofdata.GetValue()) oh.SizeOfImage = toInt(self.sizeofimage.GetValue()) oh.SizeOfHeaders = toInt(self.sizeofheaders.GetValue()) oh.SectionAlignment = toInt(self.secalignment.GetValue()) oh.FileAlignment = toInt(self.falignment.GetValue()) oh.Subsystem = toInt(self.subsystem.GetValue()) fh.Machine = toInt(self.machinetype.GetValue()) fh.NumberOfSections = toInt(self.numberofsections.GetValue()) fh.TimeDateStamp = toInt(self.timadatestamp.GetValue()) fh.PointerToSymbolTable = toInt(self.symboltable.GetValue()) fh.NumberOfSymbols = toInt(self.numberofsymbols.GetValue()) fh.SizeOfOptionalHeader = toInt(self.sizeofheaders.GetValue()) fh.Characteristics = toInt(self.characteristics.GetValue()) try: self.peInstance.write(self.get_loaded_file()) except IOError, e: raise str(e)
def OnOKButton(self, event): dos_hd = self._pe.DOS_HEADER dos_hd.e_magic = toInt(self._e_magic.GetValue()) dos_hd.e_cblp = toInt(self._e_cblp.GetValue()) dos_hd.e_cp = toInt(self._e_cp.GetValue()) dos_hd.e_crlc = toInt(self._e_crlc.GetValue()) dos_hd.e_cparhdr = toInt(self._e_cparhdr.GetValue()) dos_hd.e_minalloc = toInt(self._e_minalloc.GetValue()) dos_hd.e_maxalloc = toInt(self._e_maxalloc.GetValue()) dos_hd.e_ss = toInt(self._e_ss.GetValue()) dos_hd.e_sp = toInt(self._e_sp.GetValue()) dos_hd.e_csum = toInt(self._e_csum.GetValue()) dos_hd.e_ip = toInt(self._e_ip.GetValue()) dos_hd.e_cs = toInt(self._e_cs.GetValue()) dos_hd.e_lfarlc = toInt(self._e_lfarlc.GetValue()) dos_hd.e_ovno = toInt(self._e_ovno.GetValue()) dos_hd.e_res = str(self._e_res.GetValue()) dos_hd.e_oemid = toInt(self._e_oemid.GetValue()) dos_hd.e_oeminfo = toInt(self._e_oeminfo.GetValue()) dos_hd.e_res2 = str(self._e_res2.GetValue()) dos_hd.e_elfanew = toInt(self._e_lfanew.GetValue()) try: self._pe.write(self._fp) except IOError, e: raise str(e)