Skip to content

Commit

Permalink
fixed rebase PEI files with nonstandard alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
matrosov committed Feb 25, 2018
1 parent 8714e4c commit 60d6494
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion UEFIPatch/uefipatch_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int main(int argc, char *argv[])
result = w.patchFromFile(a.arguments().at(1));
}
else {
std::cout << "UEFIPatch 0.3.12 - UEFI image file patching utility" << std::endl << std::endl <<
std::cout << "UEFIPatch 0.3.13 - 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;
Expand Down
22 changes: 17 additions & 5 deletions ffsengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3405,11 +3405,9 @@ UINT8 FfsEngine::reconstructVolume(const QModelIndex & index, QByteArray & recon

// Normal file
// Ensure correct alignment
UINT8 alignmentPower;
UINT32 alignmentBase;
alignmentPower = ffsAlignmentTable[(fileHeader->Attributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3];
UINT8 alignmentPower = ffsAlignmentTable[(fileHeader->Attributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3];
alignment = (UINT32)(1UL <<alignmentPower);
alignmentBase = header.size() + offset + fileHeaderSize;
UINT32 alignmentBase = header.size() + offset + fileHeaderSize;
if (alignmentBase % alignment) {
// File will be unaligned if added as is, so we must add pad file before it
// Determine pad file size
Expand Down Expand Up @@ -3706,7 +3704,21 @@ UINT8 FfsEngine::reconstructFile(const QModelIndex& index, const UINT8 revision,

// Calculate section base
UINT32 sectionBase = base ? base + headerSize + offset : 0;

UINT8 alignmentPower = ffsAlignmentTable[(fileHeader->Attributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3];
UINT32 fileAlignment = (UINT32)(1UL << alignmentPower);
UINT32 alignmentBase = base + headerSize;
if (alignmentBase % fileAlignment) {
// File will be unaligned if added as is, so we must add pad file before it
// Determine pad file size
UINT32 size = fileAlignment - (alignmentBase % fileAlignment);
// Required padding is smaller then minimal pad file size
while (size < sizeof(EFI_FFS_FILE_HEADER)) {
size += fileAlignment;
}
// Adjust file base to incorporate pad file that will be added to align it
sectionBase += size;
}

// Reconstruct section
QByteArray section;
result = reconstructSection(index.child(i, 0), sectionBase, section);
Expand Down
2 changes: 1 addition & 1 deletion uefitool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
UEFITool::UEFITool(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::UEFITool),
version(tr("0.22.3"))
version(tr("0.22.4"))
{
clipboard = QApplication::clipboard();

Expand Down

0 comments on commit 60d6494

Please sign in to comment.