mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-26 01:48:23 +08:00
Add support to parse/reconstruct LZMAF86 sections (#198)
Co-authored-by: Jake Christensen <jake@privatemachines.com>
This commit is contained in:
parent
568019123e
commit
214b768b8f
1
LZMA/x86Convert.h
Normal file
1
LZMA/x86Convert.h
Normal file
@ -0,0 +1 @@
|
||||
#include "SDK/C/Bra.h"
|
@ -21,6 +21,7 @@ SOURCES += uefipatch_main.cpp \
|
||||
../LZMA/SDK/C/LzFind.c \
|
||||
../LZMA/SDK/C/LzmaDec.c \
|
||||
../LZMA/SDK/C/LzmaEnc.c \
|
||||
../LZMA/SDK/C/Bra86.c \
|
||||
../Tiano/EfiTianoDecompress.c \
|
||||
../Tiano/EfiTianoCompress.c \
|
||||
../Tiano/EfiTianoCompressLegacy.c
|
||||
@ -39,6 +40,7 @@ HEADERS += uefipatch.h \
|
||||
../version.h \
|
||||
../LZMA/LzmaCompress.h \
|
||||
../LZMA/LzmaDecompress.h \
|
||||
../LZMA/x86Convert.h \
|
||||
../Tiano/EfiTianoDecompress.h \
|
||||
../Tiano/EfiTianoCompress.h
|
||||
|
||||
|
@ -21,6 +21,7 @@ SOURCES += uefireplace_main.cpp \
|
||||
../LZMA/SDK/C/LzFind.c \
|
||||
../LZMA/SDK/C/LzmaDec.c \
|
||||
../LZMA/SDK/C/LzmaEnc.c \
|
||||
../LZMA/SDK/C/Bra86.c \
|
||||
../Tiano/EfiTianoDecompress.c \
|
||||
../Tiano/EfiTianoCompress.c \
|
||||
../Tiano/EfiTianoCompressLegacy.c
|
||||
@ -39,5 +40,6 @@ HEADERS += uefireplace.h \
|
||||
../version.h \
|
||||
../LZMA/LzmaCompress.h \
|
||||
../LZMA/LzmaDecompress.h \
|
||||
../LZMA/x86Convert.h \
|
||||
../Tiano/EfiTianoDecompress.h \
|
||||
../Tiano/EfiTianoCompress.h
|
3
ffs.h
3
ffs.h
@ -468,6 +468,9 @@ const QByteArray EFI_GUIDED_SECTION_TIANO // A31280AD-481E-41B6-95E8-127F4C98477
|
||||
const QByteArray EFI_GUIDED_SECTION_LZMA // EE4E5898-3914-4259-9D6E-DC7BD79403CF
|
||||
("\x98\x58\x4E\xEE\x14\x39\x59\x42\x9D\x6E\xDC\x7B\xD7\x94\x03\xCF", 16);
|
||||
|
||||
const QByteArray EFI_GUIDED_SECTION_LZMAF86 //D42AE6BD-1352-4BFB-909A-CA72A6EAE889
|
||||
("\xbd\xe6\x2a\xd4\x52\x13\xfb\x4b\x90\x9a\xca\x72\xa6\xea\xe8\x89", 16);
|
||||
|
||||
const QByteArray EFI_FIRMWARE_CONTENTS_SIGNED_GUID //0F9D89E8-9259-4F76-A5AF-0C89E34023DF
|
||||
("\xE8\x89\x9D\x0F\x59\x92\x76\x4F\xA5\xAF\x0C\x89\xE3\x40\x23\xDF", 16);
|
||||
|
||||
|
@ -23,6 +23,7 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#include "Tiano/EfiTianoDecompress.h"
|
||||
#include "LZMA/LzmaCompress.h"
|
||||
#include "LZMA/LzmaDecompress.h"
|
||||
#include "LZMA/x86Convert.h"
|
||||
|
||||
#ifdef _CONSOLE
|
||||
#include <iostream>
|
||||
@ -1555,6 +1556,22 @@ UINT8 FfsEngine::parseDepexSection(const QByteArray & body, QString & parsed)
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
UINT8 x86Convert(QByteArray & input, int mode) {
|
||||
unsigned char* source = (unsigned char*)input.data();
|
||||
UINT32 sourceSize = input.size();
|
||||
|
||||
UINT32 state;
|
||||
x86_Convert_Init(state);
|
||||
UINT32 converted = x86_Convert(source, sourceSize, 0, &state, mode);
|
||||
|
||||
const UINT8 x86LookAhead = 4;
|
||||
if (converted + x86LookAhead != sourceSize) {
|
||||
return ERR_INVALID_VOLUME;
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, const QModelIndex & parent, const UINT8 mode)
|
||||
{
|
||||
const EFI_COMMON_SECTION_HEADER* sectionHeader = (const EFI_COMMON_SECTION_HEADER*)(section.constData());
|
||||
@ -1643,9 +1660,10 @@ UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, c
|
||||
UINT32 dictionarySize = DEFAULT_LZMA_DICTIONARY_SIZE;
|
||||
|
||||
// Check if section requires processing
|
||||
QByteArray parsedGuid = QByteArray((const char*)&guidDefinedSectionHeader->SectionDefinitionGuid, sizeof(EFI_GUID));
|
||||
if (guidDefinedSectionHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) {
|
||||
// Tiano compressed section
|
||||
if (QByteArray((const char*)&guidDefinedSectionHeader->SectionDefinitionGuid, sizeof(EFI_GUID)) == EFI_GUIDED_SECTION_TIANO) {
|
||||
if (parsedGuid == EFI_GUIDED_SECTION_TIANO) {
|
||||
algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
|
||||
|
||||
result = decompress(body, EFI_STANDARD_COMPRESSION, processed, &algorithm);
|
||||
@ -1664,12 +1682,17 @@ UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, c
|
||||
info += tr("\nCompression type: unknown");
|
||||
}
|
||||
// LZMA compressed section
|
||||
else if (QByteArray((const char*)&guidDefinedSectionHeader->SectionDefinitionGuid, sizeof(EFI_GUID)) == EFI_GUIDED_SECTION_LZMA) {
|
||||
else if (parsedGuid == EFI_GUIDED_SECTION_LZMA || parsedGuid == EFI_GUIDED_SECTION_LZMAF86) {
|
||||
algorithm = COMPRESSION_ALGORITHM_UNKNOWN;
|
||||
|
||||
result = decompress(body, EFI_CUSTOMIZED_COMPRESSION, processed, &algorithm);
|
||||
if (result)
|
||||
parseCurrentSection = false;
|
||||
if (parsedGuid == EFI_GUIDED_SECTION_LZMAF86) {
|
||||
if (x86Convert(processed, 0) != ERR_SUCCESS) {
|
||||
msg(tr("parseSection: unable to convert LZMAF86 compressed data"));
|
||||
}
|
||||
}
|
||||
|
||||
if (algorithm == COMPRESSION_ALGORITHM_LZMA) {
|
||||
info += tr("\nCompression type: LZMA");
|
||||
@ -1683,7 +1706,7 @@ UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, c
|
||||
info += tr("\nCompression type: unknown");
|
||||
}
|
||||
// Signed section
|
||||
else if (QByteArray((const char*)&guidDefinedSectionHeader->SectionDefinitionGuid, sizeof(EFI_GUID)) == EFI_FIRMWARE_CONTENTS_SIGNED_GUID) {
|
||||
else if (parsedGuid == EFI_FIRMWARE_CONTENTS_SIGNED_GUID) {
|
||||
msgSigned = true;
|
||||
const WIN_CERTIFICATE* certificateHeader = (const WIN_CERTIFICATE*)body.constData();
|
||||
if ((UINT32)body.size() < sizeof(WIN_CERTIFICATE)) {
|
||||
@ -1738,7 +1761,7 @@ UINT8 FfsEngine::parseSection(const QByteArray & section, QModelIndex & index, c
|
||||
else if (guidDefinedSectionHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID)
|
||||
{
|
||||
// CRC32 section
|
||||
if (QByteArray((const char*)&guidDefinedSectionHeader->SectionDefinitionGuid, sizeof(EFI_GUID)) == EFI_GUIDED_SECTION_CRC32) {
|
||||
if (parsedGuid == EFI_GUIDED_SECTION_CRC32) {
|
||||
info += tr("\nChecksum type: CRC32");
|
||||
// Calculate CRC32 of section data
|
||||
UINT32 crc = crc32(0, (const UINT8*)body.constData(), body.size());
|
||||
@ -3970,6 +3993,12 @@ UINT8 FfsEngine::reconstructSection(const QModelIndex& index, const UINT32 base,
|
||||
}
|
||||
else if (model->subtype(index) == EFI_SECTION_GUID_DEFINED) {
|
||||
EFI_GUID_DEFINED_SECTION* guidDefinedHeader = (EFI_GUID_DEFINED_SECTION*)header.data();
|
||||
// Convert x86
|
||||
if (QByteArray((const char*)&guidDefinedHeader->SectionDefinitionGuid, sizeof(EFI_GUID)) == EFI_GUIDED_SECTION_LZMAF86) {
|
||||
result = x86Convert(reconstructed, 1);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
// Compress new section body
|
||||
QByteArray compressed;
|
||||
result = compress(reconstructed, model->compression(index), model->dictionarySize(index), compressed);
|
||||
|
@ -21,6 +21,7 @@ SOURCES += uefitool_main.cpp \
|
||||
LZMA/SDK/C/LzFind.c \
|
||||
LZMA/SDK/C/LzmaDec.c \
|
||||
LZMA/SDK/C/LzmaEnc.c \
|
||||
LZMA/SDK/C/Bra86.c \
|
||||
Tiano/EfiTianoDecompress.c \
|
||||
Tiano/EfiTianoCompress.c \
|
||||
Tiano/EfiTianoCompressLegacy.c
|
||||
@ -42,6 +43,7 @@ HEADERS += uefitool.h \
|
||||
version.h \
|
||||
LZMA/LzmaCompress.h \
|
||||
LZMA/LzmaDecompress.h \
|
||||
LZMA/x86Convert.h \
|
||||
Tiano/EfiTianoDecompress.h \
|
||||
Tiano/EfiTianoCompress.h
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user