mirror of
https://github.com/avast/retdec.git
synced 2024-11-23 21:10:13 +00:00
commit
220212c135
@ -202,6 +202,11 @@ class ImageLoader
|
||||
return (sectionIndex < sections.size()) ? §ions[sectionIndex] : nullptr;
|
||||
}
|
||||
|
||||
std::uint64_t getSizeOfFile() const
|
||||
{
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
std::uint64_t getOrdinalMask() const
|
||||
{
|
||||
return (uint64_t)1 << (getImageBitability() - 1);
|
||||
@ -446,6 +451,7 @@ class ImageLoader
|
||||
PELIB_IMAGE_OPTIONAL_HEADER optionalHeader; // 32/64-bit optional header
|
||||
ByteBuffer rawFileData; // Loaded content of the image in case it couldn't have been mapped
|
||||
LoaderError ldrError;
|
||||
std::uint64_t fileSize; // Size of the raw file
|
||||
std::uint32_t windowsBuildNumber;
|
||||
std::uint32_t ntSignature;
|
||||
std::uint32_t maxSectionCount;
|
||||
|
@ -871,6 +871,9 @@ int PeLib::ImageLoader::Load(
|
||||
{
|
||||
int fileError;
|
||||
|
||||
// Remember the size of the file for later use
|
||||
fileSize = fileData.size();
|
||||
|
||||
// Check and capture DOS header
|
||||
fileError = captureDosHeader(fileData);
|
||||
if(fileError != ERROR_NONE)
|
||||
|
@ -26,6 +26,7 @@ namespace PeLib
|
||||
std::uint32_t rva = imageLoader.getDataDirRva(PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC);
|
||||
std::uint32_t size = imageLoader.getDataDirSize(PELIB_IMAGE_DIRECTORY_ENTRY_BASERELOC);
|
||||
std::uint32_t sizeOfImage = imageLoader.getSizeOfImage();
|
||||
std::uint64_t sizeOfFile = imageLoader.getSizeOfFile();
|
||||
|
||||
// Check for relocations out of image
|
||||
if(rva >= sizeOfImage || (rva + size) < rva || (rva + size) > sizeOfImage)
|
||||
@ -34,9 +35,17 @@ namespace PeLib
|
||||
return ERROR_INVALID_FILE;
|
||||
}
|
||||
|
||||
// Check for relocations out of file
|
||||
if(size > sizeOfFile)
|
||||
{
|
||||
RelocationsDirectory::setLoaderError(LDR_ERROR_RELOCATIONS_OUT_OF_IMAGE);
|
||||
return ERROR_INVALID_FILE;
|
||||
}
|
||||
|
||||
// Read the entire relocation directory from the image
|
||||
std::vector<std::uint8_t> vRelocDirectory(size);
|
||||
imageLoader.readImage(vRelocDirectory.data(), rva, size);
|
||||
if(imageLoader.readImage(vRelocDirectory.data(), rva, size) != size)
|
||||
return ERROR_INVALID_FILE;
|
||||
|
||||
// Parse the relocations directory
|
||||
read(vRelocDirectory.data(), size, sizeOfImage);
|
||||
|
Loading…
Reference in New Issue
Block a user