retdec
|
#include <ImageLoader.h>
Public Member Functions | |
ImageLoader (std::uint32_t loaderFlags=0) | |
int | Load (ByteBuffer &fileData, bool loadHeadersOnly=false) |
int | Load (std::istream &fs, std::streamoff fileOffset=0, bool loadHeadersOnly=false) |
int | Load (const char *fileName, bool loadHeadersOnly=false) |
int | Save (std::ostream &fs, std::streamoff fileOffset=0, bool saveHeadersOnly=false) |
int | Save (const char *fileName, bool saveHeadersOnly=false) |
bool | relocateImage (std::uint64_t newImageBase) |
std::uint32_t | readImage (void *buffer, std::uint32_t rva, std::uint32_t bytesToRead) |
std::uint32_t | writeImage (void *buffer, std::uint32_t rva, std::uint32_t bytesToRead) |
std::uint32_t | readString (std::string &str, std::uint32_t rva, std::uint32_t maxLength=65535) |
std::uint32_t | readStringRc (std::string &str, std::uint32_t rva) |
std::uint32_t | readStringRaw (ByteBuffer &fileData, std::string &str, std::size_t offset, std::size_t maxLength=65535, bool mustBePrintable=false, bool mustNotBeTooLong=false) |
std::uint32_t | stringLength (std::uint32_t rva, std::uint32_t maxLength=65535) const |
std::uint32_t | readPointer (std::uint32_t rva, std::uint64_t &pointerValue) |
std::uint32_t | getPointerSize () const |
std::uint32_t | dumpImage (const char *fileName) |
std::uint32_t | getImageBitability () const |
std::uint32_t | vaToRva (std::uint64_t VirtualAddress) const |
std::uint32_t | getFileOffsetFromRva (std::uint32_t rva) const |
std::uint32_t | getRealPointerToRawData (std::size_t sectionIndex) const |
std::uint32_t | getImageProtection (std::uint32_t characteristics) const |
std::size_t | getSectionIndexByRva (std::uint32_t Rva) const |
std::uint32_t | getFieldOffset (PELIB_MEMBER_TYPE field) const |
const PELIB_IMAGE_DOS_HEADER & | getDosHeader () const |
const PELIB_IMAGE_FILE_HEADER & | getFileHeader () const |
const PELIB_IMAGE_OPTIONAL_HEADER & | getOptionalHeader () const |
const PELIB_SECTION_HEADER * | getSectionHeader (std::size_t sectionIndex) const |
PELIB_SECTION_HEADER * | getSectionHeader (std::size_t sectionIndex) |
std::uint64_t | getSizeOfFile () const |
std::uint64_t | getOrdinalMask () const |
std::uint32_t | getPeHeaderOffset () const |
void | setPeHeaderOffset (std::uint32_t new_e_lfanew) |
std::uint32_t | getNtSignature () const |
std::uint32_t | getMachine () const |
std::uint32_t | getPointerToSymbolTable () const |
std::uint32_t | getNumberOfSymbols () const |
std::uint32_t | getLoadedNumberOfSections () const |
std::uint32_t | getCharacteristics () const |
std::uint32_t | getNumberOfSections () const |
std::uint32_t | getMagic () const |
std::uint64_t | getImageBase () const |
std::uint32_t | getAddressOfEntryPoint () const |
std::uint32_t | getSizeOfHeaders () const |
std::uint32_t | getSizeOfImage () const |
std::uint32_t | getSizeOfImageAligned () const |
std::uint32_t | getSectionAlignment () const |
std::uint32_t | getFileAlignment () const |
std::uint32_t | getChecksumFileOffset () const |
std::uint32_t | getRealNumberOfDataDirectories () const |
std::uint32_t | getSecurityDirFileOffset () const |
std::uint32_t | getDataDirRva (std::size_t dataDirIndex) const |
std::uint32_t | getDataDirSize (std::size_t dataDirIndex) const |
std::uint64_t | getVirtualAddressMasked (std::uint32_t rva) |
void | setPointerToSymbolTable (std::uint32_t pointerToSymbolTable) |
void | setCharacteristics (std::uint32_t characteristics) |
void | setAddressOfEntryPoint (std::uint32_t addressOfEntryPoint) |
void | setSizeOfCode (std::uint32_t sizeOfCode, std::uint32_t baseOfCode=UINT32_MAX) |
void | setDataDirectory (std::uint32_t entryIndex, std::uint32_t VirtualAddress, std::uint32_t Size=UINT32_MAX) |
PELIB_IMAGE_SECTION_HEADER * | addSection (const char *name, std::uint32_t size) |
void | calcNewSectionAddresses (std::uint32_t &Rva, std::uint32_t &RawOffset) |
void | setSectionName (std::size_t sectionIndex, const char *newName) |
void | setSectionVirtualRange (std::size_t sectionIndex, std::uint32_t VirtualAddress, std::uint32_t VirtualSize=UINT32_MAX) |
void | setSectionRawDataRange (std::size_t sectionIndex, std::uint32_t PointerToRawData, std::uint32_t SizeOfRawData=UINT32_MAX) |
void | setSectionCharacteristics (std::size_t sectionIndex, std::uint32_t Characteristics) |
int | splitSection (std::size_t sectionIndex, const std::string &prevSectName, const std::string &nextSectName, std::uint32_t splitOffset) |
void | enlargeLastSection (std::uint32_t sectionSize) |
int | removeSection (std::size_t sizeIncrement) |
void | makeValid () |
int | setLoaderError (LoaderError ldrErr) |
LoaderError | loaderError () const |
std::size_t | getMismatchOffset (void *buffer1, void *buffer2, std::uint32_t rva, std::size_t length) |
void | compareWithWindowsMappedImage (PELIB_IMAGE_COMPARE &ImageCompare, void *imageData, std::uint32_t imageSize) |
template<typename LOAD_CONFIG > | |
bool | checkForBadLoadConfigXX (uint32_t loadConfigRva, uint32_t loadConfigSize) |
Protected Types | |
typedef void(* | READWRITE) (PeLib::PELIB_FILE_PAGE &page, void *buffer, std::size_t offsetInPage, std::size_t bytesInPage) |
Protected Member Functions | |
std::uint32_t | readWriteImage (void *buffer, std::uint32_t rva, std::uint32_t bytesToRead, READWRITE ReadWrite) |
std::uint32_t | readWriteImageFile (void *buffer, std::uint32_t rva, std::uint32_t bytesToRead, bool bReadOperation) |
void | processSectionHeader (PELIB_IMAGE_SECTION_HEADER *pSectionHeader) |
bool | processImageRelocation_IA64_IMM64 (std::uint32_t fixupAddress, std::uint64_t difference) |
bool | processImageRelocations (std::uint64_t oldImageBase, std::uint64_t getImageBase, std::uint32_t VirtualAddress, std::uint32_t Size) |
void | writeNewImageBase (std::uint64_t newImageBase) |
int | captureDosHeader (ByteBuffer &fileData) |
int | saveDosHeader (std::ostream &fs, std::streamoff fileOffset) |
int | captureNtHeaders (ByteBuffer &fileData) |
int | saveNtHeaders (std::ostream &fs, std::streamoff fileOffset) |
int | captureSectionName (ByteBuffer &fileData, std::string §ionName, const std::uint8_t *name) |
int | captureSectionHeaders (ByteBuffer &fileData) |
int | saveSectionHeaders (std::ostream &fs, std::streamoff fileOffset) |
int | captureImageSections (ByteBuffer &fileData) |
int | captureOptionalHeader32 (std::uint8_t *fileData, std::uint8_t *filePtr, std::uint8_t *fileEnd) |
int | captureOptionalHeader64 (std::uint8_t *fileData, std::uint8_t *filePtr, std::uint8_t *fileEnd) |
int | verifyDosHeader (PELIB_IMAGE_DOS_HEADER &hdr, std::size_t fileSize) |
int | verifyDosHeader (std::istream &fs, std::streamoff fileOffset, std::size_t fileSize) |
int | loadImageAsIs (ByteBuffer &fileData) |
std::uint32_t | captureImageSection (ByteBuffer &fileData, std::uint32_t virtualAddress, std::uint32_t virtualSize, std::uint32_t pointerToRawData, std::uint32_t sizeOfRawData, std::uint32_t characteristics, bool isImageHeader=false) |
bool | isGoodPagePointer (PFN_VERIFY_ADDRESS PfnVerifyAddress, void *pagePtr) |
bool | isGoodMappedPage (std::uint32_t rva) |
bool | isZeroPage (std::uint32_t rva) |
bool | isSectionHeaderPointerToRawData (uint32_t rva) |
bool | isLegacyImageArchitecture (std::uint16_t Machine) |
bool | checkForValid64BitMachine () |
bool | checkForValid32BitMachine () |
bool | isValidMachineForCodeIntegrifyCheck (std::uint32_t Bits) |
bool | checkForSectionTablesWithinHeader (std::uint32_t e_lfanew) |
bool | checkForBadCodeIntegrityImages (ByteBuffer &fileData) |
bool | checkForBadArchitectureSpecific () |
bool | checkForImageAfterMapping () |
template<typename LOAD_CONFIG > | |
bool | checkForBadLoadConfigXX (std::uint32_t loadConfigRva, std::uint32_t loadConfigSize) |
bool | isImageLoadable () const |
bool | isImageMappedOk () const |
bool | isValidImageBlock (std::uint32_t Rva, std::uint32_t Size) const |
bool | isPrintableChar (int ch) |
Static Protected Member Functions | |
static void | readFromPage (PELIB_FILE_PAGE &page, void *buffer, size_t offsetInPage, size_t bytesInPage) |
static void | writeToPage (PELIB_FILE_PAGE &page, void *buffer, size_t offsetInPage, size_t bytesInPage) |
static std::uint32_t | AlignToSize (std::uint32_t ByteSize, std::uint32_t AlignSize) |
static std::uint32_t | BytesToPages (std::uint32_t ByteSize) |
static std::uint64_t | signExtend32To64 (std::uint32_t value32) |
Protected Attributes | |
std::vector< PELIB_SECTION_HEADER > | sections |
std::vector< PELIB_FILE_PAGE > | pages |
PELIB_IMAGE_DOS_HEADER | dosHeader |
PELIB_IMAGE_FILE_HEADER | fileHeader |
PELIB_IMAGE_OPTIONAL_HEADER | optionalHeader |
ByteBuffer | rawFileData |
LoaderError | ldrError |
std::uint64_t | savedFileSize |
std::uint32_t | windowsBuildNumber |
std::uint32_t | ntSignature |
std::uint32_t | maxSectionCount |
std::uint32_t | realNumberOfRvaAndSizes |
std::uint32_t | checkSumFileOffset |
std::uint32_t | securityDirFileOffset |
std::uint32_t | ssiImageAlignment32 |
bool | is64BitWindows |
bool | ntHeadersSizeCheck |
bool | sizeofImageMustMatch |
bool | architectureSpecificChecks |
bool | headerSizeCheck |
bool | loadArmImages |
bool | loadArm64Images |
bool | loadItaniumImages |
bool | forceIntegrityCheckEnabled |
bool | forceIntegrityCheckCertificate |
bool | checkNonLegacyDllCharacteristics |
bool | checkImagePostMapping |
Static Protected Attributes | |
static uint8_t | ImageProtectionArray [16] |
|
protected |
PeLib::ImageLoader::ImageLoader | ( | std::uint32_t | loaderFlags = 0 | ) |
PeLib::PELIB_IMAGE_SECTION_HEADER * PeLib::ImageLoader::addSection | ( | const char * | name, |
std::uint32_t | size | ||
) |
|
inlinestaticprotected |
|
inlinestaticprotected |
void PeLib::ImageLoader::calcNewSectionAddresses | ( | std::uint32_t & | Rva, |
std::uint32_t & | RawOffset | ||
) |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
bool PeLib::ImageLoader::checkForBadLoadConfigXX | ( | uint32_t | loadConfigRva, |
uint32_t | loadConfigSize | ||
) |
|
protected |
|
protected |
|
protected |
|
protected |
void PeLib::ImageLoader::compareWithWindowsMappedImage | ( | PELIB_IMAGE_COMPARE & | ImageCompare, |
void * | imageData, | ||
std::uint32_t | imageSize | ||
) |
uint32_t PeLib::ImageLoader::dumpImage | ( | const char * | fileName | ) |
void PeLib::ImageLoader::enlargeLastSection | ( | std::uint32_t | sectionSize | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
uint32_t PeLib::ImageLoader::getFieldOffset | ( | PELIB_MEMBER_TYPE | field | ) | const |
|
inline |
|
inline |
uint32_t PeLib::ImageLoader::getFileOffsetFromRva | ( | std::uint32_t | rva | ) | const |
|
inline |
uint32_t PeLib::ImageLoader::getImageBitability | ( | ) | const |
uint32_t PeLib::ImageLoader::getImageProtection | ( | std::uint32_t | characteristics | ) | const |
|
inline |
|
inline |
|
inline |
size_t PeLib::ImageLoader::getMismatchOffset | ( | void * | buffer1, |
void * | buffer2, | ||
std::uint32_t | rva, | ||
std::size_t | length | ||
) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
uint32_t PeLib::ImageLoader::getPointerSize | ( | ) | const |
|
inline |
|
inline |
uint32_t PeLib::ImageLoader::getRealPointerToRawData | ( | std::size_t | sectionIndex | ) | const |
|
inline |
|
inline |
|
inline |
size_t PeLib::ImageLoader::getSectionIndexByRva | ( | std::uint32_t | Rva | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
inlineprotected |
|
protected |
|
protected |
|
protected |
|
protected |
int PeLib::ImageLoader::Load | ( | ByteBuffer & | fileData, |
bool | loadHeadersOnly = false |
||
) |
int PeLib::ImageLoader::Load | ( | const char * | fileName, |
bool | loadHeadersOnly = false |
||
) |
int PeLib::ImageLoader::Load | ( | std::istream & | fs, |
std::streamoff | fileOffset = 0 , |
||
bool | loadHeadersOnly = false |
||
) |
PeLib::LoaderError PeLib::ImageLoader::loaderError | ( | ) | const |
|
protected |
void PeLib::ImageLoader::makeValid | ( | ) |
|
protected |
|
protected |
|
protected |
|
staticprotected |
uint32_t PeLib::ImageLoader::readImage | ( | void * | buffer, |
std::uint32_t | rva, | ||
std::uint32_t | bytesToRead | ||
) |
uint32_t PeLib::ImageLoader::readPointer | ( | std::uint32_t | rva, |
std::uint64_t & | pointerValue | ||
) |
uint32_t PeLib::ImageLoader::readString | ( | std::string & | str, |
std::uint32_t | rva, | ||
std::uint32_t | maxLength = 65535 |
||
) |
uint32_t PeLib::ImageLoader::readStringRaw | ( | ByteBuffer & | fileData, |
std::string & | str, | ||
std::size_t | offset, | ||
std::size_t | maxLength = 65535 , |
||
bool | mustBePrintable = false , |
||
bool | mustNotBeTooLong = false |
||
) |
uint32_t PeLib::ImageLoader::readStringRc | ( | std::string & | str, |
std::uint32_t | rva | ||
) |
|
protected |
|
protected |
bool PeLib::ImageLoader::relocateImage | ( | std::uint64_t | newImageBase | ) |
int PeLib::ImageLoader::removeSection | ( | std::size_t | sizeIncrement | ) |
int PeLib::ImageLoader::Save | ( | const char * | fileName, |
bool | saveHeadersOnly = false |
||
) |
int PeLib::ImageLoader::Save | ( | std::ostream & | fs, |
std::streamoff | fileOffset = 0 , |
||
bool | saveHeadersOnly = false |
||
) |
|
protected |
|
protected |
|
protected |
void PeLib::ImageLoader::setAddressOfEntryPoint | ( | std::uint32_t | addressOfEntryPoint | ) |
void PeLib::ImageLoader::setCharacteristics | ( | std::uint32_t | characteristics | ) |
void PeLib::ImageLoader::setDataDirectory | ( | std::uint32_t | entryIndex, |
std::uint32_t | VirtualAddress, | ||
std::uint32_t | Size = UINT32_MAX |
||
) |
int PeLib::ImageLoader::setLoaderError | ( | PeLib::LoaderError | ldrErr | ) |
|
inline |
void PeLib::ImageLoader::setPointerToSymbolTable | ( | std::uint32_t | pointerToSymbolTable | ) |
void PeLib::ImageLoader::setSectionCharacteristics | ( | std::size_t | sectionIndex, |
std::uint32_t | Characteristics | ||
) |
void PeLib::ImageLoader::setSectionName | ( | std::size_t | sectionIndex, |
const char * | newName | ||
) |
void PeLib::ImageLoader::setSectionRawDataRange | ( | std::size_t | sectionIndex, |
std::uint32_t | PointerToRawData, | ||
std::uint32_t | SizeOfRawData = UINT32_MAX |
||
) |
void PeLib::ImageLoader::setSectionVirtualRange | ( | std::size_t | sectionIndex, |
std::uint32_t | VirtualAddress, | ||
std::uint32_t | VirtualSize = UINT32_MAX |
||
) |
void PeLib::ImageLoader::setSizeOfCode | ( | std::uint32_t | sizeOfCode, |
std::uint32_t | baseOfCode = UINT32_MAX |
||
) |
|
inlinestaticprotected |
int PeLib::ImageLoader::splitSection | ( | std::size_t | sectionIndex, |
const std::string & | prevSectName, | ||
const std::string & | nextSectName, | ||
std::uint32_t | splitOffset | ||
) |
uint32_t PeLib::ImageLoader::stringLength | ( | std::uint32_t | rva, |
std::uint32_t | maxLength = 65535 |
||
) | const |
uint32_t PeLib::ImageLoader::vaToRva | ( | std::uint64_t | VirtualAddress | ) | const |
|
protected |
|
protected |
uint32_t PeLib::ImageLoader::writeImage | ( | void * | buffer, |
std::uint32_t | rva, | ||
std::uint32_t | bytesToRead | ||
) |
|
protected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |