This commit is contained in:
Alex Matrosov 2018-04-29 22:33:19 -07:00
parent 1cbd3393c8
commit e3ace324ee
21 changed files with 1007 additions and 828 deletions

View file

@ -1,6 +1,6 @@
/* uefidump_main.cpp /* uefidump_main.cpp
Copyright (c) 2017, LongSoft. All rights reserved. Copyright (c) 2018, LongSoft. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -29,7 +29,7 @@ int main(int argc, char *argv[])
return (uefidumper.dump(buffer, UString(argv[1])) != U_SUCCESS); return (uefidumper.dump(buffer, UString(argv[1])) != U_SUCCESS);
} }
std::cout << "UEFIDump 0.1.6" << std::endl << std::endl std::cout << "UEFIDump 0.1.7" << std::endl << std::endl
<< "Usage: UEFIDump imagefile" << std::endl; << "Usage: UEFIDump imagefile" << std::endl;
return 0; return 0;
} }

View file

@ -1,5 +1,5 @@
/* uefiextract_main.cpp /* uefiextract_main.cpp
Copyright (c) 2017, LongSoft. All rights reserved. Copyright (c) 2018, LongSoft. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -121,7 +121,7 @@ int main(int argc, char *argv[])
} }
} }
// If parameters are different, show version and usage information // If parameters are different, show version and usage information
std::cout << "UEFIExtract 0.13.5" << std::endl << std::endl std::cout << "UEFIExtract 0.13.6" << std::endl << std::endl
<< "Usage: UEFIExtract imagefile - generate report and dump only leaf tree items into .dump folder." << std::endl << "Usage: UEFIExtract imagefile - generate report and dump only leaf tree items into .dump folder." << std::endl
<< " UEFIExtract imagefile all - generate report and dump all tree items." << std::endl << " UEFIExtract imagefile all - generate report and dump all tree items." << std::endl
<< " UEFIExtract imagefile dump - only generate dump, no report needed." << std::endl << " UEFIExtract imagefile dump - only generate dump, no report needed." << std::endl

View file

@ -1,6 +1,6 @@
/* uefifind_main.cpp /* uefifind_main.cpp
Copyright (c) 2017, LongSoft. All rights reserved. Copyright (c) 2018, LongSoft. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
@ -148,7 +148,7 @@ int main(int argc, char *argv[])
return U_SUCCESS; return U_SUCCESS;
} }
else { else {
std::cout << "UEFIFind 0.10.10" << std::endl << std::endl << std::cout << "UEFIFind 0.10.11" << std::endl << std::endl <<
"Usage: UEFIFind {header | body | all} {list | count} pattern imagefile" << std::endl << "Usage: UEFIFind {header | body | all} {list | count} pattern imagefile" << std::endl <<
" or UEFIFind file patternsfile imagefile" << std::endl; " or UEFIFind file patternsfile imagefile" << std::endl;
return U_INVALID_PARAMETER; return U_INVALID_PARAMETER;

View file

@ -165,7 +165,7 @@ void QHexEdit::setCursorPosition(qint64 position)
// 3. Calc new position of cursor // 3. Calc new position of cursor
_bPosCurrent = position / 2; _bPosCurrent = position / 2;
_pxCursorY = ((position / 2 - _bPosFirst) / _bytesPerLine + 1) * _pxCharHeight; _pxCursorY = (int)((position / 2 - _bPosFirst) / _bytesPerLine + 1) * _pxCharHeight;
int x = (position % (2 * _bytesPerLine)); int x = (position % (2 * _bytesPerLine));
if (_editAreaIsAscii) if (_editAreaIsAscii)
{ {
@ -341,7 +341,7 @@ void QHexEdit::insert(qint64 pos, const QByteArray &ba)
void QHexEdit::replace(qint64 pos, qint64 len, const QByteArray &ba) void QHexEdit::replace(qint64 pos, qint64 len, const QByteArray &ba)
{ {
_undoStack->overwrite(pos, len, ba); _undoStack->overwrite(pos, (int)len, ba);
refresh(); refresh();
} }

View file

@ -17,7 +17,11 @@
UEFITool::UEFITool(QWidget *parent) : UEFITool::UEFITool(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::UEFITool), ui(new Ui::UEFITool),
<<<<<<< HEAD
version(tr("NE alpha 48"))
=======
version(tr("NE alpha 47")) version(tr("NE alpha 47"))
>>>>>>> 775ad7d25b97e266928f437af14b47d38578af63
{ {
clipboard = QApplication::clipboard(); clipboard = QApplication::clipboard();
@ -32,6 +36,7 @@ version(tr("NE alpha 47"))
ffsFinder = NULL; ffsFinder = NULL;
ffsOps = NULL; ffsOps = NULL;
ffsBuilder = NULL; ffsBuilder = NULL;
ffsReport = NULL;
// Connect signals to slots // Connect signals to slots
connect(ui->actionOpenImageFile, SIGNAL(triggered()), this, SLOT(openImageFile())); connect(ui->actionOpenImageFile, SIGNAL(triggered()), this, SLOT(openImageFile()));
@ -60,35 +65,21 @@ version(tr("NE alpha 47"))
connect(ui->actionGoToOffset, SIGNAL(triggered()), this, SLOT(goToOffset())); connect(ui->actionGoToOffset, SIGNAL(triggered()), this, SLOT(goToOffset()));
connect(ui->actionGoToAddress, SIGNAL(triggered()), this, SLOT(goToAddress())); connect(ui->actionGoToAddress, SIGNAL(triggered()), this, SLOT(goToAddress()));
connect(ui->actionLoadGuidDatabase, SIGNAL(triggered()), this, SLOT(loadGuidDatabase())); connect(ui->actionLoadGuidDatabase, SIGNAL(triggered()), this, SLOT(loadGuidDatabase()));
connect(ui->actionUnloadGuidDatabase, SIGNAL(triggered()), this, SLOT(unloadGuidDatabase()));
connect(ui->actionLoadDefaultGuidDatabase, SIGNAL(triggered()), this, SLOT(loadDefaultGuidDatabase()));
connect(ui->actionGenerateReport, SIGNAL(triggered()), this, SLOT(generateReport()));
connect(ui->actionToggleBootGuardMarking, SIGNAL(toggled(bool)), this, SLOT(toggleBootGuardMarking(bool))); connect(ui->actionToggleBootGuardMarking, SIGNAL(toggled(bool)), this, SLOT(toggleBootGuardMarking(bool)));
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(writeSettings())); connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(writeSettings()));
// Enable Drag-and-Drop actions // Enable Drag-and-Drop actions
setAcceptDrops(true); setAcceptDrops(true);
// Disable Builder tab, doesn't work right now
ui->messagesTabWidget->setTabEnabled(4, false);
// Set current directory // Set current directory
currentDir = "."; currentDir = ".";
// Set monospace font for some controls
QFont font("Courier New", 10);
#if defined Q_OS_OSX
font = QFont("Menlo", 10);
#elif defined Q_OS_WIN
font = QFont("Consolas", 9);
#endif
ui->infoEdit->setFont(font);
ui->parserMessagesListWidget->setFont(font);
ui->finderMessagesListWidget->setFont(font);
ui->builderMessagesListWidget->setFont(font);
ui->fitTableWidget->setFont(font);
ui->bootGuardEdit->setFont(font);
ui->structureTreeView->setFont(font);
searchDialog->ui->guidEdit->setFont(font);
searchDialog->ui->hexEdit->setFont(font);
hexViewDialog->setFont(font);
goToOffsetDialog->ui->hexSpinBox->setFont(font);
goToAddressDialog->ui->hexSpinBox->setFont(font);
// Load built-in GUID database // Load built-in GUID database
initGuidDatabase(":/guids.csv"); initGuidDatabase(":/guids.csv");
@ -105,6 +96,7 @@ UEFITool::~UEFITool()
delete ffsOps; delete ffsOps;
delete ffsFinder; delete ffsFinder;
delete ffsParser; delete ffsParser;
delete ffsReport;
delete model; delete model;
delete hexViewDialog; delete hexViewDialog;
delete searchDialog; delete searchDialog;
@ -171,8 +163,9 @@ void UEFITool::init()
void UEFITool::populateUi(const QItemSelection &selected) void UEFITool::populateUi(const QItemSelection &selected)
{ {
if (selected.isEmpty()) if (selected.isEmpty()) {
return; return;
}
populateUi(selected.indexes().at(0)); populateUi(selected.indexes().at(0));
} }
@ -180,8 +173,9 @@ void UEFITool::populateUi(const QItemSelection &selected)
void UEFITool::populateUi(const QModelIndex &current) void UEFITool::populateUi(const QModelIndex &current)
{ {
// Check sanity // Check sanity
if (!current.isValid()) if (!current.isValid()) {
return; return;
}
UINT8 type = model->type(current); UINT8 type = model->type(current);
UINT8 subtype = model->subtype(current); UINT8 subtype = model->subtype(current);
@ -364,7 +358,7 @@ void UEFITool::goToAddress()
return; return;
UINT32 address = (UINT32)goToAddressDialog->ui->hexSpinBox->value(); UINT32 address = (UINT32)goToAddressDialog->ui->hexSpinBox->value();
QModelIndex index = model->findByOffset(address - ffsParser->getAddressDiff()); QModelIndex index = model->findByOffset(address - (UINT32)ffsParser->getAddressDiff());
if (index.isValid()) { if (index.isValid()) {
ui->structureTreeView->scrollTo(index, QAbstractItemView::PositionAtCenter); ui->structureTreeView->scrollTo(index, QAbstractItemView::PositionAtCenter);
ui->structureTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows | QItemSelectionModel::Clear); ui->structureTreeView->selectionModel()->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows | QItemSelectionModel::Clear);
@ -622,75 +616,75 @@ void UEFITool::extract(const UINT8 mode)
QString path; QString path;
if (mode == EXTRACT_MODE_AS_IS) { if (mode == EXTRACT_MODE_AS_IS) {
switch (type) { switch (type) {
case Types::Capsule: path = QFileDialog::getSaveFileName(this, tr("Save capsule to file"), name + ".cap", "Capsule files (*.cap *.bin);;All files (*)"); break; case Types::Capsule: path = QFileDialog::getSaveFileName(this, tr("Save capsule to file"), name + ".cap", tr("Capsule files (*.cap *.bin);;All files (*)")); break;
case Types::Image: path = QFileDialog::getSaveFileName(this, tr("Save image to file"), name + ".rom", "Image files (*.rom *.bin);;All files (*)"); break; case Types::Image: path = QFileDialog::getSaveFileName(this, tr("Save image to file"), name + ".rom", tr("Image files (*.rom *.bin);;All files (*)")); break;
case Types::Region: path = QFileDialog::getSaveFileName(this, tr("Save region to file"), name + ".rgn", "Region files (*.rgn *.bin);;All files (*)"); break; case Types::Region: path = QFileDialog::getSaveFileName(this, tr("Save region to file"), name + ".rgn", tr("Region files (*.rgn *.bin);;All files (*)")); break;
case Types::Padding: path = QFileDialog::getSaveFileName(this, tr("Save padding to file"), name + ".pad", "Padding files (*.pad *.bin);;All files (*)"); break; case Types::Padding: path = QFileDialog::getSaveFileName(this, tr("Save padding to file"), name + ".pad", tr("Padding files (*.pad *.bin);;All files (*)")); break;
case Types::Volume: path = QFileDialog::getSaveFileName(this, tr("Save volume to file"), name + ".vol", "Volume files (*.vol *.bin);;All files (*)"); break; case Types::Volume: path = QFileDialog::getSaveFileName(this, tr("Save volume to file"), name + ".vol", tr("Volume files (*.vol *.bin);;All files (*)")); break;
case Types::File: path = QFileDialog::getSaveFileName(this, tr("Save FFS file to file"), name + ".ffs", "FFS files (*.ffs *.bin);;All files (*)"); break; case Types::File: path = QFileDialog::getSaveFileName(this, tr("Save FFS file to file"), name + ".ffs", tr("FFS files (*.ffs *.bin);;All files (*)")); break;
case Types::Section: path = QFileDialog::getSaveFileName(this, tr("Save section to file"), name + ".sct", "Section files (*.sct *.bin);;All files (*)"); break; case Types::Section: path = QFileDialog::getSaveFileName(this, tr("Save section to file"), name + ".sct", tr("Section files (*.sct *.bin);;All files (*)")); break;
case Types::NvarEntry: path = QFileDialog::getSaveFileName(this, tr("Save NVAR entry to file"), name + ".nvar", "NVAR entry files (*.nvar *.bin);;All files (*)"); break; case Types::NvarEntry: path = QFileDialog::getSaveFileName(this, tr("Save NVAR entry to file"), name + ".nvar", tr("NVAR entry files (*.nvar *.bin);;All files (*)")); break;
case Types::VssEntry: path = QFileDialog::getSaveFileName(this, tr("Save VSS entry to file"), name + ".vss", "VSS entry files (*.vss *.bin);;All files (*)"); break; case Types::VssEntry: path = QFileDialog::getSaveFileName(this, tr("Save VSS entry to file"), name + ".vss", tr("VSS entry files (*.vss *.bin);;All files (*)")); break;
case Types::FsysEntry: path = QFileDialog::getSaveFileName(this, tr("Save Fsys entry to file"), name + ".fse", "Fsys entry files (*.fse *.bin);;All files (*)"); break; case Types::FsysEntry: path = QFileDialog::getSaveFileName(this, tr("Save Fsys entry to file"), name + ".fse", tr("Fsys entry files (*.fse *.bin);;All files (*)")); break;
case Types::EvsaEntry: path = QFileDialog::getSaveFileName(this, tr("Save EVSA entry to file"), name + ".evse", "EVSA entry files (*.evse *.bin);;All files (*)"); break; case Types::EvsaEntry: path = QFileDialog::getSaveFileName(this, tr("Save EVSA entry to file"), name + ".evse", tr("EVSA entry files (*.evse *.bin);;All files (*)")); break;
case Types::FlashMapEntry: path = QFileDialog::getSaveFileName(this, tr("Save FlashMap entry to file"), name + ".fme", "FlashMap entry files (*.fme *.bin);;All files (*)"); break; case Types::FlashMapEntry: path = QFileDialog::getSaveFileName(this, tr("Save FlashMap entry to file"), name + ".fme", tr("FlashMap entry files (*.fme *.bin);;All files (*)")); break;
case Types::VssStore: path = QFileDialog::getSaveFileName(this, tr("Save VSS store to file"), name + ".vss", "VSS store files (*.vss *.bin);;All files (*)"); break; case Types::VssStore: path = QFileDialog::getSaveFileName(this, tr("Save VSS store to file"), name + ".vss", tr("VSS store files (*.vss *.bin);;All files (*)")); break;
case Types::Vss2Store: path = QFileDialog::getSaveFileName(this, tr("Save VSS2 store to file"), name + ".vss2", "VSS2 store files (*.vss2 *.bin);;All files (*)"); break; case Types::Vss2Store: path = QFileDialog::getSaveFileName(this, tr("Save VSS2 store to file"), name + ".vss2", tr("VSS2 store files (*.vss2 *.bin);;All files (*)")); break;
case Types::FdcStore: path = QFileDialog::getSaveFileName(this, tr("Save FDC store to file"), name + ".fdc", "FDC store files (*.fdc *.bin);;All files (*)"); break; case Types::FdcStore: path = QFileDialog::getSaveFileName(this, tr("Save FDC store to file"), name + ".fdc", tr("FDC store files (*.fdc *.bin);;All files (*)")); break;
case Types::FsysStore: path = QFileDialog::getSaveFileName(this, tr("Save Fsys store to file"), name + ".fsys", "Fsys store files (*.fsys *.bin);;All files (*)"); break; case Types::FsysStore: path = QFileDialog::getSaveFileName(this, tr("Save Fsys store to file"), name + ".fsys", tr("Fsys store files (*.fsys *.bin);;All files (*)")); break;
case Types::EvsaStore: path = QFileDialog::getSaveFileName(this, tr("Save EVSA store to file"), name + ".evsa", "EVSA store files (*.evsa *.bin);;All files (*)"); break; case Types::EvsaStore: path = QFileDialog::getSaveFileName(this, tr("Save EVSA store to file"), name + ".evsa", tr("EVSA store files (*.evsa *.bin);;All files (*)")); break;
case Types::FtwStore: path = QFileDialog::getSaveFileName(this, tr("Save FTW store to file"), name + ".ftw", "FTW store files (*.ftw *.bin);;All files (*)"); break; case Types::FtwStore: path = QFileDialog::getSaveFileName(this, tr("Save FTW store to file"), name + ".ftw", tr("FTW store files (*.ftw *.bin);;All files (*)")); break;
case Types::FlashMapStore: path = QFileDialog::getSaveFileName(this, tr("Save FlashMap store to file"), name + ".fmap", "FlashMap store files (*.fmap *.bin);;All files (*)"); break; case Types::FlashMapStore: path = QFileDialog::getSaveFileName(this, tr("Save FlashMap store to file"), name + ".fmap", tr("FlashMap store files (*.fmap *.bin);;All files (*)")); break;
case Types::CmdbStore: path = QFileDialog::getSaveFileName(this, tr("Save CMDB store to file"), name + ".cmdb", "CMDB store files (*.cmdb *.bin);;All files (*)"); break; case Types::CmdbStore: path = QFileDialog::getSaveFileName(this, tr("Save CMDB store to file"), name + ".cmdb", tr("CMDB store files (*.cmdb *.bin);;All files (*)")); break;
case Types::Microcode: path = QFileDialog::getSaveFileName(this, tr("Save microcode binary to file"), name + ".ucd", "Microcode binary files (*.ucd *.bin);;All files (*)"); break; case Types::Microcode: path = QFileDialog::getSaveFileName(this, tr("Save microcode binary to file"), name + ".ucd", tr("Microcode binary files (*.ucd *.bin);;All files (*)")); break;
case Types::SlicData: case Types::SlicData:
if (subtype == Subtypes::PubkeySlicData) path = QFileDialog::getSaveFileName(this, tr("Save SLIC pubkey to file"), name + ".spk", "SLIC pubkey files (*.spk *.bin);;All files (*)"); if (subtype == Subtypes::PubkeySlicData) path = QFileDialog::getSaveFileName(this, tr("Save SLIC pubkey to file"), name + ".spk", tr("SLIC pubkey files (*.spk *.bin);;All files (*)"));
else path = QFileDialog::getSaveFileName(this, tr("Save SLIC marker to file"), name + ".smk", "SLIC marker files (*.smk *.bin);;All files (*)"); else path = QFileDialog::getSaveFileName(this, tr("Save SLIC marker to file"), name + ".smk", tr("SLIC marker files (*.smk *.bin);;All files (*)"));
break; break;
default: path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", "Binary files (*.bin);;All files (*)"); default: path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
} }
} }
else if (mode == EXTRACT_MODE_BODY || mode == EXTRACT_MODE_BODY_UNCOMPRESSED) { else if (mode == EXTRACT_MODE_BODY || mode == EXTRACT_MODE_BODY_UNCOMPRESSED) {
switch (type) { switch (type) {
case Types::Capsule: path = QFileDialog::getSaveFileName(this, tr("Save capsule body to image file"), name + ".rom", "Image files (*.rom *.bin);;All files (*)"); break; case Types::Capsule: path = QFileDialog::getSaveFileName(this, tr("Save capsule body to image file"), name + ".rom", tr("Image files (*.rom *.bin);;All files (*)")); break;
case Types::Volume: path = QFileDialog::getSaveFileName(this, tr("Save volume body to file"), name + ".vbd", "Volume body files (*.vbd *.bin);;All files (*)"); break; case Types::Volume: path = QFileDialog::getSaveFileName(this, tr("Save volume body to file"), name + ".vbd", tr("Volume body files (*.vbd *.bin);;All files (*)")); break;
case Types::File: case Types::File:
if (subtype == EFI_FV_FILETYPE_ALL if (subtype == EFI_FV_FILETYPE_ALL
|| subtype == EFI_FV_FILETYPE_RAW) path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to raw file"), name + ".raw", "Raw files (*.raw *.bin);;All files (*)"); || subtype == EFI_FV_FILETYPE_RAW) path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to raw file"), name + ".raw", tr("Raw files (*.raw *.bin);;All files (*)"));
else path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to file"), name + ".fbd", "FFS file body files (*.fbd *.bin);;All files (*)"); else path = QFileDialog::getSaveFileName(this, tr("Save FFS file body to file"), name + ".fbd", tr("FFS file body files (*.fbd *.bin);;All files (*)"));
break; break;
case Types::Section: case Types::Section:
if (subtype == EFI_SECTION_COMPRESSION if (subtype == EFI_SECTION_COMPRESSION
|| subtype == EFI_SECTION_GUID_DEFINED || subtype == EFI_SECTION_GUID_DEFINED
|| subtype == EFI_SECTION_DISPOSABLE) path = QFileDialog::getSaveFileName(this, tr("Save encapsulation section body to FFS body file"), name + ".fbd", "FFS file body files (*.fbd *.bin);;All files (*)"); || subtype == EFI_SECTION_DISPOSABLE) path = QFileDialog::getSaveFileName(this, tr("Save encapsulation section body to FFS body file"), name + ".fbd", tr("FFS file body files (*.fbd *.bin);;All files (*)"));
else if (subtype == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) path = QFileDialog::getSaveFileName(this, tr("Save section body to volume file"), name + ".vol", "Volume files (*.vol *.bin);;All files (*)"); else if (subtype == EFI_SECTION_FIRMWARE_VOLUME_IMAGE) path = QFileDialog::getSaveFileName(this, tr("Save section body to volume file"), name + ".vol", tr("Volume files (*.vol *.bin);;All files (*)"));
else if (subtype == EFI_SECTION_RAW) path = QFileDialog::getSaveFileName(this, tr("Save section body to raw file"), name + ".raw", "Raw files (*.raw *.bin);;All files (*)"); else if (subtype == EFI_SECTION_RAW) path = QFileDialog::getSaveFileName(this, tr("Save section body to raw file"), name + ".raw", tr("Raw files (*.raw *.bin);;All files (*)"));
else if (subtype == EFI_SECTION_PE32 else if (subtype == EFI_SECTION_PE32
|| subtype == EFI_SECTION_TE || subtype == EFI_SECTION_TE
|| subtype == EFI_SECTION_PIC) path = QFileDialog::getSaveFileName(this, tr("Save section body to EFI executable file"), name + ".efi", "EFI executable files (*.efi *.bin);;All files (*)"); || subtype == EFI_SECTION_PIC) path = QFileDialog::getSaveFileName(this, tr("Save section body to EFI executable file"), name + ".efi", tr("EFI executable files (*.efi *.bin);;All files (*)"));
else path = QFileDialog::getSaveFileName(this, tr("Save section body to file"), name + ".bin", "Binary files (*.bin);;All files (*)"); else path = QFileDialog::getSaveFileName(this, tr("Save section body to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
break; break;
case Types::NvarEntry: case Types::NvarEntry:
case Types::VssEntry: case Types::VssEntry:
case Types::EvsaEntry: case Types::EvsaEntry:
case Types::FlashMapEntry: case Types::FlashMapEntry:
case Types::FsysEntry: path = QFileDialog::getSaveFileName(this, tr("Save entry body to file"), name + ".bin", "Binary files (*.bin);;All files (*)"); break; case Types::FsysEntry: path = QFileDialog::getSaveFileName(this, tr("Save entry body to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)")); break;
case Types::VssStore: case Types::VssStore:
case Types::Vss2Store: case Types::Vss2Store:
case Types::FtwStore: case Types::FtwStore:
case Types::FdcStore: case Types::FdcStore:
case Types::FsysStore: case Types::FsysStore:
case Types::FlashMapStore: case Types::FlashMapStore:
case Types::CmdbStore: path = QFileDialog::getSaveFileName(this, tr("Save store body to file"), name + ".bin", "Binary files (*.bin);;All files (*)"); break; case Types::CmdbStore: path = QFileDialog::getSaveFileName(this, tr("Save store body to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)")); break;
case Types::Microcode: path = QFileDialog::getSaveFileName(this, tr("Save microcode body to file"), name + ".ucb", "Microcode body files (*.ucb *.bin);;All files (*)"); break; case Types::Microcode: path = QFileDialog::getSaveFileName(this, tr("Save microcode body to file"), name + ".ucb", tr("Microcode body files (*.ucb *.bin);;All files (*)")); break;
case Types::SlicData: case Types::SlicData:
if (subtype == Subtypes::PubkeySlicData) path = QFileDialog::getSaveFileName(this, tr("Save SLIC pubkey body to file"), name + ".spb", "SLIC pubkey body files (*.spb *.bin);;All files (*)"); if (subtype == Subtypes::PubkeySlicData) path = QFileDialog::getSaveFileName(this, tr("Save SLIC pubkey body to file"), name + ".spb", tr("SLIC pubkey body files (*.spb *.bin);;All files (*)"));
else path = QFileDialog::getSaveFileName(this, tr("Save SLIC marker body to file"), name + ".smb", "SLIC marker body files (*.smb *.bin);;All files (*)"); else path = QFileDialog::getSaveFileName(this, tr("Save SLIC marker body to file"), name + ".smb", tr("SLIC marker body files (*.smb *.bin);;All files (*)"));
break; break;
default: path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", "Binary files (*.bin);;All files (*)"); default: path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
} }
} }
else path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", "Binary files (*.bin);;All files (*)"); else path = QFileDialog::getSaveFileName(this, tr("Save object to file"), name + ".bin", tr("Binary files (*.bin);;All files (*)"));
if (path.trimmed().isEmpty()) if (path.trimmed().isEmpty())
return; return;
@ -733,7 +727,7 @@ void UEFITool::remove()
void UEFITool::about() void UEFITool::about()
{ {
QMessageBox::about(this, tr("About UEFITool"), tr( QMessageBox::about(this, tr("About UEFITool"), tr(
"Copyright (c) 2016, Nikolaj Schlej aka <b>CodeRush</b>.<br>" "Copyright (c) 2018, LongSoft"
"Program icon made by <a href=https://www.behance.net/alzhidkov>Alexander Zhidkov</a>.<br>" "Program icon made by <a href=https://www.behance.net/alzhidkov>Alexander Zhidkov</a>.<br>"
"The program uses QHexEdit2 library made by <a href=https://github.com/Simsys/>Simsys</a>.<br>" "The program uses QHexEdit2 library made by <a href=https://github.com/Simsys/>Simsys</a>.<br>"
"Qt-less engine is using Bstrlib made by <a href=https://github.com/websnarf/>Paul Hsieh</a>.<br><br>" "Qt-less engine is using Bstrlib made by <a href=https://github.com/websnarf/>Paul Hsieh</a>.<br><br>"
@ -757,7 +751,7 @@ void UEFITool::exit()
void UEFITool::saveImageFile() void UEFITool::saveImageFile()
{ {
/*QString path = QFileDialog::getSaveFileName(this, tr("Save BIOS image file"), currentDir, "BIOS image files (*.rom *.bin *.cap *.scap *.bio *.fd *.wph *.dec);;All files (*)"); /*QString path = QFileDialog::getSaveFileName(this, tr("Save BIOS image file"), currentDir, tr("BIOS image files (*.rom *.bin *.cap *.scap *.bio *.fd *.wph *.dec);;All files (*)"));
if (path.isEmpty()) if (path.isEmpty())
return; return;
@ -790,13 +784,13 @@ void UEFITool::saveImageFile()
void UEFITool::openImageFile() void UEFITool::openImageFile()
{ {
QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file"), currentDir, "BIOS image files (*.rom *.bin *.cap *scap *.bio *.fd *.wph *.dec);;All files (*)"); QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file"), currentDir, tr("BIOS image files (*.rom *.bin *.cap *scap *.bio *.fd *.wph *.dec);;All files (*)"));
openImageFile(path); openImageFile(path);
} }
void UEFITool::openImageFileInNewWindow() void UEFITool::openImageFileInNewWindow()
{ {
QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file in new window"), currentDir, "BIOS image files (*.rom *.bin *.cap *scap *.bio *.fd *.wph *.dec);;All files (*)"); QString path = QFileDialog::getOpenFileName(this, tr("Open BIOS image file in new window"), currentDir, tr("BIOS image files (*.rom *.bin *.cap *scap *.bio *.fd *.wph *.dec);;All files (*)"));
if (path.trimmed().isEmpty()) if (path.trimmed().isEmpty())
return; return;
QProcess::startDetached(currentProgramPath, QStringList(path)); QProcess::startDetached(currentProgramPath, QStringList(path));
@ -848,12 +842,18 @@ void UEFITool::openImageFile(QString path)
// ... and other operations // ... and other operations
delete ffsOps; delete ffsOps;
ffsOps = new FfsOperations(model); ffsOps = new FfsOperations(model);
// ... and reports
delete ffsReport;
ffsReport = new FfsReport(model);
// Enable goToOffset and goToAddress // Enable goToOffset and goToAddress
ui->actionGoToOffset->setEnabled(true); ui->actionGoToOffset->setEnabled(true);
if (ffsParser->getAddressDiff() < 0xFFFFFFFFUL) if (ffsParser->getAddressDiff() < 0xFFFFFFFFUL)
ui->actionGoToAddress->setEnabled(true); ui->actionGoToAddress->setEnabled(true);
// Enable generateReport
ui->actionGenerateReport->setEnabled(true);
// Set current directory // Set current directory
currentDir = fileInfo.absolutePath(); currentDir = fileInfo.absolutePath();
@ -1023,13 +1023,15 @@ void UEFITool::contextMenuEvent(QContextMenuEvent* event)
return; return;
} }
if (!ui->structureTreeView->underMouse()) if (!ui->structureTreeView->underMouse()) {
return; return;
}
QPoint pt = event->pos(); QPoint pt = event->pos();
QModelIndex index = ui->structureTreeView->indexAt(ui->structureTreeView->viewport()->mapFrom(this, pt)); QModelIndex index = ui->structureTreeView->indexAt(ui->structureTreeView->viewport()->mapFrom(this, pt));
if (!index.isValid()) if (!index.isValid()) {
return; return;
}
switch (model->type(index)) switch (model->type(index))
{ {
@ -1075,6 +1077,34 @@ void UEFITool::readSettings()
ui->structureTreeView->setColumnWidth(2, settings.value("tree/columnWidth2", ui->structureTreeView->columnWidth(2)).toInt()); ui->structureTreeView->setColumnWidth(2, settings.value("tree/columnWidth2", ui->structureTreeView->columnWidth(2)).toInt());
ui->structureTreeView->setColumnWidth(3, settings.value("tree/columnWidth3", ui->structureTreeView->columnWidth(3)).toInt()); ui->structureTreeView->setColumnWidth(3, settings.value("tree/columnWidth3", ui->structureTreeView->columnWidth(3)).toInt());
markingEnabled = settings.value("tree/markingEnabled", true).toBool(); markingEnabled = settings.value("tree/markingEnabled", true).toBool();
ui->actionToggleBootGuardMarking->setChecked(markingEnabled);
// Set monospace font for some controls
QString fontName;
int fontSize;
#if defined Q_OS_OSX
fontName = settings.value("mainWindow/fontName", QString("Menlo")).toString();
fontSize = settings.value("mainWindow/fontSize", 10).toInt();
#elif defined Q_OS_WIN
fontName = settings.value("mainWindow/fontName", QString("Consolas")).toString();
fontSize = settings.value("mainWindow/fontSize", 9).toInt();
#else
fontName = settings.value("mainWindow/fontName", QString("Courier New")).toString();
fontSize = settings.value("mainWindow/fontSize", 10).toInt();
#endif
currentFont = QFont(fontName, fontSize);
ui->infoEdit->setFont(currentFont);
ui->parserMessagesListWidget->setFont(currentFont);
ui->finderMessagesListWidget->setFont(currentFont);
ui->builderMessagesListWidget->setFont(currentFont);
ui->fitTableWidget->setFont(currentFont);
ui->bootGuardEdit->setFont(currentFont);
ui->structureTreeView->setFont(currentFont);
searchDialog->ui->guidEdit->setFont(currentFont);
searchDialog->ui->hexEdit->setFont(currentFont);
hexViewDialog->setFont(currentFont);
goToOffsetDialog->ui->hexSpinBox->setFont(currentFont);
goToAddressDialog->ui->hexSpinBox->setFont(currentFont);
} }
void UEFITool::writeSettings() void UEFITool::writeSettings()
@ -1091,6 +1121,8 @@ void UEFITool::writeSettings()
settings.setValue("tree/columnWidth2", ui->structureTreeView->columnWidth(2)); settings.setValue("tree/columnWidth2", ui->structureTreeView->columnWidth(2));
settings.setValue("tree/columnWidth3", ui->structureTreeView->columnWidth(3)); settings.setValue("tree/columnWidth3", ui->structureTreeView->columnWidth(3));
settings.setValue("tree/markingEnabled", markingEnabled); settings.setValue("tree/markingEnabled", markingEnabled);
settings.setValue("mainWindow/fontName", currentFont.family());
settings.setValue("mainWindow/fontSize", currentFont.pointSize());
} }
void UEFITool::showFitTable() void UEFITool::showFitTable()
@ -1155,10 +1187,44 @@ void UEFITool::currentTabChanged(int index)
void UEFITool::loadGuidDatabase() void UEFITool::loadGuidDatabase()
{ {
QString path = QFileDialog::getOpenFileName(this, tr("Select GUID database file to load"), currentDir, "GUID database files (*.gdb);;All files (*)"); QString path = QFileDialog::getOpenFileName(this, tr("Select GUID database file to load"), currentDir, tr("Comma-separated values files (*.csv);;All files (*)"));
if (!path.isEmpty()) { if (!path.isEmpty()) {
initGuidDatabase(path); initGuidDatabase(path);
if (!currentPath.isEmpty() && QMessageBox::Yes == QMessageBox::information(this, tr("New GUID database loaded"), tr("Apply new GUID database on the opened file?\nUnsaved changes and tree position will be lost."), QMessageBox::Yes, QMessageBox::No)) if (!currentPath.isEmpty() && QMessageBox::Yes == QMessageBox::information(this, tr("New GUID database loaded"), tr("Apply new GUID database on the opened file?\nUnsaved changes and tree position will be lost."), QMessageBox::Yes, QMessageBox::No))
openImageFile(currentPath); openImageFile(currentPath);
} }
} }
void UEFITool::unloadGuidDatabase()
{
initGuidDatabase();
if (!currentPath.isEmpty() && QMessageBox::Yes == QMessageBox::information(this, tr("GUID database unloaded"), tr("Apply changes on the opened file?\nUnsaved changes and tree position will be lost."), QMessageBox::Yes, QMessageBox::No))
openImageFile(currentPath);
}
void UEFITool::loadDefaultGuidDatabase()
{
initGuidDatabase(":/guids.csv");
if (!currentPath.isEmpty() && QMessageBox::Yes == QMessageBox::information(this, tr("Default GUID database loaded"), tr("Apply default GUID database on the opened file?\nUnsaved changes and tree position will be lost."), QMessageBox::Yes, QMessageBox::No))
openImageFile(currentPath);
}
void UEFITool::generateReport()
{
QString path = QFileDialog::getSaveFileName(this, tr("Save report to text file"), currentPath + ".report.txt", tr("Text files (*.txt);;All files (*)"));
if (!path.isEmpty()) {
std::vector<QString> report = ffsReport->generate();
if (report.size()) {
QFile file;
file.setFileName(path);
if (file.open(QFile::Text | QFile::WriteOnly)) {
for (size_t i = 0; i < report.size(); i++) {
file.write(report[i].toLatin1().append('\n'));
}
file.close();
}
}
}
}

View file

@ -22,6 +22,7 @@
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QFont>
#include <QListWidget> #include <QListWidget>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
@ -41,6 +42,7 @@
#include "../common/ffsparser.h" #include "../common/ffsparser.h"
#include "../common/ffsops.h" #include "../common/ffsops.h"
#include "../common/ffsbuilder.h" #include "../common/ffsbuilder.h"
#include "../common/ffsreport.h"
#include "../common/guiddatabase.h" #include "../common/guiddatabase.h"
#include "searchdialog.h" #include "searchdialog.h"
@ -115,6 +117,9 @@ private slots:
void writeSettings(); void writeSettings();
void loadGuidDatabase(); void loadGuidDatabase();
void unloadGuidDatabase();
void loadDefaultGuidDatabase();
void generateReport();
void currentTabChanged(int index); void currentTabChanged(int index);
@ -123,6 +128,7 @@ private:
TreeModel* model; TreeModel* model;
FfsParser* ffsParser; FfsParser* ffsParser;
FfsFinder* ffsFinder; FfsFinder* ffsFinder;
FfsReport* ffsReport;
FfsOperations* ffsOps; FfsOperations* ffsOps;
FfsBuilder* ffsBuilder; FfsBuilder* ffsBuilder;
SearchDialog* searchDialog; SearchDialog* searchDialog;
@ -133,6 +139,7 @@ private:
QString currentDir; QString currentDir;
QString currentPath; QString currentPath;
QString currentProgramPath; QString currentProgramPath;
QFont currentFont;
const QString version; const QString version;
bool markingEnabled; bool markingEnabled;

View file

@ -32,6 +32,7 @@ HEADERS += uefitool.h \
../common/parsingdata.h \ ../common/parsingdata.h \
../common/ffsbuilder.h \ ../common/ffsbuilder.h \
../common/ffsparser.h \ ../common/ffsparser.h \
../common/ffsreport.h \
../common/treeitem.h \ ../common/treeitem.h \
../common/treemodel.h \ ../common/treemodel.h \
../common/LZMA/LzmaCompress.h \ ../common/LZMA/LzmaCompress.h \
@ -64,6 +65,7 @@ SOURCES += uefitool_main.cpp \
../common/utility.cpp \ ../common/utility.cpp \
../common/ffsbuilder.cpp \ ../common/ffsbuilder.cpp \
../common/ffsparser.cpp \ ../common/ffsparser.cpp \
../common/ffsreport.cpp \
../common/treeitem.cpp \ ../common/treeitem.cpp \
../common/treemodel.cpp \ ../common/treemodel.cpp \
../common/LZMA/LzmaCompress.c \ ../common/LZMA/LzmaCompress.c \

View file

@ -322,7 +322,11 @@
<addaction name="actionOpenImageFileInNewWindow"/> <addaction name="actionOpenImageFileInNewWindow"/>
<addaction name="actionSaveImageFile"/> <addaction name="actionSaveImageFile"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionGenerateReport"/>
<addaction name="separator"/>
<addaction name="actionLoadGuidDatabase"/> <addaction name="actionLoadGuidDatabase"/>
<addaction name="actionLoadDefaultGuidDatabase"/>
<addaction name="actionUnloadGuidDatabase"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
</widget> </widget>
@ -473,7 +477,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="title"> <property name="title">
<string>Entry</string> <string>&amp;Entry</string>
</property> </property>
<addaction name="actionHexView"/> <addaction name="actionHexView"/>
<addaction name="actionBodyHexView"/> <addaction name="actionBodyHexView"/>
@ -532,7 +536,7 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="menuMessageActions"/> <addaction name="menuMessageActions"/>
</widget> </widget>
<widget class="QMenu" name="menu_View"> <widget class="QMenu" name="menuView">
<property name="title"> <property name="title">
<string>&amp;View</string> <string>&amp;View</string>
</property> </property>
@ -540,7 +544,7 @@
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menuAction"/> <addaction name="menuAction"/>
<addaction name="menu_View"/> <addaction name="menuView"/>
<addaction name="menuHelp"/> <addaction name="menuHelp"/>
</widget> </widget>
<action name="actionInsertAfter"> <action name="actionInsertAfter">
@ -718,7 +722,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>Sear&amp;ch...</string> <string>Searc&amp;h...</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+F</string> <string>Ctrl+F</string>
@ -867,12 +871,42 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;BootGuard marking</string> <string>BootGuard &amp;markings</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+Shift+B</string> <string>Ctrl+Shift+B</string>
</property> </property>
</action> </action>
<action name="actionGenerateReport">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Generate &amp;report...</string>
</property>
<property name="toolTip">
<string>Generate report</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+R</string>
</property>
</action>
<action name="actionUnloadGuidDatabase">
<property name="text">
<string>&amp;Unload GUID database</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+U</string>
</property>
</action>
<action name="actionLoadDefaultGuidDatabase">
<property name="text">
<string>Load &amp;default GUID database</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+D</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources/> <resources/>

View file

@ -1,6 +1,6 @@
/* uefitool_main.cpp /* uefitool_main.cpp
Copyright (c) 2014, Nikolaj Schlej. All rights reserved. Copyright (c) 2018, LongSoft. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at

View file

@ -25,8 +25,8 @@ static ISzAlloc SzAllocForLzma = { &AllocForLzma, &FreeForLzma };
SRes OnProgress(void *p, UInt64 inSize, UInt64 outSize) SRes OnProgress(void *p, UInt64 inSize, UInt64 outSize)
{ {
(void)p; (void) inSize; (void) outSize; (void)p; (void)inSize; (void)outSize;
return SZ_OK; return SZ_OK;
} }
static ICompressProgress g_ProgressCallback = { &OnProgress }; static ICompressProgress g_ProgressCallback = { &OnProgress };
@ -35,75 +35,76 @@ STATIC
UINT64 UINT64
EFIAPI EFIAPI
RShiftU64( RShiftU64(
UINT64 Operand, UINT64 Operand,
UINT32 Count UINT32 Count
) )
{ {
return Operand >> Count; return Operand >> Count;
} }
VOID VOID
SetEncodedSizeOfBuf( SetEncodedSizeOfBuf(
UINT64 EncodedSize, UINT64 EncodedSize,
UINT8 *EncodedData UINT8* EncodedData
) )
{ {
INT32 Index; INT32 Index;
EncodedData[LZMA_PROPS_SIZE] = EncodedSize & 0xFF; EncodedData[LZMA_PROPS_SIZE] = EncodedSize & 0xFF;
for (Index = LZMA_PROPS_SIZE + 1; Index <= LZMA_PROPS_SIZE + 7; Index++) for (Index = LZMA_PROPS_SIZE + 1; Index <= LZMA_PROPS_SIZE + 7; Index++)
{ {
EncodedSize = RShiftU64(EncodedSize, 8); EncodedSize = RShiftU64(EncodedSize, 8);
EncodedData[Index] = EncodedSize & 0xFF; EncodedData[Index] = EncodedSize & 0xFF;
} }
} }
INT32 INT32
EFIAPI EFIAPI
LzmaCompress( LzmaCompress(
CONST UINT8 *Source, CONST UINT8 *Source,
UINT32 SourceSize, UINTN SourceSize,
UINT8 *Destination, UINT8 *Destination,
UINT32 *DestinationSize UINTN *DestinationSize
) )
{ {
SRes LzmaResult; SRes LzmaResult;
CLzmaEncProps props; CLzmaEncProps props;
SizeT propsSize = LZMA_PROPS_SIZE; SizeT propsSize = LZMA_PROPS_SIZE;
SizeT destLen = SourceSize + SourceSize / 3 + 128; SizeT destLen = SourceSize + SourceSize / 3 + 128;
if (*DestinationSize < destLen) if (*DestinationSize < destLen)
{ {
*DestinationSize = (UINT32)destLen; *DestinationSize = destLen;
return EFI_BUFFER_TOO_SMALL; return EFI_BUFFER_TOO_SMALL;
} }
LzmaEncProps_Init(&props); LzmaEncProps_Init(&props);
props.dictSize = LZMA_DICTIONARY_SIZE; // TOOD: need to detect this instead of hardcoding
props.level = 9; props.dictSize = LZMA_DICTIONARY_SIZE;
props.fb = 273; props.level = 9;
props.fb = 273;
LzmaResult = LzmaEncode( LzmaResult = LzmaEncode(
(Byte*)((UINT8*)Destination + LZMA_HEADER_SIZE), (Byte*)((UINT8*)Destination + LZMA_HEADER_SIZE),
&destLen, &destLen,
Source, Source,
SourceSize, SourceSize,
&props, &props,
(UINT8*)Destination, (UINT8*)Destination,
&propsSize, &propsSize,
props.writeEndMark, props.writeEndMark,
&g_ProgressCallback, &g_ProgressCallback,
&SzAllocForLzma, &SzAllocForLzma,
&SzAllocForLzma); &SzAllocForLzma);
*DestinationSize = (UINT32)(destLen + LZMA_HEADER_SIZE); *DestinationSize = destLen + LZMA_HEADER_SIZE;
SetEncodedSizeOfBuf((UINT64)SourceSize, Destination); SetEncodedSizeOfBuf(SourceSize, Destination);
if (LzmaResult == SZ_OK) { if (LzmaResult == SZ_OK) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
else { else {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
} }

View file

@ -24,14 +24,14 @@ extern "C" {
#define LZMA_DICTIONARY_SIZE 0x800000 #define LZMA_DICTIONARY_SIZE 0x800000
#define _LZMA_SIZE_OPT #define _LZMA_SIZE_OPT
INT32 INT32
EFIAPI EFIAPI
LzmaCompress( LzmaCompress(
const UINT8 *Source, const UINT8 *Source,
UINT32 SourceSize, UINTN SourceSize,
UINT8 *Destination, UINT8 *Destination,
UINT32 *DestinationSize UINTN *DestinationSize
); );
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -89,17 +89,13 @@ INT32
EFIAPI EFIAPI
LzmaGetInfo( LzmaGetInfo(
CONST VOID *Source, CONST VOID *Source,
UINT32 SourceSize, UINTN SourceSize,
UINT32 *DestinationSize UINTN *DestinationSize
) )
{ {
UInt64 DecodedSize;
ASSERT(SourceSize >= LZMA_HEADER_SIZE); (void)SourceSize; ASSERT(SourceSize >= LZMA_HEADER_SIZE); (void)SourceSize;
DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);
*DestinationSize = (UINT32)DecodedSize; *DestinationSize = (UINTN)GetDecodedSizeOfBuf((UINT8*)Source);
return U_SUCCESS; return U_SUCCESS;
} }
@ -126,8 +122,8 @@ INT32
EFIAPI EFIAPI
LzmaDecompress( LzmaDecompress(
CONST VOID *Source, CONST VOID *Source,
UINT32 SourceSize, UINTN SourceSize,
VOID *Destination VOID *Destination
) )
{ {
SRes LzmaResult; SRes LzmaResult;

View file

@ -69,18 +69,15 @@ PutDword(
STATIC STATIC
EFI_STATUS EFI_STATUS
AllocateMemory ( AllocateMemory (VOID);
);
STATIC STATIC
VOID VOID
FreeMemory ( FreeMemory (VOID);
);
STATIC STATIC
VOID VOID
InitSlide ( InitSlide (VOID);
);
STATIC STATIC
NODE NODE
@ -105,28 +102,23 @@ Split (
STATIC STATIC
VOID VOID
InsertNode ( InsertNode (VOID);
);
STATIC STATIC
VOID VOID
DeleteNode ( DeleteNode (VOID);
);
STATIC STATIC
VOID VOID
GetNextMatch ( GetNextMatch (VOID);
);
STATIC STATIC
EFI_STATUS EFI_STATUS
Encode ( Encode (VOID);
);
STATIC STATIC
VOID VOID
CountTFreq ( CountTFreq (VOID);
);
STATIC STATIC
VOID VOID
@ -138,8 +130,7 @@ WritePTLen (
STATIC STATIC
VOID VOID
WriteCLen ( WriteCLen (VOID);
);
STATIC STATIC
VOID VOID
@ -155,8 +146,7 @@ EncodeP (
STATIC STATIC
VOID VOID
SendBlock ( SendBlock (VOID);
);
STATIC STATIC
VOID VOID
@ -167,18 +157,15 @@ Output (
STATIC STATIC
VOID VOID
HufEncodeStart ( HufEncodeStart (VOID);
);
STATIC STATIC
VOID VOID
HufEncodeEnd ( HufEncodeEnd (VOID);
);
STATIC STATIC
VOID VOID
MakeCrcTable ( MakeCrcTable (VOID);
);
STATIC STATIC
VOID VOID
@ -196,8 +183,7 @@ FreadCrc (
STATIC STATIC
VOID VOID
InitPutBits ( InitPutBits (VOID);
);
STATIC STATIC
VOID VOID

View file

@ -25,13 +25,13 @@ const UINT8* calculateAddress16(const UINT8* baseAddress, const UINT16 baseOrLim
return baseAddress + baseOrLimit * 0x1000; return baseAddress + baseOrLimit * 0x1000;
} }
// Calculate offset of region using it's base // Calculate offset of region using its base
UINT32 calculateRegionOffset(const UINT16 base) UINT32 calculateRegionOffset(const UINT16 base)
{ {
return base * 0x1000; return base * 0x1000;
} }
//Calculate size of region using it's base and limit //Calculate size of region using its base and limit
UINT32 calculateRegionSize(const UINT16 base, const UINT16 limit) UINT32 calculateRegionSize(const UINT16 base, const UINT16 limit)
{ {
if (limit) if (limit)

File diff suppressed because it is too large Load diff

View file

@ -75,7 +75,7 @@ private:
UByteArray openedImage; UByteArray openedImage;
UModelIndex lastVtf; UModelIndex lastVtf;
UINT32 capsuleOffsetFixup; UINT32 imageBase;
UINT64 addressDiff; UINT64 addressDiff;
std::vector<std::pair<std::vector<UString>, UModelIndex> > fitTable; std::vector<std::pair<std::vector<UString>, UModelIndex> > fitTable;
@ -93,6 +93,10 @@ private:
// First pass // First pass
USTATUS performFirstPass(const UByteArray & imageFile, UModelIndex & index); USTATUS performFirstPass(const UByteArray & imageFile, UModelIndex & index);
USTATUS parseCapsule(const UByteArray & capsule, UModelIndex & index);
USTATUS parseIntelImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
USTATUS parseGenericImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
USTATUS parseRawArea(const UModelIndex & index); USTATUS parseRawArea(const UModelIndex & index);
USTATUS parseVolumeHeader(const UByteArray & volume, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index); USTATUS parseVolumeHeader(const UByteArray & volume, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
USTATUS parseVolumeBody(const UModelIndex & index); USTATUS parseVolumeBody(const UModelIndex & index);
@ -101,7 +105,6 @@ private:
USTATUS parseSectionHeader(const UByteArray & section, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index, const bool insertIntoTree); USTATUS parseSectionHeader(const UByteArray & section, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index, const bool insertIntoTree);
USTATUS parseSectionBody(const UModelIndex & index); USTATUS parseSectionBody(const UModelIndex & index);
USTATUS parseIntelImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & root);
USTATUS parseGbeRegion(const UByteArray & gbe, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index); USTATUS parseGbeRegion(const UByteArray & gbe, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
USTATUS parseMeRegion(const UByteArray & me, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index); USTATUS parseMeRegion(const UByteArray & me, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
USTATUS parseBiosRegion(const UByteArray & bios, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index); USTATUS parseBiosRegion(const UByteArray & bios, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
@ -129,7 +132,7 @@ private:
USTATUS parseTeImageSectionBody(const UModelIndex & index); USTATUS parseTeImageSectionBody(const UModelIndex & index);
USTATUS parseAprioriRawSection(const UByteArray & body, UString & parsed); USTATUS parseAprioriRawSection(const UByteArray & body, UString & parsed);
USTATUS findNextVolume(const UModelIndex & index, const UByteArray & bios, const UINT32 localOffset, const UINT32 volumeOffset, UINT32 & nextVolumeOffset); USTATUS findNextVolume(const UModelIndex & index, const UByteArray & bios, const UINT32 globalOffset, const UINT32 volumeOffset, UINT32 & nextVolumeOffset);
USTATUS getVolumeSize(const UByteArray & bios, const UINT32 volumeOffset, UINT32 & volumeSize, UINT32 & bmVolumeSize); USTATUS getVolumeSize(const UByteArray & bios, const UINT32 volumeOffset, UINT32 & volumeSize, UINT32 & bmVolumeSize);
UINT32 getFileSize(const UByteArray & volume, const UINT32 fileOffset, const UINT8 ffsVersion); UINT32 getFileSize(const UByteArray & volume, const UINT32 fileOffset, const UINT8 ffsVersion);
UINT32 getSectionSize(const UByteArray & file, const UINT32 sectionOffset, const UINT8 ffsVersion); UINT32 getSectionSize(const UByteArray & file, const UINT32 sectionOffset, const UINT8 ffsVersion);

View file

@ -45,7 +45,7 @@ std::vector<UString> FfsReport::generate()
USTATUS FfsReport::generateRecursive(std::vector<UString> & report, UModelIndex index, UINT32 level) USTATUS FfsReport::generateRecursive(std::vector<UString> & report, UModelIndex index, UINT32 level)
{ {
if (!index.isValid()) if (!index.isValid())
return U_SUCCESS; //Nothing to report for invalid index return U_SUCCESS; // Nothing to report for invalid index
// Calculate item CRC32 // Calculate item CRC32
UByteArray data = model->header(index) + model->body(index) + model->tail(index); UByteArray data = model->header(index) + model->body(index) + model->tail(index);

View file

@ -56,7 +56,7 @@ void initGuidDatabase(const UString & path, UINT32* numEntries)
} }
if (numEntries) if (numEntries)
*numEntries = gGuidToUStringMap.size(); *numEntries = (UINT32)gGuidToUStringMap.size();
} }
UString guidDatabaseLookup(const EFI_GUID & guid) UString guidDatabaseLookup(const EFI_GUID & guid)

View file

@ -102,7 +102,7 @@ USTATUS NvramParser::parseNvarStore(const UModelIndex & index)
else { else {
// Nothing is parsed yet, but the file is not empty // Nothing is parsed yet, but the file is not empty
if (!offset) { if (!offset) {
msg(UString("parseNvarStore: file can't be parsed as NVAR variables store"), index); msg(usprintf("%s: file can't be parsed as NVAR variables store", __FUNCTION__), index);
return U_SUCCESS; return U_SUCCESS;
} }
@ -225,7 +225,8 @@ USTATUS NvramParser::parseNvarStore(const UModelIndex & index)
isInvalidLink = true; isInvalidLink = true;
UModelIndex nvarIndex; UModelIndex nvarIndex;
// Search prevously added entries for a link to this variable // Search prevously added entries for a link to this variable
for (int i = 0; i < model->rowCount(index); i++) { // WARNING: O(n^2), may be very slow
for (int i = model->rowCount(index) - 1; i >= 0; i--) {
nvarIndex = index.child(i, 0); nvarIndex = index.child(i, 0);
if (model->hasEmptyParsingData(nvarIndex) == false) { if (model->hasEmptyParsingData(nvarIndex) == false) {
UByteArray nvarData = model->parsingData(nvarIndex); UByteArray nvarData = model->parsingData(nvarIndex);
@ -352,10 +353,10 @@ USTATUS NvramParser::parseNvarStore(const UModelIndex & index)
model->setParsingData(varIndex, UByteArray((const char*)&pdata, sizeof(pdata))); model->setParsingData(varIndex, UByteArray((const char*)&pdata, sizeof(pdata)));
// Show messages // Show messages
if (msgUnknownExtDataFormat) msg(UString("parseNvarStore: unknown extended data format"), varIndex); if (msgUnknownExtDataFormat) msg(usprintf("%s: unknown extended data format", __FUNCTION__), varIndex);
if (msgExtHeaderTooLong) msg(usprintf("parseNvarStore: extended header size (%Xh) is greater than body size (%Xh)", if (msgExtHeaderTooLong) msg(usprintf("%s: extended header size (%Xh) is greater than body size (%Xh)", __FUNCTION__,
extendedHeaderSize, body.size()), varIndex); extendedHeaderSize, body.size()), varIndex);
if (msgExtDataTooShort) msg(usprintf("parseNvarStore: extended header size (%Xh) is too small for timestamp and hash", if (msgExtDataTooShort) msg(usprintf("%s: extended header size (%Xh) is too small for timestamp and hash", __FUNCTION__,
tail.size()), varIndex); tail.size()), varIndex);
// Try parsing the entry data as NVAR storage if it begins with NVAR signature // Try parsing the entry data as NVAR storage if it begins with NVAR signature
@ -433,7 +434,7 @@ USTATUS NvramParser::parseNvramVolumeBody(const UModelIndex & index)
UINT32 storeSize = 0; UINT32 storeSize = 0;
result = getStoreSize(data, storeOffset, storeSize); result = getStoreSize(data, storeOffset, storeSize);
if (result) { if (result) {
msg(UString("parseNvramVolumeBody: getStoreSize failed with error ") + errorCodeToUString(result), index); msg(usprintf("%s: getStoreSize failed with error ", __FUNCTION__) + errorCodeToUString(result), index);
return result; return result;
} }
@ -448,7 +449,7 @@ USTATUS NvramParser::parseNvramVolumeBody(const UModelIndex & index)
// Add tree item // Add tree item
UModelIndex paddingIndex = model->addItem(localOffset + storeOffset, Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), Fixed, index); UModelIndex paddingIndex = model->addItem(localOffset + storeOffset, Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), Fixed, index);
msg(UString("parseNvramVolumeBody: one of stores inside overlaps the end of data"), paddingIndex); msg(usprintf("%s: one of stores inside overlaps the end of data", __FUNCTION__), paddingIndex);
// Update variables // Update variables
prevStoreOffset = storeOffset; prevStoreOffset = storeOffset;
@ -461,7 +462,7 @@ USTATUS NvramParser::parseNvramVolumeBody(const UModelIndex & index)
UByteArray store = data.mid(storeOffset, storeSize); UByteArray store = data.mid(storeOffset, storeSize);
result = parseStoreHeader(store, localOffset + storeOffset, index, storeIndex); result = parseStoreHeader(store, localOffset + storeOffset, index, storeIndex);
if (result) if (result)
msg(UString("parseNvramVolumeBody: store header parsing failed with error ") + errorCodeToUString(result), index); msg(usprintf("%s: store header parsing failed with error ", __FUNCTION__) + errorCodeToUString(result), index);
// Go to next store // Go to next store
prevStoreOffset = storeOffset; prevStoreOffset = storeOffset;
@ -483,7 +484,7 @@ USTATUS NvramParser::parseNvramVolumeBody(const UModelIndex & index)
else { else {
// Nothing is parsed yet, but the file is not empty // Nothing is parsed yet, but the file is not empty
if (!storeOffset) { if (!storeOffset) {
msg(UString("parseNvramVolumeBody: can't be parsed as NVRAM volume"), index); msg(usprintf("%s: can't be parsed as NVRAM volume", __FUNCTION__), index);
return U_SUCCESS; return U_SUCCESS;
} }
@ -521,11 +522,11 @@ USTATUS NvramParser::findNextStore(const UModelIndex & index, const UByteArray &
if (*currentPos == NVRAM_VSS_STORE_SIGNATURE || *currentPos == NVRAM_APPLE_SVS_STORE_SIGNATURE) { //$VSS or $SVS signatures found, perform checks if (*currentPos == NVRAM_VSS_STORE_SIGNATURE || *currentPos == NVRAM_APPLE_SVS_STORE_SIGNATURE) { //$VSS or $SVS signatures found, perform checks
const VSS_VARIABLE_STORE_HEADER* vssHeader = (const VSS_VARIABLE_STORE_HEADER*)currentPos; const VSS_VARIABLE_STORE_HEADER* vssHeader = (const VSS_VARIABLE_STORE_HEADER*)currentPos;
if (vssHeader->Format != NVRAM_VSS_VARIABLE_STORE_FORMATTED) { if (vssHeader->Format != NVRAM_VSS_VARIABLE_STORE_FORMATTED) {
msg(usprintf("findNextStore: VSS store candidate at offset %Xh skipped, has invalid format %02Xh", localOffset + offset, vssHeader->Format), index); msg(usprintf("%s: VSS store candidate at offset %Xh skipped, has invalid format %02Xh", __FUNCTION__, localOffset + offset, vssHeader->Format), index);
continue; continue;
} }
if (vssHeader->Size == 0 || vssHeader->Size == 0xFFFFFFFF) { if (vssHeader->Size == 0 || vssHeader->Size == 0xFFFFFFFF) {
msg(usprintf("findNextStore: VSS store candidate at offset %Xh skipped, has invalid size %Xh", localOffset + offset, vssHeader->Size), index); msg(usprintf("%s: VSS store candidate at offset %Xh skipped, has invalid size %Xh", __FUNCTION__, localOffset + offset, vssHeader->Size), index);
continue; continue;
} }
// All checks passed, store found // All checks passed, store found
@ -538,11 +539,11 @@ USTATUS NvramParser::findNextStore(const UModelIndex & index, const UByteArray &
const VSS2_VARIABLE_STORE_HEADER* vssHeader = (const VSS2_VARIABLE_STORE_HEADER*)currentPos; const VSS2_VARIABLE_STORE_HEADER* vssHeader = (const VSS2_VARIABLE_STORE_HEADER*)currentPos;
if (vssHeader->Format != NVRAM_VSS_VARIABLE_STORE_FORMATTED) { if (vssHeader->Format != NVRAM_VSS_VARIABLE_STORE_FORMATTED) {
msg(usprintf("findNextStore: VSS2 store candidate at offset %Xh skipped, has invalid format %02Xh", localOffset + offset, vssHeader->Format), index); msg(usprintf("%s: VSS2 store candidate at offset %Xh skipped, has invalid format %02Xh", __FUNCTION__, localOffset + offset, vssHeader->Format), index);
continue; continue;
} }
if (vssHeader->Size == 0 || vssHeader->Size == 0xFFFFFFFF) { if (vssHeader->Size == 0 || vssHeader->Size == 0xFFFFFFFF) {
msg(usprintf("findNextStore: VSS2 store candidate at offset %Xh skipped, has invalid size %Xh", localOffset + offset, vssHeader->Size), index); msg(usprintf("%s: VSS2 store candidate at offset %Xh skipped, has invalid size %Xh", __FUNCTION__, localOffset + offset, vssHeader->Size), index);
continue; continue;
} }
// All checks passed, store found // All checks passed, store found
@ -551,7 +552,7 @@ USTATUS NvramParser::findNextStore(const UModelIndex & index, const UByteArray &
else if (*currentPos == NVRAM_FDC_VOLUME_SIGNATURE) { //FDC signature found else if (*currentPos == NVRAM_FDC_VOLUME_SIGNATURE) { //FDC signature found
const FDC_VOLUME_HEADER* fdcHeader = (const FDC_VOLUME_HEADER*)currentPos; const FDC_VOLUME_HEADER* fdcHeader = (const FDC_VOLUME_HEADER*)currentPos;
if (fdcHeader->Size == 0 || fdcHeader->Size == 0xFFFFFFFF) { if (fdcHeader->Size == 0 || fdcHeader->Size == 0xFFFFFFFF) {
msg(usprintf("findNextStore: FDC store candidate at offset %Xh skipped, has invalid size %Xh", localOffset + offset, fdcHeader->Size), index); msg(usprintf("%s: FDC store candidate at offset %Xh skipped, has invalid size %Xh", __FUNCTION__, localOffset + offset, fdcHeader->Size), index);
continue; continue;
} }
// All checks passed, store found // All checks passed, store found
@ -560,7 +561,7 @@ USTATUS NvramParser::findNextStore(const UModelIndex & index, const UByteArray &
else if (*currentPos == NVRAM_APPLE_FSYS_STORE_SIGNATURE || *currentPos == NVRAM_APPLE_GAID_STORE_SIGNATURE) { //Fsys or Gaid signature found else if (*currentPos == NVRAM_APPLE_FSYS_STORE_SIGNATURE || *currentPos == NVRAM_APPLE_GAID_STORE_SIGNATURE) { //Fsys or Gaid signature found
const APPLE_FSYS_STORE_HEADER* fsysHeader = (const APPLE_FSYS_STORE_HEADER*)currentPos; const APPLE_FSYS_STORE_HEADER* fsysHeader = (const APPLE_FSYS_STORE_HEADER*)currentPos;
if (fsysHeader->Size == 0 || fsysHeader->Size == 0xFFFF) { if (fsysHeader->Size == 0 || fsysHeader->Size == 0xFFFF) {
msg(usprintf("findNextStore: Fsys store candidate at offset %Xh skipped, has invalid size %Xh", localOffset + offset, fsysHeader->Size), index); msg(usprintf("%s: Fsys store candidate at offset %Xh skipped, has invalid size %Xh", __FUNCTION__, localOffset + offset, fsysHeader->Size), index);
continue; continue;
} }
// All checks passed, store found // All checks passed, store found
@ -572,11 +573,11 @@ USTATUS NvramParser::findNextStore(const UModelIndex & index, const UByteArray &
const EVSA_STORE_ENTRY* evsaHeader = (const EVSA_STORE_ENTRY*)(currentPos - 1); const EVSA_STORE_ENTRY* evsaHeader = (const EVSA_STORE_ENTRY*)(currentPos - 1);
if (evsaHeader->Header.Type != NVRAM_EVSA_ENTRY_TYPE_STORE) { if (evsaHeader->Header.Type != NVRAM_EVSA_ENTRY_TYPE_STORE) {
msg(usprintf("findNextStore: EVSA store candidate at offset %Xh skipped, has invalid type %02Xh", localOffset + offset - 4, evsaHeader->Header.Type), index); msg(usprintf("%s: EVSA store candidate at offset %Xh skipped, has invalid type %02Xh", __FUNCTION__, localOffset + offset - 4, evsaHeader->Header.Type), index);
continue; continue;
} }
if (evsaHeader->StoreSize == 0 || evsaHeader->StoreSize == 0xFFFFFFFF) { if (evsaHeader->StoreSize == 0 || evsaHeader->StoreSize == 0xFFFFFFFF) {
msg(usprintf("findNextStore: EVSA store candidate at offset %Xh skipped, has invalid size %Xh", localOffset + offset, evsaHeader->StoreSize), index); msg(usprintf("%s: EVSA store candidate at offset %Xh skipped, has invalid size %Xh", __FUNCTION__, localOffset + offset, evsaHeader->StoreSize), index);
continue; continue;
} }
// All checks passed, store found // All checks passed, store found
@ -592,14 +593,14 @@ USTATUS NvramParser::findNextStore(const UModelIndex & index, const UByteArray &
const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32* ftwHeader = (const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32*)currentPos; const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32* ftwHeader = (const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32*)currentPos;
if (ftwHeader->WriteQueueSize % 0x10 == 0x04) { // Header with 32 bit WriteQueueSize if (ftwHeader->WriteQueueSize % 0x10 == 0x04) { // Header with 32 bit WriteQueueSize
if (ftwHeader->WriteQueueSize == 0 || ftwHeader->WriteQueueSize == 0xFFFFFFFF) { if (ftwHeader->WriteQueueSize == 0 || ftwHeader->WriteQueueSize == 0xFFFFFFFF) {
msg(usprintf("findNextStore: FTW block candidate at offset %Xh skipped, has invalid body size %Xh", localOffset + offset, ftwHeader->WriteQueueSize), index); msg(usprintf("%s: FTW block candidate at offset %Xh skipped, has invalid body size %Xh", __FUNCTION__, localOffset + offset, ftwHeader->WriteQueueSize), index);
continue; continue;
} }
} }
else if (ftwHeader->WriteQueueSize % 0x10 == 0x00) { // Header with 64 bit WriteQueueSize else if (ftwHeader->WriteQueueSize % 0x10 == 0x00) { // Header with 64 bit WriteQueueSize
const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64* ftw64Header = (const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64*)currentPos; const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64* ftw64Header = (const EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64*)currentPos;
if (ftw64Header->WriteQueueSize == 0 || ftw64Header->WriteQueueSize >= 0xFFFFFFFF) { if (ftw64Header->WriteQueueSize == 0 || ftw64Header->WriteQueueSize >= 0xFFFFFFFF) {
msg(usprintf("findNextStore: FTW block candidate at offset %Xh skipped, has invalid body size %Xh", localOffset + offset, ftw64Header->WriteQueueSize), index); msg(usprintf("%s: FTW block candidate at offset %Xh skipped, has invalid body size %Xh", __FUNCTION__, localOffset + offset, ftw64Header->WriteQueueSize), index);
continue; continue;
} }
} }
@ -750,7 +751,7 @@ USTATUS NvramParser::parseVssStoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < sizeof(VSS_VARIABLE_STORE_HEADER)) { if (dataSize < sizeof(VSS_VARIABLE_STORE_HEADER)) {
msg(UString("parseVssStoreHeader: volume body is too small even for VSS store header"), parent); msg(usprintf("%s: volume body is too small even for VSS store header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -765,7 +766,7 @@ USTATUS NvramParser::parseVssStoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < storeSize) { if (dataSize < storeSize) {
msg(usprintf("parseVssStoreHeader: VSS store size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: VSS store size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
storeSize, storeSize, storeSize, storeSize,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -799,7 +800,7 @@ USTATUS NvramParser::parseVss2StoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < sizeof(VSS2_VARIABLE_STORE_HEADER)) { if (dataSize < sizeof(VSS2_VARIABLE_STORE_HEADER)) {
msg(UString("parseVss2StoreHeader: volume body is too small even for VSS2 store header"), parent); msg(usprintf("%s: volume body is too small even for VSS2 store header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -814,7 +815,7 @@ USTATUS NvramParser::parseVss2StoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < storeSize) { if (dataSize < storeSize) {
msg(usprintf("parseVssStoreHeader: VSS2 store size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: VSS2 store size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
storeSize, storeSize, storeSize, storeSize,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -847,7 +848,7 @@ USTATUS NvramParser::parseFtwStoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64)) { if (dataSize < sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64)) {
msg(UString("parseFtwStoreHeader: volume body is too small even for FTW store header"), parent); msg(usprintf("%s: volume body is too small even for FTW store header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -876,7 +877,7 @@ USTATUS NvramParser::parseFtwStoreHeader(const UByteArray & store, const UINT32
has32bitHeader = false; has32bitHeader = false;
} }
if (dataSize < ftwBlockSize) { if (dataSize < ftwBlockSize) {
msg(usprintf("parseFtwStoreHeader: FTW store size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: FTW store size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
ftwBlockSize, ftwBlockSize, ftwBlockSize, ftwBlockSize,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -917,7 +918,7 @@ USTATUS NvramParser::parseFdcStoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < sizeof(FDC_VOLUME_HEADER)) { if (dataSize < sizeof(FDC_VOLUME_HEADER)) {
msg(UString("parseFdcStoreHeader: volume body is too small even for FDC store header"), parent); msg(usprintf("%s: volume body is too small even for FDC store header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -926,7 +927,7 @@ USTATUS NvramParser::parseFdcStoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < fdcStoreHeader->Size) { if (dataSize < fdcStoreHeader->Size) {
msg(usprintf("parseFdcStoreHeader: FDC store size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: FDC store size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
fdcStoreHeader->Size, fdcStoreHeader->Size, fdcStoreHeader->Size, fdcStoreHeader->Size,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -935,7 +936,7 @@ USTATUS NvramParser::parseFdcStoreHeader(const UByteArray & store, const UINT32
// Check header size // Check header size
UINT32 headerSize = sizeof(FDC_VOLUME_HEADER); UINT32 headerSize = sizeof(FDC_VOLUME_HEADER);
if (dataSize < headerSize) { if (dataSize < headerSize) {
msg(usprintf("parseFdcStoreHeader: FDC store header size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: FDC store header size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
fdcStoreHeader->Size, fdcStoreHeader->Size, fdcStoreHeader->Size, fdcStoreHeader->Size,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -964,7 +965,7 @@ USTATUS NvramParser::parseFsysStoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < sizeof(APPLE_FSYS_STORE_HEADER)) { if (dataSize < sizeof(APPLE_FSYS_STORE_HEADER)) {
msg(UString("parseFsysStoreHeader: volume body is too small even for Fsys store header"), parent); msg(usprintf("%s: volume body is too small even for Fsys store header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -973,7 +974,7 @@ USTATUS NvramParser::parseFsysStoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < fsysStoreHeader->Size) { if (dataSize < fsysStoreHeader->Size) {
msg(usprintf("parseFsysStoreHeader: Fsys store size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: Fsys store size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
fsysStoreHeader->Size, fsysStoreHeader->Size, fsysStoreHeader->Size, fsysStoreHeader->Size,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -1011,7 +1012,7 @@ USTATUS NvramParser::parseEvsaStoreHeader(const UByteArray & store, const UINT32
// Check dataSize // Check dataSize
if (dataSize < sizeof(EVSA_STORE_ENTRY)) { if (dataSize < sizeof(EVSA_STORE_ENTRY)) {
msg(UString("parseEvsaStoreHeader: volume body is too small even for EVSA store header"), parent); msg(usprintf("%s: volume body is too small even for EVSA store header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1020,7 +1021,7 @@ USTATUS NvramParser::parseEvsaStoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < evsaStoreHeader->StoreSize) { if (dataSize < evsaStoreHeader->StoreSize) {
msg(usprintf("parseEvsaStoreHeader: EVSA store size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: EVSA store size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
evsaStoreHeader->StoreSize, evsaStoreHeader->StoreSize, evsaStoreHeader->StoreSize, evsaStoreHeader->StoreSize,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -1056,7 +1057,7 @@ USTATUS NvramParser::parseFlashMapStoreHeader(const UByteArray & store, const UI
// Check data size // Check data size
if (dataSize < sizeof(PHOENIX_FLASH_MAP_HEADER)) { if (dataSize < sizeof(PHOENIX_FLASH_MAP_HEADER)) {
msg(UString("parseFlashMapStoreHeader: volume body is too small even for FlashMap block header"), parent); msg(usprintf("%s: volume body is too small even for FlashMap block header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1066,7 +1067,7 @@ USTATUS NvramParser::parseFlashMapStoreHeader(const UByteArray & store, const UI
// Check store size // Check store size
UINT32 flashMapSize = sizeof(PHOENIX_FLASH_MAP_HEADER) + flashMapHeader->NumEntries * sizeof(PHOENIX_FLASH_MAP_ENTRY); UINT32 flashMapSize = sizeof(PHOENIX_FLASH_MAP_HEADER) + flashMapHeader->NumEntries * sizeof(PHOENIX_FLASH_MAP_ENTRY);
if (dataSize < flashMapSize) { if (dataSize < flashMapSize) {
msg(usprintf("parseFlashMapStoreHeader: FlashMap block size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: FlashMap block size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
flashMapSize, flashMapSize, flashMapSize, flashMapSize,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -1096,13 +1097,13 @@ USTATUS NvramParser::parseCmdbStoreHeader(const UByteArray & store, const UINT32
// Check store size // Check store size
if (dataSize < sizeof(PHOENIX_CMDB_HEADER)) { if (dataSize < sizeof(PHOENIX_CMDB_HEADER)) {
msg(UString("parseCmdbStoreHeader: volume body is too small even for CMDB store header"), parent); msg(usprintf("%s: volume body is too small even for CMDB store header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
UINT32 cmdbSize = NVRAM_PHOENIX_CMDB_SIZE; UINT32 cmdbSize = NVRAM_PHOENIX_CMDB_SIZE;
if (dataSize < cmdbSize) { if (dataSize < cmdbSize) {
msg(usprintf("parseCmdbStoreHeader: CMDB store size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: CMDB store size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
cmdbSize, cmdbSize, cmdbSize, cmdbSize,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -1134,7 +1135,7 @@ USTATUS NvramParser::parseSlicPubkeyHeader(const UByteArray & store, const UINT3
// Check data size // Check data size
if (dataSize < sizeof(OEM_ACTIVATION_PUBKEY)) { if (dataSize < sizeof(OEM_ACTIVATION_PUBKEY)) {
msg(UString("parseSlicPubkeyHeader: volume body is too small even for SLIC pubkey header"), parent); msg(usprintf("%s: volume body is too small even for SLIC pubkey header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1143,7 +1144,7 @@ USTATUS NvramParser::parseSlicPubkeyHeader(const UByteArray & store, const UINT3
// Check store size // Check store size
if (dataSize < pubkeyHeader->Size) { if (dataSize < pubkeyHeader->Size) {
msg(usprintf("parseSlicPubkeyHeader: SLIC pubkey size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: SLIC pubkey size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
pubkeyHeader->Size, pubkeyHeader->Size, pubkeyHeader->Size, pubkeyHeader->Size,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -1176,7 +1177,7 @@ USTATUS NvramParser::parseSlicMarkerHeader(const UByteArray & store, const UINT3
// Check data size // Check data size
if (dataSize < sizeof(OEM_ACTIVATION_MARKER)) { if (dataSize < sizeof(OEM_ACTIVATION_MARKER)) {
msg(UString("parseSlicMarkerHeader: volume body is too small even for SLIC marker header"), parent); msg(usprintf("%s: volume body is too small even for SLIC marker header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1185,7 +1186,7 @@ USTATUS NvramParser::parseSlicMarkerHeader(const UByteArray & store, const UINT3
// Check store size // Check store size
if (dataSize < markerHeader->Size) { if (dataSize < markerHeader->Size) {
msg(usprintf("parseSlicMarkerHeader: SLIC marker size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: SLIC marker size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
markerHeader->Size, markerHeader->Size, markerHeader->Size, markerHeader->Size,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -1218,7 +1219,7 @@ USTATUS NvramParser::parseIntelMicrocodeHeader(const UByteArray & store, const U
// Check data size // Check data size
if (dataSize < sizeof(INTEL_MICROCODE_HEADER)) { if (dataSize < sizeof(INTEL_MICROCODE_HEADER)) {
msg(UString("parseIntelMicrocodeHeader: volume body is too small even for Intel microcode header"), parent); msg(usprintf("%s: volume body is too small even for Intel microcode header", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1227,7 +1228,7 @@ USTATUS NvramParser::parseIntelMicrocodeHeader(const UByteArray & store, const U
// Check store size // Check store size
if (dataSize < ucodeHeader->TotalSize) { if (dataSize < ucodeHeader->TotalSize) {
msg(usprintf("parseIntelMicrocodeHeader: Intel microcode size %Xh (%u) is greater than volume body size %Xh (%u)", msg(usprintf("%s: Intel microcode size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
ucodeHeader->TotalSize, ucodeHeader->TotalSize, ucodeHeader->TotalSize, ucodeHeader->TotalSize,
dataSize, dataSize), parent); dataSize, dataSize), parent);
return U_SUCCESS; return U_SUCCESS;
@ -1267,7 +1268,7 @@ USTATUS NvramParser::parseStoreHeader(const UByteArray & store, const UINT32 loc
const UINT32* signature = (const UINT32*)store.constData(); const UINT32* signature = (const UINT32*)store.constData();
// Check store size // Check store size
if (dataSize < sizeof(UINT32)) { if (dataSize < sizeof(UINT32)) {
msg(UString("parseStoreHeader: volume body is too small even for store signature"), parent); msg(usprintf("%s: volume body is too small even for a store signature", __FUNCTION__), parent);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1288,7 +1289,7 @@ USTATUS NvramParser::parseStoreHeader(const UByteArray & store, const UINT32 loc
else if (*signature == NVRAM_APPLE_FSYS_STORE_SIGNATURE || *signature == NVRAM_APPLE_GAID_STORE_SIGNATURE) else if (*signature == NVRAM_APPLE_FSYS_STORE_SIGNATURE || *signature == NVRAM_APPLE_GAID_STORE_SIGNATURE)
return parseFsysStoreHeader(store, localOffset, parent, index); return parseFsysStoreHeader(store, localOffset, parent, index);
// EVSA store // EVSA store
else if (*(signature + 1) == NVRAM_EVSA_STORE_SIGNATURE) else if (dataSize >= 2 * sizeof(UINT32) && *(signature + 1) == NVRAM_EVSA_STORE_SIGNATURE)
return parseEvsaStoreHeader(store, localOffset, parent, index); return parseEvsaStoreHeader(store, localOffset, parent, index);
// Phoenix SCT flash map // Phoenix SCT flash map
else if (*signature == NVRAM_PHOENIX_FLASH_MAP_SIGNATURE_PART1) else if (*signature == NVRAM_PHOENIX_FLASH_MAP_SIGNATURE_PART1)
@ -1297,10 +1298,10 @@ USTATUS NvramParser::parseStoreHeader(const UByteArray & store, const UINT32 loc
else if (*signature == NVRAM_PHOENIX_CMDB_HEADER_SIGNATURE) else if (*signature == NVRAM_PHOENIX_CMDB_HEADER_SIGNATURE)
return parseCmdbStoreHeader(store, localOffset, parent, index); return parseCmdbStoreHeader(store, localOffset, parent, index);
// SLIC pubkey // SLIC pubkey
else if (*(signature + 4) == OEM_ACTIVATION_PUBKEY_MAGIC) else if (dataSize >= 5 * sizeof(UINT32) && *(signature + 4) == OEM_ACTIVATION_PUBKEY_MAGIC)
return parseSlicPubkeyHeader(store, localOffset, parent, index); return parseSlicPubkeyHeader(store, localOffset, parent, index);
// SLIC marker // SLIC marker
else if (*(const UINT64*)(store.constData() + 26) == OEM_ACTIVATION_MARKER_WINDOWS_FLAG) else if (dataSize >= 34 && *(const UINT64*)(store.constData() + 26) == OEM_ACTIVATION_MARKER_WINDOWS_FLAG)
return parseSlicMarkerHeader(store, localOffset, parent, index); return parseSlicMarkerHeader(store, localOffset, parent, index);
// Intel microcode // Intel microcode
// Must be checked after SLIC marker because of the same *signature values // Must be checked after SLIC marker because of the same *signature values
@ -1327,20 +1328,20 @@ USTATUS NvramParser::parseFdcStoreBody(const UModelIndex & index)
UModelIndex volumeIndex; UModelIndex volumeIndex;
USTATUS status = ffsParser->parseVolumeHeader(data, localOffset, index, volumeIndex); USTATUS status = ffsParser->parseVolumeHeader(data, localOffset, index, volumeIndex);
if (status || !volumeIndex.isValid()) { if (status || !volumeIndex.isValid()) {
msg(UString("parseFdcStoreBody: store can't be parsed as FDC store"), index); msg(usprintf("%s: store can't be parsed as FDC store", __FUNCTION__), index);
return U_SUCCESS; return U_SUCCESS;
} }
// Determine if it's a VSS or VSS2 store inside // Determine if it's a VSS or VSS2 store inside
UByteArray store = model->body(volumeIndex); UByteArray store = model->body(volumeIndex);
if (store.size() >= sizeof(UINT32) && *(const UINT32*)store.constData() == NVRAM_VSS_STORE_SIGNATURE) { if ((UINT32)store.size() >= sizeof(UINT32) && *(const UINT32*)store.constData() == NVRAM_VSS_STORE_SIGNATURE) {
UModelIndex vssIndex; UModelIndex vssIndex;
status = parseVssStoreHeader(store, localOffset + model->header(volumeIndex).size(), true, volumeIndex, vssIndex); status = parseVssStoreHeader(store, localOffset + model->header(volumeIndex).size(), true, volumeIndex, vssIndex);
if (status) if (status)
return status; return status;
return parseVssStoreBody(vssIndex, 0); return parseVssStoreBody(vssIndex, 0);
} }
else if (store.size() >= sizeof(EFI_GUID) && store.left(sizeof(EFI_GUID)) == NVRAM_FDC_STORE_GUID) { else if ((UINT32)store.size() >= sizeof(EFI_GUID) && store.left(sizeof(EFI_GUID)) == NVRAM_FDC_STORE_GUID) {
UModelIndex vss2Index; UModelIndex vss2Index;
status = parseVss2StoreHeader(store, localOffset + model->header(volumeIndex).size(), true, volumeIndex, vss2Index); status = parseVss2StoreHeader(store, localOffset + model->header(volumeIndex).size(), true, volumeIndex, vss2Index);
if (status) if (status)
@ -1348,7 +1349,7 @@ USTATUS NvramParser::parseFdcStoreBody(const UModelIndex & index)
return parseVssStoreBody(vss2Index, 0); return parseVssStoreBody(vss2Index, 0);
} }
else { else {
msg(UString("parseFdcStoreBody: internal volume can't be parsed as VSS/VSS2 store"), index); msg(usprintf("%s: internal volume can't be parsed as VSS/VSS2 store", __FUNCTION__), index);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1378,7 +1379,7 @@ USTATUS NvramParser::parseVssStoreBody(const UModelIndex & index, UINT8 alignmen
// Check that the is enough space for variable header // Check that the is enough space for variable header
const UINT32 dataSize = (UINT32)data.size(); const UINT32 dataSize = (UINT32)data.size();
if (dataSize < sizeof(VSS_VARIABLE_HEADER)) { if (dataSize < sizeof(VSS_VARIABLE_HEADER)) {
msg(UString("parseVssStoreBody: store body is too small even for VSS variable header"), index); msg(usprintf("%s: store body is too small even for VSS variable header", __FUNCTION__), index);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1512,7 +1513,7 @@ USTATUS NvramParser::parseVssStoreBody(const UModelIndex & index, UINT8 alignmen
else { // Padding else { // Padding
// Nothing is parsed yet, but the store is not empty // Nothing is parsed yet, but the store is not empty
if (!offset) { if (!offset) {
msg(UString("parseVssStoreBody: store can't be parsed as VSS store"), index); msg(usprintf("%s: store can't be parsed as VSS store", __FUNCTION__), index);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1647,7 +1648,7 @@ USTATUS NvramParser::parseFsysStoreBody(const UModelIndex & index)
model->addItem(localOffset + offset, Types::Padding, getPaddingType(body), UString("Padding"), UString(), info, UByteArray(), body, UByteArray(), Fixed, index); model->addItem(localOffset + offset, Types::Padding, getPaddingType(body), UString("Padding"), UString(), info, UByteArray(), body, UByteArray(), Fixed, index);
// Show message // Show message
msg(UString("parseFsysStoreBody: next variable appears too big, added as padding"), index); msg(usprintf("%s: next variable appears too big, added as padding", __FUNCTION__), index);
return U_SUCCESS; return U_SUCCESS;
} }
@ -1728,7 +1729,7 @@ USTATUS NvramParser::parseEvsaStoreBody(const UModelIndex & index)
UModelIndex itemIndex = model->addItem(localOffset + offset, Types::Padding, getPaddingType(body), UString("Padding"), UString(), info, UByteArray(), body, UByteArray(), Fixed, index); UModelIndex itemIndex = model->addItem(localOffset + offset, Types::Padding, getPaddingType(body), UString("Padding"), UString(), info, UByteArray(), body, UByteArray(), Fixed, index);
// Show message // Show message
msg(UString("parseEvsaStoreBody: variable parsing failed, the rest of unparsed store added as padding"), itemIndex); msg(usprintf("%s: variable parsing failed, the rest of unparsed store added as padding", __FUNCTION__), itemIndex);
} }
break; break;
} }
@ -1820,7 +1821,7 @@ USTATUS NvramParser::parseEvsaStoreBody(const UModelIndex & index)
UModelIndex itemIndex = model->addItem(localOffset + offset, Types::Padding, getPaddingType(body), UString("Padding"), UString(), info, UByteArray(), body, UByteArray(), Fixed, index); UModelIndex itemIndex = model->addItem(localOffset + offset, Types::Padding, getPaddingType(body), UString("Padding"), UString(), info, UByteArray(), body, UByteArray(), Fixed, index);
// Show message // Show message
msg(usprintf("parseEvsaStoreBody: unknown variable of type %02Xh found at offset %Xh, the rest of unparsed store added as padding", entryHeader->Type, offset), itemIndex); msg(usprintf("%s: unknown variable of type %02Xh found at offset %Xh, the rest of unparsed store added as padding", __FUNCTION__, entryHeader->Type, offset), itemIndex);
} }
break; break;
} }
@ -1850,17 +1851,17 @@ USTATUS NvramParser::parseEvsaStoreBody(const UModelIndex & index)
if (guid.isEmpty() && name.isEmpty()) { // Both name and guid aren't found if (guid.isEmpty() && name.isEmpty()) { // Both name and guid aren't found
model->setSubtype(current, Subtypes::InvalidEvsaEntry); model->setSubtype(current, Subtypes::InvalidEvsaEntry);
model->setName(current, UString("Invalid")); model->setName(current, UString("Invalid"));
msg(UString("parseEvsaStoreBody: data variable with invalid GuidId and invalid VarId"), current); msg(usprintf("%s: data variable with invalid GuidId and invalid VarId", __FUNCTION__), current);
} }
else if (guid.isEmpty()) { // Guid not found else if (guid.isEmpty()) { // Guid not found
model->setSubtype(current, Subtypes::InvalidEvsaEntry); model->setSubtype(current, Subtypes::InvalidEvsaEntry);
model->setName(current, UString("Invalid")); model->setName(current, UString("Invalid"));
msg(UString("parseEvsaStoreBody: data variable with invalid GuidId"), current); msg(usprintf("%s: data variable with invalid GuidId", __FUNCTION__), current);
} }
else if (name.isEmpty()) { // Name not found else if (name.isEmpty()) { // Name not found
model->setSubtype(current, Subtypes::InvalidEvsaEntry); model->setSubtype(current, Subtypes::InvalidEvsaEntry);
model->setName(current, UString("Invalid")); model->setName(current, UString("Invalid"));
msg(UString("parseEvsaStoreBody: data variable with invalid VarId"), current); msg(usprintf("%s: data variable with invalid VarId", __FUNCTION__), current);
} }
else { // Variable is OK, rename it else { // Variable is OK, rename it
if (dataHeader->Header.Type == NVRAM_EVSA_ENTRY_TYPE_DATA_INVALID) { if (dataHeader->Header.Type == NVRAM_EVSA_ENTRY_TYPE_DATA_INVALID) {
@ -1909,7 +1910,7 @@ USTATUS NvramParser::parseFlashMapBody(const UModelIndex & index)
// Show message // Show message
if (unparsedSize < entryHeader->Size) if (unparsedSize < entryHeader->Size)
msg(UString("parseFlashMapBody: next entry appears too big, added as padding"), index); msg(usprintf("%s: next entry appears too big, added as padding", __FUNCTION__), index);
break; break;
} }

View file

@ -20,9 +20,10 @@ TreeItem::TreeItem(const UINT32 offset, const UINT8 type, const UINT8 subtype,
const bool fixed, const bool compressed, const bool fixed, const bool compressed,
TreeItem *parent) : TreeItem *parent) :
itemOffset(offset), itemOffset(offset),
itemAction(Actions::NoAction), itemAction(Actions::NoAction),
itemType(type), itemType(type),
itemSubtype(subtype), itemSubtype(subtype),
itemMarking(0),
itemName(name), itemName(name),
itemText(text), itemText(text),
itemInfo(info), itemInfo(info),
@ -31,7 +32,6 @@ TreeItem::TreeItem(const UINT32 offset, const UINT8 type, const UINT8 subtype,
itemTail(tail), itemTail(tail),
itemFixed(fixed), itemFixed(fixed),
itemCompressed(compressed), itemCompressed(compressed),
itemMarking(0),
parentItem(parent) parentItem(parent)
{ {
} }

View file

@ -34,6 +34,7 @@ UString uniqueItemName(const UModelIndex & index)
UString itemText = model->text(index); UString itemText = model->text(index);
// Default name // Default name
UString name = itemName; UString name = itemName;
switch (model->type(index)) { switch (model->type(index)) {
case Types::NvarEntry: case Types::NvarEntry:
@ -49,17 +50,26 @@ UString uniqueItemName(const UModelIndex & index)
UModelIndex fileIndex = model->findParentOfType(index, Types::File); UModelIndex fileIndex = model->findParentOfType(index, Types::File);
UString fileText = model->text(fileIndex); UString fileText = model->text(fileIndex);
name = fileText.isEmpty() ? model->name(fileIndex) : model->name(fileIndex) + '_' + fileText; name = fileText.isEmpty() ? model->name(fileIndex) : model->name(fileIndex) + '_' + fileText;
} break;
// Special case of GUIDed sections
if (model->subtype(index) == EFI_SECTION_GUID_DEFINED || model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID) {
name = model->name(index) +'_' + name;
}
} break;
} }
// Populate subtypeString
UString subtypeString = itemSubtypeToUString(model->type(index), model->subtype(index)); UString subtypeString = itemSubtypeToUString(model->type(index), model->subtype(index));
// Create final name
name = itemTypeToUString(model->type(index)) name = itemTypeToUString(model->type(index))
+ (subtypeString.length() ? ('_' + subtypeString) : UString()) + (subtypeString.length() ? ('_' + subtypeString) : UString())
+ '_' + name; + '_' + name;
// Replace some symbols with underscopes for better readability
name.findreplace(' ', '_'); name.findreplace(' ', '_');
name.findreplace('/', '_'); name.findreplace('/', '_');
name.findreplace('-', '_'); name.findreplace('\\', '_');
return name; return name;
} }
@ -341,6 +351,7 @@ UINT16 calculateChecksum16(const UINT16* buffer, UINT32 bufferSize)
return (UINT16)(0x10000 - counter); return (UINT16)(0x10000 - counter);
} }
// Get padding type for a given padding
UINT8 getPaddingType(const UByteArray & padding) UINT8 getPaddingType(const UByteArray & padding)
{ {
if (padding.count('\x00') == padding.size()) if (padding.count('\x00') == padding.size())