From 1ab52fde3599c717964f99a7401d957501d05106 Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Sun, 4 Oct 2015 21:58:44 +0200 Subject: [PATCH] UT 0.21.3 / UP 0.3.7 - solved a bug with Gigabyte-specific descriptor settings (BIOS region has size of the whole image), thanks to lordkag for #37 --- UEFIPatch/uefipatch_main.cpp | 2 +- ffsengine.cpp | 24 ++++++++++++++++++++++-- uefitool.cpp | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/UEFIPatch/uefipatch_main.cpp b/UEFIPatch/uefipatch_main.cpp index f1642d0..57f7e25 100644 --- a/UEFIPatch/uefipatch_main.cpp +++ b/UEFIPatch/uefipatch_main.cpp @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) result = w.patchFromFile(a.arguments().at(1)); } else { - std::cout << "UEFIPatch 0.3.6 - UEFI image file patching utility" << std::endl << std::endl << + std::cout << "UEFIPatch 0.3.7 - UEFI image file patching utility" << std::endl << std::endl << "Usage: UEFIPatch image_file" << std::endl << std::endl << "Patches will be read from patches.txt file\n"; return ERR_SUCCESS; diff --git a/ffsengine.cpp b/ffsengine.cpp index 160dba7..a71ec4f 100644 --- a/ffsengine.cpp +++ b/ffsengine.cpp @@ -303,10 +303,18 @@ UINT8 FfsEngine::parseIntelImage(const QByteArray & intelImage, QModelIndex & in return ERR_INVALID_FLASH_DESCRIPTOR; } biosBegin = meEnd; + // biosEnd will point to the end of the image file + // it may be wrong, but it's pretty hard to detect a padding after BIOS region + // with malformed descriptor + } + // Normal descriptor map + else { + // Calculate biosEnd + biosEnd += biosBegin; } bios = intelImage.mid(biosBegin, biosEnd); - biosEnd += biosBegin; + } else { msg(tr("parseIntelImage: descriptor parsing failed, BIOS region not found in descriptor")); @@ -2843,15 +2851,27 @@ UINT8 FfsEngine::reconstructIntelImage(const QModelIndex& index, QByteArray& rec QByteArray gbe; UINT32 gbeBegin = calculateRegionOffset(regionSection->GbeBase); UINT32 gbeEnd = gbeBegin + calculateRegionSize(regionSection->GbeBase, regionSection->GbeLimit); + QByteArray me; UINT32 meBegin = calculateRegionOffset(regionSection->MeBase); UINT32 meEnd = meBegin + calculateRegionSize(regionSection->MeBase, regionSection->MeLimit); + QByteArray bios; UINT32 biosBegin = calculateRegionOffset(regionSection->BiosBase); - UINT32 biosEnd = biosBegin + calculateRegionSize(regionSection->BiosBase, regionSection->BiosLimit); + UINT32 biosEnd = calculateRegionSize(regionSection->BiosBase, regionSection->BiosLimit); + // Gigabyte descriptor map + if (biosEnd - biosBegin == model->header(index).size() + model->body(index).size()) { + biosBegin = meEnd; + biosEnd = model->header(index).size() + model->body(index).size(); + } + // Normal descriptor map + else + biosEnd += biosBegin; + QByteArray pdr; UINT32 pdrBegin = calculateRegionOffset(regionSection->PdrBase); UINT32 pdrEnd = pdrBegin + calculateRegionSize(regionSection->PdrBase, regionSection->PdrLimit); + QByteArray ec; UINT32 ecBegin = 0; UINT32 ecEnd = 0; diff --git a/uefitool.cpp b/uefitool.cpp index c300a89..99e5cbf 100644 --- a/uefitool.cpp +++ b/uefitool.cpp @@ -17,7 +17,7 @@ UEFITool::UEFITool(QWidget *parent) : QMainWindow(parent), ui(new Ui::UEFITool), -version(tr("0.21.2")) +version(tr("0.21.3")) { clipboard = QApplication::clipboard();