7 #ifndef RETDEC_FILEFORMAT_PE_FORMAT_PARSER_H
8 #define RETDEC_FILEFORMAT_PE_FORMAT_PARSER_H
110 std::uint64_t remainder;
163 return sizeof(std::uint32_t);
207 epAddress = imageBase + entryPoint;
208 return (entryPoint != 0 ||
isDll() ==
false);
216 return (entryPoint != 0 ||
isDll() ==
false) && (epOffset != UINT32_MAX);
256 std::string sectionName;
292 return (relAddr != 0);
321 if(index >= delayImports.getNumberOfFiles())
328 std::unique_ptr<PeImport>
getImport(
unsigned long long fileIndex,
unsigned long long importIndex)
const
340 auto isOrdinalNumberValid =
true;
346 if(firstThunk & ordinalMask)
348 ordinalNumber = firstThunk - ordinalMask;
350 else if(originalFirstThunk & ordinalMask)
352 ordinalNumber = originalFirstThunk - ordinalMask;
356 isOrdinalNumberValid =
false;
361 if(isOrdinalNumberValid)
363 import->setOrdinalNumber(ordinalNumber);
367 import->invalidateOrdinalNumber();
371 import->setLibraryIndex(fileIndex);
375 std::unique_ptr<PeImport>
getDelayImport(
unsigned long long fileIndex,
unsigned long long importIndex)
const
378 const auto *library = delayImports.
getFile(fileIndex);
385 const auto *
function = library->
getFunction(importIndex);
392 import->setName(function->fname);
394 import->setLibraryIndex(fileIndex);
395 import->invalidateOrdinalNumber();
396 if(library->ordinalNumbersAreValid() && function->hint != 0)
398 import->setOrdinalNumber(function->hint);
517 auto clrHeader = std::make_unique<CLRHeader>();
519 clrHeader->setHeaderSize(comHeader.getSizeOfHeader());
520 clrHeader->setMajorRuntimeVersion(comHeader.getMajorRuntimeVersion());
521 clrHeader->setMinorRuntimeVersion(comHeader.getMinorRuntimeVersion());
522 clrHeader->setMetadataDirectoryAddress(comHeader.getMetaDataVa());
523 clrHeader->setMetadataDirectorySize(comHeader.getMetaDataSize());
524 clrHeader->setFlags(comHeader.getFlags());
525 clrHeader->setEntryPointToken(comHeader.getEntryPointToken());
526 clrHeader->setResourcesAddress(comHeader.getResourcesVa());
527 clrHeader->setResourcesSize(comHeader.getResourcesSize());
528 clrHeader->setStrongNameSignatureAddress(comHeader.getStrongNameSignatureVa());
529 clrHeader->setStrongNameSignatureSize(comHeader.getStrongNameSignatureSize());
530 clrHeader->setCodeManagerTableAddress(comHeader.getCodeManagerTableVa());
531 clrHeader->setCodeManagerTableSize(comHeader.getCodeManagerTableSize());
532 clrHeader->setVTableFixupsDirectoryAddress(comHeader.getVTableFixupsVa());
533 clrHeader->setVTableFixupsDirectorySize(comHeader.getVTableFixupsSize());
534 clrHeader->setExportAddressTableAddress(comHeader.getExportAddressTableJumpsVa());
535 clrHeader->setExportAddressTableSize(comHeader.getExportAddressTableJumpsSize());
536 clrHeader->setPrecompileHeaderAddress(comHeader.getManagedNativeHeaderVa());
537 clrHeader->setPrecompileHeaderSize(comHeader.getManagedNativeHeaderSize());
576 for (
const auto& addresses : peImports.getOccupiedAddresses())
580 result.
insert(addresses.first, addresses.second);
596 for (
const auto& addresses : peExports.getOccupiedAddresses())
600 result.
insert(addresses.first, addresses.second);
616 for (
const auto& addresses : peDebug.getOccupiedAddresses())
620 result.
insert(addresses.first, addresses.second);
636 for (
const auto& addresses : peResources.getOccupiedAddresses())
640 result.
insert(addresses.first, addresses.second);
Declaration of aligning operations.
Class that handles the Debug directory.
Definition: DebugDirectory.h:22
std::uint32_t getTimeDateStamp(std::size_t uiIndex) const
Returns the TimeDateStamp value of a debug structure.
Definition: DebugDirectory.cpp:210
std::vector< std::uint8_t > getData(std::size_t index) const
Definition: DebugDirectory.cpp:281
std::uint32_t getPointerToRawData(std::size_t uiIndex) const
Returns the PointerToRawData value of a debug structure.
Definition: DebugDirectory.cpp:276
unsigned int calcNumberOfEntries() const
Returns the number of DebugDirectory image structures in the current DebugDirectory.
Definition: DebugDirectory.cpp:168
Definition: DelayImportDirectory.h:20
const PELIB_IMAGE_DELAY_IMPORT_DIRECTORY_RECORD * getFile(std::size_t index) const
Definition: DelayImportDirectory.h:231
std::size_t getNumberOfFiles() const
Definition: DelayImportDirectory.h:226
Class that handles the export directory.
Definition: ExportDirectory.h:26
std::uint32_t getAddressOfFunction(std::size_t index) const
Get the address of an exported function.
Definition: ExportDirectory.cpp:348
std::uint16_t getFunctionOrdinal(std::size_t index) const
Get the ordinal of an exported function.
Definition: ExportDirectory.cpp:330
std::string getFunctionName(std::size_t index) const
Get the name of an exported function.
Definition: ExportDirectory.cpp:321
unsigned int calcNumberOfFunctions() const
Definition: ExportDirectory.cpp:147
Definition: ImageLoader.h:138
const PELIB_SECTION_HEADER * getSectionHeader(std::size_t sectionIndex) const
Definition: ImageLoader.h:195
std::uint32_t getRealPointerToRawData(std::size_t sectionIndex) const
Definition: ImageLoader.cpp:546
std::uint32_t getChecksumFileOffset() const
Definition: ImageLoader.h:300
std::uint32_t getSecurityDirFileOffset() const
Definition: ImageLoader.h:310
std::uint32_t getDataDirSize(std::size_t dataDirIndex) const
Definition: ImageLoader.h:321
std::uint32_t getDataDirRva(std::size_t dataDirIndex) const
Definition: ImageLoader.h:315
std::uint32_t getMachine() const
Definition: ImageLoader.h:230
const PELIB_IMAGE_OPTIONAL_HEADER & getOptionalHeader() const
Definition: ImageLoader.h:190
std::uint64_t getOrdinalMask() const
Definition: ImageLoader.h:210
std::uint32_t getFileOffsetFromRva(std::uint32_t rva) const
Definition: ImageLoader.cpp:449
std::uint32_t getImageBitability() const
Definition: ImageLoader.cpp:432
std::uint32_t getPeHeaderOffset() const
Definition: ImageLoader.h:215
std::uint64_t getImageBase() const
Definition: ImageLoader.h:265
std::uint32_t getRealNumberOfDataDirectories() const
Definition: ImageLoader.h:305
const PELIB_IMAGE_FILE_HEADER & getFileHeader() const
Definition: ImageLoader.h:185
std::uint32_t getSizeOfHeaders() const
Definition: ImageLoader.h:275
std::uint32_t getFileAlignment() const
Definition: ImageLoader.h:295
std::uint32_t getNumberOfSections() const
Definition: ImageLoader.h:255
std::uint32_t getSizeOfImage() const
Definition: ImageLoader.h:280
std::uint32_t getPointerToSymbolTable() const
Definition: ImageLoader.h:235
std::uint32_t getCharacteristics() const
Definition: ImageLoader.h:250
std::uint32_t getPointerSize() const
Definition: ImageLoader.cpp:322
std::uint32_t getSectionAlignment() const
Definition: ImageLoader.h:290
std::uint32_t getNumberOfSymbols() const
Definition: ImageLoader.h:240
Class that handles import directories.
Definition: ImportDirectory.h:42
std::uint32_t getNumberOfFiles(currdir cdDir) const
Get the number of files which are imported.
Definition: ImportDirectory.h:506
std::uint32_t getNumberOfFunctions(std::uint32_t dwFilenr, currdir cdDir) const
Get the number of fucntions which are imported by a specific file.
Definition: ImportDirectory.h:520
std::uint32_t getOriginalFirstThunk(std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir) const
Returns the OriginalFirstThunk value of a function.
Definition: ImportDirectory.h:1382
std::string getFileName(std::uint32_t dwFilenr, currdir cdDir) const
Get the name of an imported file.
Definition: ImportDirectory.h:361
std::uint16_t getFunctionHint(std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir) const
Get the hint of an imported function.
Definition: ImportDirectory.h:466
std::uint32_t getFirstThunk(std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir) const
Returns the FirstThunk value of a function.
Definition: ImportDirectory.h:1362
std::string getFunctionName(std::uint32_t dwFilenr, std::uint32_t dwFuncnr, currdir cdDir) const
Get the name of an imported function.
Definition: ImportDirectory.h:383
const ExportDirectory & expDir() const
Accessor function for the export directory.
Definition: PeFile.cpp:153
const ResourceDirectory & resDir() const
Accessor function for the resource directory.
Definition: PeFile.cpp:185
const DebugDirectory & debugDir() const
Accessor function for the debug directory.
Definition: PeFile.cpp:240
const DelayImportDirectory & delayImports() const
Accessor function for the delay import directory.
Definition: PeFile.cpp:137
const ImportDirectory & impDir() const
Accessor function for the import directory.
Definition: PeFile.cpp:111
const ComHeaderDirectory & comDir() const
Accessor function for the COM+ descriptor directory.
Definition: PeFile.cpp:217
const RelocationsDirectory & relocDir() const
Accessor function for the relocations directory.
Definition: PeFile.cpp:201
const TlsDirectory & tlsDir() const
Accessor function for the TLS directory.
Definition: PeFile.cpp:124
const ImageLoader & imageLoader() const
Accessor function for the image loader.
Definition: PeFile.cpp:64
unsigned int calcNumberOfRelocationData(unsigned int ulRelocation) const
Returns the number of relocation data entries of a specific relocation.
Definition: RelocationsDirectory.cpp:193
unsigned int calcNumberOfRelocations() const
Returns the number of relocations in the relocations directory.
Definition: RelocationsDirectory.cpp:178
ResourceNode * getRoot()
Definition: ResourceDirectory.cpp:1020
unsigned int getOffset() const
Returns start offset of resource directory in file.
Definition: ResourceDirectory.cpp:1366
ResourceNodes represent the nodes in the resource tree.
Definition: ResourceDirectory.h:188
std::uint64_t getEndAddressOfRawData() const
Returns the EndAddressOfRawData value of the TLS header.
Definition: TlsDirectory.h:236
std::uint64_t getStartAddressOfRawData() const
Returns the StartAddressOfRawData value of the TLS header.
Definition: TlsDirectory.h:227
std::uint64_t getAddressOfCallBacks() const
Returns the AddressOfCallBacks value of the TLS header.
Definition: TlsDirectory.h:254
std::uint64_t getAddressOfIndex() const
Returns the AddressOfIndex value of the TLS header.
Definition: TlsDirectory.h:245
std::uint32_t getSizeOfZeroFill() const
Returns the SizeOfZeroFill value of the TLS header.
Definition: TlsDirectory.h:263
std::uint32_t getCharacteristics() const
Returns the Characteristics value of the TLS header.
Definition: TlsDirectory.h:272
const std::vector< std::uint64_t > & getCallbacks() const
Returns vector of TLS callbacks.
Definition: TlsDirectory.h:218
std::pair< iterator, bool > insert(RangeT &&range)
Definition: range.h:328
Declaration of templated Range class.
Header file for fileformat types and structures.
@ PELIB_IMAGE_FILE_DLL
Definition: PeLibAux.h:292
@ PELIB_IMAGE_DIRECTORY_ENTRY_SECURITY
Definition: PeLibAux.h:173
@ OLDDIR
Definition: ImportDirectory.h:25
@ PELIB_IMAGE_SCN_CNT_CODE
Definition: PeLibAux.h:201
@ PELIB_IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition: PeLibAux.h:203
@ PELIB_IMAGE_SCN_MEM_EXECUTE
Definition: PeLibAux.h:234
@ PELIB_IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: PeLibAux.h:202
@ PELIB_IMAGE_SCN_LNK_INFO
Definition: PeLibAux.h:205
@ PELIB_IMAGE_SCN_MEM_DISCARDABLE
Definition: PeLibAux.h:230
@ PELIB_IMAGE_SCN_MEM_WRITE
Definition: PeLibAux.h:236
bool startsWith(const std::string &str, const String &withWhat)
Returns true if str starts with the prefix withWhat, false otherwise.
Definition: string.h:105
bool isAligned(std::uint64_t value, std::uint64_t alignment, std::uint64_t &remainder)
Definition: alignment.cpp:25
Definition: archive_wrapper.h:19
const PELIB_DELAY_IMPORT * getFunction(std::size_t index) const
Definition: PeLibAux.h:1449
std::string Name
Definition: PeLibAux.h:1410