diff --git a/ffs.cpp b/ffs.cpp index 38f2edc..d82dc59 100644 --- a/ffs.cpp +++ b/ffs.cpp @@ -154,4 +154,43 @@ QString sectionTypeToQString(const UINT8 type) default: return QObject::tr("Unknown"); } +} + +UINT32 sizeOfSectionHeaderOfType(const UINT8 type) +{ + switch (type) + { + case EFI_SECTION_COMPRESSION: + return sizeof(EFI_COMMON_SECTION_HEADER); + case EFI_SECTION_GUID_DEFINED: + return sizeof(EFI_GUID_DEFINED_SECTION); + case EFI_SECTION_DISPOSABLE: + return sizeof(EFI_DISPOSABLE_SECTION); + case EFI_SECTION_PE32: + return sizeof(EFI_PE32_SECTION); + case EFI_SECTION_PIC: + return sizeof(EFI_PIC_SECTION); + case EFI_SECTION_TE: + return sizeof(EFI_TE_SECTION); + case EFI_SECTION_DXE_DEPEX: + return sizeof(EFI_DXE_DEPEX_SECTION); + case EFI_SECTION_VERSION: + return sizeof(EFI_VERSION_SECTION); + case EFI_SECTION_USER_INTERFACE: + return sizeof(EFI_USER_INTERFACE_SECTION); + case EFI_SECTION_COMPATIBILITY16: + return sizeof(EFI_COMPATIBILITY16_SECTION); + case EFI_SECTION_FIRMWARE_VOLUME_IMAGE: + return sizeof(EFI_FIRMWARE_VOLUME_IMAGE_SECTION); + case EFI_SECTION_FREEFORM_SUBTYPE_GUID: + return sizeof(EFI_FREEFORM_SUBTYPE_GUID_SECTION); + case EFI_SECTION_RAW: + return sizeof(EFI_RAW_SECTION); + case EFI_SECTION_PEI_DEPEX: + return sizeof(EFI_PEI_DEPEX_SECTION); + case EFI_SECTION_SMM_DEPEX: + return sizeof(EFI_SMM_DEPEX_SECTION); + default: + return sizeof(EFI_COMMON_SECTION_HEADER); + } } \ No newline at end of file diff --git a/ffs.h b/ffs.h index 684c1b8..6e542c8 100644 --- a/ffs.h +++ b/ffs.h @@ -406,6 +406,9 @@ typedef EFI_COMMON_SECTION_HEADER EFI_TE_SECTION; typedef EFI_COMMON_SECTION_HEADER EFI_COMPATIBILITY16_SECTION; typedef EFI_COMMON_SECTION_HEADER EFI_FIRMWARE_VOLUME_IMAGE_SECTION; +//Section routines +extern UINT32 sizeOfSectionHeaderOfType(const UINT8 type); + // Restore previous packing rules #pragma pack(pop) diff --git a/uefitool.cpp b/uefitool.cpp index 3cb3cf7..2830783 100644 --- a/uefitool.cpp +++ b/uefitool.cpp @@ -744,6 +744,8 @@ UINT8 UEFITool::parseFile(const QByteArray & file, UINT8 revision, bool erasePol UINT32 dataSize; QModelIndex index; UINT32 result; + UINT32 shittySectionSize; + EFI_COMMON_SECTION_HEADER* shittySectionHeader; switch (sectionHeader->Type) { @@ -804,8 +806,11 @@ UINT8 UEFITool::parseFile(const QByteArray & file, UINT8 revision, bool erasePol || decompressedSize != compressedSectionHeader->UncompressedLength) { // Shitty file with a section header between COMPRESSED_SECTION_HEADER and LZMA_HEADER - data = (VOID*) (file.constData() + sectionIndex + sizeof(EFI_COMPRESSION_SECTION) + sizeof(EFI_COMMON_SECTION_HEADER)); - dataSize = uint24ToUint32(sectionHeader->Size) - sizeof(EFI_COMPRESSION_SECTION) - sizeof(EFI_COMMON_SECTION_HEADER); + // We must determine section header size by checking it's type before we can unpack that non-standard compressed section + shittySectionHeader = (EFI_COMMON_SECTION_HEADER*) data; + shittySectionSize = sizeOfSectionHeaderOfType(shittySectionHeader->Type); + data = (VOID*) (file.constData() + sectionIndex + sizeof(EFI_COMPRESSION_SECTION) + shittySectionSize); + dataSize = uint24ToUint32(sectionHeader->Size) - sizeof(EFI_COMPRESSION_SECTION) - shittySectionSize; if (LzmaGetInfo(data, dataSize, &decompressedSize) != ERR_SUCCESS) debug(tr("LzmaGetInfo failed")); } diff --git a/uefitool.ui b/uefitool.ui index 74f684d..41d23bd 100644 --- a/uefitool.ui +++ b/uefitool.ui @@ -20,7 +20,7 @@ true - UEFITool 0.2.3 + UEFITool 0.2.4