signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def readStringAtRva(self, rva):
d = self.getDataAtRva(rva, <NUM_LIT:1>)<EOL>resultStr = datatypes.String("<STR_LIT>")<EOL>while d != "<STR_LIT:\x00>":<EOL><INDENT>resultStr.value += d<EOL>rva += <NUM_LIT:1><EOL>d = self.getDataAtRva(rva, <NUM_LIT:1>)<EOL><DEDENT>return resultStr<EOL>
Returns a L{String} object from a given RVA. @type rva: int @param rva: The RVA to get the string from. @rtype: L{String} @return: A new L{String} object from the given RVA.
f11791:c0:m35
def isExe(self):
if not self.isDll() and not self.isDriver() and ( consts.IMAGE_FILE_EXECUTABLE_IMAGE & self.ntHeaders.fileHeader.characteristics.value) == consts.IMAGE_FILE_EXECUTABLE_IMAGE:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>
Determines if the current L{PE} instance is an Executable file. @rtype: bool @return: C{True} if the current L{PE} instance is an Executable file. Otherwise, returns C{False}.
f11791:c0:m36
def isDll(self):
if (consts.IMAGE_FILE_DLL & self.ntHeaders.fileHeader.characteristics.value) == consts.IMAGE_FILE_DLL:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>
Determines if the current L{PE} instance is a Dynamic Link Library file. @rtype: bool @return: C{True} if the current L{PE} instance is a DLL. Otherwise, returns C{False}.
f11791:c0:m37
def isDriver(self):
modules = []<EOL>imports = self.ntHeaders.optionalHeader.dataDirectory[consts.IMPORT_DIRECTORY].info<EOL>for module in imports:<EOL><INDENT>modules.append(module.metaData.moduleName.value.lower())<EOL><DEDENT>if set(["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]).intersection(modules):<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>
Determines if the current L{PE} instance is a driver (.sys) file. @rtype: bool @return: C{True} if the current L{PE} instance is a driver. Otherwise, returns C{False}.
f11791:c0:m38
def isPe32(self):
if self.ntHeaders.optionalHeader.magic.value == consts.PE32:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>
Determines if the current L{PE} instance is a PE32 file. @rtype: bool @return: C{True} if the current L{PE} instance is a PE32 file. Otherwise, returns C{False}.
f11791:c0:m39
def isPe64(self):
if self.ntHeaders.optionalHeader.magic.value == consts.PE64:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>
Determines if the current L{PE} instance is a PE64 file. @rtype: bool @return: C{True} if the current L{PE} instance is a PE64 file. Otherwise, returns C{False}.
f11791:c0:m40
def isPeBounded(self):
boundImportsDir = self.ntHeaders.optionalHeader.dataDirectory[consts.BOUND_IMPORT_DIRECTORY]<EOL>if boundImportsDir.rva.value and boundImportsDir.size.value:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>
Determines if the current L{PE} instance is bounded, i.e. has a C{BOUND_IMPORT_DIRECTORY}. @rtype: bool @return: Returns C{True} if the current L{PE} instance is bounded. Otherwise, returns C{False}.
f11791:c0:m41
def isNXEnabled(self):
return self.ntHeaders.optionalHeader.dllCharacteristics.value & consts.IMAGE_DLL_CHARACTERISTICS_NX_COMPAT == consts.IMAGE_DLL_CHARACTERISTICS_NX_COMPAT<EOL>
Determines if the current L{PE} instance has the NXCOMPAT (Compatible with Data Execution Prevention) flag enabled. @see: U{http://msdn.microsoft.com/en-us/library/ms235442.aspx} @rtype: bool @return: Returns C{True} if the current L{PE} instance has the NXCOMPAT flag enabled. Otherwise, returns C{False}.
f11791:c0:m42
def isCFGEnabled(self):
return self.ntHeaders.optionalHeader.dllCharacteristics.value & consts.IMAGE_DLL_CHARACTERISTICS_GUARD_CF == consts.IMAGE_DLL_CHARACTERISTICS_GUARD_CF<EOL>
Determines if the current L{PE} instance has CFG (Control Flow Guard) flag enabled. @see: U{http://blogs.msdn.com/b/vcblog/archive/2014/12/08/visual-studio-2015-preview-work-in-progress-security-feature.aspx} @see: U{https://msdn.microsoft.com/en-us/library/dn919635%%28v=vs.140%%29.aspx} @rtype: bool @return: Returns C{True} if the current L{PE} instance has the CFG flag enabled. Otherwise, return C{False}.
f11791:c0:m43
def isASLREnabled(self):
return self.ntHeaders.optionalHeader.dllCharacteristics.value & consts.IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE == consts.IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE<EOL>
Determines if the current L{PE} instance has the DYNAMICBASE (Use address space layout randomization) flag enabled. @see: U{http://msdn.microsoft.com/en-us/library/bb384887.aspx} @rtype: bool @return: Returns C{True} if the current L{PE} instance has the DYNAMICBASE flag enabled. Otherwise, returns C{False}.
f11791:c0:m44
def isSAFESEHEnabled(self):
NOSEH = -<NUM_LIT:1><EOL>SAFESEH_OFF = <NUM_LIT:0><EOL>SAFESEH_ON = <NUM_LIT:1><EOL>if self.ntHeaders.optionalHeader.dllCharacteristics.value & consts.IMAGE_DLL_CHARACTERISTICS_NO_SEH:<EOL><INDENT>return NOSEH<EOL><DEDENT>loadConfigDir = self.ntHeaders.optionalHeader.dataDirectory[consts.CONFIGURATION_DIRECTORY]<EOL>if loadConfigDir.info:<EOL><INDENT>if loadConfigDir.info.SEHandlerTable.value:<EOL><INDENT>return SAFESEH_ON<EOL><DEDENT><DEDENT>return SAFESEH_OFF<EOL>
Determines if the current L{PE} instance has the SAFESEH (Image has Safe Exception Handlers) flag enabled. @see: U{http://msdn.microsoft.com/en-us/library/9a89h429.aspx} @rtype: bool @return: Returns C{True} if the current L{PE} instance has the SAFESEH flag enabled. Returns C{False} if SAFESEH is off or -1 if SAFESEH is set to NO.
f11791:c0:m45
def _parseDirectories(self, dataDirectoryInstance, magic = consts.PE32):
directories = [(consts.EXPORT_DIRECTORY, self._parseExportDirectory),(consts.IMPORT_DIRECTORY, self._parseImportDirectory),(consts.RESOURCE_DIRECTORY, self._parseResourceDirectory),(consts.EXCEPTION_DIRECTORY, self._parseExceptionDirectory),(consts.RELOCATION_DIRECTORY, self._parseRelocsDirectory),(consts.TLS_DIRECTORY, self._parseTlsDirectory),(consts.DEBUG_DIRECTORY, self._parseDebugDirectory),(consts.BOUND_IMPORT_DIRECTORY, self._parseBoundImportDirectory),(consts.DELAY_IMPORT_DIRECTORY, self._parseDelayImportDirectory),(consts.CONFIGURATION_DIRECTORY, self._parseLoadConfigDirectory),(consts.NET_METADATA_DIRECTORY, self._parseNetDirectory)]<EOL>for directory in directories:<EOL><INDENT>dir = dataDirectoryInstance[directory[<NUM_LIT:0>]]<EOL>if dir.rva.value and dir.size.value:<EOL><INDENT>try:<EOL><INDENT>dataDirectoryInstance[directory[<NUM_LIT:0>]].info = directory[<NUM_LIT:1>](dir.rva.value, dir.size.value, magic)<EOL><DEDENT>except Exception as e:<EOL><INDENT>print(excep.PEWarning("<STR_LIT>" % directory[<NUM_LIT:1>].__name__.replace("<STR_LIT>", "<STR_LIT>")))<EOL><DEDENT><DEDENT><DEDENT>
Parses all the directories in the L{PE} instance. @type dataDirectoryInstance: L{DataDirectory} @param dataDirectoryInstance: A L{DataDirectory} object with the directories data. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}.
f11791:c0:m46
def _parseResourceDirectory(self, rva, size, magic = consts.PE32):
return self.getDataAtRva(rva, size)<EOL>
Parses the C{IMAGE_RESOURCE_DIRECTORY} directory. @type rva: int @param rva: The RVA where the C{IMAGE_RESOURCE_DIRECTORY} starts. @type size: int @param size: The size of the C{IMAGE_RESOURCE_DIRECTORY} directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: str @return: The C{IMAGE_RESOURCE_DIRECTORY} data.
f11791:c0:m47
def _parseExceptionDirectory(self, rva, size, magic = consts.PE32):
return self.getDataAtRva(rva, size)<EOL>
Parses the C{IMAGE_EXCEPTION_DIRECTORY} directory. @type rva: int @param rva: The RVA where the C{IMAGE_EXCEPTION_DIRECTORY} starts. @type size: int @param size: The size of the C{IMAGE_EXCEPTION_DIRECTORY} directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: str @return: The C{IMAGE_EXCEPTION_DIRECTORY} data.
f11791:c0:m48
def _parseDelayImportDirectory(self, rva, size, magic = consts.PE32):
return self.getDataAtRva(rva, size)<EOL>
Parses the delay imports directory. @type rva: int @param rva: The RVA where the delay imports directory starts. @type size: int @param size: The size of the delay imports directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: str @return: The delay imports directory data.
f11791:c0:m49
def _parseBoundImportDirectory(self, rva, size, magic = consts.PE32):
data = self.getDataAtRva(rva, size)<EOL>rd = utils.ReadData(data)<EOL>boundImportDirectory = directories.ImageBoundImportDescriptor.parse(rd)<EOL>for i in range(len(boundImportDirectory) - <NUM_LIT:1>):<EOL><INDENT>if hasattr(boundImportDirectory[i], "<STR_LIT>"):<EOL><INDENT>if boundImportDirectory[i].forwarderRefsList:<EOL><INDENT>for forwarderRefEntry in boundImportDirectory[i].forwarderRefsList:<EOL><INDENT>offset = forwarderRefEntry.offsetModuleName.value<EOL>forwarderRefEntry.moduleName = self.readStringAtRva(offset + rva)<EOL><DEDENT><DEDENT><DEDENT>offset = boundImportDirectory[i].offsetModuleName.value<EOL>boundImportDirectory[i].moduleName = self.readStringAtRva(offset + rva)<EOL><DEDENT>return boundImportDirectory<EOL>
Parses the bound import directory. @type rva: int @param rva: The RVA where the bound import directory starts. @type size: int @param size: The size of the bound import directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: L{ImageBoundImportDescriptor} @return: A new L{ImageBoundImportDescriptor} object.
f11791:c0:m50
def _parseLoadConfigDirectory(self, rva, size, magic = consts.PE32):
<EOL>data = self.getDataAtRva(rva, directories.ImageLoadConfigDirectory().sizeof())<EOL>rd = utils.ReadData(data)<EOL>if magic == consts.PE32:<EOL><INDENT>return directories.ImageLoadConfigDirectory.parse(rd)<EOL><DEDENT>elif magic == consts.PE64:<EOL><INDENT>return directories.ImageLoadConfigDirectory64.parse(rd)<EOL><DEDENT>else:<EOL><INDENT>raise excep.InvalidParameterException("<STR_LIT>")<EOL><DEDENT>
Parses IMAGE_LOAD_CONFIG_DIRECTORY. @type rva: int @param rva: The RVA where the IMAGE_LOAD_CONFIG_DIRECTORY starts. @type size: int @param size: The size of the IMAGE_LOAD_CONFIG_DIRECTORY. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: L{ImageLoadConfigDirectory} @return: A new L{ImageLoadConfigDirectory}. @note: if the L{PE} instance is a PE64 file then a new L{ImageLoadConfigDirectory64} is returned.
f11791:c0:m51
def _parseTlsDirectory(self, rva, size, magic = consts.PE32):
data = self.getDataAtRva(rva, size)<EOL>rd = utils.ReadData(data)<EOL>if magic == consts.PE32:<EOL><INDENT>return directories.TLSDirectory.parse(rd)<EOL><DEDENT>elif magic == consts.PE64:<EOL><INDENT>return directories.TLSDirectory64.parse(rd)<EOL><DEDENT>else:<EOL><INDENT>raise excep.InvalidParameterException("<STR_LIT>")<EOL><DEDENT>
Parses the TLS directory. @type rva: int @param rva: The RVA where the TLS directory starts. @type size: int @param size: The size of the TLS directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: L{TLSDirectory} @return: A new L{TLSDirectory}. @note: if the L{PE} instance is a PE64 file then a new L{TLSDirectory64} is returned.
f11791:c0:m52
def _parseRelocsDirectory(self, rva, size, magic = consts.PE32):
data = self.getDataAtRva(rva, size)<EOL>rd = utils.ReadData(data)<EOL>relocsArray = directories.ImageBaseRelocation()<EOL>while rd.offset < size:<EOL><INDENT>relocEntry = directories.ImageBaseRelocationEntry.parse(rd)<EOL>relocsArray.append(relocEntry)<EOL><DEDENT>return relocsArray<EOL>
Parses the relocation directory. @type rva: int @param rva: The RVA where the relocation directory starts. @type size: int @param size: The size of the relocation directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: L{ImageBaseRelocation} @return: A new L{ImageBaseRelocation} object.
f11791:c0:m53
def _parseExportDirectory(self, rva, size, magic = consts.PE32):
data = self.getDataAtRva(rva, size)<EOL>rd = utils.ReadData(data)<EOL>iet = directories.ImageExportTable.parse(rd)<EOL>auxFunctionRvaArray = list()<EOL>numberOfNames = iet.numberOfNames.value<EOL>addressOfNames = iet.addressOfNames.value<EOL>addressOfNameOrdinals = iet.addressOfNameOrdinals.value<EOL>addressOfFunctions = iet.addressOfFunctions.value<EOL>for i in range(iet.numberOfFunctions.value):<EOL><INDENT>auxFunctionRvaArray.append(self.getDwordAtRva(addressOfFunctions).value)<EOL>addressOfFunctions += datatypes.DWORD().sizeof()<EOL><DEDENT>for i in range(numberOfNames):<EOL><INDENT>nameRva = self.getDwordAtRva(addressOfNames).value<EOL>nameOrdinal = self.getWordAtRva(addressOfNameOrdinals).value<EOL>exportName = self.readStringAtRva(nameRva).value<EOL>entry = directories.ExportTableEntry()<EOL>ordinal = nameOrdinal + iet.base.value<EOL>entry.ordinal.value = ordinal<EOL>entry.nameOrdinal.vaue = nameOrdinal<EOL>entry.nameRva.value = nameRva<EOL>entry.name.value = exportName<EOL>entry.functionRva.value = auxFunctionRvaArray[nameOrdinal]<EOL>iet.exportTable.append(entry)<EOL>addressOfNames += datatypes.DWORD().sizeof()<EOL>addressOfNameOrdinals += datatypes.WORD().sizeof()<EOL><DEDENT>for i in range(iet.numberOfFunctions.value):<EOL><INDENT>if auxFunctionRvaArray[i] != iet.exportTable[i].functionRva.value:<EOL><INDENT>entry = directories.ExportTableEntry()<EOL>entry.functionRva.value = auxFunctionRvaArray[i]<EOL>entry.ordinal.value = iet.base.value + i<EOL>iet.exportTable.append(entry)<EOL><DEDENT><DEDENT>sorted(iet.exportTable, key=lambda entry:entry.ordinal)<EOL>return iet<EOL>
Parses the C{IMAGE_EXPORT_DIRECTORY} directory. @type rva: int @param rva: The RVA where the C{IMAGE_EXPORT_DIRECTORY} directory starts. @type size: int @param size: The size of the C{IMAGE_EXPORT_DIRECTORY} directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: L{ImageExportTable} @return: A new L{ImageExportTable} object.
f11791:c0:m54
def _parseDebugDirectory(self, rva, size, magic = consts.PE32):
debugDirData = self.getDataAtRva(rva, size)<EOL>numberOfEntries = size / consts.SIZEOF_IMAGE_DEBUG_ENTRY32<EOL>rd = utils.ReadData(debugDirData)<EOL>return directories.ImageDebugDirectories.parse(rd, numberOfEntries)<EOL>
Parses the C{IMAGE_DEBUG_DIRECTORY} directory. @see: U{http://msdn.microsoft.com/es-es/library/windows/desktop/ms680307(v=vs.85).aspx} @type rva: int @param rva: The RVA where the C{IMAGE_DEBUG_DIRECTORY} directory starts. @type size: int @param size: The size of the C{IMAGE_DEBUG_DIRECTORY} directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: L{ImageDebugDirectory} @return: A new L{ImageDebugDirectory} object.
f11791:c0:m55
def _parseImportDirectory(self, rva, size, magic = consts.PE32):
<EOL>importsDirData = self.getDataAtRva(rva, size)<EOL>numberOfEntries = size / consts.SIZEOF_IMAGE_IMPORT_ENTRY32<EOL>rd = utils.ReadData(importsDirData)<EOL>rdAux = utils.ReadData(importsDirData)<EOL>count = <NUM_LIT:0><EOL>entry = rdAux.read(consts.SIZEOF_IMAGE_IMPORT_ENTRY32)<EOL>while rdAux.offset < len(rdAux.data) and not utils.allZero(entry):<EOL><INDENT>try:<EOL><INDENT>entry = rdAux.read(consts.SIZEOF_IMAGE_IMPORT_ENTRY32)<EOL>count += <NUM_LIT:1><EOL><DEDENT>except excep.DataLengthException:<EOL><INDENT>if self._verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>if numberOfEntries - <NUM_LIT:1> > count:<EOL><INDENT>numberOfEntries = count + <NUM_LIT:1><EOL><DEDENT>iid = directories.ImageImportDescriptor.parse(rd, numberOfEntries)<EOL>iidLength = len(iid)<EOL>peIsBounded = self.isPeBounded()<EOL>if magic == consts.PE64:<EOL><INDENT>ORDINAL_FLAG = consts.IMAGE_ORDINAL_FLAG64<EOL>ADDRESS_MASK = consts.ADDRESS_MASK64<EOL><DEDENT>elif magic == consts.PE32:<EOL><INDENT>ORDINAL_FLAG = consts.IMAGE_ORDINAL_FLAG<EOL>ADDRESS_MASK = consts.ADDRESS_MASK32<EOL><DEDENT>else:<EOL><INDENT>raise InvalidParameterException("<STR_LIT>" % magic)<EOL><DEDENT>for i in range(iidLength -<NUM_LIT:1>):<EOL><INDENT>if iid[i].originalFirstThunk.value != <NUM_LIT:0>:<EOL><INDENT>iltRva = iid[i].originalFirstThunk.value<EOL>iatRva = iid[i].firstThunk.value<EOL>if magic == consts.PE64:<EOL><INDENT>entry = self.getQwordAtRva(iltRva).value<EOL><DEDENT>elif magic == consts.PE32:<EOL><INDENT>entry = self.getDwordAtRva(iltRva).value<EOL><DEDENT>while entry != <NUM_LIT:0>:<EOL><INDENT>if magic == consts.PE64:<EOL><INDENT>iatEntry = directories.ImportAddressTableEntry64()<EOL><DEDENT>elif magic == consts.PE32:<EOL><INDENT>iatEntry = directories.ImportAddressTableEntry()<EOL><DEDENT>iatEntry.originalFirstThunk.value = entry<EOL>if iatEntry.originalFirstThunk.value & ORDINAL_FLAG:<EOL><INDENT>iatEntry.hint.value = None<EOL>iatEntry.name.value = iatEntry.originalFirstThunk.value & ADDRESS_MASK<EOL><DEDENT>else: <EOL><INDENT>iatEntry.hint.value = self.getWordAtRva(iatEntry.originalFirstThunk.value).value<EOL>iatEntry.name.value = self.readStringAtRva(iatEntry.originalFirstThunk.value + <NUM_LIT:2>).value<EOL><DEDENT>if magic == consts.PE64:<EOL><INDENT>iatEntry.firstThunk.value = self.getQwordAtRva(iatRva).value<EOL>iltRva += <NUM_LIT:8><EOL>iatRva += <NUM_LIT:8><EOL>entry = self.getQwordAtRva(iltRva).value<EOL><DEDENT>elif magic == consts.PE32:<EOL><INDENT>iatEntry.firstThunk.value = self.getDwordAtRva(iatRva).value <EOL>iltRva += <NUM_LIT:4><EOL>iatRva += <NUM_LIT:4><EOL>entry = self.getDwordAtRva(iltRva).value <EOL><DEDENT>iid[i].iat.append(iatEntry)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>iatRva = iid[i].firstThunk.value<EOL>if magic == consts.PE64:<EOL><INDENT>entry = self.getQwordAtRva(iatRva).value<EOL><DEDENT>elif magic == consts.PE32:<EOL><INDENT>entry = self.getDwordAtRva(iatRva).value<EOL><DEDENT>while entry != <NUM_LIT:0>:<EOL><INDENT>if magic == consts.PE64:<EOL><INDENT>iatEntry = directories.ImportAddressTableEntry64()<EOL><DEDENT>elif magic == consts.PE32:<EOL><INDENT>iatEntry = directories.ImportAddressTableEntry()<EOL><DEDENT>iatEntry.firstThunk.value = entry<EOL>iatEntry.originalFirstThunk.value = <NUM_LIT:0><EOL>if not peIsBounded:<EOL><INDENT>ft = iatEntry.firstThunk.value<EOL>if ft & ORDINAL_FLAG:<EOL><INDENT>iatEntry.hint.value = None<EOL>iatEntry.name.value = ft & ADDRESS_MASK<EOL><DEDENT>else:<EOL><INDENT>iatEntry.hint.value = self.getWordAtRva(ft).value<EOL>iatEntry.name.value = self.readStringAtRva(ft + <NUM_LIT:2>).value <EOL><DEDENT><DEDENT>else:<EOL><INDENT>iatEntry.hint.value = None<EOL>iatEntry.name.value = None<EOL><DEDENT>if magic == consts.PE64:<EOL><INDENT>iatRva += <NUM_LIT:8><EOL>entry = self.getQwordAtRva(iatRva).value<EOL><DEDENT>elif magic == consts.PE32:<EOL><INDENT>iatRva += <NUM_LIT:4><EOL>entry = self.getDwordAtRva(iatRva).value<EOL><DEDENT>iid[i].iat.append(iatEntry)<EOL><DEDENT><DEDENT>iid[i].metaData.moduleName.value = self.readStringAtRva(iid[i].name.value).value<EOL>iid[i].metaData.numberOfImports.value = len(iid[i].iat)<EOL><DEDENT>return iid<EOL>
Parses the C{IMAGE_IMPORT_DIRECTORY} directory. @type rva: int @param rva: The RVA where the C{IMAGE_IMPORT_DIRECTORY} directory starts. @type size: int @param size: The size of the C{IMAGE_IMPORT_DIRECTORY} directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: L{ImageImportDescriptor} @return: A new L{ImageImportDescriptor} object. @raise InvalidParameterException: If wrong magic was specified.
f11791:c0:m56
def _parseNetDirectory(self, rva, size, magic = consts.PE32):
if not rva or not size:<EOL><INDENT>return None<EOL><DEDENT>netDirectoryClass = directories.NETDirectory()<EOL>netDir = directories.NetDirectory.parse(utils.ReadData(self.getDataAtRva(rva, size)))<EOL>netDirectoryClass.directory = netDir<EOL>mdhRva = netDir.metaData.rva.value<EOL>mdhSize = netDir.metaData.size.value<EOL>rd = utils.ReadData(self.getDataAtRva(mdhRva, mdhSize))<EOL>netDirectoryClass.netMetaDataHeader = directories.NetMetaDataHeader.parse(rd)<EOL>numberOfStreams = netDirectoryClass.netMetaDataHeader.numberOfStreams.value<EOL>netDirectoryClass.netMetaDataStreams = directories.NetMetaDataStreams.parse(rd, numberOfStreams)<EOL>for i in range(numberOfStreams):<EOL><INDENT>stream = netDirectoryClass.netMetaDataStreams[i]<EOL>name = stream.name.value<EOL>rd.setOffset(stream.offset.value)<EOL>rd2 = utils.ReadData(rd.read(stream.size.value))<EOL>stream.info = []<EOL>if name == "<STR_LIT>" or i == <NUM_LIT:0>:<EOL><INDENT>stream.info = rd2<EOL><DEDENT>elif name == "<STR_LIT>" or i == <NUM_LIT:1>:<EOL><INDENT>while len(rd2) > <NUM_LIT:0>:<EOL><INDENT>offset = rd2.tell()<EOL>stream.info.append({ offset: rd2.readDotNetString() })<EOL><DEDENT><DEDENT>elif name == "<STR_LIT>" or i == <NUM_LIT:2>:<EOL><INDENT>while len(rd2) > <NUM_LIT:0>:<EOL><INDENT>offset = rd2.tell()<EOL>stream.info.append({ offset: rd2.readDotNetUnicodeString() })<EOL><DEDENT><DEDENT>elif name == "<STR_LIT>" or i == <NUM_LIT:3>:<EOL><INDENT>while len(rd2) > <NUM_LIT:0>:<EOL><INDENT>offset = rd2.tell()<EOL>stream.info.append({ offset: rd2.readDotNetGuid() })<EOL><DEDENT><DEDENT>elif name == "<STR_LIT>" or i == <NUM_LIT:4>:<EOL><INDENT>while len(rd2) > <NUM_LIT:0>:<EOL><INDENT>offset = rd2.tell()<EOL>stream.info.append({ offset: rd2.readDotNetBlob() })<EOL><DEDENT><DEDENT><DEDENT>for i in range(numberOfStreams):<EOL><INDENT>stream = netDirectoryClass.netMetaDataStreams[i]<EOL>name = stream.name.value<EOL>if name == "<STR_LIT>" or i == <NUM_LIT:0>:<EOL><INDENT>stream.info = directories.NetMetaDataTables.parse(stream.info, netDirectoryClass.netMetaDataStreams)<EOL><DEDENT><DEDENT>resRva = netDir.resources.rva.value<EOL>resSize = netDir.resources.size.value<EOL>rd = utils.ReadData(self.getDataAtRva(resRva, resSize))<EOL>resources = []<EOL>for i in netDirectoryClass.netMetaDataStreams[<NUM_LIT:0>].info.tables["<STR_LIT>"]:<EOL><INDENT>offset = i["<STR_LIT>"]<EOL>rd.setOffset(offset)<EOL>size = rd.readDword()<EOL>data = rd.read(size)<EOL>if data[:<NUM_LIT:4>] == "<STR_LIT>":<EOL><INDENT>data = directories.NetResources.parse(utils.ReadData(data))<EOL><DEDENT>resources.append({ "<STR_LIT:name>": i["<STR_LIT:name>"], "<STR_LIT>": offset + <NUM_LIT:4>, "<STR_LIT:size>": size, "<STR_LIT:data>": data })<EOL><DEDENT>netDirectoryClass.directory.resources.info = resources<EOL>return netDirectoryClass<EOL>
Parses the NET directory. @see: U{http://www.ntcore.com/files/dotnetformat.htm} @type rva: int @param rva: The RVA where the NET directory starts. @type size: int @param size: The size of the NET directory. @type magic: int @param magic: (Optional) The type of PE. This value could be L{consts.PE32} or L{consts.PE64}. @rtype: L{NETDirectory} @return: A new L{NETDirectory} object.
f11791:c0:m57
def getMd5(self):
return hashlib.md5(str(self)).hexdigest()<EOL>
Get MD5 hash from PE file. @rtype: str @return: The MD5 hash from the L{PE} instance.
f11791:c0:m58
def getSha1(self):
return hashlib.sha1(str(self)).hexdigest()<EOL>
Get SHA1 hash from PE file. @rtype: str @return: The SHA1 hash from the L{PE} instance.
f11791:c0:m59
def getSha256(self):
return hashlib.sha256(str(self)).hexdigest()<EOL>
Get SHA256 hash from PE file. @rtype: str @return: The SHA256 hash from the L{PE} instance.
f11791:c0:m60
def getSha512(self):
return hashlib.sha512(str(self)).hexdigest()<EOL>
Get SHA512 hash from PE file. @rtype: str @return: The SHA512 hash from the L{PE} instance.
f11791:c0:m61
def getCRC32(self):
return binascii.crc32(str(self)) & <NUM_LIT><EOL>
Get CRC32 checksum from PE file. @rtype: int @return: The CRD32 checksum from the L{PE} instance.
f11791:c0:m62
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.e_magic = datatypes.WORD(consts.MZ_SIGNATURE) <EOL>self.e_cblp = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_cp = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_crlc = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_cparhdr = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_minalloc = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_maxalloc = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_ss = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_sp = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_csum = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_ip = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_cs = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_lfarlc = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_ovno = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_res = datatypes.Array(datatypes.TYPE_WORD) <EOL>self.e_res.extend([datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>)])<EOL>self.e_oemid = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_oeminfo = datatypes.WORD(<NUM_LIT:0>) <EOL>self.e_res2 = datatypes.Array(datatypes.TYPE_WORD) <EOL>self.e_res2.extend([datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>),datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>),datatypes.WORD(<NUM_LIT:0>), datatypes.WORD(<NUM_LIT:0>)])<EOL>self.e_lfanew = datatypes.DWORD(<NUM_LIT>) <EOL>self._attrsList = ["<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>"]<EOL>
Class representation of the C{IMAGE_DOS_HEADER} structure. @see: U{http://msdn.microsoft.com/en-us/magazine/cc301805.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to C{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11791:c1:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
dosHdr = DosHeader()<EOL>dosHdr.e_magic.value = readDataInstance.readWord()<EOL>dosHdr.e_cblp.value = readDataInstance.readWord()<EOL>dosHdr.e_cp.value = readDataInstance.readWord()<EOL>dosHdr.e_crlc.value = readDataInstance.readWord()<EOL>dosHdr.e_cparhdr.value = readDataInstance.readWord()<EOL>dosHdr.e_minalloc.value = readDataInstance.readWord()<EOL>dosHdr.e_maxalloc.value = readDataInstance.readWord()<EOL>dosHdr.e_ss.value = readDataInstance.readWord()<EOL>dosHdr.e_sp.value = readDataInstance.readWord()<EOL>dosHdr.e_csum.value = readDataInstance.readWord()<EOL>dosHdr.e_ip.value = readDataInstance.readWord()<EOL>dosHdr.e_cs.value = readDataInstance.readWord()<EOL>dosHdr.e_lfarlc.value = readDataInstance.readWord()<EOL>dosHdr.e_ovno.value = readDataInstance.readWord()<EOL>dosHdr.e_res = datatypes.Array(datatypes.TYPE_WORD)<EOL>for i in range(<NUM_LIT:4>):<EOL><INDENT>dosHdr.e_res.append(datatypes.WORD(readDataInstance.readWord()))<EOL><DEDENT>dosHdr.e_oemid.value = readDataInstance.readWord()<EOL>dosHdr.e_oeminfo.value = readDataInstance.readWord()<EOL>dosHdr.e_res2 = datatypes.Array(datatypes.TYPE_WORD)<EOL>for i in range (<NUM_LIT:10>):<EOL><INDENT>dosHdr.e_res2.append(datatypes.WORD(readDataInstance.readWord()))<EOL><DEDENT>dosHdr.e_lfanew.value = readDataInstance.readDword()<EOL>return dosHdr<EOL>
Returns a new L{DosHeader} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with data to be parsed as a L{DosHeader} object. @rtype: L{DosHeader} @return: A new L{DosHeader} object.
f11791:c1:m1
def getType(self):
return consts.IMAGE_DOS_HEADER<EOL>
Returns L{consts.IMAGE_DOS_HEADER}.
f11791:c1:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.signature = datatypes.DWORD(consts.PE_SIGNATURE) <EOL>self.fileHeader = FileHeader() <EOL>self.optionalHeader = OptionalHeader()<EOL>
Class representation of the C{IMAGE_NT_HEADERS} structure. @see: U{http://msdn.microsoft.com/es-es/library/windows/desktop/ms680336%28v=vs.85%29.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to C{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11791:c2:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
nt = NtHeaders()<EOL>nt.signature.value = readDataInstance.readDword()<EOL>nt.fileHeader = FileHeader.parse(readDataInstance)<EOL>nt.optionalHeader = OptionalHeader.parse(readDataInstance)<EOL>return nt<EOL>
Returns a new L{NtHeaders} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with data to be parsed as a L{NtHeaders} object. @rtype: L{NtHeaders} @return: A new L{NtHeaders} object.
f11791:c2:m2
def getType(self):
return consts.IMAGE_NT_HEADERS<EOL>
Returns L{consts.IMAGE_NT_HEADERS}.
f11791:c2:m3
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack = True)<EOL>self.machine = datatypes.WORD(consts.INTEL386) <EOL>self.numberOfSections = datatypes.WORD(<NUM_LIT:1>) <EOL>self.timeDateStamp = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.pointerToSymbolTable = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.numberOfSymbols = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.sizeOfOptionalHeader = datatypes.WORD(<NUM_LIT>) <EOL>self.characteristics = datatypes.WORD(consts.COMMON_CHARACTERISTICS) <EOL>self._attrsList = ["<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>"]<EOL>
Class representation of the C{IMAGE_FILE_HEADER} structure. @see: U{http://msdn.microsoft.com/es-es/library/windows/desktop/ms680313%28v=vs.85%29.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to C{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11791:c3:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
fh = FileHeader()<EOL>fh.machine.value = readDataInstance.readWord()<EOL>fh.numberOfSections.value = readDataInstance.readWord()<EOL>fh.timeDateStamp.value = readDataInstance.readDword()<EOL>fh.pointerToSymbolTable.value = readDataInstance.readDword()<EOL>fh.numberOfSymbols.value = readDataInstance.readDword()<EOL>fh.sizeOfOptionalHeader.value = readDataInstance.readWord()<EOL>fh.characteristics.value = readDataInstance.readWord()<EOL>return fh<EOL>
Returns a new L{FileHeader} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with data to be parsed as a L{FileHeader} object. @rtype: L{FileHeader} @return: A new L{ReadData} object.
f11791:c3:m1
def getType(self):
return consts.IMAGE_FILE_HEADER<EOL>
Returns L{consts.IMAGE_FILE_HEADER}.
f11791:c3:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.magic = datatypes.WORD(consts.PE32) <EOL>self.majorLinkerVersion = datatypes.BYTE(<NUM_LIT:2>) <EOL>self.minorLinkerVersion = datatypes.BYTE(<NUM_LIT>) <EOL>self.sizeOfCode = datatypes.DWORD(<NUM_LIT>) <EOL>self.sizeOfInitializedData = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.sizeOfUninitializedData = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.addressOfEntryPoint = datatypes.DWORD(<NUM_LIT>) <EOL>self.baseOfCode = datatypes.DWORD(<NUM_LIT>) <EOL>self.baseOfData = datatypes.DWORD(<NUM_LIT>) <EOL>self.imageBase = datatypes.DWORD(<NUM_LIT>) <EOL>self.sectionAlignment = datatypes.DWORD(<NUM_LIT>) <EOL>self.fileAlignment = datatypes.DWORD(<NUM_LIT>) <EOL>self.majorOperatingSystemVersion = datatypes.WORD(<NUM_LIT:5>) <EOL>self.minorOperatingSystemVersion = datatypes.WORD(<NUM_LIT:0>) <EOL>self.majorImageVersion = datatypes.WORD(<NUM_LIT:6>) <EOL>self.minorImageVersion = datatypes.WORD(<NUM_LIT:0>) <EOL>self.majorSubsystemVersion = datatypes.WORD(<NUM_LIT:5>) <EOL>self.minorSubsystemVersion = datatypes.WORD(<NUM_LIT:0>) <EOL>self.win32VersionValue = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.sizeOfImage = datatypes.DWORD(<NUM_LIT>) <EOL>self.sizeOfHeaders = datatypes.DWORD(<NUM_LIT>) <EOL>self.checksum = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.subsystem = datatypes.WORD(consts.WINDOWSGUI) <EOL>self.dllCharacteristics = datatypes.WORD(consts.TERMINAL_SERVER_AWARE) <EOL>self.sizeOfStackReserve = datatypes.DWORD(<NUM_LIT>) <EOL>self.sizeOfStackCommit = datatypes.DWORD(<NUM_LIT>) <EOL>self.sizeOfHeapReserve = datatypes.DWORD(<NUM_LIT>) <EOL>self.sizeOfHeapCommit = datatypes.DWORD(<NUM_LIT>) <EOL>self.loaderFlags = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.numberOfRvaAndSizes = datatypes.DWORD(<NUM_LIT>) <EOL>self.dataDirectory = datadirs.DataDirectory() <EOL>self._attrsList = ["<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>"]<EOL>
Class representation of the C{IMAGE_OPTIONAL_HEADER} structure. @see: U{http://msdn.microsoft.com/es-es/library/windows/desktop/ms680339%28v=vs.85%29.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to C{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11791:c4:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
oh = OptionalHeader()<EOL>oh.magic.value = readDataInstance.readWord()<EOL>oh.majorLinkerVersion.value = readDataInstance.readByte()<EOL>oh.minorLinkerVersion.value = readDataInstance.readByte()<EOL>oh.sizeOfCode.value = readDataInstance.readDword()<EOL>oh.sizeOfInitializedData.value = readDataInstance.readDword()<EOL>oh.sizeOfUninitializedData.value = readDataInstance.readDword()<EOL>oh.addressOfEntryPoint.value = readDataInstance.readDword()<EOL>oh.baseOfCode.value = readDataInstance.readDword()<EOL>oh.baseOfData.value = readDataInstance.readDword()<EOL>oh.imageBase.value = readDataInstance.readDword()<EOL>oh.sectionAlignment.value = readDataInstance.readDword()<EOL>oh.fileAlignment.value = readDataInstance.readDword()<EOL>oh.majorOperatingSystemVersion.value = readDataInstance.readWord()<EOL>oh.minorOperatingSystemVersion.value = readDataInstance.readWord()<EOL>oh.majorImageVersion.value = readDataInstance.readWord()<EOL>oh.minorImageVersion.value = readDataInstance.readWord()<EOL>oh.majorSubsystemVersion.value = readDataInstance.readWord()<EOL>oh.minorSubsystemVersion.value = readDataInstance.readWord()<EOL>oh.win32VersionValue.value = readDataInstance.readDword()<EOL>oh.sizeOfImage.value = readDataInstance.readDword()<EOL>oh.sizeOfHeaders.value = readDataInstance.readDword()<EOL>oh.checksum.value = readDataInstance.readDword()<EOL>oh.subsystem.value = readDataInstance.readWord()<EOL>oh.dllCharacteristics.value = readDataInstance.readWord()<EOL>oh.sizeOfStackReserve.value = readDataInstance.readDword()<EOL>oh.sizeOfStackCommit.value = readDataInstance.readDword()<EOL>oh.sizeOfHeapReserve.value = readDataInstance.readDword()<EOL>oh.sizeOfHeapCommit.value = readDataInstance.readDword()<EOL>oh.loaderFlags.value = readDataInstance.readDword()<EOL>oh.numberOfRvaAndSizes.value = readDataInstance.readDword()<EOL>dirs = readDataInstance.read(consts.IMAGE_NUMBEROF_DIRECTORY_ENTRIES * <NUM_LIT:8>)<EOL>oh.dataDirectory = datadirs.DataDirectory.parse(utils.ReadData(dirs))<EOL>return oh<EOL>
Returns a new L{OptionalHeader} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with data to be parsed as a L{OptionalHeader} object. @rtype: L{OptionalHeader} @return: A new L{OptionalHeader} object.
f11791:c4:m1
def getType(self):
return consts.IMAGE_OPTIONAL_HEADER<EOL>
Returns L{consts.IMAGE_OPTIONAL_HEADER}.
f11791:c4:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.magic = datatypes.WORD(consts.PE32) <EOL>self.majorLinkerVersion = datatypes.BYTE(<NUM_LIT:2>) <EOL>self.minorLinkerVersion = datatypes.BYTE(<NUM_LIT>) <EOL>self.sizeOfCode = datatypes.DWORD(<NUM_LIT>) <EOL>self.sizeOfInitializedData = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.sizeOfUninitializedData = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.addressOfEntryPoint = datatypes.DWORD(<NUM_LIT>) <EOL>self.baseOfCode = datatypes.DWORD(<NUM_LIT>) <EOL>self.imageBase = datatypes.QWORD(<NUM_LIT>) <EOL>self.sectionAlignment = datatypes.DWORD(<NUM_LIT>) <EOL>self.fileAlignment = datatypes.DWORD(<NUM_LIT>) <EOL>self.majorOperatingSystemVersion = datatypes.WORD(<NUM_LIT:5>) <EOL>self.minorOperatingSystemVersion = datatypes.WORD(<NUM_LIT:0>) <EOL>self.majorImageVersion = datatypes.WORD(<NUM_LIT:6>) <EOL>self.minorImageVersion = datatypes.WORD(<NUM_LIT:0>) <EOL>self.majorSubsystemVersion = datatypes.WORD(<NUM_LIT:5>) <EOL>self.minorSubsystemVersion = datatypes.WORD(<NUM_LIT:0>) <EOL>self.win32VersionValue = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.sizeOfImage = datatypes.DWORD(<NUM_LIT>) <EOL>self.sizeOfHeaders = datatypes.DWORD(<NUM_LIT>) <EOL>self.checksum = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.subsystem = datatypes.WORD(consts.WINDOWSGUI) <EOL>self.dllCharacteristics = datatypes.WORD(consts.TERMINAL_SERVER_AWARE) <EOL>self.sizeOfStackReserve = datatypes.QWORD(<NUM_LIT>) <EOL>self.sizeOfStackCommit = datatypes.QWORD(<NUM_LIT>) <EOL>self.sizeOfHeapReserve = datatypes.QWORD(<NUM_LIT>) <EOL>self.sizeOfHeapCommit = datatypes.QWORD(<NUM_LIT>) <EOL>self.loaderFlags = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.numberOfRvaAndSizes = datatypes.DWORD(<NUM_LIT>) <EOL>self.dataDirectory = datadirs.DataDirectory() <EOL>self._attrsList = ["<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>", "<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>"]<EOL>
Class representation of the C{IMAGE_OPTIONAL_HEADER64} structure. @see: Remarks in U{http://msdn.microsoft.com/en-us/library/windows/desktop/ms680339%28v=vs.85%29.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to C{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11791:c5:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
oh = OptionalHeader64()<EOL>oh.magic.value = readDataInstance.readWord()<EOL>oh.majorLinkerVersion.value = readDataInstance.readByte()<EOL>oh.minorLinkerVersion.value = readDataInstance.readByte()<EOL>oh.sizeOfCode.value = readDataInstance.readDword()<EOL>oh.sizeOfInitializedData.value = readDataInstance.readDword()<EOL>oh.sizeOfUninitializedData.value = readDataInstance.readDword()<EOL>oh.addressOfEntryPoint.value = readDataInstance.readDword()<EOL>oh.baseOfCode.value = readDataInstance.readDword()<EOL>oh.imageBase.value = readDataInstance.readQword()<EOL>oh.sectionAlignment.value = readDataInstance.readDword()<EOL>oh.fileAlignment.value = readDataInstance.readDword()<EOL>oh.majorOperatingSystemVersion.value = readDataInstance.readWord()<EOL>oh.minorOperatingSystemVersion.value = readDataInstance.readWord()<EOL>oh.majorImageVersion.value = readDataInstance.readWord()<EOL>oh.minorImageVersion.value = readDataInstance.readWord()<EOL>oh.majorSubsystemVersion.value = readDataInstance.readWord()<EOL>oh.minorSubsystemVersion.value = readDataInstance.readWord()<EOL>oh.win32VersionValue.value = readDataInstance.readDword()<EOL>oh.sizeOfImage.value = readDataInstance.readDword()<EOL>oh.sizeOfHeaders.value = readDataInstance.readDword()<EOL>oh.checksum.value = readDataInstance.readDword()<EOL>oh.subsystem.value = readDataInstance.readWord()<EOL>oh.dllCharacteristics.value = readDataInstance.readWord()<EOL>oh.sizeOfStackReserve.value = readDataInstance.readQword()<EOL>oh.sizeOfStackCommit.value = readDataInstance.readQword()<EOL>oh.sizeOfHeapReserve.value = readDataInstance.readQword()<EOL>oh.sizeOfHeapCommit.value = readDataInstance.readQword()<EOL>oh.loaderFlags.value = readDataInstance.readDword()<EOL>oh.numberOfRvaAndSizes.value = readDataInstance.readDword()<EOL>dirs = readDataInstance.read(consts.IMAGE_NUMBEROF_DIRECTORY_ENTRIES * <NUM_LIT:8>)<EOL>oh.dataDirectory = datadirs.DataDirectory.parse(utils.ReadData(dirs))<EOL>return oh<EOL>
Returns a new L{OptionalHeader64} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with data to be parsed as a L{OptionalHeader64} object. @rtype: L{OptionalHeader64} @return: A new L{OptionalHeader64} object.
f11791:c5:m1
def getType(self):
return consts.IMAGE_OPTIONAL_HEADER64<EOL>
Returns L{consts.IMAGE_OPTIONAL_HEADER64}.
f11791:c5:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.name = datatypes.String('<STR_LIT>') <EOL>self.misc = datatypes.DWORD(<NUM_LIT>) <EOL>self.virtualAddress = datatypes.DWORD(<NUM_LIT>) <EOL>self.sizeOfRawData = datatypes.DWORD(<NUM_LIT>) <EOL>self.pointerToRawData = datatypes.DWORD(<NUM_LIT>) <EOL>self.pointerToRelocations = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.pointerToLineNumbers = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.numberOfRelocations = datatypes.WORD(<NUM_LIT:0>) <EOL>self.numberOfLinesNumbers = datatypes.WORD(<NUM_LIT:0>) <EOL>self.characteristics = datatypes.DWORD(<NUM_LIT>) <EOL>self._attrsList = ["<STR_LIT:name>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>","<STR_LIT>"]<EOL>
Class representation of the C{IMAGE_SECTION_HEADER} structure. @see: U{http://msdn.microsoft.com/en-us/library/windows/desktop/ms680341%28v=vs.85%29.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to C{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11791:c6:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
sh = SectionHeader()<EOL>sh.name.value = readDataInstance.read(<NUM_LIT:8>)<EOL>sh.misc.value = readDataInstance.readDword()<EOL>sh.virtualAddress.value = readDataInstance.readDword()<EOL>sh.sizeOfRawData.value = readDataInstance.readDword()<EOL>sh.pointerToRawData.value = readDataInstance.readDword()<EOL>sh.pointerToRelocations.value = readDataInstance.readDword()<EOL>sh.pointerToLineNumbers.value = readDataInstance.readDword()<EOL>sh.numberOfRelocations.value = readDataInstance.readWord()<EOL>sh.numberOfLinesNumbers.value = readDataInstance.readWord()<EOL>sh.characteristics.value = readDataInstance.readDword()<EOL>return sh<EOL>
Returns a new L{SectionHeader} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with data to be parsed as a L{SectionHeader} object. @rtype: L{SectionHeader} @return: A new L{SectionHeader} object.
f11791:c6:m1
def getType(self):
return consts.IMAGE_SECTION_HEADER<EOL>
Returns L{consts.IMAGE_SECTION_HEADER}.
f11791:c6:m2
def __init__(self, numberOfSectionHeaders = <NUM_LIT:1>, shouldPack = True):
list.__init__(self)<EOL>self.shouldPack = shouldPack<EOL>if numberOfSectionHeaders:<EOL><INDENT>for i in range(numberOfSectionHeaders):<EOL><INDENT>sh = SectionHeader()<EOL>self.append(sh)<EOL><DEDENT><DEDENT>
Array of L{SectionHeader} objects. @type shouldPack: bool @param shouldPack: (Optional) If set to C{True}, the object will be packed. If set to C{False}, the object won't be packed. @type numberOfSectionHeaders: int @param numberOfSectionHeaders: (Optional) The number of desired section headers. By default, this parameter is set to 1.
f11791:c7:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance, numberOfSectionHeaders):<DEDENT>
sHdrs = SectionHeaders(numberOfSectionHeaders = <NUM_LIT:0>)<EOL>for i in range(numberOfSectionHeaders):<EOL><INDENT>sh = SectionHeader()<EOL>sh.name.value = readDataInstance.read(<NUM_LIT:8>)<EOL>sh.misc.value = readDataInstance.readDword()<EOL>sh.virtualAddress.value = readDataInstance.readDword()<EOL>sh.sizeOfRawData.value = readDataInstance.readDword()<EOL>sh.pointerToRawData.value = readDataInstance.readDword()<EOL>sh.pointerToRelocations.value = readDataInstance.readDword()<EOL>sh.pointerToLineNumbers.value = readDataInstance.readDword()<EOL>sh.numberOfRelocations.value = readDataInstance.readWord()<EOL>sh.numberOfLinesNumbers.value = readDataInstance.readWord()<EOL>sh.characteristics.value = readDataInstance.readDword()<EOL>sHdrs.append(sh)<EOL><DEDENT>return sHdrs<EOL>
Returns a new L{SectionHeaders} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with data to be parsed as a L{SectionHeaders} object. @type numberOfSectionHeaders: int @param numberOfSectionHeaders: The number of L{SectionHeader} objects in the L{SectionHeaders} instance.
f11791:c7:m2
def __init__(self, sectionHeadersInstance = None):
list.__init__(self)<EOL>if sectionHeadersInstance:<EOL><INDENT>for sh in sectionHeadersInstance:<EOL><INDENT>self.append("<STR_LIT>" * sh.sizeOfRawData.value)<EOL><DEDENT><DEDENT>
Array with the data of each section present in the file. @type sectionHeadersInstance: instance @param sectionHeadersInstance: (Optional) A L{SectionHeaders} instance to be parsed.
f11791:c8:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance, sectionHeadersInstance):<DEDENT>
sData = Sections()<EOL>for sectionHdr in sectionHeadersInstance:<EOL><INDENT>if sectionHdr.sizeOfRawData.value > len(readDataInstance.data):<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if sectionHdr.pointerToRawData.value > len(readDataInstance.data):<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if sectionHdr.misc.value > <NUM_LIT>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if sectionHdr.virtualAddress.value > <NUM_LIT>:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if sectionHdr.pointerToRawData.value:<EOL><INDENT>sData.append(readDataInstance.read(sectionHdr.sizeOfRawData.value))<EOL><DEDENT><DEDENT>return sData<EOL>
Returns a new L{Sections} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with data to be parsed as a L{Sections} object. @type sectionHeadersInstance: instance @param sectionHeadersInstance: The L{SectionHeaders} instance with the necessary to parse every section data. @rtype: L{Sections} @return: A new L{Sections} object.
f11791:c8:m2
def powerOfTwo(value):
return value != <NUM_LIT:0> and (value & (value - <NUM_LIT:1>)) == <NUM_LIT:0><EOL>
Tries to determine if a given value is a power of two. @type value: int @param value: Value to test if it is power of two. @rtype: bool @return: C{True} if the value is power of two, C{False} if it doesn't.
f11792:m0
def allZero(buffer):
allZero = True<EOL>for byte in buffer:<EOL><INDENT>if byte != "<STR_LIT:\x00>":<EOL><INDENT>allZero = False<EOL>break<EOL><DEDENT><DEDENT>return allZero<EOL>
Tries to determine if a buffer is empty. @type buffer: str @param buffer: Buffer to test if it is empty. @rtype: bool @return: C{True} if the given buffer is empty, i.e. full of zeros, C{False} if it doesn't.
f11792:m1
def __init__(self, data, endianness = "<STR_LIT:<>", signed = False):
self.data = StringIO(data)<EOL>self.endianness = endianness<EOL>self.signed = signed<EOL>
@type data: str @param data: Data to create the L{WriteData} object. @type endianness: str @param endianness: (Optional) Indicates the endianness used to write the data. The C{<} indicates little-endian while C{>} indicates big-endian. @type signed: bool @param signed: (Optional) If set to C{True} the data will be treated as signed. If set to C{False} it will be treated as unsigned.
f11792:c0:m0
def writeByte(self, byte):
self.data.write(pack("<STR_LIT:B>" if not self.signed else "<STR_LIT:b>", byte))<EOL>
Writes a byte into the L{WriteData} stream object. @type byte: int @param byte: Byte value to write into the stream.
f11792:c0:m3
def writeWord(self, word):
self.data.write(pack(self.endianness + ("<STR_LIT:H>" if not self.signed else "<STR_LIT:h>"), word))<EOL>
Writes a word value into the L{WriteData} stream object. @type word: int @param word: Word value to write into the stream.
f11792:c0:m4
def writeDword(self, dword):
self.data.write(pack(self.endianness + ("<STR_LIT:L>" if not self.signed else "<STR_LIT:l>"), dword))<EOL>
Writes a dword value into the L{WriteData} stream object. @type dword: int @param dword: Dword value to write into the stream.
f11792:c0:m5
def writeQword(self, qword):
self.data.write(pack(self.endianness + ("<STR_LIT>" if not self.signed else "<STR_LIT:q>"), qword))<EOL>
Writes a qword value into the L{WriteData} stream object. @type qword: int @param qword: Qword value to write into the stream.
f11792:c0:m6
def write(self, dataToWrite):
self.data.write(dataToWrite)<EOL>
Writes data into the L{WriteData} stream object. @type dataToWrite: str @param dataToWrite: Data to write into the stream.
f11792:c0:m7
def setOffset(self, value):
if value >= len(self.data.getvalue()):<EOL><INDENT>raise excep.WrongOffsetValueException("<STR_LIT>" % len(self.data))<EOL><DEDENT>self.data.seek(value)<EOL>
Sets the offset of the L{WriteData} stream object in wich the data is written. @type value: int @param value: Integer value that represent the offset we want to start writing in the L{WriteData} stream. @raise WrongOffsetValueException: The value is beyond the total length of the data.
f11792:c0:m8
def skipBytes(self, nroBytes):
self.data.seek(nroBytes + self.data.tell())<EOL>
Skips the specified number as parameter to the current value of the L{WriteData} stream. @type nroBytes: int @param nroBytes: The number of bytes to skip.
f11792:c0:m9
def tell(self):
return self.data.tell()<EOL>
Returns the current position of the offset in the L{WriteData} sream object. @rtype: int @return: The value of the current offset in the stream.
f11792:c0:m10
def __init__(self, data, endianness = "<STR_LIT:<>", signed = False):
self.data = data<EOL>self.offset = <NUM_LIT:0><EOL>self.endianness = endianness<EOL>self.signed = signed<EOL>self.log = False<EOL>self.length = len(data)<EOL>
@type data: str @param data: The data from which we want to read. @type endianness: str @param endianness: (Optional) Indicates the endianness used to read the data. The C{<} indicates little-endian while C{>} indicates big-endian. @type signed: bool @param signed: (Optional) If set to C{True} the data will be treated as signed. If set to C{False} it will be treated as unsigned.
f11792:c1:m0
def readDword(self):
dword = unpack(self.endianness + ('<STR_LIT:L>' if not self.signed else '<STR_LIT:l>'), self.readAt(self.offset, <NUM_LIT:4>))[<NUM_LIT:0>]<EOL>self.offset += <NUM_LIT:4><EOL>return dword<EOL>
Reads a dword value from the L{ReadData} stream object. @rtype: int @return: The dword value read from the L{ReadData} stream.
f11792:c1:m2
def readWord(self):
word = unpack(self.endianness + ('<STR_LIT:H>' if not self.signed else '<STR_LIT:h>'), self.readAt(self.offset, <NUM_LIT:2>))[<NUM_LIT:0>]<EOL>self.offset += <NUM_LIT:2><EOL>return word<EOL>
Reads a word value from the L{ReadData} stream object. @rtype: int @return: The word value read from the L{ReadData} stream.
f11792:c1:m3
def readByte(self):
byte = unpack('<STR_LIT:B>' if not self.signed else '<STR_LIT:b>', self.readAt(self.offset, <NUM_LIT:1>))[<NUM_LIT:0>]<EOL>self.offset += <NUM_LIT:1><EOL>return byte<EOL>
Reads a byte value from the L{ReadData} stream object. @rtype: int @return: The byte value read from the L{ReadData} stream.
f11792:c1:m4
def readQword(self):
qword = unpack(self.endianness + ('<STR_LIT>' if not self.signed else '<STR_LIT:b>'), self.readAt(self.offset, <NUM_LIT:8>))[<NUM_LIT:0>]<EOL>self.offset += <NUM_LIT:8><EOL>return qword<EOL>
Reads a qword value from the L{ReadData} stream object. @rtype: int @return: The qword value read from the L{ReadData} stream.
f11792:c1:m5
def readString(self):
resultStr = "<STR_LIT>"<EOL>while self.data[self.offset] != "<STR_LIT:\x00>":<EOL><INDENT>resultStr += self.data[self.offset]<EOL>self.offset += <NUM_LIT:1><EOL><DEDENT>return resultStr<EOL>
Reads an ASCII string from the L{ReadData} stream object. @rtype: str @return: An ASCII string read form the stream.
f11792:c1:m6
def readAlignedString(self, align = <NUM_LIT:4>):
s = self.readString()<EOL>r = align - len(s) % align<EOL>while r:<EOL><INDENT>s += self.data[self.offset]<EOL>self.offset += <NUM_LIT:1><EOL>r -= <NUM_LIT:1><EOL><DEDENT>return s.rstrip("<STR_LIT:\x00>")<EOL>
Reads an ASCII string aligned to the next align-bytes boundary. @type align: int @param align: (Optional) The value we want the ASCII string to be aligned. @rtype: str @return: A 4-bytes aligned (default) ASCII string.
f11792:c1:m7
def read(self, nroBytes):
if nroBytes > self.length - self.offset:<EOL><INDENT>if self.log:<EOL><INDENT>print("<STR_LIT>" % (nroBytes, self.length - self.offset))<EOL><DEDENT>nroBytes = self.length - self.offset<EOL><DEDENT>resultStr = self.data[self.offset:self.offset + nroBytes]<EOL>self.offset += nroBytes<EOL>return resultStr<EOL>
Reads data from the L{ReadData} stream object. @type nroBytes: int @param nroBytes: The number of bytes to read. @rtype: str @return: A string containing the read data from the L{ReadData} stream object. @raise DataLengthException: The number of bytes tried to be read are more than the remaining in the L{ReadData} stream.
f11792:c1:m8
def skipBytes(self, nroBytes):
self.offset += nroBytes<EOL>
Skips the specified number as parameter to the current value of the L{ReadData} stream. @type nroBytes: int @param nroBytes: The number of bytes to skip.
f11792:c1:m9
def setOffset(self, value):
<EOL>self.offset = value<EOL>
Sets the offset of the L{ReadData} stream object in wich the data is read. @type value: int @param value: Integer value that represent the offset we want to start reading in the L{ReadData} stream. @raise WrongOffsetValueException: The value is beyond the total length of the data.
f11792:c1:m10
def readAt(self, offset, size):
if offset > self.length:<EOL><INDENT>if self.log:<EOL><INDENT>print("<STR_LIT>" % (nroBytes, self.length - self.offset))<EOL><DEDENT>offset = self.length - self.offset<EOL><DEDENT>tmpOff = self.tell()<EOL>self.setOffset(offset)<EOL>r = self.read(size)<EOL>self.setOffset(tmpOff)<EOL>return r<EOL>
Reads as many bytes indicated in the size parameter at the specific offset. @type offset: int @param offset: Offset of the value to be read. @type size: int @param size: This parameter indicates how many bytes are going to be read from a given offset. @rtype: str @return: A packed string containing the read data.
f11792:c1:m11
def tell(self):
return self.offset<EOL>
Returns the current position of the offset in the L{ReadData} sream object. @rtype: int @return: The value of the current offset in the stream.
f11792:c1:m12
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.timeDateStamp = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.offsetModuleName = datatypes.WORD(<NUM_LIT:0>) <EOL>self.reserved = datatypes.WORD(<NUM_LIT:0>) <EOL>self.moduleName = datatypes.String(shouldPack = False) <EOL>self._attrsList = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>
This class represents an element of type C{IMAGE_BOUND_FORWARDER_REF}. @see: U{http://msdn.microsoft.com/en-us/magazine/cc301808.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c0:m0
def getType(self):
return consts.IMAGE_BOUND_FORWARDER_REF_ENTRY<EOL>
Returns L{consts.IMAGE_BOUND_FORWARDER_REF_ENTRY}.
f11794:c0:m1
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
boundForwarderEntry = ImageBoundForwarderRefEntry()<EOL>boundForwarderEntry.timeDateStamp.value = readDataInstance.readDword()<EOL>boundForwarderEntry.offsetModuleName.value = readDataInstance.readWord()<EOL>boundForwarderEntry.reserved.value = readDataInstance.readWord()<EOL>return boundForwarderEntry<EOL>
Returns a new L{ImageBoundForwarderRefEntry} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with the corresponding data to generate a new L{ImageBoundForwarderRefEntry} object. @rtype: L{ImageBoundForwarderRefEntry} @return: A new L{ImageBoundForwarderRefEntry} object.
f11794:c0:m2
def __init__(self, shouldPack = True):
list.__init__(self)<EOL>self.shouldPack = shouldPack<EOL>
This class is a wrapper over an array of C{IMAGE_BOUND_FORWARDER_REF}. @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c1:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance, numberOfEntries):<DEDENT>
imageBoundForwarderRefsList = ImageBoundForwarderRef()<EOL>dLength = len(readDataInstance)<EOL>entryLength = ImageBoundForwarderRefEntry().sizeof()<EOL>toRead = numberOfEntries * entryLength<EOL>if dLength >= toRead:<EOL><INDENT>for i in range(numberOfEntries):<EOL><INDENT>entryData = readDataInstance.read(entryLength)<EOL>rd = utils.ReadData(entryData)<EOL>imageBoundForwarderRefsList.append(ImageBoundForwarderRefEntry.parse(rd))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise excep.DataLengthException("<STR_LIT>")<EOL><DEDENT>return imageBoundForwarderRefsList<EOL>
Returns a L{ImageBoundForwarderRef} array where every element is a L{ImageBoundForwarderRefEntry} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with the corresponding data to generate a new L{ImageBoundForwarderRef} object. @type numberOfEntries: int @param numberOfEntries: The number of C{IMAGE_BOUND_FORWARDER_REF} entries in the array. @rtype: L{ImageBoundForwarderRef} @return: A new L{ImageBoundForwarderRef} object. @raise DataLengthException: If the L{ReadData} instance has less data than C{NumberOfEntries} * sizeof L{ImageBoundForwarderRefEntry}.
f11794:c1:m2
def __init__(self, shouldPack = True):
list.__init__(self)<EOL>self.shouldPack = shouldPack<EOL>
Array of L{ImageBoundImportDescriptorEntry} objects. @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c2:m0
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
ibd = ImageBoundImportDescriptor()<EOL>entryData = readDataInstance.read(consts.SIZEOF_IMAGE_BOUND_IMPORT_ENTRY32)<EOL>readDataInstance.offset = <NUM_LIT:0><EOL>while not utils.allZero(entryData):<EOL><INDENT>prevOffset = readDataInstance.offset<EOL>boundEntry = ImageBoundImportDescriptorEntry.parse(readDataInstance)<EOL>if boundEntry.numberOfModuleForwarderRefs.value:<EOL><INDENT>readDataInstance.offset = prevOffset + (consts.SIZEOF_IMAGE_BOUND_FORWARDER_REF_ENTRY32 * boundEntry.numberOfModuleForwarderRefs.value)<EOL><DEDENT>else:<EOL><INDENT>readDataInstance.offset = prevOffset<EOL><DEDENT>ibd.append(boundEntry)<EOL>entryData = readDataInstance.read(consts.SIZEOF_IMAGE_BOUND_IMPORT_ENTRY32)<EOL><DEDENT>return ibd<EOL>
Returns a new L{ImageBoundImportDescriptor} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object containing the data to create a new L{ImageBoundImportDescriptor} object. @rtype: L{ImageBoundImportDescriptor} @return: A new {ImageBoundImportDescriptor} object.
f11794:c2:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.timeDateStamp = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.offsetModuleName = datatypes.WORD(<NUM_LIT:0>) <EOL>self.numberOfModuleForwarderRefs = datatypes.WORD(<NUM_LIT:0>)<EOL>self.forwarderRefsList = ImageBoundForwarderRef() <EOL>self.moduleName = datatypes.String(shouldPack = False) <EOL>self._attrsList = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>
This class represents a C{IMAGE_BOUND_IMPORT_DESCRIPTOR} structure. @see: U{http://msdn.microsoft.com/en-us/magazine/cc301808.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c3:m0
def getType(self):
return consts.IMAGE_BOUND_IMPORT_DESCRIPTOR_ENTRY<EOL>
Returns L{consts.IMAGE_BOUND_IMPORT_DESCRIPTOR_ENTRY}
f11794:c3:m1
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
boundEntry = ImageBoundImportDescriptorEntry()<EOL>boundEntry.timeDateStamp.value = readDataInstance.readDword()<EOL>boundEntry.offsetModuleName.value = readDataInstance.readWord()<EOL>boundEntry.numberOfModuleForwarderRefs.value = readDataInstance.readWord()<EOL>numberOfForwarderRefsEntries = boundEntry.numberOfModuleForwarderRefs .value<EOL>if numberOfForwarderRefsEntries:<EOL><INDENT>bytesToRead = numberOfForwarderRefsEntries * ImageBoundForwarderRefEntry().sizeof()<EOL>rd = utils.ReadData(readDataInstance.read(bytesToRead))<EOL>boundEntry.forwarderRefsList = ImageBoundForwarderRef.parse(rd, numberOfForwarderRefsEntries)<EOL><DEDENT>return boundEntry<EOL>
Returns a new L{ImageBoundImportDescriptorEntry} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object containing data to create a new L{ImageBoundImportDescriptorEntry}. @rtype: L{ImageBoundImportDescriptorEntry} @return: A new {ImageBoundImportDescriptorEntry} object.
f11794:c3:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.startAddressOfRawData = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.endAddressOfRawData = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.addressOfIndex = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.addressOfCallbacks = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.sizeOfZeroFill = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.characteristics = datatypes.DWORD(<NUM_LIT:0>) <EOL>self._attrsList = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>"]<EOL>
Class representation of a C{IMAGE_TLS_DIRECTORY} structure. @see: Figure 11 U{http://msdn.microsoft.com/en-us/magazine/bb985996.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c4:m0
def getType(self):
return consts.TLS_DIRECTORY32<EOL>
Returns L{consts.TLS_DIRECTORY}.
f11794:c4:m1
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
tlsDir = TLSDirectory()<EOL>tlsDir.startAddressOfRawData.value = readDataInstance.readDword()<EOL>tlsDir.endAddressOfRawData.value = readDataInstance.readDword()<EOL>tlsDir.addressOfIndex.value = readDataInstance.readDword()<EOL>tlsDir.addressOfCallbacks.value = readDataInstance.readDword()<EOL>tlsDir.sizeOfZeroFill.value = readDataInstance.readDword()<EOL>tlsDir.characteristics.value = readDataInstance.readDword()<EOL>return tlsDir<EOL>
Returns a new L{TLSDirectory} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object containing data to create a new L{TLSDirectory} object. @rtype: L{TLSDirectory} @return: A new {TLSDirectory} object.
f11794:c4:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.startAddressOfRawData = datatypes.QWORD(<NUM_LIT:0>) <EOL>self.endAddressOfRawData = datatypes.QWORD(<NUM_LIT:0>) <EOL>self.addressOfIndex = datatypes.QWORD(<NUM_LIT:0>) <EOL>self.addressOfCallbacks = datatypes.QWORD(<NUM_LIT:0>) <EOL>self.sizeOfZeroFill = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.characteristics = datatypes.DWORD(<NUM_LIT:0>) <EOL>self._attrsList = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>"]<EOL>
Class representation of a C{IMAGE_TLS_DIRECTORY} structure in 64 bits systems. @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c5:m0
def getType(self):
return consts.TLS_DIRECTORY64<EOL>
Returns L{consts.TLS_DIRECTORY64}.
f11794:c5:m1
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
tlsDir = TLSDirectory64()<EOL>tlsDir.startAddressOfRawData.value = readDataInstance.readQword()<EOL>tlsDir.endAddressOfRawData.value = readDataInstance.readQword()<EOL>tlsDir.addressOfIndex.value = readDataInstance.readQword()<EOL>tlsDir.addressOfCallbacks.value = readDataInstance.readQword()<EOL>tlsDir.sizeOfZeroFill.value = readDataInstance.readDword()<EOL>tlsDir.characteristics.value = readDataInstance.readDword()<EOL>return tlsDir<EOL>
Returns a new L{TLSDirectory64} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object containing data to create a new L{TLSDirectory64} object. @rtype: L{TLSDirectory64} @return: A new L{TLSDirectory64} object.
f11794:c5:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.size = datatypes.DWORD()<EOL>self.timeDateStamp = datatypes.DWORD()<EOL>self.majorVersion = datatypes.WORD()<EOL>self.minorVersion = datatypes.WORD()<EOL>self.globalFlagsClear = datatypes.DWORD()<EOL>self.globalFlagsSet = datatypes.DWORD()<EOL>self.criticalSectionDefaultTimeout = datatypes.DWORD()<EOL>self.deCommitFreeBlockThreshold = datatypes.DWORD()<EOL>self.deCommitTotalFreeThreshold = datatypes.DWORD()<EOL>self.lockPrefixTable = datatypes.DWORD() <EOL>self.maximumAllocationSize = datatypes.DWORD()<EOL>self.virtualMemoryThreshold = datatypes.DWORD()<EOL>self.processHeapFlags = datatypes.DWORD()<EOL>self.processAffinityMask = datatypes.DWORD()<EOL>self.csdVersion = datatypes.WORD()<EOL>self.reserved1 = datatypes.WORD()<EOL>self.editList = datatypes.DWORD() <EOL>self.securityCookie = datatypes.DWORD() <EOL>self.SEHandlerTable = datatypes.DWORD() <EOL>self.SEHandlerCount = datatypes.DWORD()<EOL>self.GuardCFCheckFunctionPointer = datatypes.DWORD() <EOL>self.Reserved2 = datatypes.DWORD()<EOL>self.GuardCFFunctionTable = datatypes.DWORD() <EOL>self.GuardCFFunctionCount = datatypes.DWORD()<EOL>self.GuardFlags = datatypes.DWORD()<EOL>self._attrsList = ["<STR_LIT:size>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>"]<EOL>
Class representation of a C{IMAGE_LOAD_CONFIG_DIRECTORY32} structure. @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c6:m0
def getType(self):
return consts.IMAGE_LOAD_CONFIG_DIRECTORY32<EOL>
Returns L{consts.IMAGE_LOAD_CONFIG_DIRECTORY32}.
f11794:c6:m1
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
configDir = ImageLoadConfigDirectory()<EOL>configDir.size.value = readDataInstance.readDword()<EOL>configDir.timeDateStamp.value = readDataInstance.readDword()<EOL>configDir.majorVersion.value = readDataInstance.readWord()<EOL>configDir.minorVersion.value = readDataInstance.readWord()<EOL>configDir.globalFlagsClear.value = readDataInstance.readDword()<EOL>configDir.globalFlagsSet.value = readDataInstance.readDword()<EOL>configDir.criticalSectionDefaultTimeout.value = readDataInstance.readDword()<EOL>configDir.deCommitFreeBlockThreshold.value = readDataInstance.readDword()<EOL>configDir.deCommitTotalFreeThreshold.value = readDataInstance.readDword()<EOL>configDir.lockPrefixTable.value = readDataInstance.readDword() <EOL>configDir.maximumAllocationSize.value = readDataInstance.readDword()<EOL>configDir.virtualMemoryThreshold.value = readDataInstance.readDword()<EOL>configDir.processHeapFlags.value = readDataInstance.readDword()<EOL>configDir.processAffinityMask.value = readDataInstance.readDword()<EOL>configDir.csdVersion.value = readDataInstance.readWord()<EOL>configDir.reserved1.value = readDataInstance.readWord()<EOL>configDir.editList.value = readDataInstance.readDword() <EOL>configDir.securityCookie.value = readDataInstance.readDword() <EOL>configDir.SEHandlerTable.value = readDataInstance.readDword() <EOL>configDir.SEHandlerCount.value = readDataInstance.readDword()<EOL>configDir.GuardCFCheckFunctionPointer.value = readDataInstance.readDword() <EOL>configDir.Reserved2.value = readDataInstance.readDword()<EOL>configDir.GuardCFFunctionTable.value = readDataInstance.readDword() <EOL>configDir.GuardCFFunctionCount.value = readDataInstance.readDword()<EOL>configDir.GuardFlags.value = readDataInstance.readDword()<EOL>return configDir<EOL>
Returns a new L{ImageLoadConfigDirectory} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object containing data to create a new L{ImageLoadConfigDirectory} object. @rtype: L{ImageLoadConfigDirectory} @return: A new L{ImageLoadConfigDirectory} object.
f11794:c6:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.size = datatypes.DWORD()<EOL>self.timeDateStamp = datatypes.DWORD()<EOL>self.majorVersion = datatypes.WORD()<EOL>self.minorVersion = datatypes.WORD()<EOL>self.globalFlagsClear = datatypes.DWORD()<EOL>self.globalFlagsSet = datatypes.DWORD()<EOL>self.criticalSectionDefaultTimeout = datatypes.DWORD()<EOL>self.deCommitFreeBlockThreshold = datatypes.QWORD()<EOL>self.deCommitTotalFreeThreshold = datatypes.QWORD()<EOL>self.lockPrefixTable = datatypes.QWORD()<EOL>self.maximumAllocationSize = datatypes.QWORD()<EOL>self.virtualMemoryThreshold = datatypes.QWORD()<EOL>self.processAffinityMask = datatypes.QWORD()<EOL>self.processHeapFlags = datatypes.DWORD()<EOL>self.cdsVersion = datatypes.WORD()<EOL>self.reserved1 = datatypes.WORD()<EOL>self.editList = datatypes.QWORD()<EOL>self.securityCookie = datatypes.QWORD()<EOL>self.SEHandlerTable = datatypes.QWORD()<EOL>self.SEHandlerCount = datatypes.QWORD()<EOL>self.GuardCFCheckFunctionPointer = datatypes.QWORD() <EOL>self.Reserved2 = datatypes.QWORD()<EOL>self.GuardCFFunctionTable = datatypes.QWORD() <EOL>self.GuardCFFunctionCount = datatypes.QWORD()<EOL>self.GuardFlags = datatypes.QWORD()<EOL>self._attrsList = ["<STR_LIT:size>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>"]<EOL>
Class representation of a C{IMAGE_LOAD_CONFIG_DIRECTORY64} structure in 64 bits systems. @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c7:m0
def getType(self):
return consts.IMAGE_LOAD_CONFIG_DIRECTORY64<EOL>
Returns L{consts.IMAGE_LOAD_CONFIG_DIRECTORY64}.
f11794:c7:m1
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
configDir = ImageLoadConfigDirectory64()<EOL>configDir.size.value = readDataInstance.readDword()<EOL>configDir.timeDateStamp.value = readDataInstance.readDword()<EOL>configDir.majorVersion.value = readDataInstance.readWord()<EOL>configDir.minorVersion.value = readDataInstance.readWord()<EOL>configDir.globalFlagsClear.value = readDataInstance.readDword()<EOL>configDir.globalFlagsSet.value = readDataInstance.readDword()<EOL>configDir.criticalSectionDefaultTimeout.value = readDataInstance.readDword()<EOL>configDir.deCommitFreeBlockThreshold.value = readDataInstance.readQword()<EOL>configDir.deCommitTotalFreeThreshold.value = readDataInstance.readQword()<EOL>configDir.lockPrefixTable.value = readDataInstance.readQword()<EOL>configDir.maximumAllocationSize.value = readDataInstance.readQword()<EOL>configDir.virtualMemoryThreshold.value = readDataInstance.readQword()<EOL>configDir.processAffinityMask.value = readDataInstance.readQword()<EOL>configDir.processHeapFlags.value = readDataInstance.readDword()<EOL>configDir.cdsVersion.value = readDataInstance.readWord()<EOL>configDir.reserved1.value = readDataInstance.readWord()<EOL>configDir.editList.value = readDataInstance.readQword()<EOL>configDir.securityCookie.value = readDataInstance.readQword()<EOL>configDir.SEHandlerTable.value = readDataInstance.readQword()<EOL>configDir.SEHandlerCount.value = readDataInstance.readQword()<EOL>configDir.GuardCFCheckFunctionPointer.value = readDataInstance.readQword() <EOL>configDir.Reserved2.value = readDataInstance.readQword()<EOL>configDir.GuardCFFunctionTable.value = readDataInstance.readQword() <EOL>configDir.GuardCFFunctionCount.value = readDataInstance.readQword()<EOL>configDir.GuardFlags.value = readDataInstance.readQword()<EOL>return configDir<EOL>
Returns a new L{ImageLoadConfigDirectory64} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object containing data to create a new L{ImageLoadConfigDirectory64} object. @rtype: L{ImageLoadConfigDirectory64} @return: A new L{ImageLoadConfigDirectory64} object.
f11794:c7:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.virtualAddress = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.sizeOfBlock = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.items = datatypes.Array(datatypes.TYPE_WORD) <EOL>self._attrsList = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>
A class representation of a C{IMAGE_BASE_RELOCATION} structure. @see: U{http://msdn.microsoft.com/en-us/magazine/cc301808.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c8:m0
def getType(self):
return consts.IMAGE_BASE_RELOCATION_ENTRY<EOL>
Returns L{consts.IMAGE_BASE_RELOCATION_ENTRY}.
f11794:c8:m1
@staticmethod<EOL><INDENT>def parse(readDataInstance):<DEDENT>
reloc = ImageBaseRelocationEntry()<EOL>reloc.virtualAddress.value = readDataInstance.readDword()<EOL>reloc.sizeOfBlock.value = readDataInstance.readDword()<EOL>toRead = (reloc.sizeOfBlock.value - <NUM_LIT:8>) / len(datatypes.WORD(<NUM_LIT:0>))<EOL>reloc.items = datatypes.Array.parse(readDataInstance, datatypes.TYPE_WORD, toRead)<EOL>return reloc<EOL>
Returns a new L{ImageBaseRelocationEntry} object. @type readDataInstance: L{ReadData} @param readDataInstance: A L{ReadData} object with data to parse as a L{ImageBaseRelocationEntry} object. @rtype: L{ImageBaseRelocationEntry} @return: A new L{ImageBaseRelocationEntry} object.
f11794:c8:m2
def __init__(self, shouldPack = True):
baseclasses.BaseStructClass.__init__(self, shouldPack)<EOL>self.characteristics = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.timeDateStamp = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.majorVersion = datatypes.WORD(<NUM_LIT:0>) <EOL>self.minorVersion = datatypes.WORD(<NUM_LIT:0>) <EOL>self.type = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.sizeOfData = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.addressOfData = datatypes.DWORD(<NUM_LIT:0>) <EOL>self.pointerToRawData = datatypes.DWORD(<NUM_LIT:0>) <EOL>self._attrsList = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT:type>", "<STR_LIT>","<STR_LIT>", "<STR_LIT>"]<EOL>
Class representation of a C{IMAGE_DEBUG_DIRECTORY} structure. @see: U{http://msdn.microsoft.com/es-es/library/windows/desktop/ms680307%28v=vs.85%29.aspx} @type shouldPack: bool @param shouldPack: (Optional) If set to c{True}, the object will be packed. If set to C{False}, the object won't be packed.
f11794:c10:m0
def getType(self):
return consts.IMAGE_DEBUG_DIRECTORY<EOL>
Returns L{consts.IMAGE_DEBUG_DIRECTORY}.
f11794:c10:m1