retdec
pe_format_parser.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_FILEFORMAT_PE_FORMAT_PARSER_H
8 #define RETDEC_FILEFORMAT_PE_FORMAT_PARSER_H
9 
10 #include "retdec/common/range.h"
11 #include "retdec/utils/alignment.h"
12 #include "retdec/utils/string.h"
14 #include "retdec/pelib/PeFile.h"
15 
16 namespace retdec {
17 namespace fileformat {
18 
19 class FileFormat;
20 
22 {
23  protected:
24 
25  const FileFormat *inputFile = nullptr;
26  PeLib::PeFileT *peFile = nullptr;
27 
28  public:
29 
30  PeFormatParser(const FileFormat *fInputFile, PeLib::PeFileT *inputPeFile) : inputFile(fInputFile), peFile(inputPeFile)
31  {}
32 
33  virtual ~PeFormatParser() = default;
34 
37 
38  std::uint32_t getPointerSize() const
39  {
40  return peFile->imageLoader().getPointerSize();
41  }
42 
43  std::uint32_t getPeHeaderOffset() const
44  {
46  }
47 
48  std::uint32_t getImageBitability() const
49  {
51  }
52 
53  std::uint32_t getDeclaredNumberOfSections() const
54  {
56  }
57 
58  std::uint32_t getStoredNumberOfSections() const
59  {
61  }
62 
63  std::uint32_t getMachineType() const
64  {
65  return peFile->imageLoader().getMachine();
66  }
67 
68  std::uint64_t getImageBaseAddress() const
69  {
70  return peFile->imageLoader().getImageBase();
71  }
72 
73  std::uint32_t getCoffSymbolTableOffset() const
74  {
76  }
77 
78  std::uint32_t getNumberOfCoffSymbols() const
79  {
81  }
82 
83  std::uint32_t getMajorLinkerVersion() const
84  {
86  }
87 
88  std::uint32_t getMinorLinkerVersion() const
89  {
91  }
92 
93  std::uint32_t getFileFlags() const
94  {
96  }
97 
98  std::uint32_t getTimeStamp() const
99  {
101  }
102 
103  std::uint32_t getOptionalHeaderSize() const
104  {
106  }
107 
109  {
110  std::uint64_t remainder;
113  remainder);
114  }
115 
116  std::uint32_t getFileAlignment() const
117  {
118  return peFile->imageLoader().getFileAlignment();
119  }
120 
121  std::uint32_t getSectionAlignment() const
122  {
124  }
125 
126  std::uint32_t getSizeOfHeaders() const
127  {
128  return peFile->imageLoader().getSizeOfHeaders();
129  }
130 
131  std::uint32_t getSizeOfImage() const
132  {
133  return peFile->imageLoader().getSizeOfImage();
134  }
135 
136  std::uint32_t getChecksum() const
137  {
139  }
140 
141  std::uint64_t getSizeOfStackReserve() const
142  {
144  }
145 
146  std::uint64_t getSizeOfStackCommit() const
147  {
149  }
150 
151  std::uint64_t getSizeOfHeapReserve() const
152  {
154  }
155 
156  std::uint64_t getSizeOfHeapCommit() const
157  {
159  }
160 
161  std::uint32_t getSizeOfPeSignature() const
162  {
163  return sizeof(std::uint32_t);
164  }
165 
166  std::uint32_t getLoadedSizeOfNtHeaders() const
167  {
169  }
170 
171  std::uint32_t getAllocatedSizeOfNtHeaders() const
172  {
174  }
175 
177  {
179  }
180 
181  std::uint32_t getStoredNumberOfDataDirectories() const
182  {
184  }
185 
186  std::uint32_t getNumberOfImportedLibraries() const
187  {
189  }
190 
191  std::uint32_t getNumberOfDelayImportedLibraries() const
192  {
194  }
195 
196  bool isDll() const
197  {
199  }
200 
201  bool getEpAddress(std::uint64_t & epAddress) const
202  {
203  std::uint64_t imageBase = peFile->imageLoader().getImageBase();
204  std::uint32_t entryPoint = peFile->imageLoader().getOptionalHeader().AddressOfEntryPoint;
205 
206  // Do not report zero entry point on DLLs
207  epAddress = imageBase + entryPoint;
208  return (entryPoint != 0 || isDll() == false);
209  }
210 
211  bool getEpOffset(std::uint64_t & epOffset) const
212  {
213  std::uint32_t entryPoint = peFile->imageLoader().getOptionalHeader().AddressOfEntryPoint;
214 
215  epOffset = peFile->imageLoader().getFileOffsetFromRva(entryPoint);
216  return (entryPoint != 0 || isDll() == false) && (epOffset != UINT32_MAX);
217  }
218 
219  bool getSectionType(const PeLib::PELIB_SECTION_HEADER * pSectionHeader, PeCoffSection::Type & secType) const
220  {
221  std::uint32_t Characteristics = pSectionHeader->Characteristics;
222 
224  {
225  secType = PeCoffSection::Type::CODE;
226  }
227  else if(Characteristics & PeLib::PELIB_IMAGE_SCN_CNT_UNINITIALIZED_DATA)
228  {
229  secType = PeCoffSection::Type::BSS;
230  }
231  else if(Characteristics & PeLib::PELIB_IMAGE_SCN_MEM_DISCARDABLE && retdec::utils::startsWith(pSectionHeader->getName(), ".debug_"))
232  {
233  secType = PeCoffSection::Type::DEBUG;
234  }
235  else if(Characteristics & PeLib::PELIB_IMAGE_SCN_CNT_INITIALIZED_DATA)
236  {
238  }
239  else if(Characteristics & PeLib::PELIB_IMAGE_SCN_LNK_INFO)
240  {
241  secType = PeCoffSection::Type::INFO;
242  }
243  else
244  {
246  }
247 
248  return true;
249  }
250 
251  bool getSection(std::size_t secIndex, PeCoffSection &section) const
252  {
253  const PeLib::PELIB_SECTION_HEADER * pSectionHeader;
254  PeCoffSection::Type sectionType;
255  PeLib::ImageLoader & imageLoader = peFile->imageLoader();
256  std::string sectionName;
257 
258  // Retrieve the section header. If the function returns nullptr, then there is no such section
259  if((pSectionHeader = imageLoader.getSectionHeader(secIndex)) == nullptr)
260  return false;
261  if(!getSectionType(pSectionHeader, sectionType))
262  return false;
263 
264  section.setName(pSectionHeader->getName());
265  section.setType(sectionType);
266  section.setIndex(secIndex);
267  section.setOffset(imageLoader.getRealPointerToRawData(secIndex));
268  section.setSizeInFile(pSectionHeader->SizeOfRawData);
269  section.setSizeInMemory(pSectionHeader->VirtualSize);
270  section.setAddress(pSectionHeader->VirtualAddress ? imageLoader.getImageBase() + pSectionHeader->VirtualAddress : 0);
271  section.setMemory(section.getAddress());
272  section.setPeCoffFlags(pSectionHeader->Characteristics);
273  section.load(inputFile);
274  return true;
275  }
276 
277  bool getDllFlags(unsigned long long & dllFlags) const
278  {
280  {
282  return true;
283  }
284 
285  return false;
286  }
287 
288  bool getDataDirectoryRelative(unsigned long long index, unsigned long long &relAddr, unsigned long long &size) const
289  {
290  relAddr = peFile->imageLoader().getDataDirRva(index);
291  size = peFile->imageLoader().getDataDirSize(index);
292  return (relAddr != 0);
293  }
294 
295  bool getDataDirectoryAbsolute(unsigned long long index, unsigned long long &absAddr, unsigned long long &size) const
296  {
297  if(getDataDirectoryRelative(index, absAddr, size))
298  {
299  absAddr += peFile->imageLoader().getImageBase();
300  return true;
301  }
302 
303  return false;
304  }
305 
306  bool getImportedLibraryFileName(std::uint32_t index, std::string &fileName) const
307  {
308  const auto & imports = peFile->impDir();
309 
310  if(index >= imports.getNumberOfFiles(PeLib::OLDDIR))
311  return false;
312 
313  fileName = imports.getFileName(index, PeLib::OLDDIR);
314  return true;
315  }
316 
317  bool getDelayImportedLibraryFileName(unsigned long long index, std::string &fileName) const
318  {
319  const auto & delayImports = peFile->delayImports();
320 
321  if(index >= delayImports.getNumberOfFiles())
322  return false;
323 
324  fileName = delayImports.getFile(index)->Name;
325  return true;
326  }
327 
328  std::unique_ptr<PeImport> getImport(unsigned long long fileIndex, unsigned long long importIndex) const
329  {
330  const PeLib::ImportDirectory & peImports = peFile->impDir();
331  const auto ordinalMask = peFile->imageLoader().getOrdinalMask();
332  const auto bits = peFile->imageLoader().getImageBitability();
333 
334  if(fileIndex >= peImports.getNumberOfFiles(PeLib::OLDDIR) ||
335  importIndex >= peImports.getNumberOfFunctions(fileIndex, PeLib::OLDDIR))
336  {
337  return nullptr;
338  }
339 
340  auto isOrdinalNumberValid = true;
341  unsigned long long ordinalNumber = peImports.getFunctionHint(fileIndex, importIndex, PeLib::OLDDIR);
342  if(!ordinalNumber)
343  {
344  const auto firstThunk = peImports.getFirstThunk(fileIndex, importIndex, PeLib::OLDDIR);
345  const auto originalFirstThunk = peImports.getOriginalFirstThunk(fileIndex, importIndex, PeLib::OLDDIR);
346  if(firstThunk & ordinalMask)
347  {
348  ordinalNumber = firstThunk - ordinalMask;
349  }
350  else if(originalFirstThunk & ordinalMask)
351  {
352  ordinalNumber = originalFirstThunk - ordinalMask;
353  }
354  else
355  {
356  isOrdinalNumberValid = false;
357  }
358  }
359 
360  auto import = std::make_unique<PeImport>(PeImportFlag::None);
361  if(isOrdinalNumberValid)
362  {
363  import->setOrdinalNumber(ordinalNumber);
364  }
365  else
366  {
367  import->invalidateOrdinalNumber();
368  }
369  import->setName(peImports.getFunctionName(fileIndex, importIndex, PeLib::OLDDIR));
370  import->setAddress(peFile->imageLoader().getImageBase() + peImports.getFirstThunk(fileIndex, PeLib::OLDDIR) + importIndex * (bits / 8));
371  import->setLibraryIndex(fileIndex);
372  return import;
373  }
374 
375  std::unique_ptr<PeImport> getDelayImport(unsigned long long fileIndex, unsigned long long importIndex) const
376  {
377  const PeLib::DelayImportDirectory & delayImports = peFile->delayImports();
378  const auto *library = delayImports.getFile(fileIndex);
379 
380  if(!library)
381  {
382  return nullptr;
383  }
384 
385  const auto *function = library->getFunction(importIndex);
386  if(!function)
387  {
388  return nullptr;
389  }
390 
391  auto import = std::make_unique<PeImport>(PeImportFlag::Delayed);
392  import->setName(function->fname);
393  import->setAddress(peFile->imageLoader().getImageBase() + function->address);
394  import->setLibraryIndex(fileIndex);
395  import->invalidateOrdinalNumber();
396  if(library->ordinalNumbersAreValid() && function->hint != 0)
397  {
398  import->setOrdinalNumber(function->hint);
399  }
400 
401  return import;
402  }
403 
404  std::uint32_t getNumberOfExportedFunctions() const
405  {
406  return peFile->expDir().calcNumberOfFunctions();
407  }
408 
409  bool getExportedFunction(unsigned long long index, Export& exportedFunction) const
410  {
411  const PeLib::ExportDirectory & exports = peFile->expDir();
412  const PeLib::ImageLoader & imageLoader = peFile->imageLoader();
413 
414  if (index >= exports.calcNumberOfFunctions())
415  {
416  return false;
417  }
418 
419  exportedFunction.setAddress(exports.getAddressOfFunction(index) + imageLoader.getImageBase());
420  exportedFunction.setOrdinalNumber(exports.getFunctionOrdinal(index));
421  exportedFunction.setName(exports.getFunctionName(index));
422  return true;
423  }
424 
425  std::uint32_t getNumberOfDebugEntries() const
426  {
427  return peFile->debugDir().calcNumberOfEntries();
428  }
429 
430  bool getDebugEntryData(unsigned long long index, std::vector<std::uint8_t>& data) const
431  {
432  const PeLib::DebugDirectory & debug = peFile->debugDir();
433 
434  if (index < debug.calcNumberOfEntries())
435  {
436  data = debug.getData(index);
437  return true;
438  }
439 
440  return false;
441  }
442 
443  bool getDebugEntryTimeDateStamp(unsigned long long index, unsigned long long& timeDateStamp) const
444  {
445  const PeLib::DebugDirectory & debug = peFile->debugDir();
446 
447  if (index < debug.calcNumberOfEntries())
448  {
449  timeDateStamp = debug.getTimeDateStamp(index);
450  return true;
451  }
452 
453  return false;
454  }
455 
456  bool getDebugEntryPointerToRawData(unsigned long long index, unsigned long long& pointerToRawData) const
457  {
458  const PeLib::DebugDirectory & debug = peFile->debugDir();
459 
460  if (index < debug.calcNumberOfEntries())
461  {
462  pointerToRawData = debug.getPointerToRawData(index);
463  return true;
464  }
465 
466  return false;
467  }
468 
469  std::uint32_t getResourceDirectoryOffset() const
470  {
471  return peFile->resDir().getOffset();
472  }
473 
475  {
476  return peFile->resDir().getRoot();
477  }
478 
479  std::uint64_t getTlsStartAddressOfRawData() const
480  {
482  }
483 
484  std::uint64_t getTlsEndAddressOfRawData() const
485  {
487  }
488 
489  std::uint64_t getTlsAddressOfIndex() const
490  {
491  return peFile->tlsDir().getAddressOfIndex();
492  }
493 
494  const std::vector<uint64_t> & getCallbacks() const
495  {
496  return peFile->tlsDir().getCallbacks();
497  }
498 
499  std::uint64_t getTlsAddressOfCallBacks() const
500  {
501  return peFile->tlsDir().getAddressOfCallBacks();
502  }
503 
504  std::uint32_t getTlsSizeOfZeroFill() const
505  {
506  return peFile->tlsDir().getSizeOfZeroFill();
507  }
508 
509  std::uint32_t getTlsCharacteristics() const
510  {
511  return peFile->tlsDir().getCharacteristics();
512  }
513 
514  std::unique_ptr<CLRHeader> getClrHeader() const
515  {
516  const auto & comHeader = peFile->comDir();
517  auto clrHeader = std::make_unique<CLRHeader>();
518 
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());
538  return clrHeader;
539  }
540 
541  std::uint32_t getNumberOfRelocations() const
542  {
544  }
545 
546  std::uint32_t getNumberOfRelocationData(std::uint32_t index) const
547  {
548  return peFile->relocDir().calcNumberOfRelocationData(index);
549  }
550 
551  std::uint64_t getChecksumFileOffset() const
552  {
554  }
555 
556  std::uint64_t getSecurityDirFileOffset() const
557  {
559  }
560 
561  std::uint32_t getSecurityDirRva() const
562  {
564  }
565 
566  std::uint32_t getSecurityDirSize() const
567  {
569  }
570 
572  {
574  const auto & peImports = peFile->impDir();
575 
576  for (const auto& addresses : peImports.getOccupiedAddresses())
577  {
578  try
579  {
580  result.insert(addresses.first, addresses.second);
581  }
583  {
584  continue;
585  }
586  }
587 
588  return result;
589  }
590 
592  {
594  const auto & peExports = peFile->expDir();
595 
596  for (const auto& addresses : peExports.getOccupiedAddresses())
597  {
598  try
599  {
600  result.insert(addresses.first, addresses.second);
601  }
603  {
604  continue;
605  }
606  }
607 
608  return result;
609  }
610 
612  {
614  const auto & peDebug = peFile->debugDir();
615 
616  for (const auto& addresses : peDebug.getOccupiedAddresses())
617  {
618  try
619  {
620  result.insert(addresses.first, addresses.second);
621  }
623  {
624  continue;
625  }
626  }
627 
628  return result;
629  }
630 
632  {
634  const auto & peResources = peFile->resDir();
635 
636  for (const auto& addresses : peResources.getOccupiedAddresses())
637  {
638  try
639  {
640  result.insert(addresses.first, addresses.second);
641  }
643  {
644  continue;
645  }
646  }
647 
648  return result;
649  }
650 
651 };
652 
653 } // namespace fileformat
654 } // namespace retdec
655 
656 #endif
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
Definition: PeFile.h:109
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
Definition: export.h:19
void setName(std::string exportName)
Definition: export.cpp:51
void setAddress(unsigned long long exportAddress)
Definition: export.cpp:60
void setOrdinalNumber(unsigned long long exportOrdinalNumber)
Definition: export.cpp:69
Definition: file_format.h:45
Definition: pe_coff_section.h:19
void setPeCoffFlags(unsigned long long sPeCoffFlags)
Definition: pe_coff_section.cpp:33
Definition: pe_format_parser.h:22
std::uint32_t getMachineType() const
Definition: pe_format_parser.h:63
std::uint32_t getPointerSize() const
Definition: pe_format_parser.h:38
std::uint32_t getSizeOfImage() const
Definition: pe_format_parser.h:131
std::uint32_t getChecksum() const
Definition: pe_format_parser.h:136
std::uint32_t getTlsSizeOfZeroFill() const
Definition: pe_format_parser.h:504
std::unique_ptr< PeImport > getImport(unsigned long long fileIndex, unsigned long long importIndex) const
Definition: pe_format_parser.h:328
std::uint32_t getMinorLinkerVersion() const
Definition: pe_format_parser.h:88
std::uint32_t getPeHeaderOffset() const
Definition: pe_format_parser.h:43
std::uint64_t getTlsEndAddressOfRawData() const
Definition: pe_format_parser.h:484
std::uint32_t getDeclaredNumberOfSections() const
Definition: pe_format_parser.h:53
bool getDelayImportedLibraryFileName(unsigned long long index, std::string &fileName) const
Definition: pe_format_parser.h:317
bool getEpAddress(std::uint64_t &epAddress) const
Definition: pe_format_parser.h:201
const std::vector< uint64_t > & getCallbacks() const
Definition: pe_format_parser.h:494
const FileFormat * inputFile
pointer to input file
Definition: pe_format_parser.h:25
bool getDebugEntryPointerToRawData(unsigned long long index, unsigned long long &pointerToRawData) const
Definition: pe_format_parser.h:456
std::uint32_t getStoredNumberOfDataDirectories() const
Definition: pe_format_parser.h:181
std::uint64_t getTlsStartAddressOfRawData() const
Definition: pe_format_parser.h:479
std::uint32_t getNumberOfRelocationData(std::uint32_t index) const
Definition: pe_format_parser.h:546
std::uint32_t getTlsCharacteristics() const
Definition: pe_format_parser.h:509
std::uint32_t getNumberOfDebugEntries() const
Definition: pe_format_parser.h:425
const PeLib::ResourceNode * getResourceTreeRoot() const
Definition: pe_format_parser.h:474
retdec::common::RangeContainer< std::uint64_t > getImportDirectoryOccupiedAddresses() const
Definition: pe_format_parser.h:571
PeFormatParser(const FileFormat *fInputFile, PeLib::PeFileT *inputPeFile)
Definition: pe_format_parser.h:30
PeLib::PeFileT * peFile
32-bit PE file
Definition: pe_format_parser.h:26
std::uint32_t getSizeOfPeSignature() const
Definition: pe_format_parser.h:161
std::uint64_t getTlsAddressOfIndex() const
Definition: pe_format_parser.h:489
std::uint32_t getNumberOfRelocations() const
Definition: pe_format_parser.h:541
std::uint32_t getResourceDirectoryOffset() const
Definition: pe_format_parser.h:469
std::uint32_t getMajorLinkerVersion() const
Definition: pe_format_parser.h:83
std::uint32_t getSecurityDirSize() const
Definition: pe_format_parser.h:566
std::uint32_t getNumberOfDelayImportedLibraries() const
Definition: pe_format_parser.h:191
std::uint64_t getSizeOfStackReserve() const
Definition: pe_format_parser.h:141
std::uint32_t getCoffSymbolTableOffset() const
Definition: pe_format_parser.h:73
std::uint32_t getStoredNumberOfSections() const
Definition: pe_format_parser.h:58
std::uint32_t getTimeStamp() const
Definition: pe_format_parser.h:98
retdec::common::RangeContainer< std::uint64_t > getExportDirectoryOccupiedAddresses() const
Definition: pe_format_parser.h:591
std::uint64_t getTlsAddressOfCallBacks() const
Definition: pe_format_parser.h:499
bool getEpOffset(std::uint64_t &epOffset) const
Definition: pe_format_parser.h:211
std::uint32_t getNumberOfImportedLibraries() const
Definition: pe_format_parser.h:186
bool getDllFlags(unsigned long long &dllFlags) const
Definition: pe_format_parser.h:277
std::uint32_t getNumberOfCoffSymbols() const
Definition: pe_format_parser.h:78
std::uint32_t getNumberOfExportedFunctions() const
Definition: pe_format_parser.h:404
retdec::common::RangeContainer< std::uint64_t > getResourceDirectoryOccupiedAddresses() const
Definition: pe_format_parser.h:631
bool getImportedLibraryFileName(std::uint32_t index, std::string &fileName) const
Definition: pe_format_parser.h:306
bool getDataDirectoryRelative(unsigned long long index, unsigned long long &relAddr, unsigned long long &size) const
Definition: pe_format_parser.h:288
bool isDll() const
Definition: pe_format_parser.h:196
std::unique_ptr< PeImport > getDelayImport(unsigned long long fileIndex, unsigned long long importIndex) const
Definition: pe_format_parser.h:375
std::unique_ptr< CLRHeader > getClrHeader() const
Definition: pe_format_parser.h:514
std::uint64_t getSizeOfStackCommit() const
Definition: pe_format_parser.h:146
std::uint32_t getOptionalHeaderSize() const
Definition: pe_format_parser.h:103
bool getSection(std::size_t secIndex, PeCoffSection &section) const
Definition: pe_format_parser.h:251
std::uint32_t getSecurityDirRva() const
Definition: pe_format_parser.h:561
bool getDebugEntryTimeDateStamp(unsigned long long index, unsigned long long &timeDateStamp) const
Definition: pe_format_parser.h:443
std::uint32_t getFileFlags() const
Definition: pe_format_parser.h:93
bool getExportedFunction(unsigned long long index, Export &exportedFunction) const
Definition: pe_format_parser.h:409
std::uint32_t getImageBitability() const
Definition: pe_format_parser.h:48
bool getDebugEntryData(unsigned long long index, std::vector< std::uint8_t > &data) const
Definition: pe_format_parser.h:430
std::uint32_t getSectionAlignment() const
Definition: pe_format_parser.h:121
bool isSizeOfHeaderMultipleOfFileAlignment() const
Definition: pe_format_parser.h:108
std::uint64_t getChecksumFileOffset() const
Definition: pe_format_parser.h:551
std::uint32_t getLoadedSizeOfNtHeaders() const
Definition: pe_format_parser.h:166
bool getSectionType(const PeLib::PELIB_SECTION_HEADER *pSectionHeader, PeCoffSection::Type &secType) const
Definition: pe_format_parser.h:219
std::uint64_t getImageBaseAddress() const
Definition: pe_format_parser.h:68
std::uint64_t getSizeOfHeapReserve() const
Definition: pe_format_parser.h:151
std::uint32_t getAllocatedSizeOfNtHeaders() const
Definition: pe_format_parser.h:171
std::uint64_t getSizeOfHeapCommit() const
Definition: pe_format_parser.h:156
std::uint32_t getDeclaredNumberOfDataDirectories() const
Definition: pe_format_parser.h:176
std::uint32_t getFileAlignment() const
Definition: pe_format_parser.h:116
bool getDataDirectoryAbsolute(unsigned long long index, unsigned long long &absAddr, unsigned long long &size) const
Definition: pe_format_parser.h:295
retdec::common::RangeContainer< std::uint64_t > getDebugDirectoryOccupiedAddresses() const
Definition: pe_format_parser.h:611
std::uint32_t getSizeOfHeaders() const
Definition: pe_format_parser.h:126
std::uint64_t getSecurityDirFileOffset() const
Definition: pe_format_parser.h:556
void setSizeInFile(unsigned long long sFileSize)
Definition: sec_seg.cpp:478
Type
Definition: sec_seg.h:27
@ INFO
auxiliary information
void setAddress(unsigned long long sAddress)
Definition: sec_seg.cpp:487
void load(const FileFormat *sOwner)
Definition: sec_seg.cpp:572
void setOffset(unsigned long long sOffset)
Definition: sec_seg.cpp:469
void setIndex(unsigned long long sIndex)
Definition: sec_seg.cpp:460
unsigned long long getAddress() const
Definition: sec_seg.cpp:296
void setType(SecSeg::Type sType)
Definition: sec_seg.cpp:451
void setMemory(bool sMemory)
Definition: sec_seg.cpp:516
void setSizeInMemory(unsigned long long sMemorySize)
Definition: sec_seg.cpp:496
void setName(std::string sName)
Definition: sec_seg.cpp:442
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
@ None
Definition: pe_import.h:17
@ Delayed
Definition: pe_import.h:18
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
std::uint32_t TimeDateStamp
Definition: PeLibAux.h:590
std::uint16_t SizeOfOptionalHeader
Definition: PeLibAux.h:593
std::uint16_t Characteristics
Definition: PeLibAux.h:594
std::uint16_t NumberOfSections
Definition: PeLibAux.h:589
std::uint8_t MajorLinkerVersion
Definition: PeLibAux.h:702
std::uint16_t DllCharacteristics
Definition: PeLibAux.h:724
std::uint64_t SizeOfHeapReserve
Definition: PeLibAux.h:727
std::uint32_t AddressOfEntryPoint
Definition: PeLibAux.h:707
std::uint64_t SizeOfStackReserve
Definition: PeLibAux.h:725
std::uint32_t CheckSum
Definition: PeLibAux.h:722
std::uint64_t SizeOfStackCommit
Definition: PeLibAux.h:726
std::uint32_t NumberOfRvaAndSizes
Definition: PeLibAux.h:730
std::uint8_t MinorLinkerVersion
Definition: PeLibAux.h:703
std::uint64_t SizeOfHeapCommit
Definition: PeLibAux.h:728
std::uint32_t SizeOfRawData
Definition: PeLibAux.h:797
std::uint32_t VirtualSize
Definition: PeLibAux.h:795
std::uint32_t VirtualAddress
Definition: PeLibAux.h:796
std::uint32_t Characteristics
Definition: PeLibAux.h:803
Definition: PeLibAux.h:807
const std::string & getName() const
Definition: PeLibAux.h:823
String utilities.