Version 0.16.1

- fixed a serious bug in section rebuild process
- opening search windows sets text focus into search edit box
This commit is contained in:
Nikolaj Schlej 2014-01-12 00:02:54 +01:00
parent 1fedb2becf
commit 5789e2f9e6
15 changed files with 641 additions and 670 deletions

View File

@ -85,9 +85,9 @@ typedef struct {
typedef struct {
FLASH_PARAMETERS FlashParameters;
UINT8 InvalidInstruction0; // Instructions for SPI chip, that must not be executed, like FLASH ERASE
UINT8 InvalidInstruction1; //
UINT8 InvalidInstruction2; //
UINT8 InvalidInstruction3; //
UINT8 InvalidInstruction1; //
UINT8 InvalidInstruction2; //
UINT8 InvalidInstruction3; //
UINT16 PartitionBoundary; // Upper 16 bit of partition boundary address. Default is 0x0000, which makes the boundary to be 0x00001000
UINT16 ReservedZero; // Still unknown, zero in all descriptors I have seen
} FLASH_DESCRIPTOR_COMPONENT_SECTION;
@ -98,8 +98,8 @@ typedef struct {
typedef struct {
UINT16 ReservedZero; // Still unknown, zero in all descriptors I have seen
UINT16 FlashBlockEraseSize; // Size of block erased by single BLOCK ERASE command
UINT16 BiosBase;
UINT16 BiosLimit;
UINT16 BiosBase;
UINT16 BiosLimit;
UINT16 MeBase;
UINT16 MeLimit;
UINT16 GbeBase;

30
ffs.cpp
View File

@ -55,9 +55,9 @@ VOID uint32ToUint24(UINT32 size, UINT8* ffsSize)
UINT32 uint24ToUint32(UINT8* ffsSize)
{
return (ffsSize[2] << 16) +
(ffsSize[1] << 8) +
ffsSize[0];
return (ffsSize[2] << 16) +
(ffsSize[1] << 8) +
ffsSize[0];
}
QString guidToQString(const EFI_GUID guid)
@ -76,17 +76,17 @@ QString guidToQString(const EFI_GUID guid)
UINT8 i8_7 = *(UINT8*)baGuid.mid(15, 1).constData();
return QString("%1-%2-%3-%4%5-%6%7%8%9%10%11")
.arg(i32, 8, 16, QChar('0'))
.arg(i16_0, 4, 16, QChar('0'))
.arg(i16_1, 4, 16, QChar('0'))
.arg(i8_0, 2, 16, QChar('0'))
.arg(i8_1, 2, 16, QChar('0'))
.arg(i8_2, 2, 16, QChar('0'))
.arg(i8_3, 2, 16, QChar('0'))
.arg(i8_4, 2, 16, QChar('0'))
.arg(i8_5, 2, 16, QChar('0'))
.arg(i8_6, 2, 16, QChar('0'))
.arg(i8_7, 2, 16, QChar('0')).toUpper();
.arg(i32, 8, 16, QChar('0'))
.arg(i16_0, 4, 16, QChar('0'))
.arg(i16_1, 4, 16, QChar('0'))
.arg(i8_0, 2, 16, QChar('0'))
.arg(i8_1, 2, 16, QChar('0'))
.arg(i8_2, 2, 16, QChar('0'))
.arg(i8_3, 2, 16, QChar('0'))
.arg(i8_4, 2, 16, QChar('0'))
.arg(i8_5, 2, 16, QChar('0'))
.arg(i8_6, 2, 16, QChar('0'))
.arg(i8_7, 2, 16, QChar('0')).toUpper();
}
QString fileTypeToQString(const UINT8 type)
@ -202,4 +202,4 @@ UINT32 sizeOfSectionHeaderOfType(const UINT8 type)
default:
return sizeof(EFI_COMMON_SECTION_HEADER);
}
}
}

36
ffs.h
View File

@ -36,10 +36,10 @@ extern "C" {
//*****************************************************************************
// Capsule header
typedef struct {
EFI_GUID CapsuleGuid;
UINT32 HeaderSize;
UINT32 Flags;
UINT32 CapsuleImageSize;
EFI_GUID CapsuleGuid;
UINT32 HeaderSize;
UINT32 Flags;
UINT32 CapsuleImageSize;
} EFI_CAPSULE_HEADER;
// Capsule flags
@ -54,10 +54,10 @@ const QByteArray EFI_CAPSULE_GUID("\xBD\x86\x66\x3B\x76\x0D\x30\x40\xB7\x0E\xB5\
typedef struct {
EFI_CAPSULE_HEADER CapsuleHeader;
UINT16 RomImageOffset; // offset in bytes from the beginning of the capsule header to the start of
// the capsule volume
// the capsule volume
//!TODO: Enable certificate and rom layout reading
//UINT16 RomLayoutOffset; // offset to the table of the module descriptors in the capsule's volume
// that are included in the signature calculation
// that are included in the signature calculation
//FW_CERTIFICATE FWCert;
//ROM_AREA RomAreaMap[1];
} APTIO_CAPSULE_HEADER;
@ -72,8 +72,8 @@ const QByteArray APTIO_CAPSULE_GUID
// Firmware block map entry
// FvBlockMap ends with an entry {0x00000000, 0x00000000}
typedef struct {
UINT32 NumBlocks;
UINT32 Length;
UINT32 NumBlocks;
UINT32 Length;
} EFI_FV_BLOCK_MAP_ENTRY;
// Volume header
@ -188,8 +188,8 @@ const QByteArray EFI_FV_SIGNATURE("_FVH", 4);
// Extended firmware volume header
typedef struct {
EFI_GUID FvName;
UINT32 ExtHeaderSize;
EFI_GUID FvName;
UINT32 ExtHeaderSize;
} EFI_FIRMWARE_VOLUME_EXT_HEADER;
// Extended header entry
@ -197,23 +197,23 @@ typedef struct {
// terminated by ExtHeaderType EFI_FV_EXT_TYPE_END
#define EFI_FV_EXT_TYPE_END 0x00
typedef struct {
UINT16 ExtEntrySize;
UINT16 ExtEntryType;
UINT16 ExtEntrySize;
UINT16 ExtEntryType;
} EFI_FIRMWARE_VOLUME_EXT_ENTRY;
// GUID that maps OEM file types to GUIDs
#define EFI_FV_EXT_TYPE_OEM_TYPE 0x01
typedef struct {
EFI_FIRMWARE_VOLUME_EXT_ENTRY Header;
UINT32 TypeMask;
//EFI_GUID Types[1];
EFI_FIRMWARE_VOLUME_EXT_ENTRY Header;
UINT32 TypeMask;
//EFI_GUID Types[1];
} EFI_FIRMWARE_VOLUME_EXT_HEADER_OEM_TYPE;
#define EFI_FV_EXT_TYPE_GUID_TYPE 0x02
typedef struct {
EFI_FIRMWARE_VOLUME_EXT_ENTRY Header;
EFI_GUID FormatType;
//UINT8 Data[];
EFI_FIRMWARE_VOLUME_EXT_ENTRY Header;
EFI_GUID FormatType;
//UINT8 Data[];
} EFI_FIRMWARE_VOLUME_EXT_ENTRY_GUID_TYPE;

View File

@ -94,9 +94,9 @@ UINT8 FfsEngine::parseInputFile(const QByteArray & buffer)
QByteArray body = buffer.right(buffer.size() - capsuleHeaderSize);
QString name = tr("UEFI capsule");
QString info = tr("Header size: %1\nFlags: %2\nImage size: %3")
.arg(capsuleHeader->HeaderSize, 8, 16, QChar('0'))
.arg(capsuleHeader->Flags, 8, 16, QChar('0'))
.arg(capsuleHeader->CapsuleImageSize, 8, 16, QChar('0'));
.arg(capsuleHeader->HeaderSize, 8, 16, QChar('0'))
.arg(capsuleHeader->Flags, 8, 16, QChar('0'))
.arg(capsuleHeader->CapsuleImageSize, 8, 16, QChar('0'));
// Add tree item
index = model->addItem(Capsule, UefiCapsule, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body);
}
@ -110,9 +110,9 @@ UINT8 FfsEngine::parseInputFile(const QByteArray & buffer)
QByteArray body = buffer.right(buffer.size() - capsuleHeaderSize);
QString name = tr("AMI Aptio capsule");
QString info = tr("Header size: %1\nFlags: %2\nImage size: %3")
.arg(aptioCapsuleHeader->RomImageOffset, 4, 16, QChar('0'))
.arg(aptioCapsuleHeader->CapsuleHeader.Flags, 8, 16, QChar('0'))
.arg(aptioCapsuleHeader->CapsuleHeader.CapsuleImageSize - aptioCapsuleHeader->RomImageOffset, 8, 16, QChar('0'));
.arg(aptioCapsuleHeader->RomImageOffset, 4, 16, QChar('0'))
.arg(aptioCapsuleHeader->CapsuleHeader.Flags, 8, 16, QChar('0'))
.arg(aptioCapsuleHeader->CapsuleHeader.CapsuleImageSize - aptioCapsuleHeader->RomImageOffset, 8, 16, QChar('0'));
//!TODO: more info about Aptio capsule
// Add tree item
index = model->addItem(Capsule, AptioCapsule, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body);
@ -137,7 +137,7 @@ UINT8 FfsEngine::parseInputFile(const QByteArray & buffer)
// Get info
QString name = tr("BIOS image");
QString info = tr("Size: %1")
.arg(flashImage.size(), 8, 16, QChar('0'));
.arg(flashImage.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem(Image, BiosImage, COMPRESSION_ALGORITHM_NONE, name, "", info, QByteArray(), flashImage, QByteArray(), index);
@ -261,13 +261,13 @@ UINT8 FfsEngine::parseIntelImage(const QByteArray & intelImage, QModelIndex & in
// Intel image
name = tr("Intel image");
info = tr("Size: %1\nFlash chips: %2\nRegions: %3\nMasters: %4\nPCH straps: %5\nPROC straps: %6\nICC table entries: %7")
.arg(intelImage.size(), 8, 16, QChar('0'))
.arg(descriptorMap->NumberOfFlashChips + 1) //
.arg(descriptorMap->NumberOfRegions + 1) // Zero-based numbers in storage
.arg(descriptorMap->NumberOfMasters + 1) //
.arg(descriptorMap->NumberOfPchStraps)
.arg(descriptorMap->NumberOfProcStraps)
.arg(descriptorMap->NumberOfIccTableEntries);
.arg(intelImage.size(), 8, 16, QChar('0'))
.arg(descriptorMap->NumberOfFlashChips + 1) //
.arg(descriptorMap->NumberOfRegions + 1) // Zero-based numbers in storage
.arg(descriptorMap->NumberOfMasters + 1) //
.arg(descriptorMap->NumberOfPchStraps)
.arg(descriptorMap->NumberOfProcStraps)
.arg(descriptorMap->NumberOfIccTableEntries);
// Add Intel image tree item
index = model->addItem(Image, IntelImage, COMPRESSION_ALGORITHM_NONE, name, "", info, QByteArray(), intelImage, QByteArray(), parent);
@ -343,15 +343,15 @@ UINT8 FfsEngine::parseGbeRegion(const QByteArray & gbe, QModelIndex & index, con
GBE_MAC* mac = (GBE_MAC*) gbe.constData();
GBE_VERSION* version = (GBE_VERSION*) (gbe.constData() + GBE_VERSION_OFFSET);
QString info = tr("Size: %1\nMAC: %2:%3:%4:%5:%6:%7\nVersion: %8.%9")
.arg(gbe.size(), 8, 16, QChar('0'))
.arg(mac->vendor[0], 2, 16, QChar('0'))
.arg(mac->vendor[1], 2, 16, QChar('0'))
.arg(mac->vendor[2], 2, 16, QChar('0'))
.arg(mac->device[0], 2, 16, QChar('0'))
.arg(mac->device[1], 2, 16, QChar('0'))
.arg(mac->device[2], 2, 16, QChar('0'))
.arg(version->major)
.arg(version->minor);
.arg(gbe.size(), 8, 16, QChar('0'))
.arg(mac->vendor[0], 2, 16, QChar('0'))
.arg(mac->vendor[1], 2, 16, QChar('0'))
.arg(mac->vendor[2], 2, 16, QChar('0'))
.arg(mac->device[0], 2, 16, QChar('0'))
.arg(mac->device[1], 2, 16, QChar('0'))
.arg(mac->device[2], 2, 16, QChar('0'))
.arg(version->major)
.arg(version->minor);
// Add tree item
index = model->addItem( Region, GbeRegion, COMPRESSION_ALGORITHM_NONE, name, "", info, QByteArray(), gbe, QByteArray(), parent);
@ -367,7 +367,7 @@ UINT8 FfsEngine::parseMeRegion(const QByteArray & me, QModelIndex & index, const
// Get info
QString name = tr("ME region");
QString info = tr("Size: %1").
arg(me.size(), 8, 16, QChar('0'));
arg(me.size(), 8, 16, QChar('0'));
ME_VERSION* version;
INT32 versionOffset = me.indexOf(ME_VERSION_SIGNATURE);
@ -378,10 +378,10 @@ UINT8 FfsEngine::parseMeRegion(const QByteArray & me, QModelIndex & index, const
else {
version = (ME_VERSION*) (me.constData() + versionOffset);
info += tr("\nVersion: %1.%2.%3.%4")
.arg(version->major)
.arg(version->minor)
.arg(version->bugfix)
.arg(version->build);
.arg(version->major)
.arg(version->minor)
.arg(version->bugfix)
.arg(version->build);
}
// Add tree item
@ -398,7 +398,7 @@ UINT8 FfsEngine::parsePdrRegion(const QByteArray & pdr, QModelIndex & index, con
// Get info
QString name = tr("PDR region");
QString info = tr("Size: %1").
arg(pdr.size(), 8, 16, QChar('0'));
arg(pdr.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Region, PdrRegion, COMPRESSION_ALGORITHM_NONE, name, "", info, QByteArray(), pdr, QByteArray(), parent);
@ -414,7 +414,7 @@ UINT8 FfsEngine::parseBiosRegion(const QByteArray & bios, QModelIndex & index, c
// Get info
QString name = tr("BIOS region");
QString info = tr("Size: %1").
arg(bios.size(), 8, 16, QChar('0'));
arg(bios.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Region, BiosRegion, COMPRESSION_ALGORITHM_NONE, name, "", info, QByteArray(), bios, QByteArray(), parent);
@ -440,7 +440,7 @@ UINT8 FfsEngine::parseBios(const QByteArray & bios, const QModelIndex & parent)
QByteArray padding = bios.left(prevVolumeOffset);
name = tr("Padding");
info = tr("Size: %1")
.arg(padding.size(), 8, 16, QChar('0'));
.arg(padding.size(), 8, 16, QChar('0'));
// Add tree item
model->addItem( Padding, 0, COMPRESSION_ALGORITHM_NONE, name, "", info, QByteArray(), padding, QByteArray(), parent);
}
@ -459,7 +459,7 @@ UINT8 FfsEngine::parseBios(const QByteArray & bios, const QModelIndex & parent)
// Get info
name = tr("Padding");
info = tr("Size: %1")
.arg(padding.size(), 8, 16, QChar('0'));
.arg(padding.size(), 8, 16, QChar('0'));
// Add tree item
model->addItem( Padding, 0, COMPRESSION_ALGORITHM_NONE, name, "", info, QByteArray(), padding, QByteArray(), parent);
}
@ -500,10 +500,10 @@ UINT8 FfsEngine::parseBios(const QByteArray & bios, const QModelIndex & parent)
// Check alignment setup
if (!alignmentCap &&
( alignment2 || alignment4 || alignment8 || alignment16
|| alignment32 || alignment64 || alignment128 || alignment256
|| alignment512 || alignment1k || alignment2k || alignment4k
|| alignment8k || alignment16k || alignment32k || alignment64k))
( alignment2 || alignment4 || alignment8 || alignment16
|| alignment32 || alignment64 || alignment128 || alignment256
|| alignment512 || alignment1k || alignment2k || alignment4k
|| alignment8k || alignment16k || alignment32k || alignment64k))
msg("parseBios: Incompatible revision 1 volume alignment setup", parent);
// Assume that smaller alignment value consumes greater
@ -578,7 +578,7 @@ UINT8 FfsEngine::parseBios(const QByteArray & bios, const QModelIndex & parent)
// Get info
name = tr("Padding");
info = tr("Size: %2")
.arg(padding.size(), 8, 16, QChar('0'));
.arg(padding.size(), 8, 16, QChar('0'));
// Add tree item
model->addItem( Padding, 0, COMPRESSION_ALGORITHM_NONE, name, "", info, QByteArray(), padding, QByteArray(), parent);
}
@ -687,10 +687,10 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co
// Get info
QString name = guidToQString(volumeHeader->FileSystemGuid);
QString info = tr("Size: %1\nRevision: %2\nAttributes: %3\nHeader size: %4")
.arg(volumeSize, 8, 16, QChar('0'))
.arg(volumeHeader->Revision)
.arg(volumeHeader->Attributes, 8, 16, QChar('0'))
.arg(volumeHeader->HeaderLength, 4, 16, QChar('0'));
.arg(volumeSize, 8, 16, QChar('0'))
.arg(volumeHeader->Revision)
.arg(volumeHeader->Attributes, 8, 16, QChar('0'))
.arg(volumeHeader->HeaderLength, 4, 16, QChar('0'));
// Add tree item
QByteArray header = volume.left(headerSize);
@ -831,9 +831,9 @@ UINT8 FfsEngine::parseFile(const QByteArray & file, QModelIndex & index, const U
UINT16 tailValue = *(UINT16*) tail.constData();
if (fileHeader->IntegrityCheck.TailReference != (UINT16)~tailValue)
msg(tr("parseFile: %1, bitwise not of tail value %2 differs from %3 stored in file header")
.arg(guidToQString(fileHeader->Name))
.arg(~tailValue, 4, 16, QChar('0'))
.arg(fileHeader->IntegrityCheck.TailReference, 4, 16, QChar('0')), parent);
.arg(guidToQString(fileHeader->Name))
.arg(~tailValue, 4, 16, QChar('0'))
.arg(fileHeader->IntegrityCheck.TailReference, 4, 16, QChar('0')), parent);
// Remove tail from file body
body = body.left(body.size() - sizeof(UINT16));
@ -903,10 +903,10 @@ UINT8 FfsEngine::parseFile(const QByteArray & file, QModelIndex & index, const U
else
name = tr("Padding");
info = tr("Type: %1\nAttributes: %2\nSize: %3\nState: %4")
.arg(fileHeader->Type, 2, 16, QChar('0'))
.arg(fileHeader->Attributes, 2, 16, QChar('0'))
.arg(uint24ToUint32(fileHeader->Size), 6, 16, QChar('0'))
.arg(fileHeader->State, 2, 16, QChar('0'));
.arg(fileHeader->Type, 2, 16, QChar('0'))
.arg(fileHeader->Attributes, 2, 16, QChar('0'))
.arg(uint24ToUint32(fileHeader->Size), 6, 16, QChar('0'))
.arg(fileHeader->State, 2, 16, QChar('0'));
// Add tree item
index = model->addItem( File, fileHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, tail, parent, mode);
@ -984,106 +984,106 @@ UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, c
switch (sectionHeader->Type) {
// Encapsulated sections
case EFI_SECTION_COMPRESSION:
{
bool parseCurrentSection = true;
QByteArray decompressed;
UINT8 algorithm;
EFI_COMPRESSION_SECTION* compressedSectionHeader = (EFI_COMPRESSION_SECTION*) sectionHeader;
header = section.left(sizeof(EFI_COMPRESSION_SECTION));
body = section.mid(sizeof(EFI_COMPRESSION_SECTION), sectionSize - sizeof(EFI_COMPRESSION_SECTION));
algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
// Decompress section
result = decompress(body, compressedSectionHeader->CompressionType, decompressed, &algorithm);
if (result) {
msg(tr("parseSection: Section decompression failed (%1)").arg(result), parent);
parseCurrentSection = false;
}
{
bool parseCurrentSection = true;
QByteArray decompressed;
UINT8 algorithm;
EFI_COMPRESSION_SECTION* compressedSectionHeader = (EFI_COMPRESSION_SECTION*) sectionHeader;
header = section.left(sizeof(EFI_COMPRESSION_SECTION));
body = section.mid(sizeof(EFI_COMPRESSION_SECTION), sectionSize - sizeof(EFI_COMPRESSION_SECTION));
algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
// Decompress section
result = decompress(body, compressedSectionHeader->CompressionType, decompressed, &algorithm);
if (result) {
msg(tr("parseSection: Section decompression failed (%1)").arg(result), parent);
parseCurrentSection = false;
}
// Get info
info = tr("Type: %1\nSize: %2\nCompression type: %3\nDecompressed size: %4")
// Get info
info = tr("Type: %1\nSize: %2\nCompression type: %3\nDecompressed size: %4")
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'))
.arg(compressionTypeToQString(algorithm))
.arg(compressedSectionHeader->UncompressedLength, 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Section, sectionHeader->Type, algorithm, name, "", info, header, body, QByteArray(), parent, mode);
// Add tree item
index = model->addItem( Section, sectionHeader->Type, algorithm, name, "", info, header, body, QByteArray(), parent, mode);
// Parse decompressed data
if (parseCurrentSection) {
result = parseSections(decompressed, index);
if (result)
return result;
}
// Parse decompressed data
if (parseCurrentSection) {
result = parseSections(decompressed, index);
if (result)
return result;
}
}
break;
case EFI_SECTION_GUID_DEFINED:
{
bool parseCurrentSection = true;
EFI_GUID_DEFINED_SECTION* guidDefinedSectionHeader;
header = section.left(sizeof(EFI_GUID_DEFINED_SECTION));
guidDefinedSectionHeader = (EFI_GUID_DEFINED_SECTION*) (header.constData());
header = section.left(guidDefinedSectionHeader->DataOffset);
guidDefinedSectionHeader = (EFI_GUID_DEFINED_SECTION*) (header.constData());
body = section.mid(guidDefinedSectionHeader->DataOffset, sectionSize - guidDefinedSectionHeader->DataOffset);
QByteArray decompressed = body;
UINT8 algorithm = COMPRESSION_ALGORITHM_NONE;
// Check if section requires processing
if (guidDefinedSectionHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) {
// Try to decompress section body using both known compression algorithms
algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
// Tiano
result = decompress(body, EFI_STANDARD_COMPRESSION, decompressed, &algorithm);
{
bool parseCurrentSection = true;
EFI_GUID_DEFINED_SECTION* guidDefinedSectionHeader;
header = section.left(sizeof(EFI_GUID_DEFINED_SECTION));
guidDefinedSectionHeader = (EFI_GUID_DEFINED_SECTION*) (header.constData());
header = section.left(guidDefinedSectionHeader->DataOffset);
guidDefinedSectionHeader = (EFI_GUID_DEFINED_SECTION*) (header.constData());
body = section.mid(guidDefinedSectionHeader->DataOffset, sectionSize - guidDefinedSectionHeader->DataOffset);
QByteArray decompressed = body;
UINT8 algorithm = COMPRESSION_ALGORITHM_NONE;
// Check if section requires processing
if (guidDefinedSectionHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) {
// Try to decompress section body using both known compression algorithms
algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
// Tiano
result = decompress(body, EFI_STANDARD_COMPRESSION, decompressed, &algorithm);
if (result) {
result = decompress(body, EFI_CUSTOMIZED_COMPRESSION, decompressed, &algorithm);
if (result) {
result = decompress(body, EFI_CUSTOMIZED_COMPRESSION, decompressed, &algorithm);
if (result) {
msg(tr("parseSection: GUID defined section can not be decompressed (%1)").arg(result), parent);
parseCurrentSection = false;
}
msg(tr("parseSection: GUID defined section can not be decompressed (%1)").arg(result), parent);
parseCurrentSection = false;
}
}
}
// Get info
name = guidToQString(guidDefinedSectionHeader->SectionDefinitionGuid);
info = tr("Type: %1\nSize: %2\nData offset: %3\nAttributes: %4\nCompression type: %5")
// Get info
name = guidToQString(guidDefinedSectionHeader->SectionDefinitionGuid);
info = tr("Type: %1\nSize: %2\nData offset: %3\nAttributes: %4\nCompression type: %5")
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'))
.arg(guidDefinedSectionHeader->DataOffset, 4, 16, QChar('0'))
.arg(guidDefinedSectionHeader->Attributes, 4, 16, QChar('0'))
.arg(compressionTypeToQString(algorithm));
// Add tree item
index = model->addItem( Section, sectionHeader->Type, algorithm, name, "", info, header, body, QByteArray(), parent, mode);
// Add tree item
index = model->addItem( Section, sectionHeader->Type, algorithm, name, "", info, header, body, QByteArray(), parent, mode);
// Parse decompressed data
if (parseCurrentSection) {
result = parseSections(decompressed, index);
if (result)
return result;
}
}
break;
case EFI_SECTION_DISPOSABLE:
{
header = section.left(sizeof(EFI_DISPOSABLE_SECTION));
body = section.mid(sizeof(EFI_DISPOSABLE_SECTION), sectionSize - sizeof(EFI_DISPOSABLE_SECTION));
// Get info
info = tr("parseSection: %1\nSize: %2")
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Section, sectionHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
// Parse section body
result = parseSections(body, index);
// Parse decompressed data
if (parseCurrentSection) {
result = parseSections(decompressed, index);
if (result)
return result;
}
}
break;
case EFI_SECTION_DISPOSABLE:
{
header = section.left(sizeof(EFI_DISPOSABLE_SECTION));
body = section.mid(sizeof(EFI_DISPOSABLE_SECTION), sectionSize - sizeof(EFI_DISPOSABLE_SECTION));
// Get info
info = tr("parseSection: %1\nSize: %2")
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Section, sectionHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
// Parse section body
result = parseSections(body, index);
if (result)
return result;
}
break;
// Leaf sections
// Leaf sections
case EFI_SECTION_PE32:
case EFI_SECTION_TE:
case EFI_SECTION_PIC:
@ -1099,36 +1099,36 @@ UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, c
// Get info
info = tr("Type: %1\nSize: %2")
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Section, sectionHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
// Special case of PEI Core
if ((sectionHeader->Type == EFI_SECTION_PE32 || sectionHeader->Type == EFI_SECTION_TE) && model->subtype(parent) == EFI_FV_FILETYPE_PEI_CORE) {
result = getEntryPoint(model->body(index) , oldPeiCoreEntryPoint);
if (result)
msg(tr("parseSection: can't get entry point of image file"), index);
}
result = getEntryPoint(model->body(index) , oldPeiCoreEntryPoint);
if (result)
msg(tr("parseSection: can't get entry point of image file"), index);
}
break;
case EFI_SECTION_USER_INTERFACE:
{
header = section.left(sizeof(EFI_USER_INTERFACE_SECTION));
body = section.mid(sizeof(EFI_USER_INTERFACE_SECTION), sectionSize - sizeof(EFI_USER_INTERFACE_SECTION));
{
header = section.left(sizeof(EFI_USER_INTERFACE_SECTION));
body = section.mid(sizeof(EFI_USER_INTERFACE_SECTION), sectionSize - sizeof(EFI_USER_INTERFACE_SECTION));
// Get info
info = tr("Type: %1\nSize: %2")
// Get info
info = tr("Type: %1\nSize: %2")
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Section, sectionHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
// Add tree item
index = model->addItem( Section, sectionHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
// Rename parent file
QString text = QString::fromUtf16((const ushort*)body.constData());
model->setTextString(model->findParentOfType(parent, File), text);
}
// Rename parent file
QString text = QString::fromUtf16((const ushort*)body.constData());
model->setTextString(model->findParentOfType(parent, File), text);
}
break;
case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:
header = section.left(sizeof(EFI_FIRMWARE_VOLUME_IMAGE_SECTION));
@ -1136,8 +1136,8 @@ UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, c
// Get info
info = tr("Type: %1\nSize: %2")
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Section, sectionHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
@ -1155,8 +1155,8 @@ UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, c
// Get info
info = tr("Type: %1\nSize: %2")
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Section, sectionHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
@ -1173,8 +1173,8 @@ UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, c
body = section.mid(sizeof(EFI_COMMON_SECTION_HEADER), sectionSize - sizeof(EFI_COMMON_SECTION_HEADER));
// Get info
info = tr("Type: %1\nSize: %2")
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
.arg(sectionHeader->Type, 2, 16, QChar('0'))
.arg(body.size(), 8, 16, QChar('0'));
// Add tree item
index = model->addItem( Section, sectionHeader->Type, COMPRESSION_ALGORITHM_NONE, name, "", info, header, body, QByteArray(), parent, mode);
@ -1284,98 +1284,98 @@ UINT8 FfsEngine::create(const QModelIndex & index, const UINT8 type, const QByte
switch (commonHeader->Type)
{
case EFI_SECTION_COMPRESSION: {
EFI_COMPRESSION_SECTION* sectionHeader = (EFI_COMPRESSION_SECTION*) newHeader.data();
// Correct uncompressed size
sectionHeader->UncompressedLength = body.size();
EFI_COMPRESSION_SECTION* sectionHeader = (EFI_COMPRESSION_SECTION*) newHeader.data();
// Correct uncompressed size
sectionHeader->UncompressedLength = body.size();
// Set compression type
if (algorithm == COMPRESSION_ALGORITHM_NONE)
sectionHeader->CompressionType = EFI_NOT_COMPRESSED;
else if (algorithm == COMPRESSION_ALGORITHM_EFI11 || algorithm == COMPRESSION_ALGORITHM_TIANO)
sectionHeader->CompressionType = EFI_STANDARD_COMPRESSION;
else if (algorithm == COMPRESSION_ALGORITHM_LZMA || algorithm == COMPRESSION_ALGORITHM_IMLZMA)
sectionHeader->CompressionType = EFI_CUSTOMIZED_COMPRESSION;
else
return ERR_UNKNOWN_COMPRESSION_ALGORITHM;
// Set compression type
if (algorithm == COMPRESSION_ALGORITHM_NONE)
sectionHeader->CompressionType = EFI_NOT_COMPRESSED;
else if (algorithm == COMPRESSION_ALGORITHM_EFI11 || algorithm == COMPRESSION_ALGORITHM_TIANO)
sectionHeader->CompressionType = EFI_STANDARD_COMPRESSION;
else if (algorithm == COMPRESSION_ALGORITHM_LZMA || algorithm == COMPRESSION_ALGORITHM_IMLZMA)
sectionHeader->CompressionType = EFI_CUSTOMIZED_COMPRESSION;
else
return ERR_UNKNOWN_COMPRESSION_ALGORITHM;
// Compress body
QByteArray compressed;
result = compress(body, algorithm, compressed);
if (result)
return result;
// Compress body
QByteArray compressed;
result = compress(body, algorithm, compressed);
if (result)
return result;
// Correct section size
uint32ToUint24(header.size() + compressed.size(), commonHeader->Size);
// Correct section size
uint32ToUint24(header.size() + compressed.size(), commonHeader->Size);
// Append header and body
created.append(newHeader).append(compressed);
// Append header and body
created.append(newHeader).append(compressed);
// Parse section
QModelIndex sectionIndex;
result = parseSection(created, sectionIndex, index, mode);
if (result)
return result;
// Parse section
QModelIndex sectionIndex;
result = parseSection(created, sectionIndex, index, mode);
if (result)
return result;
// Set create action
model->setAction(sectionIndex, action);
// Set create action
model->setAction(sectionIndex, action);
// If inside boot volume, rebase all PE32 and TE sections, that follow
QModelIndex fileIndex = model->findParentOfType(parent, File);
if (model->subtype(fileIndex.parent()) == BootVolume) {
for(int i = fileIndex.row(); i < model->rowCount(fileIndex.parent()); i++) {
// File inside boot volume
QModelIndex currentFileIndex = fileIndex.parent().child(i, index.column());
for(int j = 0; j < model->rowCount(currentFileIndex); j++) {
// Section in that file
QModelIndex currentSectionIndex = currentFileIndex.child(j, currentFileIndex.column());
// If section stores PE32 or TE image
if (model->subtype(currentSectionIndex) == EFI_SECTION_PE32 || model->subtype(currentSectionIndex) == EFI_SECTION_TE)
// Set rebase action
model->setAction(currentSectionIndex, Rebase);
}
// If inside boot volume, rebase all PE32 and TE sections, that follow
QModelIndex fileIndex = model->findParentOfType(parent, File);
if (model->subtype(fileIndex.parent()) == BootVolume) {
for(int i = fileIndex.row(); i < model->rowCount(fileIndex.parent()); i++) {
// File inside boot volume
QModelIndex currentFileIndex = fileIndex.parent().child(i, index.column());
for(int j = 0; j < model->rowCount(currentFileIndex); j++) {
// Section in that file
QModelIndex currentSectionIndex = currentFileIndex.child(j, currentFileIndex.column());
// If section stores PE32 or TE image
if (model->subtype(currentSectionIndex) == EFI_SECTION_PE32 || model->subtype(currentSectionIndex) == EFI_SECTION_TE)
// Set rebase action
model->setAction(currentSectionIndex, Rebase);
}
}
}
}
break;
case EFI_SECTION_GUID_DEFINED:{
// Compress body
QByteArray compressed;
result = compress(body, algorithm, compressed);
if (result)
return result;
// Compress body
QByteArray compressed;
result = compress(body, algorithm, compressed);
if (result)
return result;
// Correct section size
uint32ToUint24(header.size() + compressed.size(), commonHeader->Size);
// Correct section size
uint32ToUint24(header.size() + compressed.size(), commonHeader->Size);
// Append header and body
created.append(newHeader).append(compressed);
// Append header and body
created.append(newHeader).append(compressed);
// Parse section
QModelIndex sectionIndex;
result = parseSection(created, sectionIndex, index, mode);
if (result)
return result;
// Parse section
QModelIndex sectionIndex;
result = parseSection(created, sectionIndex, index, mode);
if (result)
return result;
// Set create action
model->setAction(sectionIndex, action);
// Set create action
model->setAction(sectionIndex, action);
// If inside boot volume, rebase all PE32 and TE sections, that follow
QModelIndex fileIndex = model->findParentOfType(parent, File);
if (model->subtype(fileIndex.parent()) == BootVolume) {
for(int i = fileIndex.row(); i < model->rowCount(fileIndex.parent()); i++) {
// File inside boot volume
QModelIndex currentFileIndex = fileIndex.parent().child(i, index.column());
for(int j = 0; j < model->rowCount(currentFileIndex); j++) {
// Section in that file
QModelIndex currentSectionIndex = currentFileIndex.child(j, currentFileIndex.column());
// If section stores PE32 or TE image
if (model->subtype(currentSectionIndex) == EFI_SECTION_PE32 || model->subtype(currentSectionIndex) == EFI_SECTION_TE)
// Set rebase action
model->setAction(currentSectionIndex, Rebase);
}
// If inside boot volume, rebase all PE32 and TE sections, that follow
QModelIndex fileIndex = model->findParentOfType(parent, File);
if (model->subtype(fileIndex.parent()) == BootVolume) {
for(int i = fileIndex.row(); i < model->rowCount(fileIndex.parent()); i++) {
// File inside boot volume
QModelIndex currentFileIndex = fileIndex.parent().child(i, index.column());
for(int j = 0; j < model->rowCount(currentFileIndex); j++) {
// Section in that file
QModelIndex currentSectionIndex = currentFileIndex.child(j, currentFileIndex.column());
// If section stores PE32 or TE image
if (model->subtype(currentSectionIndex) == EFI_SECTION_PE32 || model->subtype(currentSectionIndex) == EFI_SECTION_TE)
// Set rebase action
model->setAction(currentSectionIndex, Rebase);
}
}
}
}
break;
default:
// Correct section size
@ -1714,63 +1714,63 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA
switch (algorithm) {
case COMPRESSION_ALGORITHM_NONE:
{
compressedData = data;
return ERR_SUCCESS;
}
{
compressedData = data;
return ERR_SUCCESS;
}
break;
case COMPRESSION_ALGORITHM_EFI11:
{
if (EfiCompress((UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (EfiCompress((UINT8*) data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS)
return ERR_STANDARD_COMPRESSION_FAILED;
compressedData = QByteArray((const char*) compressed, compressedSize);
delete[] compressed;
return ERR_SUCCESS;
}
{
if (EfiCompress((UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (EfiCompress((UINT8*) data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS)
return ERR_STANDARD_COMPRESSION_FAILED;
compressedData = QByteArray((const char*) compressed, compressedSize);
delete[] compressed;
return ERR_SUCCESS;
}
break;
case COMPRESSION_ALGORITHM_TIANO:
{
if (TianoCompress((UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (TianoCompress((UINT8*) data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS)
return ERR_STANDARD_COMPRESSION_FAILED;
compressedData = QByteArray((const char*) compressed, compressedSize);
delete[] compressed;
return ERR_SUCCESS;
}
{
if (TianoCompress((UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (TianoCompress((UINT8*) data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS)
return ERR_STANDARD_COMPRESSION_FAILED;
compressedData = QByteArray((const char*) compressed, compressedSize);
delete[] compressed;
return ERR_SUCCESS;
}
break;
case COMPRESSION_ALGORITHM_LZMA:
{
if (LzmaCompress((const UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (LzmaCompress((const UINT8*) data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS)
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressedData = QByteArray((const char*) compressed, compressedSize);
delete[] compressed;
return ERR_SUCCESS;
}
{
if (LzmaCompress((const UINT8*) data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (LzmaCompress((const UINT8*) data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS)
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressedData = QByteArray((const char*) compressed, compressedSize);
delete[] compressed;
return ERR_SUCCESS;
}
break;
case COMPRESSION_ALGORITHM_IMLZMA:
{
QByteArray header = data.left(sizeof(EFI_COMMON_SECTION_HEADER));
EFI_COMMON_SECTION_HEADER* sectionHeader = (EFI_COMMON_SECTION_HEADER*) header.constData();
UINT32 headerSize = sizeOfSectionHeaderOfType(sectionHeader->Type);
header = data.left(headerSize);
QByteArray newData = data.mid(headerSize);
if (LzmaCompress((UINT8*) newData.constData(), newData.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (LzmaCompress((UINT8*) newData.constData(), newData.size(), compressed, &compressedSize) != ERR_SUCCESS)
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressedData = header.append(QByteArray((const char*) compressed, compressedSize));
delete[] compressed;
return ERR_SUCCESS;
}
{
QByteArray header = data.left(sizeof(EFI_COMMON_SECTION_HEADER));
EFI_COMMON_SECTION_HEADER* sectionHeader = (EFI_COMMON_SECTION_HEADER*) header.constData();
UINT32 headerSize = sizeOfSectionHeaderOfType(sectionHeader->Type);
header = data.left(headerSize);
QByteArray newData = data.mid(headerSize);
if (LzmaCompress((UINT8*) newData.constData(), newData.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (LzmaCompress((UINT8*) newData.constData(), newData.size(), compressed, &compressedSize) != ERR_SUCCESS)
return ERR_CUSTOMIZED_COMPRESSION_FAILED;
compressedData = header.append(QByteArray((const char*) compressed, compressedSize));
delete[] compressed;
return ERR_SUCCESS;
}
break;
default:
msg(tr("compress: Unknown compression algorithm (%1)").arg(algorithm));
@ -1946,13 +1946,13 @@ UINT8 FfsEngine::reconstructRegion(const QModelIndex& index, QByteArray& reconst
// Check size of reconstructed region, it must be same
if (reconstructed.size() > model->body(index).size()) {
msg(tr("reconstructRegion: reconstructed body %1 is bigger then original %2")
msg(tr("reconstructRegion: reconstructed region (%1) is bigger then original (%2)")
.arg(reconstructed.size(), 8, 16, QChar('0'))
.arg(model->body(index).size(), 8, 16, QChar('0')), index);
return ERR_INVALID_PARAMETER;
}
else if (reconstructed.size() < model->body(index).size()) {
msg(tr("reconstructRegion: reconstructed body %1 is smaller then original %2")
msg(tr("reconstructRegion: reconstructed region (%1) is smaller then original (%2)")
.arg(reconstructed.size(), 8, 16, QChar('0'))
.arg(model->body(index).size(), 8, 16, QChar('0')), index);
return ERR_INVALID_PARAMETER;
@ -2009,8 +2009,8 @@ UINT8 FfsEngine::reconstructVolume(const QModelIndex& index, QByteArray& reconst
// Calculate volume base for boot volume
UINT32 volumeBase = 0;
QByteArray file;
if (model->subtype(index) == BootVolume) {
QByteArray file;
bool baseFound = false;
// Search for VTF
for (int i = 0; i < model->rowCount(index); i++) {
@ -2027,39 +2027,39 @@ UINT8 FfsEngine::reconstructVolume(const QModelIndex& index, QByteArray& reconst
if (!baseFound) {
// Search for first PEI-file and use it as base source
UINT32 fileOffset = header.size();
for (int i = 0; i < model->rowCount(index); i++) {
if ((model->subtype(index.child(i, 0)) == EFI_FV_FILETYPE_PEI_CORE ||
for (int i = 0; i < model->rowCount(index); i++) {
if ((model->subtype(index.child(i, 0)) == EFI_FV_FILETYPE_PEI_CORE ||
model->subtype(index.child(i, 0)) == EFI_FV_FILETYPE_PEIM ||
model->subtype(index.child(i, 0)) == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER)){
QModelIndex peiFile = index.child(i, 0);
UINT32 sectionOffset = sizeof(EFI_FFS_FILE_HEADER);
UINT32 sectionOffset = sizeof(EFI_FFS_FILE_HEADER);
// Search for PE32 or TE section
for(int j = 0; j < model->rowCount(peiFile); j++) {
if (model->subtype(peiFile.child(j,0)) == EFI_SECTION_PE32 ||
model->subtype(peiFile.child(j,0)) == EFI_SECTION_TE) {
QModelIndex image = peiFile.child(j,0);
// Check for correct action
if (model->action(image) == Remove || model->action(image) == Insert)
continue;
// Calculate relative base address
UINT32 relbase = fileOffset + sectionOffset + model->header(image).size();
// Calculate offset of image relative to file base
UINT32 imagebase;
result = getBase(model->body(image), imagebase);
if (!result) {
// Calculate volume base
volumeBase = imagebase - relbase;
baseFound = true;
}
goto out;
}
sectionOffset += model->header(peiFile.child(j,0)).size() + model->body(peiFile.child(j,0)).size();
sectionOffset = ALIGN4(sectionOffset);
}
for(int j = 0; j < model->rowCount(peiFile); j++) {
if (model->subtype(peiFile.child(j,0)) == EFI_SECTION_PE32 ||
model->subtype(peiFile.child(j,0)) == EFI_SECTION_TE) {
QModelIndex image = peiFile.child(j,0);
// Check for correct action
if (model->action(image) == Remove || model->action(image) == Insert)
continue;
// Calculate relative base address
UINT32 relbase = fileOffset + sectionOffset + model->header(image).size();
// Calculate offset of image relative to file base
UINT32 imagebase;
result = getBase(model->body(image), imagebase);
if (!result) {
// Calculate volume base
volumeBase = imagebase - relbase;
baseFound = true;
}
goto out;
}
sectionOffset += model->header(peiFile.child(j,0)).size() + model->body(peiFile.child(j,0)).size();
sectionOffset = ALIGN4(sectionOffset);
}
}
fileOffset += model->header(index.child(i, 0)).size() + model->body(index.child(i, 0)).size() + model->tail(index.child(i, 0)).size();
fileOffset = ALIGN8(fileOffset);
fileOffset += model->header(index.child(i, 0)).size() + model->body(index.child(i, 0)).size() + model->tail(index.child(i, 0)).size();
fileOffset = ALIGN8(fileOffset);
}
}
out:
@ -2085,6 +2085,7 @@ out:
}
// Reconstruct file
QByteArray file;
result = reconstructFile(index.child(i, 0), volumeHeader->Revision, polarity, volumeBase + offset, file);
if (result)
return result;
@ -2357,7 +2358,7 @@ UINT8 FfsEngine::reconstructFile(const QModelIndex& index, const UINT8 revision,
reconstructed.clear();
// Construct new file body
UINT32 offset = 0;
QByteArray section;
for (int i = 0; i < model->rowCount(index); i++) {
// Align to 4 byte boundary
UINT8 alignment = offset % 4;
@ -2373,6 +2374,7 @@ UINT8 FfsEngine::reconstructFile(const QModelIndex& index, const UINT8 revision,
sectionBase = base + sizeof(EFI_FFS_FILE_HEADER) + offset;
// Reconstruct section
QByteArray section;
result = reconstructSection(index.child(i, 0), sectionBase, section);
if (result)
return result;
@ -2456,9 +2458,10 @@ UINT8 FfsEngine::reconstructSection(const QModelIndex& index, const UINT32 base,
// Reconstruct section with children
if (model->rowCount(index)) {
reconstructed.clear();
// Construct new section body
UINT32 offset = 0;
QByteArray section;
// Reconstruct section body
for (int i = 0; i < model->rowCount(index); i++) {
// Align to 4 byte boundary
@ -2470,6 +2473,7 @@ UINT8 FfsEngine::reconstructSection(const QModelIndex& index, const UINT32 base,
}
// Reconstruct subsections
QByteArray section;
result = reconstruct(index.child(i,0), section);
if (result)
return result;
@ -2547,9 +2551,9 @@ UINT8 FfsEngine::reconstructSection(const QModelIndex& index, const UINT32 base,
// Special case of PEI Core rebase
if (model->subtype(index.parent()) == EFI_FV_FILETYPE_PEI_CORE) {
result = getEntryPoint(reconstructed, newPeiCoreEntryPoint);
if (result)
msg(tr("reconstructSection: can't get entry point of image file"), index);
}
if (result)
msg(tr("reconstructSection: can't get entry point of image file"), index);
}
}
// Reconstruction successfull
@ -2796,7 +2800,7 @@ UINT8 FfsEngine::rebase(QByteArray &executable, const UINT32 base)
relocSize = optHeader->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
// Set new base
optHeader->ImageBase = base;
}
}
else
return ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE;
}
@ -2815,8 +2819,8 @@ UINT8 FfsEngine::rebase(QByteArray &executable, const UINT32 base)
}
else
return ERR_UNKNOWN_IMAGE_TYPE;
// No relocations
// No relocations
if (relocOffset == 0) {
// No need to fix relocations
executable = file;
@ -2894,10 +2898,10 @@ UINT8 FfsEngine::patchVtf(QByteArray &vtf)
return ERR_PEI_CORE_ENTRY_POINT_NOT_FOUND;
}
if (!newPeiCoreEntryPoint || oldPeiCoreEntryPoint == newPeiCoreEntryPoint)
if (!newPeiCoreEntryPoint || oldPeiCoreEntryPoint == newPeiCoreEntryPoint)
// No need to patch anything
return ERR_SUCCESS;
// Replace last occurence of oldPeiCoreEntryPoint with newPeiCoreEntryPoint
QByteArray old((char*) &oldPeiCoreEntryPoint, sizeof(oldPeiCoreEntryPoint));
int i = vtf.lastIndexOf(old);
@ -2940,8 +2944,8 @@ UINT8 FfsEngine::getEntryPoint(const QByteArray &file, UINT32& peiCoreEntryPoint
EFI_IMAGE_OPTIONAL_HEADER64* optHeader = (EFI_IMAGE_OPTIONAL_HEADER64*) (file.data() + offset);
peiCoreEntryPoint = optHeader->ImageBase + optHeader->AddressOfEntryPoint;
}
else
return ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE;
else
return ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE;
}
else if (dosHeader->e_magic == EFI_IMAGE_TE_SIGNATURE){
// Populate TE header
@ -2949,12 +2953,12 @@ UINT8 FfsEngine::getEntryPoint(const QByteArray &file, UINT32& peiCoreEntryPoint
UINT32 teFixup = teHeader->StrippedSize - sizeof(EFI_IMAGE_TE_HEADER);
peiCoreEntryPoint = teHeader->ImageBase + teHeader->AddressOfEntryPoint - teFixup;
}
return ERR_SUCCESS;
return ERR_SUCCESS;
}
UINT8 FfsEngine::getBase(const QByteArray& file, UINT32& base)
{
if(file.isEmpty())
if(file.isEmpty())
return ERR_INVALID_FILE;
// Populate DOS header
@ -2981,14 +2985,14 @@ UINT8 FfsEngine::getBase(const QByteArray& file, UINT32& base)
EFI_IMAGE_OPTIONAL_HEADER64* optHeader = (EFI_IMAGE_OPTIONAL_HEADER64*) (file.data() + offset);
base = optHeader->ImageBase;
}
else
return ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE;
else
return ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE;
}
else if (dosHeader->e_magic == EFI_IMAGE_TE_SIGNATURE){
// Populate TE header
EFI_IMAGE_TE_HEADER* teHeader = (EFI_IMAGE_TE_HEADER*) file.data();
base = teHeader->ImageBase;
}
return ERR_SUCCESS;
}
return ERR_SUCCESS;
}

View File

@ -94,14 +94,14 @@ public:
private:
TreeModel *model;
// PEI Core entry point
// PEI Core entry point
UINT32 oldPeiCoreEntryPoint;
UINT32 newPeiCoreEntryPoint;
// Rebase routines
UINT8 getBase(const QByteArray& file, UINT32& base);
UINT8 getEntryPoint(const QByteArray& file, UINT32 &peiCoreEntryPoint);
UINT8 getBase(const QByteArray& file, UINT32& base);
UINT8 getEntryPoint(const QByteArray& file, UINT32 &peiCoreEntryPoint);
UINT8 rebase(QByteArray & executable, const UINT32 base);
// Patch routines

View File

@ -44,4 +44,4 @@ QModelIndex MessageListItem::index() const
void MessageListItem::setIndex(QModelIndex & index)
{
itemIndex = index;
}
}

454
peimage.h
View File

@ -48,38 +48,38 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
// under DOS it can print an error message.
//
typedef struct {
UINT16 e_magic; // Magic number
UINT16 e_cblp; // Bytes on last page of file
UINT16 e_cp; // Pages in file
UINT16 e_crlc; // Relocations
UINT16 e_cparhdr; // Size of header in paragraphs
UINT16 e_minalloc; // Minimum extra paragraphs needed
UINT16 e_maxalloc; // Maximum extra paragraphs needed
UINT16 e_ss; // Initial (relative) SS value
UINT16 e_sp; // Initial SP value
UINT16 e_csum; // Checksum
UINT16 e_ip; // Initial IP value
UINT16 e_cs; // Initial (relative) CS value
UINT16 e_lfarlc; // File address of relocation table
UINT16 e_ovno; // Overlay number
UINT16 e_res[4]; // Reserved words
UINT16 e_oemid; // OEM identifier (for e_oeminfo)
UINT16 e_oeminfo; // OEM information; e_oemid specific
UINT16 e_res2[10]; // Reserved words
UINT32 e_lfanew; // File address of new exe header
UINT16 e_magic; // Magic number
UINT16 e_cblp; // Bytes on last page of file
UINT16 e_cp; // Pages in file
UINT16 e_crlc; // Relocations
UINT16 e_cparhdr; // Size of header in paragraphs
UINT16 e_minalloc; // Minimum extra paragraphs needed
UINT16 e_maxalloc; // Maximum extra paragraphs needed
UINT16 e_ss; // Initial (relative) SS value
UINT16 e_sp; // Initial SP value
UINT16 e_csum; // Checksum
UINT16 e_ip; // Initial IP value
UINT16 e_cs; // Initial (relative) CS value
UINT16 e_lfarlc; // File address of relocation table
UINT16 e_ovno; // Overlay number
UINT16 e_res[4]; // Reserved words
UINT16 e_oemid; // OEM identifier (for e_oeminfo)
UINT16 e_oeminfo; // OEM information; e_oemid specific
UINT16 e_res2[10]; // Reserved words
UINT32 e_lfanew; // File address of new exe header
} EFI_IMAGE_DOS_HEADER;
//
// COFF File Header (Object and Image)
//
typedef struct {
UINT16 Machine;
UINT16 NumberOfSections;
UINT32 TimeDateStamp;
UINT32 PointerToSymbolTable;
UINT32 NumberOfSymbols;
UINT16 SizeOfOptionalHeader;
UINT16 Characteristics;
UINT16 Machine;
UINT16 NumberOfSections;
UINT32 TimeDateStamp;
UINT32 PointerToSymbolTable;
UINT32 NumberOfSymbols;
UINT16 SizeOfOptionalHeader;
UINT16 Characteristics;
} EFI_IMAGE_FILE_HEADER;
//
@ -105,8 +105,8 @@ typedef struct {
// Header Data Directories.
//
typedef struct {
UINT32 VirtualAddress;
UINT32 Size;
UINT32 VirtualAddress;
UINT32 Size;
} EFI_IMAGE_DATA_DIRECTORY;
//
@ -132,48 +132,48 @@ typedef struct {
// The data structures only vary after NT additional fields
//
#define EFI_IMAGE_PE_OPTIONAL_HDR32_MAGIC 0x10b
//
// Optional Header Standard Fields for PE32
//
typedef struct {
//
// Standard fields.
//
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
UINT32 BaseOfData; // PE32 contains this additional field, which is absent in PE32+.
//
// Optional Header Windows-Specific Fields.
//
UINT32 ImageBase;
UINT32 SectionAlignment;
UINT32 FileAlignment;
UINT16 MajorOperatingSystemVersion;
UINT16 MinorOperatingSystemVersion;
UINT16 MajorImageVersion;
UINT16 MinorImageVersion;
UINT16 MajorSubsystemVersion;
UINT16 MinorSubsystemVersion;
UINT32 Win32VersionValue;
UINT32 SizeOfImage;
UINT32 SizeOfHeaders;
UINT32 CheckSum;
UINT16 Subsystem;
UINT16 DllCharacteristics;
UINT32 SizeOfStackReserve;
UINT32 SizeOfStackCommit;
UINT32 SizeOfHeapReserve;
UINT32 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
//
// Standard fields.
//
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
UINT32 BaseOfData; // PE32 contains this additional field, which is absent in PE32+.
//
// Optional Header Windows-Specific Fields.
//
UINT32 ImageBase;
UINT32 SectionAlignment;
UINT32 FileAlignment;
UINT16 MajorOperatingSystemVersion;
UINT16 MinorOperatingSystemVersion;
UINT16 MajorImageVersion;
UINT16 MinorImageVersion;
UINT16 MajorSubsystemVersion;
UINT16 MinorSubsystemVersion;
UINT32 Win32VersionValue;
UINT32 SizeOfImage;
UINT32 SizeOfHeaders;
UINT32 CheckSum;
UINT16 Subsystem;
UINT16 DllCharacteristics;
UINT32 SizeOfStackReserve;
UINT32 SizeOfStackCommit;
UINT32 SizeOfHeapReserve;
UINT32 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
} EFI_IMAGE_OPTIONAL_HEADER32;
//
@ -187,42 +187,42 @@ typedef struct {
// Optional Header Standard Fields for PE32+.
//
typedef struct {
//
// Standard fields.
//
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
//
// Optional Header Windows-Specific Fields.
//
UINT64 ImageBase;
UINT32 SectionAlignment;
UINT32 FileAlignment;
UINT16 MajorOperatingSystemVersion;
UINT16 MinorOperatingSystemVersion;
UINT16 MajorImageVersion;
UINT16 MinorImageVersion;
UINT16 MajorSubsystemVersion;
UINT16 MinorSubsystemVersion;
UINT32 Win32VersionValue;
UINT32 SizeOfImage;
UINT32 SizeOfHeaders;
UINT32 CheckSum;
UINT16 Subsystem;
UINT16 DllCharacteristics;
UINT64 SizeOfStackReserve;
UINT64 SizeOfStackCommit;
UINT64 SizeOfHeapReserve;
UINT64 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
//
// Standard fields.
//
UINT16 Magic;
UINT8 MajorLinkerVersion;
UINT8 MinorLinkerVersion;
UINT32 SizeOfCode;
UINT32 SizeOfInitializedData;
UINT32 SizeOfUninitializedData;
UINT32 AddressOfEntryPoint;
UINT32 BaseOfCode;
//
// Optional Header Windows-Specific Fields.
//
UINT64 ImageBase;
UINT32 SectionAlignment;
UINT32 FileAlignment;
UINT16 MajorOperatingSystemVersion;
UINT16 MinorOperatingSystemVersion;
UINT16 MajorImageVersion;
UINT16 MinorImageVersion;
UINT16 MajorSubsystemVersion;
UINT16 MinorSubsystemVersion;
UINT32 Win32VersionValue;
UINT32 SizeOfImage;
UINT32 SizeOfHeaders;
UINT32 CheckSum;
UINT16 Subsystem;
UINT16 DllCharacteristics;
UINT64 SizeOfStackReserve;
UINT64 SizeOfStackCommit;
UINT64 SizeOfHeapReserve;
UINT64 SizeOfHeapCommit;
UINT32 LoaderFlags;
UINT32 NumberOfRvaAndSizes;
EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
} EFI_IMAGE_OPTIONAL_HEADER64;
typedef struct
@ -251,26 +251,26 @@ typedef struct
// Section Table. This table immediately follows the optional header.
//
typedef struct {
UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME];
union {
UINT32 PhysicalAddress;
UINT32 VirtualSize;
} Misc;
UINT32 VirtualAddress;
UINT32 SizeOfRawData;
UINT32 PointerToRawData;
UINT32 PointerToRelocations;
UINT32 PointerToLinenumbers;
UINT16 NumberOfRelocations;
UINT16 NumberOfLinenumbers;
UINT32 Characteristics;
UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME];
union {
UINT32 PhysicalAddress;
UINT32 VirtualSize;
} Misc;
UINT32 VirtualAddress;
UINT32 SizeOfRawData;
UINT32 PointerToRawData;
UINT32 PointerToRelocations;
UINT32 PointerToLinenumbers;
UINT16 NumberOfRelocations;
UINT16 NumberOfLinenumbers;
UINT32 Characteristics;
} EFI_IMAGE_SECTION_HEADER;
//
// Size of EFI_IMAGE_SECTION_HEADER
//
#define EFI_IMAGE_SIZEOF_SECTION_HEADER 40
//
// Section Flags Values
//
@ -278,12 +278,12 @@ typedef struct {
#define EFI_IMAGE_SCN_CNT_CODE 0x00000020
#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
#define EFI_IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved
#define EFI_IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information
#define EFI_IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image
#define EFI_IMAGE_SCN_LNK_COMDAT 0x00001000
#define EFI_IMAGE_SCN_ALIGN_1BYTES 0x00100000
#define EFI_IMAGE_SCN_ALIGN_2BYTES 0x00200000
#define EFI_IMAGE_SCN_ALIGN_4BYTES 0x00300000
@ -291,7 +291,7 @@ typedef struct {
#define EFI_IMAGE_SCN_ALIGN_16BYTES 0x00500000
#define EFI_IMAGE_SCN_ALIGN_32BYTES 0x00600000
#define EFI_IMAGE_SCN_ALIGN_64BYTES 0x00700000
#define EFI_IMAGE_SCN_MEM_DISCARDABLE 0x02000000
#define EFI_IMAGE_SCN_MEM_NOT_CACHED 0x04000000
#define EFI_IMAGE_SCN_MEM_NOT_PAGED 0x08000000
@ -389,7 +389,7 @@ typedef struct {
#define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3
#define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4
#define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
//
// The following values only be referred in PeCoff, not defined in PECOFF
//
@ -401,9 +401,9 @@ typedef struct {
// Relocation format
//
typedef struct {
UINT32 VirtualAddress;
UINT32 SymbolTableIndex;
UINT16 Type;
UINT32 VirtualAddress;
UINT32 SymbolTableIndex;
UINT16 Type;
} EFI_IMAGE_RELOCATION;
//
@ -449,8 +449,8 @@ typedef struct {
// Based relocation format
//
typedef struct {
UINT32 VirtualAddress;
UINT32 SizeOfBlock;
UINT32 VirtualAddress;
UINT32 SizeOfBlock;
} EFI_IMAGE_BASE_RELOCATION;
//
@ -477,11 +477,11 @@ typedef struct {
// Line number format
//
typedef struct {
union {
UINT32 SymbolTableIndex; // Symbol table index of function name if Linenumber is 0
UINT32 VirtualAddress; // Virtual address of line number
} Type;
UINT16 Linenumber; // Line number
union {
UINT32 SymbolTableIndex; // Symbol table index of function name if Linenumber is 0
UINT32 VirtualAddress; // Virtual address of line number
} Type;
UINT16 Linenumber; // Line number
} EFI_IMAGE_LINENUMBER;
//
@ -503,13 +503,13 @@ typedef struct {
// Archive Member Headers
//
typedef struct {
UINT8 Name[16]; // File member name - `/' terminated
UINT8 Date[12]; // File member date - decimal
UINT8 UserID[6]; // File member user id - decimal
UINT8 GroupID[6]; // File member group id - decimal
UINT8 Mode[8]; // File member mode - octal
UINT8 Size[10]; // File member size - decimal
UINT8 EndHeader[2]; // String to end header. (0x60 0x0A)
UINT8 Name[16]; // File member name - `/' terminated
UINT8 Date[12]; // File member date - decimal
UINT8 UserID[6]; // File member user id - decimal
UINT8 GroupID[6]; // File member group id - decimal
UINT8 Mode[8]; // File member mode - octal
UINT8 Size[10]; // File member size - decimal
UINT8 EndHeader[2]; // String to end header. (0x60 0x0A)
} EFI_IMAGE_ARCHIVE_MEMBER_HEADER;
//
@ -526,36 +526,36 @@ typedef struct {
// Export Directory Table
//
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT32 Name;
UINT32 Base;
UINT32 NumberOfFunctions;
UINT32 NumberOfNames;
UINT32 AddressOfFunctions;
UINT32 AddressOfNames;
UINT32 AddressOfNameOrdinals;
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT32 Name;
UINT32 Base;
UINT32 NumberOfFunctions;
UINT32 NumberOfNames;
UINT32 AddressOfFunctions;
UINT32 AddressOfNames;
UINT32 AddressOfNameOrdinals;
} EFI_IMAGE_EXPORT_DIRECTORY;
//
// Hint/Name Table
//
typedef struct {
UINT16 Hint;
UINT8 Name[1];
UINT16 Hint;
UINT8 Name[1];
} EFI_IMAGE_IMPORT_BY_NAME;
//
// Import Address Table RVA (Thunk Table)
//
typedef struct {
union {
UINT32 Function;
UINT32 Ordinal;
EFI_IMAGE_IMPORT_BY_NAME *AddressOfData;
} u1;
union {
UINT32 Function;
UINT32 Ordinal;
EFI_IMAGE_IMPORT_BY_NAME *AddressOfData;
} u1;
} EFI_IMAGE_THUNK_DATA;
#define EFI_IMAGE_ORDINAL_FLAG 0x80000000 // Flag for PE32.
@ -566,11 +566,11 @@ typedef struct {
// Import Directory Table
//
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT32 ForwarderChain;
UINT32 Name;
EFI_IMAGE_THUNK_DATA *FirstThunk;
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT32 ForwarderChain;
UINT32 Name;
EFI_IMAGE_THUNK_DATA *FirstThunk;
} EFI_IMAGE_IMPORT_DESCRIPTOR;
@ -578,14 +578,14 @@ typedef struct {
// Debug Directory Format
//
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT32 Type;
UINT32 SizeOfData;
UINT32 RVA; // The address of the debug data when loaded, relative to the image base
UINT32 FileOffset; // The file pointer to the debug data
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT32 Type;
UINT32 SizeOfData;
UINT32 RVA; // The address of the debug data when loaded, relative to the image base
UINT32 FileOffset; // The file pointer to the debug data
} EFI_IMAGE_DEBUG_DIRECTORY_ENTRY;
#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 // The Visual C++ debug information.
@ -595,13 +595,13 @@ typedef struct {
//
#define CODEVIEW_SIGNATURE_NB10 0x3031424E // NB10
typedef struct {
UINT32 Signature;
UINT32 Unknown;
UINT32 Unknown2;
UINT32 Unknown3;
//
// Filename of .PDB goes here
//
UINT32 Signature;
UINT32 Unknown;
UINT32 Unknown2;
UINT32 Unknown3;
//
// Filename of .PDB goes here
//
} EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY;
//
@ -609,15 +609,15 @@ typedef struct {
//
#define CODEVIEW_SIGNATURE_RSDS 0x53445352 // RSDS
typedef struct {
UINT32 Signature;
UINT32 Unknown;
UINT32 Unknown2;
UINT32 Unknown3;
UINT32 Unknown4;
UINT32 Unknown5;
//
// Filename of .PDB goes here
//
UINT32 Signature;
UINT32 Unknown;
UINT32 Unknown2;
UINT32 Unknown3;
UINT32 Unknown4;
UINT32 Unknown5;
//
// Filename of .PDB goes here
//
} EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;
@ -626,79 +626,79 @@ typedef struct {
//
#define CODEVIEW_SIGNATURE_MTOC 0x434F544D // MTOC
typedef struct {
UINT32 Signature;
UINT8 MachOUuid[16];
//
// Filename of .DLL (Mach-O with debug info) goes here
//
UINT32 Signature;
UINT8 MachOUuid[16];
//
// Filename of .DLL (Mach-O with debug info) goes here
//
} EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY;
//
// Resource format
//
typedef struct {
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT16 NumberOfNamedEntries;
UINT16 NumberOfIdEntries;
//
// Array of EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY entries goes here
//
UINT32 Characteristics;
UINT32 TimeDateStamp;
UINT16 MajorVersion;
UINT16 MinorVersion;
UINT16 NumberOfNamedEntries;
UINT16 NumberOfIdEntries;
//
// Array of EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY entries goes here
//
} EFI_IMAGE_RESOURCE_DIRECTORY;
//
// Resource directory entry format
//
typedef struct {
union {
struct {
UINT32 NameOffset:31;
UINT32 NameIsString:1;
} s;
UINT32 Id;
} u1;
union {
UINT32 OffsetToData;
struct {
UINT32 OffsetToDirectory:31;
UINT32 DataIsDirectory:1;
} s;
} u2;
union {
struct {
UINT32 NameOffset:31;
UINT32 NameIsString:1;
} s;
UINT32 Id;
} u1;
union {
UINT32 OffsetToData;
struct {
UINT32 OffsetToDirectory:31;
UINT32 DataIsDirectory:1;
} s;
} u2;
} EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY;
//
// Resource directory entry for string
//
typedef struct {
UINT16 Length;
CHAR16 String[1];
UINT16 Length;
CHAR16 String[1];
} EFI_IMAGE_RESOURCE_DIRECTORY_STRING;
//
// Resource directory entry for data array
//
typedef struct {
UINT32 OffsetToData;
UINT32 Size;
UINT32 CodePage;
UINT32 Reserved;
UINT32 OffsetToData;
UINT32 Size;
UINT32 CodePage;
UINT32 Reserved;
} EFI_IMAGE_RESOURCE_DATA_ENTRY;
//
// Header format for TE images, defined in the PI Specification 1.0.
//
typedef struct {
UINT16 Signature; // The signature for TE format = "VZ"
UINT16 Machine; // From original file header
UINT8 NumberOfSections; // From original file header
UINT8 Subsystem; // From original optional header
UINT16 StrippedSize; // Number of bytes we removed from header
UINT32 AddressOfEntryPoint; // Offset to entry point -- from original optional header
UINT32 BaseOfCode; // From original image -- required for ITP debug
UINT64 ImageBase; // From original file header
EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; // Only base relocation and debug directory
UINT16 Signature; // The signature for TE format = "VZ"
UINT16 Machine; // From original file header
UINT8 NumberOfSections; // From original file header
UINT8 Subsystem; // From original optional header
UINT16 StrippedSize; // Number of bytes we removed from header
UINT32 AddressOfEntryPoint; // Offset to entry point -- from original optional header
UINT32 BaseOfCode; // From original image -- required for ITP debug
UINT64 ImageBase; // From original file header
EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; // Only base relocation and debug directory
} EFI_IMAGE_TE_HEADER;
#define EFI_IMAGE_TE_SIGNATURE 0x5A56 // VZ

View File

@ -23,11 +23,11 @@ class SearchDialog : public QDialog
public:
SearchDialog(QWidget *parent = 0);
~SearchDialog();
Ui::SearchDialog* ui;
~SearchDialog();
Ui::SearchDialog* ui;
private slots:
//void setEditMask();
//void setEditMask();
};

View File

@ -299,8 +299,8 @@ void TreeItem::setAction(const UINT8 action)
// Set rebuild action for parent, if it has no action now
if (parentItem && parentItem->type() != Root
&& parentItem->action() == NoAction)
parentItem->setAction(Rebuild);
&& parentItem->action() == NoAction)
parentItem->setAction(Rebuild);
}
void TreeItem::setSubtype(const UINT8 subtype)

View File

@ -29,9 +29,9 @@ class TreeItem
{
public:
TreeItem(const UINT8 type, const UINT8 subtype = 0, const UINT8 compression = COMPRESSION_ALGORITHM_NONE,
const QString &name = QString(), const QString &text = QString(), const QString &info = QString(),
const QByteArray & header = QByteArray(), const QByteArray & body = QByteArray(), const QByteArray & tail = QByteArray(),
TreeItem *parent = 0);
const QString &name = QString(), const QString &text = QString(), const QString &info = QString(),
const QByteArray & header = QByteArray(), const QByteArray & body = QByteArray(), const QByteArray & tail = QByteArray(),
TreeItem *parent = 0);
~TreeItem();
// Operations with items

View File

@ -82,7 +82,7 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
}
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
const
const
{
if (!hasIndex(row, column, parent))
return QModelIndex();

View File

@ -68,9 +68,9 @@ public:
UINT8 compression(const QModelIndex &index) const;
QModelIndex addItem(const UINT8 type, const UINT8 subtype = 0, const UINT8 compression = COMPRESSION_ALGORITHM_NONE,
const QString & name = QString(), const QString & text = QString(), const QString & info = QString(),
const QByteArray & header = QByteArray(), const QByteArray & body = QByteArray(), const QByteArray & tail = QByteArray(),
const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
const QString & name = QString(), const QString & text = QString(), const QString & info = QString(),
const QByteArray & header = QByteArray(), const QByteArray & body = QByteArray(), const QByteArray & tail = QByteArray(),
const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND);
QModelIndex findParentOfType(const QModelIndex & index, UINT8 type) const;

View File

@ -82,7 +82,7 @@ void UEFITool::init()
// Connect
connect(ui->structureTreeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(populateUi(const QModelIndex &)));
this, SLOT(populateUi(const QModelIndex &)));
connect(ui->messageListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(scrollTreeView(QListWidgetItem*)));
}
@ -121,6 +121,9 @@ void UEFITool::populateUi(const QModelIndex &current)
void UEFITool::search()
{
// Set focus to edit box
searchDialog->ui->searchEdit->setFocus();
if (searchDialog->exec() != QDialog::Accepted)
return;
@ -144,7 +147,7 @@ void UEFITool::search()
if (pattern.isEmpty())
return;
ffsEngine->findTextPattern(pattern, searchDialog->ui->unicodeCheckBox->isChecked(),
(Qt::CaseSensitivity) searchDialog->ui->caseSensitiveCheckBox->isChecked());
(Qt::CaseSensitivity) searchDialog->ui->caseSensitiveCheckBox->isChecked());
showMessages();
}
}
@ -193,12 +196,12 @@ void UEFITool::insert(const UINT8 mode)
case Volume:
path = QFileDialog::getOpenFileName(this, tr("Select FFS file to insert"),".","FFS files (*.ffs *.bin);;All files (*.*)");
objectType = File;
break;
break;
case File:
case Section:
path = QFileDialog::getOpenFileName(this, tr("Select section file to insert"),".","Section files (*.sct *.bin);;All files (*.*)");
objectType = Section;
break;
break;
default:
return;
}
@ -361,7 +364,7 @@ void UEFITool::extract(const UINT8 mode)
break;
case Section:
path = QFileDialog::getSaveFileName(this, tr("Save section file to file"),".","Section files (*.sct *.bin);;All files (*.*)");
break;
break;
default:
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
}
@ -372,11 +375,11 @@ void UEFITool::extract(const UINT8 mode)
path = QFileDialog::getSaveFileName(this, tr("Save capsule body to image file"),".","Image files (*.rom *.bin);;All files (*.*)");
break;
case File: {
if (model->subtype(index) == EFI_FV_FILETYPE_ALL || model->subtype(index) == EFI_FV_FILETYPE_RAW)
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to raw file"),".","Raw files (*.raw *.bin);;All files (*.*)");
else
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to file"),".","FFS file body files (*.fbd *.bin);;All files (*.*)");
}
if (model->subtype(index) == EFI_FV_FILETYPE_ALL || model->subtype(index) == EFI_FV_FILETYPE_RAW)
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to raw file"),".","Raw files (*.raw *.bin);;All files (*.*)");
else
path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to file"),".","FFS file body files (*.fbd *.bin);;All files (*.*)");
}
break;
case Section: {
if (model->subtype(index) == EFI_SECTION_COMPRESSION || model->subtype(index) == EFI_SECTION_GUID_DEFINED || model->subtype(index) == EFI_SECTION_DISPOSABLE)
@ -387,8 +390,8 @@ void UEFITool::extract(const UINT8 mode)
path = QFileDialog::getSaveFileName(this, tr("Save section body to raw file"),".","Raw files (*.raw *.bin);;All files (*.*)");
else
path = QFileDialog::getSaveFileName(this, tr("Save section body to file"),".","Binary files (*.bin);;All files (*.*)");
}
break;
}
break;
default:
path = QFileDialog::getSaveFileName(this, tr("Save object to file"),".","Binary files (*.bin);;All files (*.*)");
}
@ -417,13 +420,13 @@ void UEFITool::extract(const UINT8 mode)
void UEFITool::about()
{
QMessageBox::about(this, tr("About UEFITool"), tr(
"Copyright (c) 2013, Nikolaj Schlej aka <b>CodeRush</b>.<br><br>"
"The program is dedicated to <b>RevoGirl</b>. Rest in peace, young genius.<br><br>"
"The program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License.<br>"
"The full text of the license may be found at <a href=http://opensource.org/licenses/bsd-license.php>OpenSource.org</a>.<br><br>"
"<b>THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN \"AS IS\" BASIS, "
"WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, "
"EITHER EXPRESS OR IMPLIED.</b>"));
"Copyright (c) 2013, Nikolaj Schlej aka <b>CodeRush</b>.<br><br>"
"The program is dedicated to <b>RevoGirl</b>. Rest in peace, young genius.<br><br>"
"The program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License.<br>"
"The full text of the license may be found at <a href=http://opensource.org/licenses/bsd-license.php>OpenSource.org</a>.<br><br>"
"<b>THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN \"AS IS\" BASIS, "
"WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, "
"EITHER EXPRESS OR IMPLIED.</b>"));
}
void UEFITool::aboutQt()
@ -508,7 +511,7 @@ void UEFITool::clearMessages()
void UEFITool::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
event->acceptProposedAction();
}
void UEFITool::dropEvent(QDropEvent* event)

View File

@ -38,7 +38,7 @@
#include "searchdialog.h"
namespace Ui {
class UEFITool;
class UEFITool;
}
class UEFITool : public QMainWindow
@ -54,13 +54,13 @@ public:
private slots:
void init();
void populateUi(const QModelIndex &current);
//void resizeTreeViewColumns();
//void resizeTreeViewColumns();
void scrollTreeView(QListWidgetItem* item);
void openImageFile();
void saveImageFile();
void search();
void search();
void extract(const UINT8 mode);
void extractAsIs();
void extractBody();
@ -70,21 +70,21 @@ private slots:
void insertBefore();
void insertAfter();
void replace(const UINT8 mode);
void replace(const UINT8 mode);
void replaceAsIs();
void replaceBody();
void rebuild();
void rebuild();
void remove();
void clearMessages();
void remove();
void clearMessages();
void about();
void aboutQt();
void exit();
void writeSettings();
void writeSettings();
private:
Ui::UEFITool* ui;
@ -97,7 +97,7 @@ private:
void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event);
void contextMenuEvent(QContextMenuEvent* event);
void readSettings();
void readSettings();
};
#endif

View File

@ -20,7 +20,7 @@
<bool>true</bool>
</property>
<property name="windowTitle">
<string>UEFITool 0.16.0</string>
<string>UEFITool 0.16.1</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">
@ -33,16 +33,7 @@
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
@ -62,16 +53,7 @@
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>5</number>
</property>
<item>
@ -109,16 +91,7 @@
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>5</number>
</property>
<item>
@ -148,16 +121,7 @@
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>5</number>
</property>
<item>