Skip to content

Commit

Permalink
fix for #99
Browse files Browse the repository at this point in the history
  • Loading branch information
matrosov committed Jan 23, 2018
1 parent 3ffdae1 commit 9d623c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions ffsengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,8 @@ UINT8 FfsEngine::parseBios(const QByteArray & bios, const QModelIndex & parent)
if (msgUnknownRevision)
msg(tr("parseBios: unknown volume revision %1").arg(volumeHeader->Revision), index);
if (msgSizeMismach)
msg(tr("parseBios: volume size stored in header %1h (%2) differs from calculated using block map %3h (%4)")
.hexarg(volumeSize).arg(volumeSize)
.hexarg(bmVolumeSize).arg(bmVolumeSize),
msg(tr("parseBios: volume size stored in header %1h differs from calculated using block map %3h")
.hexarg(volumeSize).arg(bmVolumeSize),
index);

// Go to next volume
Expand Down Expand Up @@ -1219,16 +1218,16 @@ UINT8 FfsEngine::parseFile(const QByteArray & file, QModelIndex & index, const U
// Construct empty byte for this file
char empty = erasePolarity ? '\xFF' : '\x00';

// Get file header
// Get file header
QByteArray header = file.left(sizeof(EFI_FFS_FILE_HEADER));
if (revision > 1 && (fileHeader->Attributes & FFS_ATTRIB_LARGE_FILE)) {
if ((UINT32)file.size() < sizeof(EFI_FFS_FILE_HEADER2))
return ERR_INVALID_FILE;
header = file.left(sizeof(EFI_FFS_FILE_HEADER2));
}
}

// Check header checksum
UINT8 calculatedHeader = 0x100 -(calculateSum8((const UINT8*)header.constData(), header.size()) - fileHeader->IntegrityCheck.Checksum.Header - fileHeader->IntegrityCheck.Checksum.File - fileHeader->State);
UINT8 calculatedHeader = 0x100 - (calculateSum8((const UINT8*)header.constData(), header.size()) - fileHeader->IntegrityCheck.Checksum.Header - fileHeader->IntegrityCheck.Checksum.File - fileHeader->State);
if (fileHeader->IntegrityCheck.Checksum.Header != calculatedHeader)
msgInvalidHeaderChecksum = true;

Expand All @@ -1253,12 +1252,16 @@ UINT8 FfsEngine::parseFile(const QByteArray & file, QModelIndex & index, const U
UINT8 calculatedData = 0;
if (fileHeader->Attributes & FFS_ATTRIB_CHECKSUM) {
calculatedData = calculateChecksum8((const UINT8*)body.constData(), body.size());
if (fileHeader->IntegrityCheck.Checksum.File != calculatedData)
msgInvalidDataChecksum = true;
}
// Data checksum must be one of predefined values
else if ((revision == 1 && fileHeader->IntegrityCheck.Checksum.File != FFS_FIXED_CHECKSUM)
|| fileHeader->IntegrityCheck.Checksum.File != FFS_FIXED_CHECKSUM2)
else if (revision == 1) {
calculatedData = FFS_FIXED_CHECKSUM;
}
else {
calculatedData = FFS_FIXED_CHECKSUM2;
}

if (fileHeader->IntegrityCheck.Checksum.File != calculatedData)
msgInvalidDataChecksum = true;

// Parse current file by default
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.1"))
version(tr("0.22.2"))
{
clipboard = QApplication::clipboard();

Expand Down

0 comments on commit 9d623c9

Please sign in to comment.