mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-05-13 06:34:42 -04:00
LessQt, part 1
- added wrappers over Qt classes for seamless replacement if Qt is not available - added bstrlib as submodule - only UEFIExtract works with this changes for now, others will followa bit later
This commit is contained in:
parent
71ce2a07b2
commit
bf8632c063
32 changed files with 2891 additions and 2774 deletions
|
@ -11,7 +11,7 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
*/
|
||||
#include "fitparser.h"
|
||||
|
||||
STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIndex)
|
||||
USTATUS FitParser::parse(const UModelIndex & index, const UModelIndex & lastVtfIndex)
|
||||
{
|
||||
// Check sanity
|
||||
if (!index.isValid() || !lastVtfIndex.isValid())
|
||||
|
@ -21,15 +21,15 @@ STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIn
|
|||
lastVtf = lastVtfIndex;
|
||||
|
||||
// Search for FIT
|
||||
QModelIndex fitIndex;
|
||||
UModelIndex fitIndex;
|
||||
UINT32 fitOffset;
|
||||
STATUS result = findFitRecursive(index, fitIndex, fitOffset);
|
||||
USTATUS result = findFitRecursive(index, fitIndex, fitOffset);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
// FIT not found
|
||||
if (!fitIndex.isValid())
|
||||
return ERR_SUCCESS;
|
||||
return U_SUCCESS;
|
||||
|
||||
// Explicitly set the item as fixed
|
||||
model->setFixed(index, true);
|
||||
|
@ -41,27 +41,27 @@ STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIn
|
|||
UINT32 fitSize = (fitHeader->Size & 0xFFFFFF) << 4;
|
||||
if (fitHeader->Type & 0x80) {
|
||||
// Calculate FIT entry checksum
|
||||
QByteArray tempFIT = model->body(fitIndex).mid(fitOffset, fitSize);
|
||||
UByteArray tempFIT = model->body(fitIndex).mid(fitOffset, fitSize);
|
||||
FIT_ENTRY* tempFitHeader = (FIT_ENTRY*)tempFIT.data();
|
||||
tempFitHeader->Checksum = 0;
|
||||
UINT8 calculated = calculateChecksum8((const UINT8*)tempFitHeader, fitSize);
|
||||
if (calculated != fitHeader->Checksum) {
|
||||
msg(QObject::tr("Invalid FIT table checksum %1h, should be %2h").hexarg2(fitHeader->Checksum, 2).hexarg2(calculated, 2), fitIndex);
|
||||
msg(usprintf("Invalid FIT table checksum %02Xh, should be %02Xh", fitHeader->Checksum, calculated), fitIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Check fit header type
|
||||
if ((fitHeader->Type & 0x7F) != FIT_TYPE_HEADER) {
|
||||
msg(QObject::tr("Invalid FIT header type"), fitIndex);
|
||||
msg(("Invalid FIT header type"), fitIndex);
|
||||
}
|
||||
|
||||
// Add FIT header to fitTable
|
||||
std::vector<QString> currentStrings;
|
||||
currentStrings.push_back(QObject::tr("_FIT_ "));
|
||||
currentStrings.push_back(QObject::tr("%1").hexarg2(fitSize, 8));
|
||||
currentStrings.push_back(QObject::tr("%1").hexarg2(fitHeader->Version, 4));
|
||||
currentStrings.push_back(fitEntryTypeToQString(fitHeader->Type));
|
||||
currentStrings.push_back(QObject::tr("%1").hexarg2(fitHeader->Checksum, 2));
|
||||
std::vector<UString> currentStrings;
|
||||
currentStrings.push_back(UString("_FIT_ "));
|
||||
currentStrings.push_back(usprintf("%08X",fitSize));
|
||||
currentStrings.push_back(usprintf("%04X",fitHeader->Version));
|
||||
currentStrings.push_back(fitEntryTypeToUString(fitHeader->Type));
|
||||
currentStrings.push_back(usprintf("%02X",fitHeader->Checksum));
|
||||
fitTable.push_back(currentStrings);
|
||||
|
||||
// Process all other entries
|
||||
|
@ -73,7 +73,7 @@ STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIn
|
|||
// Check entry type
|
||||
switch (currentEntry->Type & 0x7F) {
|
||||
case FIT_TYPE_HEADER:
|
||||
msg(QObject::tr("Second FIT header found, the table is damaged"), fitIndex);
|
||||
msg(UString("Second FIT header found, the table is damaged"), fitIndex);
|
||||
break;
|
||||
|
||||
case FIT_TYPE_EMPTY:
|
||||
|
@ -93,52 +93,52 @@ STATUS FitParser::parse(const QModelIndex & index, const QModelIndex & lastVtfIn
|
|||
}
|
||||
|
||||
// Add entry to fitTable
|
||||
currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Address, 16));
|
||||
currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Size, 8));
|
||||
currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Version, 4));
|
||||
currentStrings.push_back(fitEntryTypeToQString(currentEntry->Type));
|
||||
currentStrings.push_back(QObject::tr("%1").hexarg2(currentEntry->Checksum, 2));
|
||||
currentStrings.push_back(usprintf("%016X",currentEntry->Address));
|
||||
currentStrings.push_back(usprintf("%08X", currentEntry->Size));
|
||||
currentStrings.push_back(usprintf("%04X", currentEntry->Version));
|
||||
currentStrings.push_back(fitEntryTypeToUString(currentEntry->Type));
|
||||
currentStrings.push_back(usprintf("%02X", currentEntry->Checksum));
|
||||
fitTable.push_back(currentStrings);
|
||||
}
|
||||
|
||||
if (msgModifiedImageMayNotWork)
|
||||
msg(QObject::tr("Opened image may not work after any modification"));
|
||||
msg(("Opened image may not work after any modification"));
|
||||
|
||||
return ERR_SUCCESS;
|
||||
return U_SUCCESS;
|
||||
}
|
||||
|
||||
QString FitParser::fitEntryTypeToQString(UINT8 type)
|
||||
UString FitParser::fitEntryTypeToUString(UINT8 type)
|
||||
{
|
||||
switch (type & 0x7F) {
|
||||
case FIT_TYPE_HEADER: return QObject::tr("Header ");
|
||||
case FIT_TYPE_MICROCODE: return QObject::tr("Microcode ");
|
||||
case FIT_TYPE_BIOS_AC_MODULE: return QObject::tr("BIOS ACM ");
|
||||
case FIT_TYPE_BIOS_INIT_MODULE: return QObject::tr("BIOS Init ");
|
||||
case FIT_TYPE_TPM_POLICY: return QObject::tr("TPM Policy ");
|
||||
case FIT_TYPE_BIOS_POLICY_DATA: return QObject::tr("BIOS Policy Data ");
|
||||
case FIT_TYPE_TXT_CONF_POLICY: return QObject::tr("TXT Configuration Policy");
|
||||
case FIT_TYPE_AC_KEY_MANIFEST: return QObject::tr("BootGuard Key Manifest ");
|
||||
case FIT_TYPE_AC_BOOT_POLICY: return QObject::tr("BootGuard Boot Policy ");
|
||||
case FIT_TYPE_EMPTY: return QObject::tr("Empty ");
|
||||
default: return QObject::tr("Unknown ");
|
||||
case FIT_TYPE_HEADER: return ("Header ");
|
||||
case FIT_TYPE_MICROCODE: return ("Microcode ");
|
||||
case FIT_TYPE_BIOS_AC_MODULE: return ("BIOS ACM ");
|
||||
case FIT_TYPE_BIOS_INIT_MODULE: return ("BIOS Init ");
|
||||
case FIT_TYPE_TPM_POLICY: return ("TPM Policy ");
|
||||
case FIT_TYPE_BIOS_POLICY_DATA: return ("BIOS Policy Data ");
|
||||
case FIT_TYPE_TXT_CONF_POLICY: return ("TXT Configuration Policy");
|
||||
case FIT_TYPE_AC_KEY_MANIFEST: return ("BootGuard Key Manifest ");
|
||||
case FIT_TYPE_AC_BOOT_POLICY: return ("BootGuard Boot Policy ");
|
||||
case FIT_TYPE_EMPTY: return ("Empty ");
|
||||
default: return ("Unknown ");
|
||||
}
|
||||
}
|
||||
|
||||
STATUS FitParser::findFitRecursive(const QModelIndex & index, QModelIndex & found, UINT32 & fitOffset)
|
||||
USTATUS FitParser::findFitRecursive(const UModelIndex & index, UModelIndex & found, UINT32 & fitOffset)
|
||||
{
|
||||
// Sanity check
|
||||
if (!index.isValid())
|
||||
return ERR_SUCCESS;
|
||||
return U_SUCCESS;
|
||||
|
||||
// Process child items
|
||||
for (int i = 0; i < model->rowCount(index); i++) {
|
||||
findFitRecursive(index.child(i, 0), found, fitOffset);
|
||||
if (found.isValid())
|
||||
return ERR_SUCCESS;
|
||||
return U_SUCCESS;
|
||||
}
|
||||
|
||||
// Get parsing data for the current item
|
||||
PARSING_DATA pdata = parsingDataFromQModelIndex(index);
|
||||
PARSING_DATA pdata = parsingDataFromUModelIndex(index);
|
||||
|
||||
// Check for all FIT signatures in item's body
|
||||
for (INT32 offset = model->body(index).indexOf(FIT_SIGNATURE);
|
||||
|
@ -148,16 +148,16 @@ STATUS FitParser::findFitRecursive(const QModelIndex & index, QModelIndex & foun
|
|||
UINT32 fitAddress = pdata.address + model->header(index).size() + (UINT32)offset;
|
||||
|
||||
// Check FIT address to be in the last VTF
|
||||
QByteArray lastVtfBody = model->body(lastVtf);
|
||||
UByteArray lastVtfBody = model->body(lastVtf);
|
||||
if (*(const UINT32*)(lastVtfBody.constData() + lastVtfBody.size() - FIT_POINTER_OFFSET) == fitAddress) {
|
||||
found = index;
|
||||
fitOffset = offset;
|
||||
msg(QObject::tr("Real FIT table found at physical address %1h").hexarg(fitAddress), found);
|
||||
return ERR_SUCCESS;
|
||||
msg(usprintf("Real FIT table found at physical address %Xh", fitAddress), found);
|
||||
return U_SUCCESS;
|
||||
}
|
||||
else if (model->rowCount(index) == 0) // Show messages only to leaf items
|
||||
msg(QObject::tr("FIT table candidate found, but not referenced from the last VTF"), index);
|
||||
msg(("FIT table candidate found, but not referenced from the last VTF"), index);
|
||||
}
|
||||
|
||||
return ERR_SUCCESS;
|
||||
return U_SUCCESS;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue