UEFITool 0.19.2

- correct a bug with legacy EFI1.1/Tiano compression routines, which lead to possible image corruption
This commit is contained in:
Nikolaj Schlej 2014-11-10 17:48:59 +01:00
parent b9f4142aac
commit d89aac244c
6 changed files with 3364 additions and 1608 deletions

File diff suppressed because it is too large Load Diff

View File

@ -55,15 +55,23 @@ extern "C" {
EFI_INVALID_PARAMETER - Parameter supplied is wrong. EFI_INVALID_PARAMETER - Parameter supplied is wrong.
--*/ --*/
UINT8 EFI_STATUS
TianoCompress( TianoCompress(
CONST VOID *SrcBuffer, CONST VOID *SrcBuffer,
CONST UINT64 SrcSize, UINT32 SrcSize,
VOID *DstBuffer, VOID *DstBuffer,
UINT64 *DstSize UINT32 *DstSize
) )
; ;
EFI_STATUS
TianoCompressLegacy(
CONST VOID *SrcBuffer,
UINT32 SrcSize,
VOID *DstBuffer,
UINT32 *DstSize
)
;
/*++ /*++
Routine Description: Routine Description:
@ -87,12 +95,20 @@ extern "C" {
EFI_INVALID_PARAMETER - Parameter supplied is wrong. EFI_INVALID_PARAMETER - Parameter supplied is wrong.
--*/ --*/
UINT8 EFI_STATUS
EfiCompress( EfiCompress(
CONST VOID *SrcBuffer, CONST VOID *SrcBuffer,
CONST UINT64 SrcSize, UINT32 SrcSize,
VOID *DstBuffer, VOID *DstBuffer,
UINT64 *DstSize UINT32 *DstSize
)
;
EFI_STATUS
EfiCompressLegacy(
CONST VOID *SrcBuffer,
UINT32 SrcSize,
VOID *DstBuffer,
UINT32 *DstSize
) )
; ;

File diff suppressed because it is too large Load Diff

View File

@ -895,7 +895,7 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co
.arg(volumeHeader->Revision) .arg(volumeHeader->Revision)
.hexarg(volumeHeader->Attributes, 8) .hexarg(volumeHeader->Attributes, 8)
.arg(empty ? "1" : "0") .arg(empty ? "1" : "0")
.hexarg(headerSize, 4); .hexarg(headerSize, 8);
// Extended header present // Extended header present
if (volumeHeader->Revision > 1 && volumeHeader->ExtHeaderOffset) { if (volumeHeader->Revision > 1 && volumeHeader->ExtHeaderOffset) {
EFI_FIRMWARE_VOLUME_EXT_HEADER* extendedHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(volume.constData() + volumeHeader->ExtHeaderOffset); EFI_FIRMWARE_VOLUME_EXT_HEADER* extendedHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER*)(volume.constData() + volumeHeader->ExtHeaderOffset);
@ -2242,7 +2242,28 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA
break; break;
case COMPRESSION_ALGORITHM_EFI11: case COMPRESSION_ALGORITHM_EFI11:
{ {
UINT64 compressedSize = 0; // Try legacy function first
UINT32 compressedSize = 0;
if (EfiCompressLegacy(data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (EfiCompressLegacy(data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS) {
delete[] compressed;
return ERR_STANDARD_COMPRESSION_FAILED;
}
compressedData = QByteArray((const char*)compressed, compressedSize);
// Check that compressed data can be decompressed normally
QByteArray decompressed;
if (decompress(compressedData, EFI_STANDARD_COMPRESSION, decompressed, NULL) == ERR_SUCCESS
&& decompressed == data) {
delete[] compressed;
return ERR_SUCCESS;
}
delete[] compressed;
// Legacy function failed, use current one
compressedSize = 0;
if (EfiCompress(data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL) if (EfiCompress(data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED; return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize]; compressed = new UINT8[compressedSize];
@ -2251,13 +2272,36 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA
return ERR_STANDARD_COMPRESSION_FAILED; return ERR_STANDARD_COMPRESSION_FAILED;
} }
compressedData = QByteArray((const char*)compressed, compressedSize); compressedData = QByteArray((const char*)compressed, compressedSize);
// New functions will be trusted here, because another check will reduce performance
delete[] compressed; delete[] compressed;
return ERR_SUCCESS; return ERR_SUCCESS;
} }
break; break;
case COMPRESSION_ALGORITHM_TIANO: case COMPRESSION_ALGORITHM_TIANO:
{ {
UINT64 compressedSize = 0; // Try legacy function first
UINT32 compressedSize = 0;
if (TianoCompressLegacy(data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize];
if (TianoCompressLegacy(data.constData(), data.size(), compressed, &compressedSize) != ERR_SUCCESS) {
delete[] compressed;
return ERR_STANDARD_COMPRESSION_FAILED;
}
compressedData = QByteArray((const char*)compressed, compressedSize);
// Check that compressed data can be decompressed normally
QByteArray decompressed;
if (decompress(compressedData, EFI_STANDARD_COMPRESSION, decompressed, NULL) == ERR_SUCCESS
&& decompressed == data) {
delete[] compressed;
return ERR_SUCCESS;
}
delete[] compressed;
// Legacy function failed, use current one
compressedSize = 0;
if (TianoCompress(data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL) if (TianoCompress(data.constData(), data.size(), NULL, &compressedSize) != ERR_BUFFER_TOO_SMALL)
return ERR_STANDARD_COMPRESSION_FAILED; return ERR_STANDARD_COMPRESSION_FAILED;
compressed = new UINT8[compressedSize]; compressed = new UINT8[compressedSize];
@ -2266,6 +2310,8 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA
return ERR_STANDARD_COMPRESSION_FAILED; return ERR_STANDARD_COMPRESSION_FAILED;
} }
compressedData = QByteArray((const char*)compressed, compressedSize); compressedData = QByteArray((const char*)compressed, compressedSize);
// New functions will be trusted here, because another check will reduce performance
delete[] compressed; delete[] compressed;
return ERR_SUCCESS; return ERR_SUCCESS;
} }

View File

@ -17,7 +17,7 @@
UEFITool::UEFITool(QWidget *parent) : UEFITool::UEFITool(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::UEFITool), ui(new Ui::UEFITool),
version(tr("0.19.1.1")) version(tr("0.19.2"))
{ {
clipboard = QApplication::clipboard(); clipboard = QApplication::clipboard();

View File

@ -21,8 +21,9 @@ SOURCES += uefitool_main.cpp \
LZMA/SDK/C/LzmaDec.c \ LZMA/SDK/C/LzmaDec.c \
LZMA/SDK/C/LzmaEnc.c \ LZMA/SDK/C/LzmaEnc.c \
Tiano/EfiTianoDecompress.c \ Tiano/EfiTianoDecompress.c \
Tiano/EfiTianoCompress.c Tiano/EfiTianoCompress.c \
Tiano/EfiTianoCompressLegacy.c
HEADERS += uefitool.h \ HEADERS += uefitool.h \
searchdialog.h \ searchdialog.h \
basetypes.h \ basetypes.h \