From bf8632c0637fa16dc6743a90a7d8a30752afe3e6 Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Sun, 26 Jun 2016 05:54:21 +0200 Subject: [PATCH] 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 --- .gitmodules | 3 + UEFIExtract/ffsdumper.cpp | 45 +- UEFIExtract/ffsdumper.h | 13 +- UEFIExtract/uefiextract.pro | 16 +- UEFIExtract/uefiextract_main.cpp | 33 +- common/LZMA/LzmaDecompress.c | 6 +- common/basetypes.h | 98 +- common/ffs.cpp | 104 +- common/ffs.h | 64 +- common/ffsparser.cpp | 2484 +++++++++++++++--------------- common/ffsparser.h | 139 +- common/ffsreport.cpp | 40 +- common/ffsreport.h | 12 +- common/fitparser.cpp | 84 +- common/fitparser.h | 27 +- common/me.h | 4 +- common/nvram.cpp | 117 +- common/nvram.h | 58 +- common/peimage.cpp | 34 +- common/peimage.h | 1476 +++++++++--------- common/treeitem.cpp | 21 +- common/treeitem.h | 48 +- common/treemodel.cpp | 112 +- common/treemodel.h | 84 +- common/types.cpp | 200 ++- common/types.h | 12 +- common/ubytearray.h | 67 + common/umodelindex.h | 23 + common/ustring.cpp | 25 + common/ustring.h | 34 + common/utility.cpp | 166 +- common/utility.h | 16 +- 32 files changed, 2891 insertions(+), 2774 deletions(-) create mode 100644 .gitmodules create mode 100644 common/ubytearray.h create mode 100644 common/umodelindex.h create mode 100644 common/ustring.cpp create mode 100644 common/ustring.h diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2f51807 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "bstrlib"] + path = bstrlib + url = https://github.com/websnarf/bstrlib diff --git a/UEFIExtract/ffsdumper.cpp b/UEFIExtract/ffsdumper.cpp index 05db4a8..7e97448 100644 --- a/UEFIExtract/ffsdumper.cpp +++ b/UEFIExtract/ffsdumper.cpp @@ -22,48 +22,48 @@ FfsDumper::~FfsDumper() { } -STATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const bool dumpAll, const QString & guid) +USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const bool dumpAll, const UString & guid) { dumped = false; UINT8 result = recursiveDump(root, path, dumpAll, guid); if (result) return result; else if (!dumped) - return ERR_ITEM_NOT_FOUND; - return ERR_SUCCESS; + return U_ITEM_NOT_FOUND; + return U_SUCCESS; } -STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, const bool dumpAll, const QString & guid) +USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path, const bool dumpAll, const UString & guid) { if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; QDir dir; if (guid.isEmpty() || - guidToQString(*(const EFI_GUID*)model->header(index).constData()) == guid || - guidToQString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) { + guidToUString(*(const EFI_GUID*)model->header(index).constData()) == guid || + guidToUString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) { if (dir.cd(path)) - return ERR_DIR_ALREADY_EXIST; + return U_DIR_ALREADY_EXIST; if (!dir.mkpath(path)) - return ERR_DIR_CREATE; + return U_DIR_CREATE; QFile file; if (dumpAll || model->rowCount(index) == 0) { // Dump if leaf item or dumpAll is true if (!model->header(index).isEmpty()) { - file.setFileName(QObject::tr("%1/header.bin").arg(path)); + file.setFileName(path + UString("/header.bin")); if (!file.open(QFile::WriteOnly)) - return ERR_FILE_OPEN; + return U_FILE_OPEN; file.write(model->header(index)); file.close(); } if (!model->body(index).isEmpty()) { - file.setFileName(QObject::tr("%1/body.bin").arg(path)); + file.setFileName(path + UString("/body.bin")); if (!file.open(QFile::WriteOnly)) - return ERR_FILE_OPEN; + return U_FILE_OPEN; file.write(model->body(index)); file.close(); @@ -71,14 +71,13 @@ STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, } // Always dump info - QString info = QObject::tr("Type: %1\nSubtype: %2\n%3%4\n") - .arg(itemTypeToQString(model->type(index))) - .arg(itemSubtypeToQString(model->type(index), model->subtype(index))) - .arg(model->text(index).isEmpty() ? QObject::tr("") : QObject::tr("Text: %1\n").arg(model->text(index))) - .arg(model->info(index)); - file.setFileName(QObject::tr("%1/info.txt").arg(path)); + UString info = UString("Type: ") + itemTypeToUString(model->type(index)) + UString("\n") + + UString("Subtype: ") + itemSubtypeToUString(model->type(index), model->subtype(index)) + UString("\n") + + (model->text(index).isEmpty() ? UString("") : UString("Text: ") + model->text(index) + UString("\n")) + + model->info(index) + UString("\n"); + file.setFileName(path + UString("/info.txt")); if (!file.open(QFile::Text | QFile::WriteOnly)) - return ERR_FILE_OPEN; + return U_FILE_OPEN; file.write(info.toLatin1()); file.close(); @@ -87,16 +86,16 @@ STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, UINT8 result; for (int i = 0; i < model->rowCount(index); i++) { - QModelIndex childIndex = index.child(i, 0); + UModelIndex childIndex = index.child(i, 0); bool useText = FALSE; if (model->type(childIndex) != Types::Volume) useText = !model->text(childIndex).isEmpty(); - QString childPath = QString("%1/%2 %3").arg(path).arg(i).arg(useText ? model->text(childIndex) : model->name(childIndex)); + UString childPath = path + usprintf("/%u ", i) + (useText ? model->text(childIndex) : model->name(childIndex)); result = recursiveDump(childIndex, childPath, dumpAll, guid); if (result) return result; } - return ERR_SUCCESS; + return U_SUCCESS; } diff --git a/UEFIExtract/ffsdumper.h b/UEFIExtract/ffsdumper.h index 11ef4e8..23481e3 100644 --- a/UEFIExtract/ffsdumper.h +++ b/UEFIExtract/ffsdumper.h @@ -14,12 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #ifndef FFSDUMPER_H #define FFSDUMPER_H -#include -#include -#include -#include -#include +#include +#include "../common/ubytearray.h" +#include "../common/ustring.h" +#include "../common/umodelindex.h" #include "../common/basetypes.h" #include "../common/treemodel.h" #include "../common/ffs.h" @@ -30,10 +29,10 @@ public: explicit FfsDumper(TreeModel * treeModel); ~FfsDumper(); - STATUS dump(const QModelIndex & root, const QString & path, const bool dumpAll = false, const QString & guid = QString()); + USTATUS dump(const UModelIndex & root, const UString & path, const bool dumpAll = false, const UString & guid = UString()); private: - STATUS recursiveDump(const QModelIndex & root, const QString & path, const bool dumpAll, const QString & guid); + USTATUS recursiveDump(const UModelIndex & root, const UString & path, const bool dumpAll, const UString & guid); TreeModel* model; bool dumped; }; diff --git a/UEFIExtract/uefiextract.pro b/UEFIExtract/uefiextract.pro index 4cc84a8..63297d9 100644 --- a/UEFIExtract/uefiextract.pro +++ b/UEFIExtract/uefiextract.pro @@ -6,7 +6,8 @@ TEMPLATE = app CONFIG += console CONFIG -= app_bundle -SOURCES += uefiextract_main.cpp \ +SOURCES += \ + uefiextract_main.cpp \ ffsdumper.cpp \ ../common/types.cpp \ ../common/descriptor.cpp \ @@ -22,8 +23,12 @@ SOURCES += uefiextract_main.cpp \ ../common/LZMA/LzmaDecompress.c \ ../common/LZMA/SDK/C/LzmaDec.c \ ../common/Tiano/EfiTianoDecompress.c \ + ../common/ustring.cpp \ + ../bstrlib/bstrlib.c \ + ../bstrlib/bstrwrap.cpp -HEADERS += ffsdumper.h \ +HEADERS += \ + ffsdumper.h \ ../common/basetypes.h \ ../common/descriptor.h \ ../common/gbe.h \ @@ -39,5 +44,10 @@ HEADERS += ffsdumper.h \ ../common/treemodel.h \ ../common/utility.h \ ../common/LZMA/LzmaDecompress.h \ - ../common/Tiano/EfiTianoDecompress.h + ../common/Tiano/EfiTianoDecompress.h \ + ../common/umodelindex.h \ + ../common/ubytearray.h \ + ../common/ustring.h \ + ../bstrlib/bstrlib.h \ + ../bstrlib/bstrwrap.cpp diff --git a/UEFIExtract/uefiextract_main.cpp b/UEFIExtract/uefiextract_main.cpp index 6cbf3ec..37a7978 100644 --- a/UEFIExtract/uefiextract_main.cpp +++ b/UEFIExtract/uefiextract_main.cpp @@ -11,11 +11,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. */ #include -#include #include - #include +#include <../common/ustring.h> #include "../common/ffsparser.h" #include "../common/ffsreport.h" #include "../common/fitparser.h" @@ -35,51 +34,51 @@ int main(int argc, char *argv[]) if (a.arguments().length() > 1) { // Check that input file exists - QString path = a.arguments().at(1); + UString path = a.arguments().at(1); QFileInfo fileInfo(path); if (!fileInfo.exists()) - return ERR_FILE_OPEN; + return U_FILE_OPEN; // Open the input file QFile inputFile; inputFile.setFileName(path); if (!inputFile.open(QFile::ReadOnly)) - return ERR_FILE_OPEN; + return U_FILE_OPEN; // Read and close the file - QByteArray buffer = inputFile.readAll(); + UByteArray buffer = inputFile.readAll(); inputFile.close(); // Create model and ffsParser TreeModel model; FfsParser ffsParser(&model); // Parse input buffer - STATUS result = ffsParser.parse(buffer); + USTATUS result = ffsParser.parse(buffer); if (result) return result; // Show ffsParser's messages - std::vector > messages = ffsParser.getMessages(); + std::vector > messages = ffsParser.getMessages(); for (size_t i = 0; i < messages.size(); i++) { std::cout << messages[i].first.toLatin1().constData() << std::endl; } // Get last VTF - QModelIndex lastVtf = ffsParser.getLastVtf(); + UModelIndex lastVtf = ffsParser.getLastVtf(); if (lastVtf.isValid()) { // Create fitParser FitParser fitParser(&model); // Find and parse FIT table result = fitParser.parse(model.index(0, 0), lastVtf); - if (ERR_SUCCESS == result) { + if (U_SUCCESS == result) { // Show fitParser's messages - std::vector > fitMessages = fitParser.getMessages(); + std::vector > fitMessages = fitParser.getMessages(); for (size_t i = 0; i < fitMessages.size(); i++) { std::cout << fitMessages[i].first.toLatin1().constData() << std::endl; } // Show FIT table - std::vector > fitTable = fitParser.getFitTable(); + std::vector > fitTable = fitParser.getFitTable(); if (fitTable.size()) { std::cout << "-------------------------------------------------------------------" << std::endl; std::cout << " Address | Size | Ver | Type | CS " << std::endl; @@ -97,7 +96,7 @@ int main(int argc, char *argv[]) // Create ffsReport FfsReport ffsReport(&model); - std::vector report = ffsReport.generate(); + std::vector report = ffsReport.generate(); if (report.size()) { QFile file; file.setFileName(fileInfo.fileName().append(".report.txt")); @@ -114,12 +113,12 @@ int main(int argc, char *argv[]) // Dump all non-leaf elements if (a.arguments().length() == 2) { - return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != ERR_SUCCESS); + return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS); } - else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("all")) { // Dump everything - return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), true) != ERR_SUCCESS); + else if (a.arguments().length() == 3 && a.arguments().at(2) == UString("all")) { // Dump everything + return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), true) != U_SUCCESS); } - else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("none")) { // Skip dumping + else if (a.arguments().length() == 3 && a.arguments().at(2) == UString("none")) { // Skip dumping return 0; } else { // Dump specific files diff --git a/common/LZMA/LzmaDecompress.c b/common/LZMA/LzmaDecompress.c index 34e176d..1bac9d7 100644 --- a/common/LZMA/LzmaDecompress.c +++ b/common/LZMA/LzmaDecompress.c @@ -100,7 +100,7 @@ UINT32 *DestinationSize DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source); *DestinationSize = (UINT32)DecodedSize; - return ERR_SUCCESS; + return U_SUCCESS; } /* @@ -151,9 +151,9 @@ VOID *Destination ); if (LzmaResult == SZ_OK) { - return ERR_SUCCESS; + return U_SUCCESS; } else { - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; } } diff --git a/common/basetypes.h b/common/basetypes.h index 92356f3..9adac9c 100644 --- a/common/basetypes.h +++ b/common/basetypes.h @@ -17,6 +17,48 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include +typedef uint8_t USTATUS; +#define U_SUCCESS 0 +#define U_INVALID_PARAMETER 1 +#define U_BUFFER_TOO_SMALL 2 +#define U_OUT_OF_RESOURCES 3 +#define U_OUT_OF_MEMORY 4 +#define U_FILE_OPEN 5 +#define U_FILE_READ 6 +#define U_FILE_WRITE 7 +#define U_ITEM_NOT_FOUND 8 +#define U_UNKNOWN_ITEM_TYPE 9 +#define U_INVALID_FLASH_DESCRIPTOR 10 +#define U_INVALID_REGION 11 +#define U_EMPTY_REGION 12 +#define U_BIOS_REGION_NOT_FOUND 13 +#define U_VOLUMES_NOT_FOUND 14 +#define U_INVALID_VOLUME 15 +#define U_VOLUME_REVISION_NOT_SUPPORTED 16 +#define U_COMPLEX_BLOCK_MAP 17 +#define U_UNKNOWN_FFS 18 +#define U_INVALID_FILE 19 +#define U_INVALID_SECTION 20 +#define U_UNKNOWN_SECTION 21 +#define U_STANDARD_COMPRESSION_FAILED 22 +#define U_CUSTOMIZED_COMPRESSION_FAILED 23 +#define U_STANDARD_DECOMPRESSION_FAILED 24 +#define U_CUSTOMIZED_DECOMPRESSION_FAILED 25 +#define U_UNKNOWN_COMPRESSION_TYPE 26 +#define U_DEPEX_PARSE_FAILED 27 +#define U_UNKNOWN_EXTRACT_MODE 28 +#define U_UNKNOWN_REPLACE_MODE 29 +#define U_UNKNOWN_IMAGE_TYPE 30 +#define U_UNKNOWN_PE_OPTIONAL_HEADER_TYPE 31 +#define U_UNKNOWN_RELOCATION_TYPE 32 +#define U_DIR_ALREADY_EXIST 33 +#define U_DIR_CREATE 34 +#define U_TRUNCATED_IMAGE 35 +#define U_INVALID_CAPSULE 36 +#define U_STORES_NOT_FOUND 37 +#define U_NOT_IMPLEMENTED 0xFF + +// UDK porting definitions typedef uint8_t BOOLEAN; typedef int8_t INT8; typedef uint8_t UINT8; @@ -28,7 +70,7 @@ typedef int64_t INT64; typedef uint64_t UINT64; typedef char CHAR8; typedef uint16_t CHAR16; -typedef unsigned int UINTN; +typedef unsigned int UINTN; #define CONST const #define VOID void @@ -42,56 +84,14 @@ typedef unsigned int UINTN; #define FALSE ((BOOLEAN)(0==1)) #endif -typedef UINT8 STATUS; -#define ERR_SUCCESS 0 -#define ERR_INVALID_PARAMETER 1 -#define ERR_BUFFER_TOO_SMALL 2 -#define ERR_OUT_OF_RESOURCES 3 -#define ERR_OUT_OF_MEMORY 4 -#define ERR_FILE_OPEN 5 -#define ERR_FILE_READ 6 -#define ERR_FILE_WRITE 7 -#define ERR_ITEM_NOT_FOUND 8 -#define ERR_UNKNOWN_ITEM_TYPE 9 -#define ERR_INVALID_FLASH_DESCRIPTOR 10 -#define ERR_INVALID_REGION 11 -#define ERR_EMPTY_REGION 12 -#define ERR_BIOS_REGION_NOT_FOUND 13 -#define ERR_VOLUMES_NOT_FOUND 14 -#define ERR_INVALID_VOLUME 15 -#define ERR_VOLUME_REVISION_NOT_SUPPORTED 16 -#define ERR_COMPLEX_BLOCK_MAP 17 -#define ERR_UNKNOWN_FFS 18 -#define ERR_INVALID_FILE 19 -#define ERR_INVALID_SECTION 20 -#define ERR_UNKNOWN_SECTION 21 -#define ERR_STANDARD_COMPRESSION_FAILED 22 -#define ERR_CUSTOMIZED_COMPRESSION_FAILED 23 -#define ERR_STANDARD_DECOMPRESSION_FAILED 24 -#define ERR_CUSTOMIZED_DECOMPRESSION_FAILED 25 -#define ERR_UNKNOWN_COMPRESSION_TYPE 26 -#define ERR_DEPEX_PARSE_FAILED 27 -#define ERR_UNKNOWN_EXTRACT_MODE 28 -#define ERR_UNKNOWN_REPLACE_MODE 29 -#define ERR_UNKNOWN_IMAGE_TYPE 30 -#define ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE 31 -#define ERR_UNKNOWN_RELOCATION_TYPE 32 -#define ERR_DIR_ALREADY_EXIST 33 -#define ERR_DIR_CREATE 34 -#define ERR_TRUNCATED_IMAGE 35 -#define ERR_INVALID_CAPSULE 36 -#define ERR_STORES_NOT_FOUND 37 -#define ERR_NOT_IMPLEMENTED 0xFF - -// UDK porting definitions #define IN #define OUT #define EFIAPI #define EFI_STATUS UINTN -#define EFI_SUCCESS ERR_SUCCESS -#define EFI_INVALID_PARAMETER ERR_INVALID_PARAMETER -#define EFI_OUT_OF_RESOURCES ERR_OUT_OF_RESOURCES -#define EFI_BUFFER_TOO_SMALL ERR_BUFFER_TOO_SMALL +#define EFI_SUCCESS U_SUCCESS +#define EFI_INVALID_PARAMETER U_INVALID_PARAMETER +#define EFI_OUT_OF_RESOURCES U_OUT_OF_RESOURCES +#define EFI_BUFFER_TOO_SMALL U_BUFFER_TOO_SMALL #define EFI_ERROR(X) (X) // Compression algorithms @@ -162,10 +162,6 @@ typedef struct EFI_TIME_ { #include #define ASSERT(x) assert(x) -//Hexarg macros -#define hexarg(X) arg(QString("%1").arg((X),0,16).toUpper()) -#define hexarg2(X, Y) arg(QString("%1").arg((X),(Y),16,QLatin1Char('0')).toUpper()) - // SHA256 hash size in bytes #define SHA256_HASH_SIZE 0x20 diff --git a/common/ffs.cpp b/common/ffs.cpp index a7e8ce8..29ed276 100644 --- a/common/ffs.cpp +++ b/common/ffs.cpp @@ -10,11 +10,11 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. */ -#include +#include "ustring.h" #include "ffs.h" // This is a workaround for the lack of static std::vector initializer before C++11 -const QByteArray FFSv2VolumesInt[] = { +const UByteArray FFSv2VolumesInt[] = { EFI_FIRMWARE_FILE_SYSTEM_GUID, EFI_FIRMWARE_FILE_SYSTEM2_GUID, EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM_GUID, @@ -25,9 +25,9 @@ const QByteArray FFSv2VolumesInt[] = { }; // This number must be updated if the array above is grown #define FFSv2VolumesIntSize 7 -const std::vector FFSv2Volumes(FFSv2VolumesInt, FFSv2VolumesInt + FFSv2VolumesIntSize); +const std::vector FFSv2Volumes(FFSv2VolumesInt, FFSv2VolumesInt + FFSv2VolumesIntSize); // Luckily, FFSv3Volumes now only has 1 element -const std::vector FFSv3Volumes(1, EFI_FIRMWARE_FILE_SYSTEM3_GUID); +const std::vector FFSv3Volumes(1, EFI_FIRMWARE_FILE_SYSTEM3_GUID); const UINT8 ffsAlignmentTable[] = { 0, 4, 7, 9, 10, 12, 15, 16 }; @@ -44,66 +44,66 @@ UINT32 uint24ToUint32(const UINT8* ffsSize) return *(UINT32*)ffsSize & 0x00FFFFFF; } -QString guidToQString(const EFI_GUID & guid) +UString guidToUString(const EFI_GUID & guid) { - return QString("%1-%2-%3-%4%5-%6%7%8%9%10%11") - .arg(*(const UINT32*)&guid.Data[0], 8, 16, QChar('0')) - .arg(*(const UINT16*)&guid.Data[4], 4, 16, QChar('0')) - .arg(*(const UINT16*)&guid.Data[6], 4, 16, QChar('0')) - .arg(guid.Data[8], 2, 16, QChar('0')) - .arg(guid.Data[9], 2, 16, QChar('0')) - .arg(guid.Data[10], 2, 16, QChar('0')) - .arg(guid.Data[11], 2, 16, QChar('0')) - .arg(guid.Data[12], 2, 16, QChar('0')) - .arg(guid.Data[13], 2, 16, QChar('0')) - .arg(guid.Data[14], 2, 16, QChar('0')) - .arg(guid.Data[15], 2, 16, QChar('0')).toUpper(); + return usprintf("%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", + *(const UINT32*)&guid.Data[0], + *(const UINT16*)&guid.Data[4], + *(const UINT16*)&guid.Data[6], + guid.Data[8], + guid.Data[9], + guid.Data[10], + guid.Data[11], + guid.Data[12], + guid.Data[13], + guid.Data[14], + guid.Data[15]); } -QString fileTypeToQString(const UINT8 type) +UString fileTypeToUString(const UINT8 type) { switch (type) { - case EFI_FV_FILETYPE_RAW: return QObject::tr("Raw"); - case EFI_FV_FILETYPE_FREEFORM: return QObject::tr("Freeform"); - case EFI_FV_FILETYPE_SECURITY_CORE: return QObject::tr("SEC core"); - case EFI_FV_FILETYPE_PEI_CORE: return QObject::tr("PEI core"); - case EFI_FV_FILETYPE_DXE_CORE: return QObject::tr("DXE core"); - case EFI_FV_FILETYPE_PEIM: return QObject::tr("PEI module"); - case EFI_FV_FILETYPE_DRIVER: return QObject::tr("DXE driver"); - case EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER: return QObject::tr("Combined PEI/DXE"); - case EFI_FV_FILETYPE_APPLICATION: return QObject::tr("Application"); - case EFI_FV_FILETYPE_SMM: return QObject::tr("SMM module"); - case EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE: return QObject::tr("Volume image"); - case EFI_FV_FILETYPE_COMBINED_SMM_DXE: return QObject::tr("Combined SMM/DXE"); - case EFI_FV_FILETYPE_SMM_CORE: return QObject::tr("SMM core"); - case EFI_FV_FILETYPE_PAD: return QObject::tr("Pad"); - default: return QObject::tr("Unknown"); + case EFI_FV_FILETYPE_RAW: return UString("Raw"); + case EFI_FV_FILETYPE_FREEFORM: return UString("Freeform"); + case EFI_FV_FILETYPE_SECURITY_CORE: return UString("SEC core"); + case EFI_FV_FILETYPE_PEI_CORE: return UString("PEI core"); + case EFI_FV_FILETYPE_DXE_CORE: return UString("DXE core"); + case EFI_FV_FILETYPE_PEIM: return UString("PEI module"); + case EFI_FV_FILETYPE_DRIVER: return UString("DXE driver"); + case EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER: return UString("Combined PEI/DXE"); + case EFI_FV_FILETYPE_APPLICATION: return UString("Application"); + case EFI_FV_FILETYPE_SMM: return UString("SMM module"); + case EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE: return UString("Volume image"); + case EFI_FV_FILETYPE_COMBINED_SMM_DXE: return UString("Combined SMM/DXE"); + case EFI_FV_FILETYPE_SMM_CORE: return UString("SMM core"); + case EFI_FV_FILETYPE_PAD: return UString("Pad"); + default: return UString("Unknown"); }; } -QString sectionTypeToQString(const UINT8 type) +UString sectionTypeToUString(const UINT8 type) { switch (type) { - case EFI_SECTION_COMPRESSION: return QObject::tr("Compressed"); - case EFI_SECTION_GUID_DEFINED: return QObject::tr("GUID defined"); - case EFI_SECTION_DISPOSABLE: return QObject::tr("Disposable"); - case EFI_SECTION_PE32: return QObject::tr("PE32 image"); - case EFI_SECTION_PIC: return QObject::tr("PIC image"); - case EFI_SECTION_TE: return QObject::tr("TE image"); - case EFI_SECTION_DXE_DEPEX: return QObject::tr("DXE dependency"); - case EFI_SECTION_VERSION: return QObject::tr("Version"); - case EFI_SECTION_USER_INTERFACE: return QObject::tr("UI"); - case EFI_SECTION_COMPATIBILITY16: return QObject::tr("16-bit image"); - case EFI_SECTION_FIRMWARE_VOLUME_IMAGE: return QObject::tr("Volume image"); - case EFI_SECTION_FREEFORM_SUBTYPE_GUID: return QObject::tr("Freeform subtype GUID"); - case EFI_SECTION_RAW: return QObject::tr("Raw"); - case EFI_SECTION_PEI_DEPEX: return QObject::tr("PEI dependency"); - case EFI_SECTION_SMM_DEPEX: return QObject::tr("SMM dependency"); - case INSYDE_SECTION_POSTCODE: return QObject::tr("Insyde postcode"); - case PHOENIX_SECTION_POSTCODE: return QObject::tr("Phoenix postcode"); - default: return QObject::tr("Unknown"); + case EFI_SECTION_COMPRESSION: return UString("Compressed"); + case EFI_SECTION_GUID_DEFINED: return UString("GUID defined"); + case EFI_SECTION_DISPOSABLE: return UString("Disposable"); + case EFI_SECTION_PE32: return UString("PE32 image"); + case EFI_SECTION_PIC: return UString("PIC image"); + case EFI_SECTION_TE: return UString("TE image"); + case EFI_SECTION_DXE_DEPEX: return UString("DXE dependency"); + case EFI_SECTION_VERSION: return UString("Version"); + case EFI_SECTION_USER_INTERFACE: return UString("UI"); + case EFI_SECTION_COMPATIBILITY16: return UString("16-bit image"); + case EFI_SECTION_FIRMWARE_VOLUME_IMAGE: return UString("Volume image"); + case EFI_SECTION_FREEFORM_SUBTYPE_GUID: return UString("Freeform subtype GUID"); + case EFI_SECTION_RAW: return UString("Raw"); + case EFI_SECTION_PEI_DEPEX: return UString("PEI dependency"); + case EFI_SECTION_SMM_DEPEX: return UString("SMM dependency"); + case INSYDE_SECTION_POSTCODE: return UString("Insyde postcode"); + case PHOENIX_SECTION_POSTCODE: return UString("Phoenix postcode"); + default: return UString("Unknown"); } } diff --git a/common/ffs.h b/common/ffs.h index ade17b3..1c12ce6 100644 --- a/common/ffs.h +++ b/common/ffs.h @@ -15,16 +15,16 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include -#include -#include +#include "ubytearray.h" +#include "ustring.h" #include "basetypes.h" // Make sure we use right packing rules #pragma pack(push,1) -extern QString guidToQString(const EFI_GUID& guid); -extern QString fileTypeToQString(const UINT8 type); -extern QString sectionTypeToQString(const UINT8 type); +extern UString guidToUString(const EFI_GUID& guid); +extern UString fileTypeToUString(const UINT8 type); +extern UString sectionTypeToUString(const UINT8 type); //***************************************************************************** // EFI Capsule @@ -43,19 +43,19 @@ typedef struct EFI_CAPSULE_HEADER_ { #define EFI_CAPSULE_HEADER_FLAG_POPULATE_SYSTEM_TABLE 0x00020000 // Standard EFI capsule GUID -const QByteArray EFI_CAPSULE_GUID +const UByteArray EFI_CAPSULE_GUID ("\xBD\x86\x66\x3B\x76\x0D\x30\x40\xB7\x0E\xB5\x51\x9E\x2F\xC5\xA0", 16); // Intel capsule GUID -const QByteArray INTEL_CAPSULE_GUID +const UByteArray INTEL_CAPSULE_GUID ("\xB9\x82\x91\x53\xB5\xAB\x91\x43\xB6\x9A\xE3\xA9\x43\xF7\x2F\xCC", 16); // Lenovo capsule GUID -const QByteArray LENOVO_CAPSULE_GUID +const UByteArray LENOVO_CAPSULE_GUID ("\xD3\xAF\x0B\xE2\x14\x99\x4F\x4F\x95\x37\x31\x29\xE0\x90\xEB\x3C", 16); // Another Lenovo capsule GUID -const QByteArray LENOVO2_CAPSULE_GUID +const UByteArray LENOVO2_CAPSULE_GUID ("\x76\xFE\xB5\x25\x43\x82\x5C\x4A\xA9\xBD\x7E\xE3\x24\x61\x98\xB5", 16); // Toshiba EFI Capsule header @@ -67,7 +67,7 @@ typedef struct TOSHIBA_CAPSULE_HEADER_ { } TOSHIBA_CAPSULE_HEADER; // Toshiba capsule GUID -const QByteArray TOSHIBA_CAPSULE_GUID +const UByteArray TOSHIBA_CAPSULE_GUID ("\x62\x70\xE0\x3B\x51\x1D\xD2\x45\x83\x2B\xF0\x93\x25\x7E\xD4\x61", 16); // AMI Aptio extended capsule header @@ -80,11 +80,11 @@ typedef struct APTIO_CAPSULE_HEADER_ { } APTIO_CAPSULE_HEADER; // AMI Aptio signed extended capsule GUID -const QByteArray APTIO_SIGNED_CAPSULE_GUID +const UByteArray APTIO_SIGNED_CAPSULE_GUID ("\x8B\xA6\x3C\x4A\x23\x77\xFB\x48\x80\x3D\x57\x8C\xC1\xFE\xC4\x4D", 16); // AMI Aptio unsigned extended capsule GUID -const QByteArray APTIO_UNSIGNED_CAPSULE_GUID +const UByteArray APTIO_UNSIGNED_CAPSULE_GUID ("\x90\xBB\xEE\x14\x0A\x89\xDB\x43\xAE\xD1\x5D\x3C\x45\x88\xA4\x18", 16); //***************************************************************************** @@ -113,38 +113,38 @@ typedef struct EFI_FIRMWARE_VOLUME_HEADER_ { } EFI_FIRMWARE_VOLUME_HEADER; // Standard file system GUIDs -const QByteArray EFI_FIRMWARE_FILE_SYSTEM_GUID +const UByteArray EFI_FIRMWARE_FILE_SYSTEM_GUID ("\xD9\x54\x93\x7A\x68\x04\x4A\x44\x81\xCE\x0B\xF6\x17\xD8\x90\xDF", 16); -const QByteArray EFI_FIRMWARE_FILE_SYSTEM2_GUID +const UByteArray EFI_FIRMWARE_FILE_SYSTEM2_GUID ("\x78\xE5\x8C\x8C\x3D\x8A\x1C\x4F\x99\x35\x89\x61\x85\xC3\x2D\xD3", 16); // Vendor-specific file system GUIDs -const QByteArray EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM_GUID +const UByteArray EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM_GUID ("\xAD\xEE\xAD\x04\xFF\x61\x31\x4D\xB6\xBA\x64\xF8\xBF\x90\x1F\x5A", 16); -const QByteArray EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM2_GUID +const UByteArray EFI_APPLE_BOOT_VOLUME_FILE_SYSTEM2_GUID ("\x8C\x1B\x00\xBD\x71\x6A\x7B\x48\xA1\x4F\x0C\x2A\x2D\xCF\x7A\x5D", 16); // AD3FFFFF-D28B-44C4-9F13-9EA98A97F9F0 // Intel 1 -const QByteArray EFI_INTEL_FILE_SYSTEM_GUID +const UByteArray EFI_INTEL_FILE_SYSTEM_GUID ("\xFF\xFF\x3F\xAD\x8B\xD2\xC4\x44\x9F\x13\x9E\xA9\x8A\x97\xF9\xF0", 16); // D6A1CD70-4B33-4994-A6EA-375F2CCC5437 // Intel 2 -const QByteArray EFI_INTEL_FILE_SYSTEM2_GUID +const UByteArray EFI_INTEL_FILE_SYSTEM2_GUID ("\x70\xCD\xA1\xD6\x33\x4B\x94\x49\xA6\xEA\x37\x5F\x2C\xCC\x54\x37", 16); // 4F494156-AED6-4D64-A537-B8A5557BCEEC // Sony 1 -const QByteArray EFI_SONY_FILE_SYSTEM_GUID +const UByteArray EFI_SONY_FILE_SYSTEM_GUID ("\x56\x41\x49\x4F\xD6\xAE\x64\x4D\xA5\x37\xB8\xA5\x55\x7B\xCE\xEC", 16); // Vector of volume GUIDs with FFSv2-compatible files -extern const std::vector FFSv2Volumes; +extern const std::vector FFSv2Volumes; -const QByteArray EFI_FIRMWARE_FILE_SYSTEM3_GUID // 5473C07A-3DCB-4DCA-BD6F-1E9689E7349A +const UByteArray EFI_FIRMWARE_FILE_SYSTEM3_GUID // 5473C07A-3DCB-4DCA-BD6F-1E9689E7349A ("\x7A\xC0\x73\x54\xCB\x3D\xCA\x4D\xBD\x6F\x1E\x96\x89\xE7\x34\x9A", 16); // Vector of volume GUIDs with FFSv3-compatible files -extern const std::vector FFSv3Volumes; +extern const std::vector FFSv3Volumes; // Firmware volume signature -const QByteArray EFI_FV_SIGNATURE("_FVH", 4); +const UByteArray EFI_FV_SIGNATURE("_FVH", 4); #define EFI_FV_SIGNATURE_OFFSET 0x28 // Firmware volume attributes @@ -338,19 +338,19 @@ extern const UINT8 ffsAlignmentTable[]; #define EFI_FILE_HEADER_INVALID 0x20 // PEI apriori file -const QByteArray EFI_PEI_APRIORI_FILE_GUID +const UByteArray EFI_PEI_APRIORI_FILE_GUID ("\x0A\xCC\x45\x1B\x6A\x15\x8A\x42\xAF\x62\x49\x86\x4D\xA0\xE6\xE6", 16); // DXE apriori file -const QByteArray EFI_DXE_APRIORI_FILE_GUID +const UByteArray EFI_DXE_APRIORI_FILE_GUID ("\xE7\x0E\x51\xFC\xDC\xFF\xD4\x11\xBD\x41\x00\x80\xC7\x3C\x88\x81", 16); // Volume top file -const QByteArray EFI_FFS_VOLUME_TOP_FILE_GUID +const UByteArray EFI_FFS_VOLUME_TOP_FILE_GUID ("\x2E\x06\xA0\x1B\x79\xC7\x82\x45\x85\x66\x33\x6A\xE8\xF7\x8F\x09", 16); // Pad file GUID -const QByteArray EFI_FFS_PAD_FILE_GUID +const UByteArray EFI_FFS_PAD_FILE_GUID ("\x85\x65\x53\xE4\x09\x79\x60\x4A\xB5\xC6\xEC\xDE\xA6\xEB\xFB\x54", 16); // FFS size conversion routines @@ -445,16 +445,16 @@ typedef struct EFI_GUID_DEFINED_SECTION_APPLE_ { #define EFI_GUIDED_SECTION_AUTH_STATUS_VALID 0x02 // GUIDs of GUID-defined sections -const QByteArray EFI_GUIDED_SECTION_CRC32 // FC1BCDB0-7D31-49AA-936A-A4600D9DD083 +const UByteArray EFI_GUIDED_SECTION_CRC32 // FC1BCDB0-7D31-49AA-936A-A4600D9DD083 ("\xB0\xCD\x1B\xFC\x31\x7D\xAA\x49\x93\x6A\xA4\x60\x0D\x9D\xD0\x83", 16); -const QByteArray EFI_GUIDED_SECTION_TIANO // A31280AD-481E-41B6-95E8-127F4C984779 +const UByteArray EFI_GUIDED_SECTION_TIANO // A31280AD-481E-41B6-95E8-127F4C984779 ("\xAD\x80\x12\xA3\x1E\x48\xB6\x41\x95\xE8\x12\x7F\x4C\x98\x47\x79", 16); -const QByteArray EFI_GUIDED_SECTION_LZMA // EE4E5898-3914-4259-9D6E-DC7BD79403CF +const UByteArray EFI_GUIDED_SECTION_LZMA // EE4E5898-3914-4259-9D6E-DC7BD79403CF ("\x98\x58\x4E\xEE\x14\x39\x59\x42\x9D\x6E\xDC\x7B\xD7\x94\x03\xCF", 16); -const QByteArray EFI_FIRMWARE_CONTENTS_SIGNED_GUID // 0F9D89E8-9259-4F76-A5AF-0C89E34023DF +const UByteArray EFI_FIRMWARE_CONTENTS_SIGNED_GUID // 0F9D89E8-9259-4F76-A5AF-0C89E34023DF ("\xE8\x89\x9D\x0F\x59\x92\x76\x4F\xA5\xAF\x0C\x89\xE3\x40\x23\xDF", 16); //#define WIN_CERT_TYPE_PKCS_SIGNED_DATA 0x0002 @@ -474,7 +474,7 @@ typedef struct WIN_CERTIFICATE_UEFI_GUID_ { } WIN_CERTIFICATE_UEFI_GUID; // WIN_CERTIFICATE_UEFI_GUID.CertType -const QByteArray EFI_CERT_TYPE_RSA2048_SHA256_GUID +const UByteArray EFI_CERT_TYPE_RSA2048_SHA256_GUID ("\x14\x74\x71\xA7\x16\xC6\x77\x49\x94\x20\x84\x47\x12\xA7\x35\xBF"); // WIN_CERTIFICATE_UEFI_GUID.CertData diff --git a/common/ffsparser.cpp b/common/ffsparser.cpp index 88810bd..f3880e7 100644 --- a/common/ffsparser.cpp +++ b/common/ffsparser.cpp @@ -20,15 +20,15 @@ struct REGION_INFO { UINT32 offset; UINT32 length; UINT8 type; - QByteArray data; + UByteArray data; friend bool operator< (const REGION_INFO & lhs, const REGION_INFO & rhs){ return lhs.offset < rhs.offset; } }; // Firmware image parsing functions -STATUS FfsParser::parse(const QByteArray & buffer) +USTATUS FfsParser::parse(const UByteArray & buffer) { - QModelIndex root; - STATUS result = performFirstPass(buffer, root); + UModelIndex root; + USTATUS result = performFirstPass(buffer, root); addOffsetsRecursive(root); if (result) return result; @@ -36,20 +36,20 @@ STATUS FfsParser::parse(const QByteArray & buffer) if (lastVtf.isValid()) result = performSecondPass(root); else - msg(QObject::tr("parse: not a single Volume Top File is found, the image may be corrupted")); + msg(("parse: not a single Volume Top File is found, the image may be corrupted")); return result; } -STATUS FfsParser::performFirstPass(const QByteArray & buffer, QModelIndex & index) +USTATUS FfsParser::performFirstPass(const UByteArray & buffer, UModelIndex & index) { // Reset capsule offset fixup value capsuleOffsetFixup = 0; // Check buffer size to be more than or equal to size of EFI_CAPSULE_HEADER if ((UINT32)buffer.size() <= sizeof(EFI_CAPSULE_HEADER)) { - msg(QObject::tr("performFirstPass: image file is smaller than minimum size of %1h (%2) bytes").hexarg(sizeof(EFI_CAPSULE_HEADER)).arg(sizeof(EFI_CAPSULE_HEADER))); - return ERR_INVALID_PARAMETER; + msg(UString("performFirstPass: image file is smaller than minimum size of 1Ch (28) bytes")); + return U_INVALID_PARAMETER; } UINT32 capsuleHeaderSize = 0; @@ -63,32 +63,34 @@ STATUS FfsParser::performFirstPass(const QByteArray & buffer, QModelIndex & inde // Check sanity of HeaderSize and CapsuleImageSize values if (capsuleHeader->HeaderSize == 0 || capsuleHeader->HeaderSize > (UINT32)buffer.size() || capsuleHeader->HeaderSize > capsuleHeader->CapsuleImageSize) { - msg(QObject::tr("performFirstPass: UEFI capsule header size of %1h (%2) bytes is invalid") - .hexarg(capsuleHeader->HeaderSize).arg(capsuleHeader->HeaderSize)); - return ERR_INVALID_CAPSULE; + msg(usprintf("performFirstPass: UEFI capsule header size of %Xh (%u) bytes is invalid", + capsuleHeader->HeaderSize, + capsuleHeader->HeaderSize)); + return U_INVALID_CAPSULE; } if (capsuleHeader->CapsuleImageSize == 0 || capsuleHeader->CapsuleImageSize > (UINT32)buffer.size()) { - msg(QObject::tr("performFirstPass: UEFI capsule image size of %1h (%2) bytes is invalid") - .hexarg(capsuleHeader->CapsuleImageSize).arg(capsuleHeader->CapsuleImageSize)); - return ERR_INVALID_CAPSULE; + msg(usprintf("performFirstPass: UEFI capsule image size of %Xh (%u) bytes is invalid", + capsuleHeader->CapsuleImageSize, + capsuleHeader->CapsuleImageSize)); + return U_INVALID_CAPSULE; } capsuleHeaderSize = capsuleHeader->HeaderSize; - QByteArray header = buffer.left(capsuleHeaderSize); - QByteArray body = buffer.mid(capsuleHeaderSize); - QString name = QObject::tr("UEFI capsule"); - QString info = QObject::tr("Capsule GUID: %1\nFull size: %2h (%3)\nHeader size: %4h (%5)\nImage size: %6h (%7)\nFlags: %8h") - .arg(guidToQString(capsuleHeader->CapsuleGuid)) - .hexarg(buffer.size()).arg(buffer.size()) - .hexarg(capsuleHeaderSize).arg(capsuleHeaderSize) - .hexarg(capsuleHeader->CapsuleImageSize - capsuleHeaderSize).arg(capsuleHeader->CapsuleImageSize - capsuleHeaderSize) - .hexarg2(capsuleHeader->Flags, 8); + UByteArray header = buffer.left(capsuleHeaderSize); + UByteArray body = buffer.mid(capsuleHeaderSize); + UString name("UEFI capsule"); + UString info = UString("Capsule GUID: ") + guidToUString(capsuleHeader->CapsuleGuid) + + usprintf("\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nImage size: %Xh (%u)\nFlags: %08Xh", + buffer.size(), buffer.size(), + capsuleHeaderSize, capsuleHeaderSize, + capsuleHeader->CapsuleImageSize - capsuleHeaderSize, capsuleHeader->CapsuleImageSize - capsuleHeaderSize, + capsuleHeader->Flags); // Set capsule offset fixup for correct volume allignment warnings capsuleOffsetFixup = capsuleHeaderSize; // Add tree item - index = model->addItem(Types::Capsule, Subtypes::UefiCapsule, name, QString(), info, header, body, QByteArray(), true); + index = model->addItem(Types::Capsule, Subtypes::UefiCapsule, name, UString(), info, header, body, UByteArray(), true); } // Check buffer for being Toshiba capsule header else if (buffer.startsWith(TOSHIBA_CAPSULE_GUID)) { @@ -97,40 +99,40 @@ STATUS FfsParser::performFirstPass(const QByteArray & buffer, QModelIndex & inde // Check sanity of HeaderSize and FullSize values if (capsuleHeader->HeaderSize == 0 || capsuleHeader->HeaderSize > (UINT32)buffer.size() || capsuleHeader->HeaderSize > capsuleHeader->FullSize) { - msg(QObject::tr("performFirstPass: Toshiba capsule header size of %1h (%2) bytes is invalid") - .hexarg(capsuleHeader->HeaderSize).arg(capsuleHeader->HeaderSize)); - return ERR_INVALID_CAPSULE; + msg(usprintf("performFirstPass: Toshiba capsule header size of %Xh (%u) bytes is invalid", + capsuleHeader->HeaderSize, capsuleHeader->HeaderSize)); + return U_INVALID_CAPSULE; } if (capsuleHeader->FullSize == 0 || capsuleHeader->FullSize > (UINT32)buffer.size()) { - msg(QObject::tr("performFirstPass: Toshiba capsule full size of %1h (%2) bytes is invalid") - .hexarg(capsuleHeader->FullSize).arg(capsuleHeader->FullSize)); - return ERR_INVALID_CAPSULE; + msg(usprintf("performFirstPass: Toshiba capsule full size of %Xh (%u) bytes is invalid", + capsuleHeader->FullSize, capsuleHeader->FullSize)); + return U_INVALID_CAPSULE; } capsuleHeaderSize = capsuleHeader->HeaderSize; - QByteArray header = buffer.left(capsuleHeaderSize); - QByteArray body = buffer.right(buffer.size() - capsuleHeaderSize); - QString name = QObject::tr("Toshiba capsule"); - QString info = QObject::tr("Capsule GUID: %1\nFull size: %2h (%3)\nHeader size: %4h (%5)\nImage size: %6h (%7)\nFlags: %8h") - .arg(guidToQString(capsuleHeader->CapsuleGuid)) - .hexarg(buffer.size()).arg(buffer.size()) - .hexarg(capsuleHeaderSize).arg(capsuleHeaderSize) - .hexarg(capsuleHeader->FullSize - capsuleHeaderSize).arg(capsuleHeader->FullSize - capsuleHeaderSize) - .hexarg2(capsuleHeader->Flags, 8); + UByteArray header = buffer.left(capsuleHeaderSize); + UByteArray body = buffer.right(buffer.size() - capsuleHeaderSize); + UString name("Toshiba capsule"); + UString info = UString("Capsule GUID: ") + guidToUString(capsuleHeader->CapsuleGuid) + + usprintf("\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nImage size: %Xh (%u)\nFlags: %08Xh", + buffer.size(), buffer.size(), + capsuleHeaderSize, capsuleHeaderSize, + capsuleHeader->FullSize - capsuleHeaderSize, capsuleHeader->FullSize - capsuleHeaderSize, + capsuleHeader->Flags); // Set capsule offset fixup for correct volume allignment warnings capsuleOffsetFixup = capsuleHeaderSize; // Add tree item - index = model->addItem(Types::Capsule, Subtypes::ToshibaCapsule, name, QString(), info, header, body, QByteArray(), true); + index = model->addItem(Types::Capsule, Subtypes::ToshibaCapsule, name, UString(), info, header, body, UByteArray(), true); } // Check buffer for being extended Aptio capsule header else if (buffer.startsWith(APTIO_SIGNED_CAPSULE_GUID) || buffer.startsWith(APTIO_UNSIGNED_CAPSULE_GUID)) { bool signedCapsule = buffer.startsWith(APTIO_SIGNED_CAPSULE_GUID); if ((UINT32)buffer.size() <= sizeof(APTIO_CAPSULE_HEADER)) { - msg(QObject::tr("performFirstPass: AMI capsule image file is smaller than minimum size of %1h (%2) bytes").hexarg(sizeof(APTIO_CAPSULE_HEADER)).arg(sizeof(APTIO_CAPSULE_HEADER))); - return ERR_INVALID_PARAMETER; + msg(UString("performFirstPass: AMI capsule image file is smaller than minimum size of 20h (32) bytes")); + return U_INVALID_PARAMETER; } // Get info @@ -138,50 +140,53 @@ STATUS FfsParser::performFirstPass(const QByteArray & buffer, QModelIndex & inde // Check sanity of RomImageOffset and CapsuleImageSize values if (capsuleHeader->RomImageOffset == 0 || capsuleHeader->RomImageOffset > (UINT32)buffer.size() || capsuleHeader->RomImageOffset > capsuleHeader->CapsuleHeader.CapsuleImageSize) { - msg(QObject::tr("performFirstPass: AMI capsule image offset of %1h (%2) bytes is invalid").hexarg(capsuleHeader->RomImageOffset).arg(capsuleHeader->RomImageOffset)); - return ERR_INVALID_CAPSULE; + msg(usprintf("performFirstPass: AMI capsule image offset of %Xh (%u) bytes is invalid", + capsuleHeader->RomImageOffset, capsuleHeader->RomImageOffset)); + return U_INVALID_CAPSULE; } if (capsuleHeader->CapsuleHeader.CapsuleImageSize == 0 || capsuleHeader->CapsuleHeader.CapsuleImageSize > (UINT32)buffer.size()) { - msg(QObject::tr("performFirstPass: AMI capsule image size of %1h (%2) bytes is invalid").hexarg(capsuleHeader->CapsuleHeader.CapsuleImageSize).arg(capsuleHeader->CapsuleHeader.CapsuleImageSize)); - return ERR_INVALID_CAPSULE; + msg(usprintf("performFirstPass: AMI capsule image size of %Xh (%u) bytes is invalid", + capsuleHeader->CapsuleHeader.CapsuleImageSize, + capsuleHeader->CapsuleHeader.CapsuleImageSize)); + return U_INVALID_CAPSULE; } capsuleHeaderSize = capsuleHeader->RomImageOffset; - QByteArray header = buffer.left(capsuleHeaderSize); - QByteArray body = buffer.mid(capsuleHeaderSize); - QString name = QObject::tr("AMI Aptio capsule"); - QString info = QObject::tr("Capsule GUID: %1\nFull size: %2h (%3)\nHeader size: %4h (%5)\nImage size: %6h (%7)\nFlags: %8h") - .arg(guidToQString(capsuleHeader->CapsuleHeader.CapsuleGuid)) - .hexarg(buffer.size()).arg(buffer.size()) - .hexarg(capsuleHeaderSize).arg(capsuleHeaderSize) - .hexarg(capsuleHeader->CapsuleHeader.CapsuleImageSize - capsuleHeaderSize).arg(capsuleHeader->CapsuleHeader.CapsuleImageSize - capsuleHeaderSize) - .hexarg2(capsuleHeader->CapsuleHeader.Flags, 8); + UByteArray header = buffer.left(capsuleHeaderSize); + UByteArray body = buffer.mid(capsuleHeaderSize); + UString name("AMI Aptio capsule"); + UString info = UString("Capsule GUID: ") + guidToUString(capsuleHeader->CapsuleHeader.CapsuleGuid) + + usprintf("\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nImage size: %Xh (%u)\nFlags: %08Xh", + buffer.size(), buffer.size(), + capsuleHeaderSize, capsuleHeaderSize, + capsuleHeader->CapsuleHeader.CapsuleImageSize - capsuleHeaderSize, capsuleHeader->CapsuleHeader.CapsuleImageSize - capsuleHeaderSize, + capsuleHeader->CapsuleHeader.Flags); // Set capsule offset fixup for correct volume allignment warnings capsuleOffsetFixup = capsuleHeaderSize; // Add tree item - index = model->addItem(Types::Capsule, signedCapsule ? Subtypes::AptioSignedCapsule : Subtypes::AptioUnsignedCapsule, name, QString(), info, header, body, QByteArray(), true); + index = model->addItem(Types::Capsule, signedCapsule ? Subtypes::AptioSignedCapsule : Subtypes::AptioUnsignedCapsule, name, UString(), info, header, body, UByteArray(), true); // Show message about possible Aptio signature break if (signedCapsule) { - msg(QObject::tr("performFirstPass: Aptio capsule signature may become invalid after image modifications"), index); + msg(UString("performFirstPass: Aptio capsule signature may become invalid after image modifications"), index); } } // Skip capsule header to have flash chip image - QByteArray flashImage = buffer.mid(capsuleHeaderSize); + UByteArray flashImage = buffer.mid(capsuleHeaderSize); // Check for Intel flash descriptor presence const FLASH_DESCRIPTOR_HEADER* descriptorHeader = (const FLASH_DESCRIPTOR_HEADER*)flashImage.constData(); // Check descriptor signature - STATUS result; + USTATUS result; if (descriptorHeader->Signature == FLASH_DESCRIPTOR_SIGNATURE) { // Parse as Intel image - QModelIndex imageIndex; + UModelIndex imageIndex; result = parseIntelImage(flashImage, capsuleHeaderSize, index, imageIndex); - if (result != ERR_INVALID_FLASH_DESCRIPTOR) { + if (result != U_INVALID_FLASH_DESCRIPTOR) { if (!index.isValid()) index = imageIndex; return result; @@ -189,15 +194,15 @@ STATUS FfsParser::performFirstPass(const QByteArray & buffer, QModelIndex & inde } // Get info - QString name = QObject::tr("UEFI image"); - QString info = QObject::tr("Full size: %1h (%2)").hexarg(flashImage.size()).arg(flashImage.size()); + UString name("UEFI image"); + UString info = usprintf("Full size: %Xh (%u)", flashImage.size(), flashImage.size()); // Construct parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); pdata.offset = capsuleHeaderSize; // Add tree item - QModelIndex biosIndex = model->addItem(Types::Image, Subtypes::UefiImage, name, QString(), info, QByteArray(), flashImage, QByteArray(), true, parsingDataToQByteArray(pdata), index); + UModelIndex biosIndex = model->addItem(Types::Image, Subtypes::UefiImage, name, UString(), info, UByteArray(), flashImage, UByteArray(), true, parsingDataToUByteArray(pdata), index); // Parse the image result = parseRawArea(biosIndex); @@ -206,22 +211,22 @@ STATUS FfsParser::performFirstPass(const QByteArray & buffer, QModelIndex & inde return result; } -STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseIntelImage(const UByteArray & intelImage, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { // Sanity check if (intelImage.isEmpty()) return EFI_INVALID_PARAMETER; // Get parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Store the beginning of descriptor as descriptor base address const UINT8* descriptor = (const UINT8*)intelImage.constData(); // Check for buffer size to be greater or equal to descriptor region size if (intelImage.size() < FLASH_DESCRIPTOR_SIZE) { - msg(QObject::tr("parseIntelImage: input file is smaller than minimum descriptor size of %1h (%2) bytes").hexarg(FLASH_DESCRIPTOR_SIZE).arg(FLASH_DESCRIPTOR_SIZE)); - return ERR_INVALID_FLASH_DESCRIPTOR; + msg(usprintf("parseIntelImage: input file is smaller than minimum descriptor size of %X (%u) bytes", FLASH_DESCRIPTOR_SIZE, FLASH_DESCRIPTOR_SIZE)); + return U_INVALID_FLASH_DESCRIPTOR; } // Parse descriptor map @@ -232,17 +237,17 @@ STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 pa if (descriptorMap->MasterBase > FLASH_DESCRIPTOR_MAX_BASE || descriptorMap->MasterBase == descriptorMap->RegionBase || descriptorMap->MasterBase == descriptorMap->ComponentBase) { - msg(QObject::tr("parseIntelImage: invalid descriptor master base %1h").hexarg2(descriptorMap->MasterBase, 2)); - return ERR_INVALID_FLASH_DESCRIPTOR; + msg(usprintf("parseIntelImage: invalid descriptor master base %02Xh", descriptorMap->MasterBase)); + return U_INVALID_FLASH_DESCRIPTOR; } if (descriptorMap->RegionBase > FLASH_DESCRIPTOR_MAX_BASE || descriptorMap->RegionBase == descriptorMap->ComponentBase) { - msg(QObject::tr("parseIntelImage: invalid descriptor region base %1h").hexarg2(descriptorMap->RegionBase, 2)); - return ERR_INVALID_FLASH_DESCRIPTOR; + msg(usprintf("parseIntelImage: invalid descriptor region base %02Xh", descriptorMap->RegionBase)); + return U_INVALID_FLASH_DESCRIPTOR; } if (descriptorMap->ComponentBase > FLASH_DESCRIPTOR_MAX_BASE) { - msg(QObject::tr("parseIntelImage: invalid descriptor component base %1h").hexarg2(descriptorMap->ComponentBase, 2)); - return ERR_INVALID_FLASH_DESCRIPTOR; + msg(usprintf("parseIntelImage: invalid descriptor component base %02Xh", descriptorMap->ComponentBase)); + return U_INVALID_FLASH_DESCRIPTOR; } const FLASH_DESCRIPTOR_REGION_SECTION* regionSection = (const FLASH_DESCRIPTOR_REGION_SECTION*)calculateAddress8(descriptor, descriptorMap->RegionBase); @@ -255,8 +260,8 @@ STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 pa else if (componentSection->FlashParameters.ReadClockFrequency == FLASH_FREQUENCY_17MHZ) // Skylake+ descriptor descriptorVersion = 2; else { - msg(QObject::tr("parseIntelImage: unknown descriptor version with ReadClockFrequency %1h").hexarg(componentSection->FlashParameters.ReadClockFrequency)); - return ERR_INVALID_FLASH_DESCRIPTOR; + msg(usprintf("parseIntelImage: unknown descriptor version with ReadClockFrequency %02Xh", componentSection->FlashParameters.ReadClockFrequency)); + return U_INVALID_FLASH_DESCRIPTOR; } // Regions @@ -286,8 +291,8 @@ STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 pa // Check for Gigabyte specific descriptor map if (bios.length == (UINT32)intelImage.size()) { if (!me.offset) { - msg(QObject::tr("parseIntelImage: can't determine BIOS region start from Gigabyte-specific descriptor")); - return ERR_INVALID_FLASH_DESCRIPTOR; + msg(("parseIntelImage: can't determine BIOS region start from Gigabyte-specific descriptor")); + return U_INVALID_FLASH_DESCRIPTOR; } // Use ME region end as BIOS region offset bios.offset = me.offset + me.length; @@ -302,8 +307,8 @@ STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 pa regions.push_back(bios); } else { - msg(QObject::tr("parseIntelImage: descriptor parsing failed, BIOS region not found in descriptor")); - return ERR_INVALID_FLASH_DESCRIPTOR; + msg(("parseIntelImage: descriptor parsing failed, BIOS region not found in descriptor")); + return U_INVALID_FLASH_DESCRIPTOR; } // GbE region @@ -403,8 +408,10 @@ STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 pa REGION_INFO region; // Check intersection with the descriptor if (regions.front().offset < FLASH_DESCRIPTOR_SIZE) { - msg(QObject::tr("parseIntelImage: %1 region has intersection with flash descriptor").arg(itemSubtypeToQString(Types::Region, regions.front().type)), index); - return ERR_INVALID_FLASH_DESCRIPTOR; + msg(UString("parseIntelImage: ") + itemSubtypeToUString(Types::Region, regions.front().type) + + UString(" region has intersection with flash descriptor"), + index); + return U_INVALID_FLASH_DESCRIPTOR; } // Check for padding between descriptor and the first region else if (regions.front().offset > FLASH_DESCRIPTOR_SIZE) { @@ -419,17 +426,18 @@ STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 pa UINT32 previousRegionEnd = regions[i-1].offset + regions[i-1].length; // Check that current region is fully present in the image if (regions[i].offset + regions[i].length > (UINT32)intelImage.size()) { - msg(QObject::tr("parseIntelImage: %1 region is located outside of opened image, if your system uses dual-chip storage, please append another part to the opened image") - .arg(itemSubtypeToQString(Types::Region, regions[i].type)), index); - return ERR_TRUNCATED_IMAGE; + msg(UString("parseIntelImage: ") + itemSubtypeToUString(Types::Region, regions[i].type) + + UString(" region is located outside of opened image, if your system uses dual-chip storage, please append another part to the opened image"), + index); + return U_TRUNCATED_IMAGE; } // Check for intersection with previous region if (regions[i].offset < previousRegionEnd) { - msg(QObject::tr("parseIntelImage: %1 region has intersection with %2 region") - .arg(itemSubtypeToQString(Types::Region, regions[i].type)) - .arg(itemSubtypeToQString(Types::Region, regions[i-1].type)), index); - return ERR_INVALID_FLASH_DESCRIPTOR; + msg(UString("parseIntelImage: ") + itemSubtypeToUString(Types::Region, regions[i].type) + + UString(" region has intersection with ") + itemSubtypeToUString(Types::Region, regions[i - 1].type) +UString(" region"), + index); + return U_INVALID_FLASH_DESCRIPTOR; } // Check for padding between current and previous regions else if (regions[i].offset > previousRegionEnd) { @@ -454,114 +462,109 @@ STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 pa // Region map is consistent // Intel image - QString name = QObject::tr("Intel image"); - QString info = QObject::tr("Full size: %1h (%2)\nFlash chips: %3\nRegions: %4\nMasters: %5\nPCH straps: %6\nPROC straps: %7") - .hexarg(intelImage.size()).arg(intelImage.size()) - .arg(descriptorMap->NumberOfFlashChips + 1) // - .arg(descriptorMap->NumberOfRegions + 1) // Zero-based numbers in storage - .arg(descriptorMap->NumberOfMasters + 1) // - .arg(descriptorMap->NumberOfPchStraps) - .arg(descriptorMap->NumberOfProcStraps); + UString name("Intel image"); + UString info = usprintf("Full size: %Xh (%u)\nFlash chips: %u\nRegions: %u\nMasters: %u\nPCH straps: %u\nPROC straps: %u", + intelImage.size(), intelImage.size(), + descriptorMap->NumberOfFlashChips + 1, // + descriptorMap->NumberOfRegions + 1, // Zero-based numbers in storage + descriptorMap->NumberOfMasters + 1, // + descriptorMap->NumberOfPchStraps, + descriptorMap->NumberOfProcStraps); // Construct parsing data pdata.offset = parentOffset; // Add Intel image tree item - index = model->addItem(Types::Image, Subtypes::IntelImage, name, QString(), info, QByteArray(), intelImage, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Image, Subtypes::IntelImage, name, UString(), info, UByteArray(), intelImage, UByteArray(), true, parsingDataToUByteArray(pdata), parent); // Descriptor // Get descriptor info - QByteArray body = intelImage.left(FLASH_DESCRIPTOR_SIZE); - name = QObject::tr("Descriptor region"); - info = QObject::tr("Full size: %1h (%2)").hexarg(FLASH_DESCRIPTOR_SIZE).arg(FLASH_DESCRIPTOR_SIZE); + UByteArray body = intelImage.left(FLASH_DESCRIPTOR_SIZE); + name = UString("Descriptor region"); + info = usprintf("Full size: %Xh (%u)", FLASH_DESCRIPTOR_SIZE, FLASH_DESCRIPTOR_SIZE); // Add offsets of actual regions for (size_t i = 0; i < regions.size(); i++) { if (regions[i].type != Subtypes::ZeroPadding && regions[i].type != Subtypes::OnePadding && regions[i].type != Subtypes::DataPadding) - info += QObject::tr("\n%1 region offset: %2h").arg(itemSubtypeToQString(Types::Region, regions[i].type)).hexarg(regions[i].offset + parentOffset); + info += itemSubtypeToUString(Types::Region, regions[i].type).prepend("\n") + + usprintf(" region offset: %Xh", itemSubtypeToUString(Types::Region, regions[i].type), regions[i].offset + parentOffset); } // Region access settings if (descriptorVersion == 1) { const FLASH_DESCRIPTOR_MASTER_SECTION* masterSection = (const FLASH_DESCRIPTOR_MASTER_SECTION*)calculateAddress8(descriptor, descriptorMap->MasterBase); - info += QObject::tr("\nRegion access settings:"); - info += QObject::tr("\nBIOS: %1h %2h ME: %3h %4h\nGbE: %5h %6h") - .hexarg2(masterSection->BiosRead, 2) - .hexarg2(masterSection->BiosWrite, 2) - .hexarg2(masterSection->MeRead, 2) - .hexarg2(masterSection->MeWrite, 2) - .hexarg2(masterSection->GbeRead, 2) - .hexarg2(masterSection->GbeWrite, 2); + info += UString("\nRegion access settings:"); + info += usprintf("\nBIOS: %02Xh %02Xh ME: %02Xh %02Xh\nGbE: %02Xh %02Xh", + masterSection->BiosRead, + masterSection->BiosWrite, + masterSection->MeRead, + masterSection->MeWrite, + masterSection->GbeRead, + masterSection->GbeWrite); // BIOS access table - info += QObject::tr("\nBIOS access table:"); - info += QObject::tr("\n Read Write"); - info += QObject::tr("\nDesc %1 %2") - .arg(masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_DESC ? "Yes " : "No ") - .arg(masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_DESC ? "Yes " : "No "); - info += QObject::tr("\nBIOS Yes Yes"); - info += QObject::tr("\nME %1 %2") - .arg(masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_ME ? "Yes " : "No ") - .arg(masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_ME ? "Yes " : "No "); - info += QObject::tr("\nGbE %1 %2") - .arg(masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_GBE ? "Yes " : "No ") - .arg(masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_GBE ? "Yes " : "No "); - info += QObject::tr("\nPDR %1 %2") - .arg(masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_PDR ? "Yes " : "No ") - .arg(masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_PDR ? "Yes " : "No "); + info += UString("\nBIOS access table:") + + UString("\n Read Write") + + usprintf("\nDesc %s %s", masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_DESC ? "Yes " : "No ", + masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_DESC ? "Yes " : "No "); + info += UString("\nBIOS Yes Yes") + + usprintf("\nME %s %s", masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_ME ? "Yes " : "No ", + masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_ME ? "Yes " : "No "); + info += usprintf("\nGbE %s %s", masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_GBE ? "Yes " : "No ", + masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_GBE ? "Yes " : "No "); + info += usprintf("\nPDR %s %s", masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_PDR ? "Yes " : "No ", + masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_PDR ? "Yes " : "No "); } else if (descriptorVersion == 2) { const FLASH_DESCRIPTOR_MASTER_SECTION_V2* masterSection = (const FLASH_DESCRIPTOR_MASTER_SECTION_V2*)calculateAddress8(descriptor, descriptorMap->MasterBase); - info += QObject::tr("\nRegion access settings:"); - info += QObject::tr("\nBIOS: %1h %2h ME: %3h %4h\nGbE: %5h %6h EC: %7h %8h") - .hexarg2(masterSection->BiosRead, 3) - .hexarg2(masterSection->BiosWrite, 3) - .hexarg2(masterSection->MeRead, 3) - .hexarg2(masterSection->MeWrite, 3) - .hexarg2(masterSection->GbeRead, 3) - .hexarg2(masterSection->GbeWrite, 3) - .hexarg2(masterSection->EcRead, 3) - .hexarg2(masterSection->EcWrite, 3); + info += ("\nRegion access settings:"); + info += ("\nBIOS: %03Xh %03Xh ME: %03Xh %03Xh\nGbE: %03Xh %03Xh EC: %03Xh %03Xh", + masterSection->BiosRead, + masterSection->BiosWrite, + masterSection->MeRead, + masterSection->MeWrite, + masterSection->GbeRead, + masterSection->GbeWrite, + masterSection->EcRead, + masterSection->EcWrite); // BIOS access table - info += QObject::tr("\nBIOS access table:"); - info += QObject::tr("\n Read Write"); - info += QObject::tr("\nDesc %1 %2") - .arg(masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_DESC ? "Yes " : "No ") - .arg(masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_DESC ? "Yes " : "No "); - info += QObject::tr("\nBIOS Yes Yes"); - info += QObject::tr("\nME %1 %2") - .arg(masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_ME ? "Yes " : "No ") - .arg(masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_ME ? "Yes " : "No "); - info += QObject::tr("\nGbE %1 %2") - .arg(masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_GBE ? "Yes " : "No ") - .arg(masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_GBE ? "Yes " : "No "); - info += QObject::tr("\nPDR %1 %2") - .arg(masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_PDR ? "Yes " : "No ") - .arg(masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_PDR ? "Yes " : "No "); - info += QObject::tr("\nEC %1 %2") - .arg(masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_EC ? "Yes " : "No ") - .arg(masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_EC ? "Yes " : "No "); + info += UString("\nBIOS access table:") + + UString("\n Read Write") + + usprintf("\nDesc %s %s", + masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_DESC ? "Yes " : "No ", + masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_DESC ? "Yes " : "No "); + info += UString("\nBIOS Yes Yes") + + usprintf("\nME %s %s", + masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_ME ? "Yes " : "No ", + masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_ME ? "Yes " : "No "); + info += usprintf("\nGbE %s %s", + masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_GBE ? "Yes " : "No ", + masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_GBE ? "Yes " : "No "); + info += usprintf("\nPDR %s %s", + masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_PDR ? "Yes " : "No ", + masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_PDR ? "Yes " : "No "); + info += usprintf("\nEC %s %s", + masterSection->BiosRead & FLASH_DESCRIPTOR_REGION_ACCESS_EC ? "Yes " : "No ", + masterSection->BiosWrite & FLASH_DESCRIPTOR_REGION_ACCESS_EC ? "Yes " : "No "); } // VSCC table const VSCC_TABLE_ENTRY* vsccTableEntry = (const VSCC_TABLE_ENTRY*)(descriptor + ((UINT16)upperMap->VsccTableBase << 4)); - info += QObject::tr("\nFlash chips in VSCC table:"); + info += UString("\nFlash chips in VSCC table:"); UINT8 vsscTableSize = upperMap->VsccTableSize * sizeof(UINT32) / sizeof(VSCC_TABLE_ENTRY); for (int i = 0; i < vsscTableSize; i++) { - info += QObject::tr("\n%1%2%3h") - .hexarg2(vsccTableEntry->VendorId, 2) - .hexarg2(vsccTableEntry->DeviceId0, 2) - .hexarg2(vsccTableEntry->DeviceId1, 2); + info += usprintf("\n02X%02X%02Xh", + vsccTableEntry->VendorId, vsccTableEntry->DeviceId0, vsccTableEntry->DeviceId1); vsccTableEntry++; } // Add descriptor tree item - QModelIndex regionIndex = model->addItem(Types::Region, Subtypes::DescriptorRegion, name, QString(), info, QByteArray(), body, QByteArray(), true, parsingDataToQByteArray(pdata), index); + UModelIndex regionIndex = model->addItem(Types::Region, Subtypes::DescriptorRegion, name, UString(), info, UByteArray(), body, UByteArray(), true, parsingDataToUByteArray(pdata), index); // Parse regions - UINT8 result = ERR_SUCCESS; - UINT8 parseResult = ERR_SUCCESS; + UINT8 result = U_SUCCESS; + UINT8 parseResult = U_SUCCESS; for (size_t i = 0; i < regions.size(); i++) { region = regions[i]; switch (region.type) { @@ -588,26 +591,26 @@ STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 pa case Subtypes::OnePadding: case Subtypes::DataPadding: { // Add padding between regions - QByteArray padding = intelImage.mid(region.offset, region.length); + UByteArray padding = intelImage.mid(region.offset, region.length); // Get parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); // Get info - name = QObject::tr("Padding"); - info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + name = UString("Padding"); + info = usprintf("Full size: %X (%u)", + padding.size(), padding.size()); // Construct parsing data pdata.offset = parentOffset + region.offset; // Add tree item - regionIndex = model->addItem(Types::Padding, getPaddingType(padding), name, QString(), info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); - result = ERR_SUCCESS; + regionIndex = model->addItem(Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); + result = U_SUCCESS; } break; default: - msg(QObject::tr("parseIntelImage: region of unknown type found"), index); - result = ERR_INVALID_FLASH_DESCRIPTOR; + msg(("parseIntelImage: region of unknown type found"), index); + result = U_INVALID_FLASH_DESCRIPTOR; } // Store the first failed result as a final result if (!parseResult && result) @@ -617,54 +620,49 @@ STATUS FfsParser::parseIntelImage(const QByteArray & intelImage, const UINT32 pa return parseResult; } -STATUS FfsParser::parseGbeRegion(const QByteArray & gbe, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseGbeRegion(const UByteArray & gbe, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { // Check sanity if (gbe.isEmpty()) - return ERR_EMPTY_REGION; + return U_EMPTY_REGION; if ((UINT32)gbe.size() < GBE_VERSION_OFFSET + sizeof(GBE_VERSION)) - return ERR_INVALID_REGION; + return U_INVALID_REGION; // Get parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Get info - QString name = QObject::tr("GbE region"); + UString name("GbE region"); const GBE_MAC_ADDRESS* mac = (const GBE_MAC_ADDRESS*)gbe.constData(); const GBE_VERSION* version = (const GBE_VERSION*)(gbe.constData() + GBE_VERSION_OFFSET); - QString info = QObject::tr("Full size: %1h (%2)\nMAC: %3:%4:%5:%6:%7:%8\nVersion: %9.%10") - .hexarg(gbe.size()).arg(gbe.size()) - .hexarg2(mac->vendor[0], 2) - .hexarg2(mac->vendor[1], 2) - .hexarg2(mac->vendor[2], 2) - .hexarg2(mac->device[0], 2) - .hexarg2(mac->device[1], 2) - .hexarg2(mac->device[2], 2) - .arg(version->major) - .arg(version->minor); + UString info = usprintf("Full size: %Xh (%u)\nMAC: %02X:%02X:%02X:%02X:%02X:%02X\nVersion: %u.%u", + gbe.size(), gbe.size(), + mac->vendor[0], mac->vendor[1], mac->vendor[2], + mac->device[0], mac->device[1], mac->device[2], + version->major, + version->minor); // Construct parsing data pdata.offset += parentOffset; // Add tree item - index = model->addItem(Types::Region, Subtypes::GbeRegion, name, QString(), info, QByteArray(), gbe, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Region, Subtypes::GbeRegion, name, UString(), info, UByteArray(), gbe, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseMeRegion(const QByteArray & me, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseMeRegion(const UByteArray & me, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { // Check sanity if (me.isEmpty()) - return ERR_EMPTY_REGION; + return U_EMPTY_REGION; // Get parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Get info - QString name = QObject::tr("ME region"); - QString info = QObject::tr("Full size: %1h (%2)"). - hexarg(me.size()).arg(me.size()); + UString name("ME region"); + UString info = usprintf("Full size: %Xh (%u)", me.size(), me.size()); // Parse region bool versionFound = true; @@ -673,7 +671,7 @@ STATUS FfsParser::parseMeRegion(const QByteArray & me, const UINT32 parentOffset if (me.count() == me.count('\xFF') || me.count() == me.count('\x00')) { // Further parsing not needed emptyRegion = true; - info += QObject::tr("\nState: empty"); + info += ("\nState: empty"); } else { // Search for new signature @@ -682,23 +680,23 @@ STATUS FfsParser::parseMeRegion(const QByteArray & me, const UINT32 parentOffset // Search for old signature versionOffset = me.indexOf(ME_VERSION_SIGNATURE); if (versionOffset < 0){ - info += QObject::tr("\nVersion: unknown"); + info += ("\nVersion: unknown"); versionFound = false; } } // Check sanity if ((UINT32)me.size() < (UINT32)versionOffset + sizeof(ME_VERSION)) - return ERR_INVALID_REGION; + return U_INVALID_REGION; // Add version information if (versionFound) { const ME_VERSION* version = (const ME_VERSION*)(me.constData() + versionOffset); - info += QObject::tr("\nVersion: %1.%2.%3.%4") - .arg(version->major) - .arg(version->minor) - .arg(version->bugfix) - .arg(version->build); + info += usprintf("\nVersion: %u.%u.%u.%u", + version->major, + version->minor, + version->bugfix, + version->build); } } @@ -706,94 +704,91 @@ STATUS FfsParser::parseMeRegion(const QByteArray & me, const UINT32 parentOffset pdata.offset += parentOffset; // Add tree item - index = model->addItem(Types::Region, Subtypes::MeRegion, name, QString(), info, QByteArray(), me, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Region, Subtypes::MeRegion, name, UString(), info, UByteArray(), me, UByteArray(), true, parsingDataToUByteArray(pdata), parent); // Show messages if (emptyRegion) { - msg(QObject::tr("parseMeRegion: ME region is empty"), index); + msg(UString("parseMeRegion: ME region is empty"), index); } else if (!versionFound) { - msg(QObject::tr("parseMeRegion: ME version is unknown, it can be damaged"), index); + msg(UString("parseMeRegion: ME version is unknown, it can be damaged"), index); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parsePdrRegion(const QByteArray & pdr, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parsePdrRegion(const UByteArray & pdr, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { // Check sanity if (pdr.isEmpty()) - return ERR_EMPTY_REGION; + return U_EMPTY_REGION; // Get parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Get info - QString name = QObject::tr("PDR region"); - QString info = QObject::tr("Full size: %1h (%2)"). - hexarg(pdr.size()).arg(pdr.size()); + UString name("PDR region"); + UString info = usprintf("Full size: %Xh (%u)", pdr.size(), pdr.size()); // Construct parsing data pdata.offset += parentOffset; // Add tree item - index = model->addItem(Types::Region, Subtypes::PdrRegion, name, QString(), info, QByteArray(), pdr, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Region, Subtypes::PdrRegion, name, UString(), info, UByteArray(), pdr, UByteArray(), true, parsingDataToUByteArray(pdata), parent); // Parse PDR region as BIOS space UINT8 result = parseRawArea(index); - if (result && result != ERR_VOLUMES_NOT_FOUND && result != ERR_INVALID_VOLUME) + if (result && result != U_VOLUMES_NOT_FOUND && result != U_INVALID_VOLUME) return result; - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseGeneralRegion(const UINT8 subtype, const QByteArray & region, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseGeneralRegion(const UINT8 subtype, const UByteArray & region, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { // Check sanity if (region.isEmpty()) - return ERR_EMPTY_REGION; + return U_EMPTY_REGION; // Get parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Get info - QString name = QObject::tr("%1 region").arg(itemSubtypeToQString(Types::Region, subtype)); - QString info = QObject::tr("Full size: %1h (%2)"). - hexarg(region.size()).arg(region.size()); + UString name = itemSubtypeToUString(Types::Region, subtype) + UString(" region"); + UString info = usprintf("Full size: %Xh (%u)", region.size(), region.size()); // Construct parsing data pdata.offset += parentOffset; // Add tree item - index = model->addItem(Types::Region, subtype, name, QString(), info, QByteArray(), region, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Region, subtype, name, UString(), info, UByteArray(), region, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseBiosRegion(const QByteArray & bios, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseBiosRegion(const UByteArray & bios, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { // Sanity check if (bios.isEmpty()) - return ERR_EMPTY_REGION; + return U_EMPTY_REGION; // Get parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Get info - QString name = QObject::tr("BIOS region"); - QString info = QObject::tr("Full size: %1h (%2)"). - hexarg(bios.size()).arg(bios.size()); + UString name("BIOS region"); + UString info = usprintf("Full size: %Xh (%u)", bios.size(), bios.size()); // Construct parsing data pdata.offset += parentOffset; // Add tree item - index = model->addItem(Types::Region, Subtypes::BiosRegion, name, QString(), info, QByteArray(), bios, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Region, Subtypes::BiosRegion, name, UString(), info, UByteArray(), bios, UByteArray(), true, parsingDataToUByteArray(pdata), parent); return parseRawArea(index); } -UINT8 FfsParser::getPaddingType(const QByteArray & padding) +UINT8 FfsParser::getPaddingType(const UByteArray & padding) { if (padding.count('\x00') == padding.count()) return Subtypes::ZeroPadding; @@ -802,22 +797,22 @@ UINT8 FfsParser::getPaddingType(const QByteArray & padding) return Subtypes::DataPadding; } -STATUS FfsParser::parseRawArea(const QModelIndex & index) +USTATUS FfsParser::parseRawArea(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); UINT32 headerSize = model->header(index).size(); UINT32 offset = pdata.offset + headerSize; // Get item data - QByteArray data = model->body(index); + UByteArray data = model->body(index); // Search for first volume - STATUS result; + USTATUS result; UINT32 prevVolumeOffset; result = findNextVolume(index, data, offset, 0, prevVolumeOffset); @@ -825,20 +820,19 @@ STATUS FfsParser::parseRawArea(const QModelIndex & index) return result; // First volume is not at the beginning of RAW area - QString name; - QString info; + UString name; + UString info; if (prevVolumeOffset > 0) { // Get info - QByteArray padding = data.left(prevVolumeOffset); - name = QObject::tr("Padding"); - info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + UByteArray padding = data.left(prevVolumeOffset); + name = UString("Padding"); + info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = offset; // Add tree item - model->addItem(Types::Padding, getPaddingType(padding), name, QString(), info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); + model->addItem(Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); } // Search for and parse all volumes @@ -851,18 +845,17 @@ STATUS FfsParser::parseRawArea(const QModelIndex & index) if (volumeOffset > prevVolumeOffset + prevVolumeSize) { UINT32 paddingOffset = prevVolumeOffset + prevVolumeSize; UINT32 paddingSize = volumeOffset - paddingOffset; - QByteArray padding = data.mid(paddingOffset, paddingSize); + UByteArray padding = data.mid(paddingOffset, paddingSize); // Get info - name = QObject::tr("Padding"); - info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + name = UString("Padding"); + info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = offset + paddingOffset; // Add tree item - model->addItem(Types::Padding, getPaddingType(padding), name, QString(), info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); + model->addItem(Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); } // Get volume size @@ -870,32 +863,31 @@ STATUS FfsParser::parseRawArea(const QModelIndex & index) UINT32 bmVolumeSize = 0; result = getVolumeSize(data, volumeOffset, volumeSize, bmVolumeSize); if (result) { - msg(QObject::tr("parseRawArea: getVolumeSize failed with error \"%1\"").arg(errorCodeToQString(result)), index); + msg(UString("parseRawArea: getVolumeSize failed with error ") + errorCodeToUString(result), index); return result; } // Check that volume is fully present in input if (volumeSize > (UINT32)data.size() || volumeOffset + volumeSize > (UINT32)data.size()) { - msg(QObject::tr("parseRawArea: one of volumes inside overlaps the end of data"), index); - return ERR_INVALID_VOLUME; + msg(UString("parseRawArea: one of volumes inside overlaps the end of data"), index); + return U_INVALID_VOLUME; } - QByteArray volume = data.mid(volumeOffset, volumeSize); + UByteArray volume = data.mid(volumeOffset, volumeSize); if (volumeSize > (UINT32)volume.size()) { // Mark the rest as padding and finish the parsing - QByteArray padding = data.right(volume.size()); + UByteArray padding = data.right(volume.size()); // Get info - name = QObject::tr("Padding"); - info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + name = UString("Padding"); + info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = offset + volumeOffset; // Add tree item - QModelIndex paddingIndex = model->addItem(Types::Padding, getPaddingType(padding), name, QString(), info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); - msg(QObject::tr("parseRawArea: one of volumes inside overlaps the end of data"), paddingIndex); + UModelIndex paddingIndex = model->addItem(Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); + msg(UString("parseRawArea: one of volumes inside overlaps the end of data"), paddingIndex); // Update variables prevVolumeOffset = volumeOffset; @@ -904,16 +896,16 @@ STATUS FfsParser::parseRawArea(const QModelIndex & index) } // Parse current volume's header - QModelIndex volumeIndex; + UModelIndex volumeIndex; result = parseVolumeHeader(volume, headerSize + volumeOffset, index, volumeIndex); if (result) - msg(QObject::tr("parseRawArea: volume header parsing failed with error \"%1\"").arg(errorCodeToQString(result)), index); + msg(UString("parseRawArea: volume header parsing failed with error ") + errorCodeToUString(result), index); else { // Show messages if (volumeSize != bmVolumeSize) - msg(QObject::tr("parseRawArea: volume size stored in header %1h (%2) differs from calculated using block map %3h (%4)") - .hexarg(volumeSize).arg(volumeSize) - .hexarg(bmVolumeSize).arg(bmVolumeSize), + msg(usprintf("parseRawArea: volume size stored in header %Xh (%u) differs from calculated using block map %Xh (%u)", + volumeSize, volumeSize, + bmVolumeSize, bmVolumeSize), volumeIndex); } @@ -926,23 +918,22 @@ STATUS FfsParser::parseRawArea(const QModelIndex & index) // Padding at the end of RAW area volumeOffset = prevVolumeOffset + prevVolumeSize; if ((UINT32)data.size() > volumeOffset) { - QByteArray padding = data.mid(volumeOffset); + UByteArray padding = data.mid(volumeOffset); // Get info - name = QObject::tr("Padding"); - info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + name = UString("Padding"); + info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = offset + headerSize + volumeOffset; // Add tree item - model->addItem(Types::Padding, getPaddingType(padding), name, QString(), info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); + model->addItem(Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); } // Parse bodies for (int i = 0; i < model->rowCount(index); i++) { - QModelIndex current = index.child(i, 0); + UModelIndex current = index.child(i, 0); switch (model->type(current)) { case Types::Volume: parseVolumeBody(current); @@ -951,26 +942,26 @@ STATUS FfsParser::parseRawArea(const QModelIndex & index) // No parsing required break; default: - return ERR_UNKNOWN_ITEM_TYPE; + return U_UNKNOWN_ITEM_TYPE; } } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseVolumeHeader(const QByteArray & volume, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseVolumeHeader(const UByteArray & volume, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { // Sanity check if (volume.isEmpty()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Check that there is space for the volume header if ((UINT32)volume.size() < sizeof(EFI_FIRMWARE_VOLUME_HEADER)) { - msg(QObject::tr("parseVolumeHeader: input volume size %1h (%2) is smaller than volume header size 40h (64)").hexarg(volume.size()).arg(volume.size())); - return ERR_INVALID_VOLUME; + msg(usprintf("parseVolumeHeader: input volume size %Xh (%u) is smaller than volume header size 40h (64)", volume.size(), volume.size())); + return U_INVALID_VOLUME; } // Populate volume header @@ -978,14 +969,14 @@ STATUS FfsParser::parseVolumeHeader(const QByteArray & volume, const UINT32 pare // Check sanity of HeaderLength value if ((UINT32)ALIGN8(volumeHeader->HeaderLength) > (UINT32)volume.size()) { - msg(QObject::tr("parseVolumeHeader: volume header overlaps the end of data")); - return ERR_INVALID_VOLUME; + msg(UString("parseVolumeHeader: volume header overlaps the end of data")); + return U_INVALID_VOLUME; } // Check sanity of ExtHeaderOffset value if (volumeHeader->Revision > 1 && volumeHeader->ExtHeaderOffset && (UINT32)ALIGN8(volumeHeader->ExtHeaderOffset + sizeof(EFI_FIRMWARE_VOLUME_EXT_HEADER)) > (UINT32)volume.size()) { - msg(QObject::tr("parseVolumeHeader: extended volume header overlaps the end of data")); - return ERR_INVALID_VOLUME; + msg(UString("parseVolumeHeader: extended volume header overlaps the end of data")); + return U_INVALID_VOLUME; } // Calculate volume header size @@ -1010,7 +1001,7 @@ STATUS FfsParser::parseVolumeHeader(const QByteArray & volume, const UINT32 pare UINT8 ffsVersion = 0; // Check for FFS v2 volume - QByteArray guid = QByteArray((const char*)volumeHeader->FileSystemGuid.Data, sizeof(EFI_GUID)); + UByteArray guid = UByteArray((const char*)volumeHeader->FileSystemGuid.Data, sizeof(EFI_GUID)); if (std::find(FFSv2Volumes.begin(), FFSv2Volumes.end(), guid) != FFSv2Volumes.end()) { isUnknown = false; ffsVersion = 2; @@ -1096,38 +1087,38 @@ STATUS FfsParser::parseVolumeHeader(const QByteArray & volume, const UINT32 pare // Check header checksum by recalculating it bool msgInvalidChecksum = false; - QByteArray tempHeader((const char*)volumeHeader, volumeHeader->HeaderLength); + UByteArray tempHeader((const char*)volumeHeader, volumeHeader->HeaderLength); ((EFI_FIRMWARE_VOLUME_HEADER*)tempHeader.data())->Checksum = 0; UINT16 calculated = calculateChecksum16((const UINT16*)tempHeader.constData(), volumeHeader->HeaderLength); if (volumeHeader->Checksum != calculated) msgInvalidChecksum = true; // Get info - QByteArray header = volume.left(headerSize); - QByteArray body = volume.mid(headerSize); - QString name = guidToQString(volumeHeader->FileSystemGuid); - QString info = QObject::tr("Signature: _FVH\nZeroVector:\n%1 %2 %3 %4 %5 %6 %7 %8\n%9 %10 %11 %12 %13 %14 %15 %16\nFileSystem GUID: %17\nFull size: %18h (%19)\n" - "Header size: %20h (%21)\nBody size: %22h (%23)\nRevision: %24\nAttributes: %25h\nErase polarity: %26\nChecksum: %27h, %28") - .hexarg2(volumeHeader->ZeroVector[0], 2).hexarg2(volumeHeader->ZeroVector[1], 2).hexarg2(volumeHeader->ZeroVector[2], 2).hexarg2(volumeHeader->ZeroVector[3], 2) - .hexarg2(volumeHeader->ZeroVector[4], 2).hexarg2(volumeHeader->ZeroVector[5], 2).hexarg2(volumeHeader->ZeroVector[6], 2).hexarg2(volumeHeader->ZeroVector[7], 2) - .hexarg2(volumeHeader->ZeroVector[8], 2).hexarg2(volumeHeader->ZeroVector[9], 2).hexarg2(volumeHeader->ZeroVector[10], 2).hexarg2(volumeHeader->ZeroVector[11], 2) - .hexarg2(volumeHeader->ZeroVector[12], 2).hexarg2(volumeHeader->ZeroVector[13], 2).hexarg2(volumeHeader->ZeroVector[14], 2).hexarg2(volumeHeader->ZeroVector[15], 2) - .arg(guidToQString(volumeHeader->FileSystemGuid)) - .hexarg(volumeSize).arg(volumeSize) - .hexarg(headerSize).arg(headerSize) - .hexarg(volumeSize - headerSize).arg(volumeSize - headerSize) - .arg(volumeHeader->Revision) - .hexarg2(volumeHeader->Attributes, 8) - .arg(emptyByte ? "1" : "0") - .hexarg2(volumeHeader->Checksum, 4) - .arg(msgInvalidChecksum ? QObject::tr("invalid, should be %1h").hexarg2(calculated, 4) : QObject::tr("valid")); + UByteArray header = volume.left(headerSize); + UByteArray body = volume.mid(headerSize); + UString name = guidToUString(volumeHeader->FileSystemGuid); + UString info = usprintf("Signature: _FVH\nZeroVector:\n%02X %02X %02X %02X %02X %02X %02X %02X\n" + "%02X %02X %02X %02X %02X %02X %02X %02X\nFileSystem GUID: ", + volumeHeader->ZeroVector[0], volumeHeader->ZeroVector[1], volumeHeader->ZeroVector[2], volumeHeader->ZeroVector[3], + volumeHeader->ZeroVector[4], volumeHeader->ZeroVector[5], volumeHeader->ZeroVector[6], volumeHeader->ZeroVector[7], + volumeHeader->ZeroVector[8], volumeHeader->ZeroVector[9], volumeHeader->ZeroVector[10], volumeHeader->ZeroVector[11], + volumeHeader->ZeroVector[12], volumeHeader->ZeroVector[13], volumeHeader->ZeroVector[14], volumeHeader->ZeroVector[15]) + + guidToUString(volumeHeader->FileSystemGuid) \ + + usprintf("\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nRevision: %u\nAttributes: %08Xh\nErase polarity: %u\nChecksum: %02Xh", + volumeSize, volumeSize, + headerSize, headerSize, + volumeSize - headerSize, volumeSize - headerSize, + volumeHeader->Revision, + volumeHeader->Attributes, 8, + emptyByte ? 1 : 0, + volumeHeader->Checksum) + + (msgInvalidChecksum ? usprintf("invalid, should be %04Xh", calculated) : UString("valid")); // Extended header present if (volumeHeader->Revision > 1 && volumeHeader->ExtHeaderOffset) { const EFI_FIRMWARE_VOLUME_EXT_HEADER* extendedHeader = (const EFI_FIRMWARE_VOLUME_EXT_HEADER*)(volume.constData() + volumeHeader->ExtHeaderOffset); - info += QObject::tr("\nExtended header size: %1h (%2)\nVolume GUID: %3") - .hexarg(extendedHeader->ExtHeaderSize).arg(extendedHeader->ExtHeaderSize) - .arg(guidToQString(extendedHeader->FvName)); + info += usprintf("\nExtended header size: %Xh (%u)\nVolume GUID: ", + extendedHeader->ExtHeaderSize, extendedHeader->ExtHeaderSize) + guidToUString(extendedHeader->FvName); } // Construct parsing data @@ -1143,11 +1134,11 @@ STATUS FfsParser::parseVolumeHeader(const QByteArray & volume, const UINT32 pare pdata.volume.isWeakAligned = (volumeHeader->Revision > 1 && (volumeHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT)); // Add text - QString text; + UString text; if (hasAppleCrc32) - text += QObject::tr("AppleCRC32 "); + text += UString("AppleCRC32 "); if (hasAppleFSO) - text += QObject::tr("AppleFSO "); + text += UString("AppleFSO "); // Add tree item UINT8 subtype = Subtypes::UnknownVolume; @@ -1159,42 +1150,48 @@ STATUS FfsParser::parseVolumeHeader(const QByteArray & volume, const UINT32 pare else if (isNvramVolume) subtype = Subtypes::NvramVolume; } - index = model->addItem(Types::Volume, subtype, name, text, info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Volume, subtype, name, text, info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); // Show messages if (isUnknown) - msg(QObject::tr("parseVolumeHeader: unknown file system %1").arg(guidToQString(volumeHeader->FileSystemGuid)), index); + msg(UString("parseVolumeHeader: unknown file system ") + guidToUString(volumeHeader->FileSystemGuid), index); if (msgInvalidChecksum) - msg(QObject::tr("parseVolumeHeader: volume header checksum is invalid"), index); + msg(UString("parseVolumeHeader: volume header checksum is invalid"), index); if (msgAlignmentBitsSet) - msg(QObject::tr("parseVolumeHeader: alignment bits set on volume without alignment capability"), index); + msg(UString("parseVolumeHeader: alignment bits set on volume without alignment capability"), index); if (msgUnaligned) - msg(QObject::tr("parseVolumeHeader: unaligned volume"), index); + msg(UString("parseVolumeHeader: unaligned volume"), index); if (msgUnknownRevision) - msg(QObject::tr("parseVolumeHeader: unknown volume revision %1").arg(volumeHeader->Revision), index); + msg(usprintf("parseVolumeHeader: unknown volume revision %u", volumeHeader->Revision), index); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::findNextVolume(const QModelIndex & index, const QByteArray & bios, const UINT32 parentOffset, const UINT32 volumeOffset, UINT32 & nextVolumeOffset) +USTATUS FfsParser::findNextVolume(const UModelIndex & index, const UByteArray & bios, const UINT32 parentOffset, const UINT32 volumeOffset, UINT32 & nextVolumeOffset) { int nextIndex = bios.indexOf(EFI_FV_SIGNATURE, volumeOffset); if (nextIndex < EFI_FV_SIGNATURE_OFFSET) - return ERR_VOLUMES_NOT_FOUND; + return U_VOLUMES_NOT_FOUND; // Check volume header to be sane for (; nextIndex > 0; nextIndex = bios.indexOf(EFI_FV_SIGNATURE, nextIndex + 1)) { const EFI_FIRMWARE_VOLUME_HEADER* volumeHeader = (const EFI_FIRMWARE_VOLUME_HEADER*)(bios.constData() + nextIndex - EFI_FV_SIGNATURE_OFFSET); if (volumeHeader->FvLength < sizeof(EFI_FIRMWARE_VOLUME_HEADER) + 2 * sizeof(EFI_FV_BLOCK_MAP_ENTRY) || volumeHeader->FvLength >= 0xFFFFFFFFUL) { - msg(QObject::tr("findNextVolume: volume candidate at offset %1h skipped, has invalid FvLength %2h").hexarg(parentOffset + (nextIndex - EFI_FV_SIGNATURE_OFFSET)).hexarg2(volumeHeader->FvLength, 16), index); + msg(usprintf("findNextVolume: volume candidate at offset %Xh skipped, has invalid FvLength %Xh", + parentOffset + (nextIndex - EFI_FV_SIGNATURE_OFFSET), + volumeHeader->FvLength), index); continue; } if (volumeHeader->Reserved != 0xFF && volumeHeader->Reserved != 0x00) { - msg(QObject::tr("findNextVolume: volume candidate at offset %1h skipped, has invalid Reserved byte value %2").hexarg(parentOffset + (nextIndex - EFI_FV_SIGNATURE_OFFSET)).hexarg2(volumeHeader->Reserved, 2), index); + msg(usprintf("findNextVolume: volume candidate at offset %Xh skipped, has invalid Reserved byte value %02X", + parentOffset + (nextIndex - EFI_FV_SIGNATURE_OFFSET), + volumeHeader->Reserved), index); continue; } if (volumeHeader->Revision != 1 && volumeHeader->Revision != 2) { - msg(QObject::tr("findNextVolume: volume candidate at offset %1h skipped, has invalid Revision byte value %2").hexarg(parentOffset + (nextIndex - EFI_FV_SIGNATURE_OFFSET)).hexarg2(volumeHeader->Revision, 2), index); + msg(usprintf("findNextVolume: volume candidate at offset %Xh skipped, has invalid Revision byte value %02X", + parentOffset + (nextIndex - EFI_FV_SIGNATURE_OFFSET) + ,volumeHeader->Revision), index); continue; } // All checks passed, volume found @@ -1202,31 +1199,31 @@ STATUS FfsParser::findNextVolume(const QModelIndex & index, const QByteArray & b } // No more volumes found if (nextIndex < EFI_FV_SIGNATURE_OFFSET) - return ERR_VOLUMES_NOT_FOUND; + return U_VOLUMES_NOT_FOUND; nextVolumeOffset = nextIndex - EFI_FV_SIGNATURE_OFFSET; - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::getVolumeSize(const QByteArray & bios, UINT32 volumeOffset, UINT32 & volumeSize, UINT32 & bmVolumeSize) +USTATUS FfsParser::getVolumeSize(const UByteArray & bios, UINT32 volumeOffset, UINT32 & volumeSize, UINT32 & bmVolumeSize) { // Check that there is space for the volume header and at least two block map entries. if ((UINT32)bios.size() < volumeOffset + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + 2 * sizeof(EFI_FV_BLOCK_MAP_ENTRY)) - return ERR_INVALID_VOLUME; + return U_INVALID_VOLUME; // Populate volume header const EFI_FIRMWARE_VOLUME_HEADER* volumeHeader = (const EFI_FIRMWARE_VOLUME_HEADER*)(bios.constData() + volumeOffset); // Check volume signature - if (QByteArray((const char*)&volumeHeader->Signature, sizeof(volumeHeader->Signature)) != EFI_FV_SIGNATURE) - return ERR_INVALID_VOLUME; + if (UByteArray((const char*)&volumeHeader->Signature, sizeof(volumeHeader->Signature)) != EFI_FV_SIGNATURE) + return U_INVALID_VOLUME; // Calculate volume size using BlockMap const EFI_FV_BLOCK_MAP_ENTRY* entry = (const EFI_FV_BLOCK_MAP_ENTRY*)(bios.constData() + volumeOffset + sizeof(EFI_FIRMWARE_VOLUME_HEADER)); UINT32 calcVolumeSize = 0; while (entry->NumBlocks != 0 && entry->Length != 0) { if ((void*)entry > bios.constData() + bios.size()) - return ERR_INVALID_VOLUME; + return U_INVALID_VOLUME; calcVolumeSize += entry->NumBlocks * entry->Length; entry += 1; @@ -1236,26 +1233,26 @@ STATUS FfsParser::getVolumeSize(const QByteArray & bios, UINT32 volumeOffset, UI bmVolumeSize = calcVolumeSize; if (volumeSize == 0) - return ERR_INVALID_VOLUME; + return U_INVALID_VOLUME; - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseVolumeNonUefiData(const QByteArray & data, const UINT32 parentOffset, const QModelIndex & index) +USTATUS FfsParser::parseVolumeNonUefiData(const UByteArray & data, const UINT32 parentOffset, const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); // Modify it pdata.offset += parentOffset; // Search for VTF GUID backwards in received data - QByteArray padding = data; - QByteArray vtf; + UByteArray padding = data; + UByteArray vtf; INT32 vtfIndex = data.lastIndexOf(EFI_FFS_VOLUME_TOP_FILE_GUID); if (vtfIndex >= 0) { // VTF candidate found inside non-UEFI data padding = data.left(vtfIndex); @@ -1273,52 +1270,52 @@ STATUS FfsParser::parseVolumeNonUefiData(const QByteArray & data, const UINT32 p // Add non-UEFI data first // Get info - QString info = QObject::tr("Full size: %1h (%2)").hexarg(padding.size()).arg(padding.size()); + UString info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Add padding tree item - QModelIndex paddingIndex = model->addItem(Types::Padding, Subtypes::DataPadding, QObject::tr("Non-UEFI data"), "", info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); - msg(QObject::tr("parseVolumeNonUefiData: non-UEFI data found in volume's free space"), paddingIndex); + UModelIndex paddingIndex = model->addItem(Types::Padding, Subtypes::DataPadding, UString("Non-UEFI data"), "", info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); + msg(UString("parseVolumeNonUefiData: non-UEFI data found in volume's free space"), paddingIndex); if (vtfIndex >= 0) { // Get VTF file header - QByteArray header = vtf.left(sizeof(EFI_FFS_FILE_HEADER)); + UByteArray header = vtf.left(sizeof(EFI_FFS_FILE_HEADER)); const EFI_FFS_FILE_HEADER* fileHeader = (const EFI_FFS_FILE_HEADER*)header.constData(); if (pdata.ffsVersion == 3 && (fileHeader->Attributes & FFS_ATTRIB_LARGE_FILE)) { header = vtf.left(sizeof(EFI_FFS_FILE_HEADER2)); } //Parse VTF file header - QModelIndex fileIndex; - STATUS result = parseFileHeader(vtf, parentOffset + vtfIndex, index, fileIndex); + UModelIndex fileIndex; + USTATUS result = parseFileHeader(vtf, parentOffset + vtfIndex, index, fileIndex); if (result) { - msg(QObject::tr("parseVolumeNonUefiData: VTF file header parsing failed with error \"%1\"").arg(errorCodeToQString(result)), index); + msg(UString("parseVolumeNonUefiData: VTF file header parsing failed with error ") + errorCodeToUString(result), index); // Add the rest as non-UEFI data too pdata.offset += vtfIndex; // Get info - QString info = QObject::tr("Full size: %1h (%2)").hexarg(vtf.size()).arg(vtf.size()); + UString info = usprintf("Full size: %Xh (%u)", vtf.size(), vtf.size()); // Add padding tree item - QModelIndex paddingIndex = model->addItem(Types::Padding, Subtypes::DataPadding, QObject::tr("Non-UEFI data"), "", info, QByteArray(), vtf, QByteArray(), true, parsingDataToQByteArray(pdata), index); - msg(QObject::tr("parseVolumeNonUefiData: non-UEFI data found in volume's free space"), paddingIndex); + UModelIndex paddingIndex = model->addItem(Types::Padding, Subtypes::DataPadding, UString("Non-UEFI data"), "", info, UByteArray(), vtf, UByteArray(), true, parsingDataToUByteArray(pdata), index); + msg(("parseVolumeNonUefiData: non-UEFI data found in volume's free space"), paddingIndex); } } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseVolumeBody(const QModelIndex & index) +USTATUS FfsParser::parseVolumeBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get volume header size and body - QByteArray volumeBody = model->body(index); + UByteArray volumeBody = model->body(index); UINT32 volumeHeaderSize = model->header(index).size(); // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); UINT32 offset = pdata.offset; // Parse VSS NVRAM volumes with a dedicated function @@ -1326,7 +1323,7 @@ STATUS FfsParser::parseVolumeBody(const QModelIndex & index) return parseNvramVolumeBody(index); if (pdata.ffsVersion != 2 && pdata.ffsVersion != 3) // Don't parse unknown volumes - return ERR_SUCCESS; + return U_SUCCESS; // Search for and parse all files UINT32 volumeBodySize = volumeBody.size(); @@ -1337,10 +1334,10 @@ STATUS FfsParser::parseVolumeBody(const QModelIndex & index) // Check file size if (fileSize < sizeof(EFI_FFS_FILE_HEADER) || fileSize > volumeBodySize - fileOffset) { // Check that we are at the empty space - QByteArray header = volumeBody.mid(fileOffset, sizeof(EFI_FFS_FILE_HEADER)); + UByteArray header = volumeBody.mid(fileOffset, sizeof(EFI_FFS_FILE_HEADER)); if (header.count(pdata.emptyByte) == header.size()) { //Empty space // Check free space to be actually free - QByteArray freeSpace = volumeBody.mid(fileOffset); + UByteArray freeSpace = volumeBody.mid(fileOffset); if (freeSpace.count(pdata.emptyByte) != freeSpace.count()) { // Search for the first non-empty byte UINT32 i; @@ -1361,13 +1358,13 @@ STATUS FfsParser::parseVolumeBody(const QModelIndex & index) // Add all bytes before as free space if (i > 0) { - QByteArray free = freeSpace.left(i); + UByteArray free = freeSpace.left(i); // Get info - QString info = QObject::tr("Full size: %1h (%2)").hexarg(free.size()).arg(free.size()); + UString info = usprintf("Full size: %Xh (%u)", free.size(), free.size()); // Add free space item - model->addItem(Types::FreeSpace, 0, QObject::tr("Volume free space"), "", info, QByteArray(), free, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::FreeSpace, 0, UString("Volume free space"), "", info, UByteArray(), free, UByteArray(), false, parsingDataToUByteArray(pdata), index); } // Parse non-UEFI data @@ -1378,10 +1375,10 @@ STATUS FfsParser::parseVolumeBody(const QModelIndex & index) pdata.offset = offset + volumeHeaderSize + fileOffset; // Get info - QString info = QObject::tr("Full size: %1h (%2)").hexarg(freeSpace.size()).arg(freeSpace.size()); + UString info = usprintf("Full size: %Xh (%u)", freeSpace.size(), freeSpace.size()); // Add free space item - model->addItem(Types::FreeSpace, 0, QObject::tr("Volume free space"), "", info, QByteArray(), freeSpace, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::FreeSpace, 0, UString("Volume free space"), "", info, UByteArray(), freeSpace, UByteArray(), false, parsingDataToUByteArray(pdata), index); } break; // Exit from parsing loop } @@ -1393,18 +1390,18 @@ STATUS FfsParser::parseVolumeBody(const QModelIndex & index) } // Get file header - QByteArray file = volumeBody.mid(fileOffset, fileSize); - QByteArray header = file.left(sizeof(EFI_FFS_FILE_HEADER)); + UByteArray file = volumeBody.mid(fileOffset, fileSize); + UByteArray header = file.left(sizeof(EFI_FFS_FILE_HEADER)); const EFI_FFS_FILE_HEADER* fileHeader = (const EFI_FFS_FILE_HEADER*)header.constData(); if (pdata.ffsVersion == 3 && (fileHeader->Attributes & FFS_ATTRIB_LARGE_FILE)) { header = file.left(sizeof(EFI_FFS_FILE_HEADER2)); } //Parse current file's header - QModelIndex fileIndex; - STATUS result = parseFileHeader(file, volumeHeaderSize + fileOffset, index, fileIndex); + UModelIndex fileIndex; + USTATUS result = parseFileHeader(file, volumeHeaderSize + fileOffset, index, fileIndex); if (result) - msg(QObject::tr("parseVolumeBody: file header parsing failed with error \"%1\"").arg(errorCodeToQString(result)), index); + msg(UString("parseVolumeBody: file header parsing failed with error ") + errorCodeToUString(result), index); // Move to next file fileOffset += fileSize; @@ -1413,37 +1410,37 @@ STATUS FfsParser::parseVolumeBody(const QModelIndex & index) // Check for duplicate GUIDs for (int i = 0; i < model->rowCount(index); i++) { - QModelIndex current = index.child(i, 0); + UModelIndex current = index.child(i, 0); // Skip non-file entries and pad files if (model->type(current) != Types::File || model->subtype(current) == EFI_FV_FILETYPE_PAD) continue; // Get current file parsing data - PARSING_DATA currentPdata = parsingDataFromQModelIndex(current); - QByteArray currentGuid((const char*)¤tPdata.file.guid, sizeof(EFI_GUID)); + PARSING_DATA currentPdata = parsingDataFromUModelIndex(current); + UByteArray currentGuid((const char*)¤tPdata.file.guid, sizeof(EFI_GUID)); // Check files after current for having an equal GUID for (int j = i + 1; j < model->rowCount(index); j++) { - QModelIndex another = index.child(j, 0); + UModelIndex another = index.child(j, 0); // Skip non-file entries if (model->type(another) != Types::File) continue; // Get another file parsing data - PARSING_DATA anotherPdata = parsingDataFromQModelIndex(another); - QByteArray anotherGuid((const char*)&anotherPdata.file.guid, sizeof(EFI_GUID)); + PARSING_DATA anotherPdata = parsingDataFromUModelIndex(another); + UByteArray anotherGuid((const char*)&anotherPdata.file.guid, sizeof(EFI_GUID)); // Check GUIDs for being equal if (currentGuid == anotherGuid) { - msg(QObject::tr("parseVolumeBody: file with duplicate GUID %1").arg(guidToQString(anotherPdata.file.guid)), another); + msg(UString("parseVolumeBody: file with duplicate GUID ") + guidToUString(anotherPdata.file.guid), another); } } } //Parse bodies for (int i = 0; i < model->rowCount(index); i++) { - QModelIndex current = index.child(i, 0); + UModelIndex current = index.child(i, 0); switch (model->type(current)) { case Types::File: parseFileBody(current); @@ -1453,14 +1450,14 @@ STATUS FfsParser::parseVolumeBody(const QModelIndex & index) // No parsing required break; default: - return ERR_UNKNOWN_ITEM_TYPE; + return U_UNKNOWN_ITEM_TYPE; } } - return ERR_SUCCESS; + return U_SUCCESS; } -UINT32 FfsParser::getFileSize(const QByteArray & volume, const UINT32 fileOffset, const UINT8 ffsVersion) +UINT32 FfsParser::getFileSize(const UByteArray & volume, const UINT32 fileOffset, const UINT8 ffsVersion) { if (ffsVersion == 2) { if ((UINT32)volume.size() < fileOffset + sizeof(EFI_FFS_FILE_HEADER)) @@ -1481,24 +1478,24 @@ UINT32 FfsParser::getFileSize(const QByteArray & volume, const UINT32 fileOffset return 0; } -STATUS FfsParser::parseFileHeader(const QByteArray & file, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseFileHeader(const UByteArray & file, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { // Sanity check if (file.isEmpty()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; if ((UINT32)file.size() < sizeof(EFI_FFS_FILE_HEADER)) - return ERR_INVALID_FILE; + return U_INVALID_FILE; // Get parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Get file header - QByteArray header = file.left(sizeof(EFI_FFS_FILE_HEADER)); + UByteArray header = file.left(sizeof(EFI_FFS_FILE_HEADER)); const EFI_FFS_FILE_HEADER* fileHeader = (const EFI_FFS_FILE_HEADER*)header.constData(); if (pdata.ffsVersion == 3 && (fileHeader->Attributes & FFS_ATTRIB_LARGE_FILE)) { if ((UINT32)file.size() < sizeof(EFI_FFS_FILE_HEADER2)) - return ERR_INVALID_FILE; + return U_INVALID_FILE; header = file.left(sizeof(EFI_FFS_FILE_HEADER2)); } @@ -1515,7 +1512,7 @@ STATUS FfsParser::parseFileHeader(const QByteArray & file, const UINT32 parentOf msgFileAlignmentIsGreaterThanVolumes = true; // Check header checksum - QByteArray tempHeader = header; + UByteArray tempHeader = header; EFI_FFS_FILE_HEADER* tempFileHeader = (EFI_FFS_FILE_HEADER*)(tempHeader.data()); tempFileHeader->IntegrityCheck.Checksum.Header = 0; tempFileHeader->IntegrityCheck.Checksum.File = 0; @@ -1554,10 +1551,10 @@ STATUS FfsParser::parseFileHeader(const QByteArray & file, const UINT32 parentOf }; // Get file body - QByteArray body = file.mid(header.size()); + UByteArray body = file.mid(header.size()); // Check for file tail presence - QByteArray tail; + UByteArray tail; bool msgInvalidTailValue = false; if (pdata.volume.revision == 1 && (fileHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT)) { @@ -1572,40 +1569,37 @@ STATUS FfsParser::parseFileHeader(const QByteArray & file, const UINT32 parentOf } // Get info - QString name; - QString info; + UString name; + UString info; if (fileHeader->Type != EFI_FV_FILETYPE_PAD) - name = guidToQString(fileHeader->Name); + name = guidToUString(fileHeader->Name); else - name = QObject::tr("Pad-file"); + name = UString("Pad-file"); - info = QObject::tr("File GUID: %1\nType: %2h\nAttributes: %3h\nFull size: %4h (%5)\nHeader size: %6h (%7)\nBody size: %8h (%9)\nTail size: %10h (%11)\n" - "State: %12h\nHeader checksum: %13h, %14\nData checksum: %15h, %16") - .arg(guidToQString(fileHeader->Name)) - .hexarg2(fileHeader->Type, 2) - .hexarg2(fileHeader->Attributes, 2) - .hexarg(header.size() + body.size() + tail.size()).arg(header.size() + body.size() + tail.size()) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .hexarg(tail.size()).arg(tail.size()) - .hexarg2(fileHeader->State, 2) - .hexarg2(fileHeader->IntegrityCheck.Checksum.Header, 2) - .arg(msgInvalidHeaderChecksum ? QObject::tr("invalid, should be %1h").hexarg2(calculatedHeader, 2) : QObject::tr("valid")) - .hexarg2(fileHeader->IntegrityCheck.Checksum.File, 2) - .arg(msgInvalidDataChecksum ? QObject::tr("invalid, should be %1h").hexarg2(calculatedData, 2) : QObject::tr("valid")); + info = guidToUString(fileHeader->Name).prepend("File GUID : ") + + usprintf("\nType: %02Xh\nAttributes: %02Xh\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nTail size: %Xh (%u)\nState: %02Xh\n", + fileHeader->Type, + fileHeader->Attributes, + header.size() + body.size() + tail.size(), header.size() + body.size() + tail.size(), + header.size(), header.size(), + body.size(), body.size(), + tail.size(), tail.size(), + fileHeader->State) + + (msgInvalidHeaderChecksum ? usprintf("%02Xh, invalid, should be %02Xh", fileHeader->IntegrityCheck.Checksum.Header, calculatedHeader) : usprintf("%02X, valid", calculatedHeader)) + + (msgInvalidDataChecksum ? usprintf("%02Xh, invalid, should be %02Xh", fileHeader->IntegrityCheck.Checksum.File, calculatedData) : usprintf("%02X, valid", calculatedData)); // Add file GUID to parsing data pdata.file.guid = fileHeader->Name; - QString text; + UString text; bool isVtf = false; // Check if the file is a Volume Top File - if (QByteArray((const char*)&fileHeader->Name, sizeof(EFI_GUID)) == EFI_FFS_VOLUME_TOP_FILE_GUID) { + if (UByteArray((const char*)&fileHeader->Name, sizeof(EFI_GUID)) == EFI_FFS_VOLUME_TOP_FILE_GUID) { // Mark it as the last VTF // This information will later be used to determine memory addresses of uncompressed image elements // Because the last byte of the last VFT is mapped to 0xFFFFFFFF physical memory address isVtf = true; - text = QObject::tr("Volume Top File"); + text = UString("Volume Top File"); } // Construct parsing data @@ -1614,7 +1608,7 @@ STATUS FfsParser::parseFileHeader(const QByteArray & file, const UINT32 parentOf // Add tree item - index = model->addItem(Types::File, fileHeader->Type, name, text, info, header, body, tail, fixed, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::File, fileHeader->Type, name, text, info, header, body, tail, fixed, parsingDataToUByteArray(pdata), parent); // Overwrite lastVtf, if needed if (isVtf) { @@ -1623,22 +1617,22 @@ STATUS FfsParser::parseFileHeader(const QByteArray & file, const UINT32 parentOf // Show messages if (msgUnalignedFile) - msg(QObject::tr("parseFileHeader: unaligned file"), index); + msg(UString("parseFileHeader: unaligned file"), index); if (msgFileAlignmentIsGreaterThanVolumes) - msg(QObject::tr("parseFileHeader: file alignment %1h is greater than parent volume alignment %2h").hexarg(alignment).hexarg(pdata.volume.alignment), index); + msg(usprintf("parseFileHeader: file alignment %Xh is greater than parent volume alignment %Xh", alignment, pdata.volume.alignment), index); if (msgInvalidHeaderChecksum) - msg(QObject::tr("parseFileHeader: invalid header checksum"), index); + msg(UString("parseFileHeader: invalid header checksum"), index); if (msgInvalidDataChecksum) - msg(QObject::tr("parseFileHeader: invalid data checksum"), index); + msg(UString("parseFileHeader: invalid data checksum"), index); if (msgInvalidTailValue) - msg(QObject::tr("parseFileHeader: invalid tail value"), index); + msg(UString("parseFileHeader: invalid tail value"), index); if (msgUnknownType) - msg(QObject::tr("parseFileHeader: unknown file type %1h").hexarg2(fileHeader->Type, 2), index); + msg(usprintf("parseFileHeader: unknown file type %02Xh", fileHeader->Type), index); - return ERR_SUCCESS; + return U_SUCCESS; } -UINT32 FfsParser::getSectionSize(const QByteArray & file, const UINT32 sectionOffset, const UINT8 ffsVersion) +UINT32 FfsParser::getSectionSize(const UByteArray & file, const UINT32 sectionOffset, const UINT8 ffsVersion) { if (ffsVersion == 2) { if ((UINT32)file.size() < sectionOffset + sizeof(EFI_COMMON_SECTION_HEADER)) @@ -1660,15 +1654,15 @@ UINT32 FfsParser::getSectionSize(const QByteArray & file, const UINT32 sectionOf return 0; } -STATUS FfsParser::parseFileBody(const QModelIndex & index) +USTATUS FfsParser::parseFileBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Do not parse non-file bodies if (model->type(index) != Types::File) - return ERR_SUCCESS; + return U_SUCCESS; // Parse pad-file body if (model->subtype(index) == EFI_FV_FILETYPE_PAD) @@ -1677,10 +1671,10 @@ STATUS FfsParser::parseFileBody(const QModelIndex & index) // Parse raw files as raw areas if (model->subtype(index) == EFI_FV_FILETYPE_RAW || model->subtype(index) == EFI_FV_FILETYPE_ALL) { // Get data from parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); // Parse NVAR store - if (QByteArray((const char*)&pdata.file.guid, sizeof(EFI_GUID)) == NVRAM_NVAR_STORE_FILE_GUID) + if (UByteArray((const char*)&pdata.file.guid, sizeof(EFI_GUID)) == NVRAM_NVAR_STORE_FILE_GUID) return parseNvarStore(index); return parseRawArea(index); @@ -1690,19 +1684,19 @@ STATUS FfsParser::parseFileBody(const QModelIndex & index) return parseSections(model->body(index), index); } -STATUS FfsParser::parsePadFileBody(const QModelIndex & index) +USTATUS FfsParser::parsePadFileBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get data from parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); // Check if all bytes of the file are empty - QByteArray body = model->body(index); + UByteArray body = model->body(index); if (body.size() == body.count(pdata.emptyByte)) - return ERR_SUCCESS; + return U_SUCCESS; // Search for the first non-empty byte UINT32 i; @@ -1719,56 +1713,56 @@ STATUS FfsParser::parsePadFileBody(const QModelIndex & index) if (i != ALIGN8(i)) i = ALIGN8(i) - 8; - QByteArray free = body.left(i); + UByteArray free = body.left(i); // Get info - QString info = QObject::tr("Full size: %1h (%2)").hexarg(free.size()).arg(free.size()); + UString info = usprintf("Full size: %Xh (%u)", free.size(), free.size()); // Constuct parsing data pdata.offset += model->header(index).size(); // Add tree item - model->addItem(Types::FreeSpace, 0, QObject::tr("Free space"), QString(), info, QByteArray(), free, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::FreeSpace, 0, UString("Free space"), UString(), info, UByteArray(), free, UByteArray(), false, parsingDataToUByteArray(pdata), index); } else i = 0; // ... and all bytes after as a padding - QByteArray padding = body.mid(i); + UByteArray padding = body.mid(i); // Get info - QString info = QObject::tr("Full size: %1h (%2)").hexarg(padding.size()).arg(padding.size()); + UString info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Constuct parsing data pdata.offset += i; // Add tree item - QModelIndex dataIndex = model->addItem(Types::Padding, Subtypes::DataPadding, QObject::tr("Non-UEFI data"), "", info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); + UModelIndex dataIndex = model->addItem(Types::Padding, Subtypes::DataPadding, UString("Non-UEFI data"), "", info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); // Show message - msg(QObject::tr("parsePadFileBody: non-UEFI data found in pad-file"), dataIndex); + msg(UString("parsePadFileBody: non-UEFI data found in pad-file"), dataIndex); // Rename the file - model->setName(index, QObject::tr("Non-empty pad-file")); + model->setName(index, UString("Non-empty pad-file")); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseSections(const QByteArray & sections, const QModelIndex & index, const bool preparse) +USTATUS FfsParser::parseSections(const UByteArray & sections, const UModelIndex & index, const bool preparse) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get data from parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); // Search for and parse all sections UINT32 bodySize = sections.size(); UINT32 headerSize = model->header(index).size(); UINT32 sectionOffset = 0; - STATUS result = ERR_SUCCESS; + USTATUS result = U_SUCCESS; while (sectionOffset < bodySize) { // Get section size UINT32 sectionSize = getSectionSize(sections, sectionOffset, pdata.ffsVersion); @@ -1776,9 +1770,9 @@ STATUS FfsParser::parseSections(const QByteArray & sections, const QModelIndex & // Check section size if (sectionSize < sizeof(EFI_COMMON_SECTION_HEADER) || sectionSize > (bodySize - sectionOffset)) { // Add padding to fill the rest of sections - QByteArray padding = sections.mid(sectionOffset); + UByteArray padding = sections.mid(sectionOffset); // Get info - QString info = QObject::tr("Full size: %1h (%2)").hexarg(padding.size()).arg(padding.size()); + UString info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Constuct parsing data pdata.offset += headerSize + sectionOffset; @@ -1786,26 +1780,26 @@ STATUS FfsParser::parseSections(const QByteArray & sections, const QModelIndex & // Final parsing if (!preparse) { // Add tree item - QModelIndex dataIndex = model->addItem(Types::Padding, Subtypes::DataPadding, QObject::tr("Non-UEFI data"), "", info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); + UModelIndex dataIndex = model->addItem(Types::Padding, Subtypes::DataPadding, UString("Non-UEFI data"), "", info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); // Show message - msg(QObject::tr("parseSections: non-UEFI data found in sections area"), dataIndex); + msg(UString("parseSections: non-UEFI data found in sections area"), dataIndex); } // Preparsing else { - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; } break; // Exit from parsing loop } // Parse section header - QModelIndex sectionIndex; + UModelIndex sectionIndex; result = parseSectionHeader(sections.mid(sectionOffset, sectionSize), headerSize + sectionOffset, index, sectionIndex, preparse); if (result) { if (!preparse) - msg(QObject::tr("parseSections: section header parsing failed with error \"%1\"").arg(errorCodeToQString(result)), index); + msg(UString("parseSections: section header parsing failed with error ") + errorCodeToUString(result), index); else - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; } // Move to next section sectionOffset += sectionSize; @@ -1814,7 +1808,7 @@ STATUS FfsParser::parseSections(const QByteArray & sections, const QModelIndex & //Parse bodies, will be skipped on preparse phase for (int i = 0; i < model->rowCount(index); i++) { - QModelIndex current = index.child(i, 0); + UModelIndex current = index.child(i, 0); switch (model->type(current)) { case Types::Section: parseSectionBody(current); @@ -1823,18 +1817,18 @@ STATUS FfsParser::parseSections(const QByteArray & sections, const QModelIndex & // No parsing required break; default: - return ERR_UNKNOWN_ITEM_TYPE; + return U_UNKNOWN_ITEM_TYPE; } } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse) +USTATUS FfsParser::parseSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse) { // Check sanity if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; const EFI_COMMON_SECTION_HEADER* sectionHeader = (const EFI_COMMON_SECTION_HEADER*)(section.constData()); switch (sectionHeader->Type) { @@ -1859,20 +1853,20 @@ STATUS FfsParser::parseSectionHeader(const QByteArray & section, const UINT32 pa case EFI_SECTION_RAW: return parseCommonSectionHeader(section, parentOffset, parent, index, preparse); // Unknown default: - STATUS result = parseCommonSectionHeader(section, parentOffset, parent, index, preparse); - msg(QObject::tr("parseSectionHeader: section with unknown type %1h").hexarg2(sectionHeader->Type, 2), index); + USTATUS result = parseCommonSectionHeader(section, parentOffset, parent, index, preparse); + msg(usprintf("parseSectionHeader: section with unknown type %02Xh", sectionHeader->Type), index); return result; } } -STATUS FfsParser::parseCommonSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse) +USTATUS FfsParser::parseCommonSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse) { // Check sanity if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; // Get data from parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Obtain header fields UINT32 headerSize; @@ -1892,37 +1886,37 @@ STATUS FfsParser::parseCommonSectionHeader(const QByteArray & section, const UIN // Check sanity again if ((UINT32)section.size() < headerSize) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; - QByteArray header = section.left(headerSize); - QByteArray body = section.mid(headerSize); + UByteArray header = section.left(headerSize); + UByteArray body = section.mid(headerSize); // Get info - QString name = sectionTypeToQString(type) + QObject::tr(" section"); - QString info = QObject::tr("Type: %1h\nFull size: %2h (%3)\nHeader size: %4h (%5)\nBody size: %6h (%7)") - .hexarg2(type, 2) - .hexarg(section.size()).arg(section.size()) - .hexarg(headerSize).arg(headerSize) - .hexarg(body.size()).arg(body.size()); + UString name = sectionTypeToUString(type) + UString(" section"); + UString info = usprintf("Type: %02Xh\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)", + type, + section.size(), section.size(), + headerSize, headerSize, + body.size(), body.size()); // Construct parsing data pdata.offset += parentOffset; // Add tree item if (!preparse) { - index = model->addItem(Types::Section, type, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Section, type, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseCompressedSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse) +USTATUS FfsParser::parseCompressedSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse) { // Check sanity if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; // Get data from parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Obtain header fields UINT32 headerSize; @@ -1941,7 +1935,7 @@ STATUS FfsParser::parseCompressedSectionHeader(const QByteArray & section, const else if (pdata.ffsVersion == 3 && uint24ToUint32(sectionHeader->Size) == EFI_SECTION2_IS_USED) { // Check for extended header section const EFI_COMPRESSION_SECTION* compressedSectionHeader = (const EFI_COMPRESSION_SECTION*)(section2Header + 1); if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER2) + sizeof(EFI_COMPRESSION_SECTION)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; headerSize = sizeof(EFI_COMMON_SECTION_HEADER2) + sizeof(EFI_COMPRESSION_SECTION); compressionType = compressedSectionHeader->CompressionType; uncompressedLength = compressedSectionHeader->UncompressedLength; @@ -1955,20 +1949,20 @@ STATUS FfsParser::parseCompressedSectionHeader(const QByteArray & section, const // Check sanity again if ((UINT32)section.size() < headerSize) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; - QByteArray header = section.left(headerSize); - QByteArray body = section.mid(headerSize); + UByteArray header = section.left(headerSize); + UByteArray body = section.mid(headerSize); // Get info - QString name = sectionTypeToQString(sectionHeader->Type) + QObject::tr(" section"); - QString info = QObject::tr("Type: %1h\nFull size: %2h (%3)\nHeader size: %4h (%5)\nBody size: %6h (%7)\nCompression type: %8h\nDecompressed size: %9h (%10)") - .hexarg2(sectionHeader->Type, 2) - .hexarg(section.size()).arg(section.size()) - .hexarg(headerSize).arg(headerSize) - .hexarg(body.size()).arg(body.size()) - .hexarg2(compressionType, 2) - .hexarg(uncompressedLength).arg(uncompressedLength); + UString name = sectionTypeToUString(sectionHeader->Type) + UString(" section"); + UString info = usprintf("Type: %02Xh\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nCompression type: %02Xh\nDecompressed size: %Xh (%u)", + sectionHeader->Type, + section.size(), section.size(), + headerSize, headerSize, + body.size(), body.size(), + compressionType, + uncompressedLength, uncompressedLength); // Construct parsing data pdata.offset += parentOffset; @@ -1977,19 +1971,19 @@ STATUS FfsParser::parseCompressedSectionHeader(const QByteArray & section, const // Add tree item if (!preparse) { - index = model->addItem(Types::Section, sectionHeader->Type, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Section, sectionHeader->Type, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseGuidedSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse) +USTATUS FfsParser::parseGuidedSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse) { // Check sanity if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; // Get data from parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Obtain header fields UINT32 headerSize; @@ -2004,7 +1998,7 @@ STATUS FfsParser::parseGuidedSectionHeader(const QByteArray & section, const UIN const EFI_GUID_DEFINED_SECTION_APPLE* appleSectionHeader = (const EFI_GUID_DEFINED_SECTION_APPLE*)(appleHeader + 1); headerSize = sizeof(EFI_COMMON_SECTION_HEADER_APPLE) + sizeof(EFI_GUID_DEFINED_SECTION_APPLE); if ((UINT32)section.size() < headerSize) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; guid = appleSectionHeader->SectionDefinitionGuid; dataOffset = appleSectionHeader->DataOffset; attributes = appleSectionHeader->Attributes; @@ -2012,7 +2006,7 @@ STATUS FfsParser::parseGuidedSectionHeader(const QByteArray & section, const UIN else if (pdata.ffsVersion == 3 && uint24ToUint32(sectionHeader->Size) == EFI_SECTION2_IS_USED) { // Check for extended header section const EFI_GUID_DEFINED_SECTION* guidDefinedSectionHeader = (const EFI_GUID_DEFINED_SECTION*)(section2Header + 1); if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER2) + sizeof(EFI_GUID_DEFINED_SECTION)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; headerSize = sizeof(EFI_COMMON_SECTION_HEADER2) + sizeof(EFI_GUID_DEFINED_SECTION); guid = guidDefinedSectionHeader->SectionDefinitionGuid; dataOffset = guidDefinedSectionHeader->DataOffset; @@ -2027,11 +2021,11 @@ STATUS FfsParser::parseGuidedSectionHeader(const QByteArray & section, const UIN } // Check sanity again if ((UINT32)section.size() < headerSize) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; // Check for special GUIDed sections - QByteArray additionalInfo; - QByteArray baGuid((const char*)&guid, sizeof(EFI_GUID)); + UByteArray additionalInfo; + UByteArray baGuid((const char*)&guid, sizeof(EFI_GUID)); bool msgSignedSectionFound = false; bool msgNoAuthStatusAttribute = false; bool msgNoProcessingRequiredAttributeCompressed = false; @@ -2045,17 +2039,17 @@ STATUS FfsParser::parseGuidedSectionHeader(const QByteArray & section, const UIN } if ((UINT32)section.size() < headerSize + sizeof(UINT32)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; UINT32 crc = *(UINT32*)(section.constData() + headerSize); - additionalInfo += QObject::tr("\nChecksum type: CRC32"); + additionalInfo += UString("\nChecksum type: CRC32"); // Calculate CRC32 of section data UINT32 calculated = crc32(0, (const UINT8*)section.constData() + dataOffset, section.size() - dataOffset); if (crc == calculated) { - additionalInfo += QObject::tr("\nChecksum: %1h, valid").hexarg2(crc, 8); + additionalInfo += usprintf("\nChecksum: %08Xh, valid", crc); } else { - additionalInfo += QObject::tr("\nChecksum: %1h, invalid, should be %2h").hexarg2(crc, 8).hexarg2(calculated, 8); + additionalInfo += usprintf("\nChecksum: %02Xh, invalid, should be %02Xh", crc, calculated); msgInvalidCrc = true; } // No need to change dataOffset here @@ -2073,7 +2067,7 @@ STATUS FfsParser::parseGuidedSectionHeader(const QByteArray & section, const UIN // Get certificate type and length if ((UINT32)section.size() < headerSize + sizeof(WIN_CERTIFICATE)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; const WIN_CERTIFICATE* winCertificate = (const WIN_CERTIFICATE*)(section.constData() + headerSize); UINT32 certLength = winCertificate->Length; @@ -2084,44 +2078,44 @@ STATUS FfsParser::parseGuidedSectionHeader(const QByteArray & section, const UIN // Check section size once again if ((UINT32)section.size() < dataOffset) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; // Check certificate type if (certType == WIN_CERT_TYPE_EFI_GUID) { - additionalInfo += QObject::tr("\nCertificate type: UEFI"); + additionalInfo += UString("\nCertificate type: UEFI"); // Get certificate GUID const WIN_CERTIFICATE_UEFI_GUID* winCertificateUefiGuid = (const WIN_CERTIFICATE_UEFI_GUID*)(section.constData() + headerSize); - QByteArray certTypeGuid((const char*)&winCertificateUefiGuid->CertType, sizeof(EFI_GUID)); + UByteArray certTypeGuid((const char*)&winCertificateUefiGuid->CertType, sizeof(EFI_GUID)); if (certTypeGuid == EFI_CERT_TYPE_RSA2048_SHA256_GUID) { - additionalInfo += QObject::tr("\nCertificate subtype: RSA2048/SHA256"); + additionalInfo += UString("\nCertificate subtype: RSA2048/SHA256"); } else { - additionalInfo += QObject::tr("\nCertificate subtype: unknown, GUID %1").arg(guidToQString(winCertificateUefiGuid->CertType)); + additionalInfo += UString("\nCertificate subtype: unknown, GUID ") + guidToUString(winCertificateUefiGuid->CertType); msgUnknownCertSubtype = true; } } else { - additionalInfo += QObject::tr("\nCertificate type: unknown (%1h)").hexarg2(certType, 4); + additionalInfo += usprintf("\nCertificate type: unknown (%04Xh)", certType); msgUnknownCertType = true; } msgSignedSectionFound = true; } - QByteArray header = section.left(dataOffset); - QByteArray body = section.mid(dataOffset); + UByteArray header = section.left(dataOffset); + UByteArray body = section.mid(dataOffset); // Get info - QString name = guidToQString(guid); - QString info = QObject::tr("Section GUID: %1\nType: %2h\nFull size: %3h (%4)\nHeader size: %5h (%6)\nBody size: %7h (%8)\nData offset: %9h\nAttributes: %10h") - .arg(name) - .hexarg2(sectionHeader->Type, 2) - .hexarg(section.size()).arg(section.size()) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .hexarg(dataOffset) - .hexarg2(attributes, 4); + UString name = guidToUString(guid); + UString info = UString("Section GUID: ") + name + + usprintf("\nType: %02Xh\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nData offset: %Xh\nAttributes: %04Xh", + sectionHeader->Type, + section.size(), section.size(), + header.size(), header.size(), + body.size(), body.size(), + dataOffset, + attributes); // Append additional info info.append(additionalInfo); @@ -2132,36 +2126,36 @@ STATUS FfsParser::parseGuidedSectionHeader(const QByteArray & section, const UIN // Add tree item if (!preparse) { - index = model->addItem(Types::Section, sectionHeader->Type, name, QString(), info, header, body, QByteArray(), false, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Section, sectionHeader->Type, name, UString(), info, header, body, UByteArray(), false, parsingDataToUByteArray(pdata), parent); // Show messages if (msgSignedSectionFound) - msg(QObject::tr("parseGuidedSectionHeader: section signature may become invalid after any modification"), index); + msg(UString("parseGuidedSectionHeader: section signature may become invalid after any modification"), index); if (msgNoAuthStatusAttribute) - msg(QObject::tr("parseGuidedSectionHeader: CRC32 GUIDed section without AuthStatusValid attribute"), index); + msg(UString("parseGuidedSectionHeader: CRC32 GUIDed section without AuthStatusValid attribute"), index); if (msgNoProcessingRequiredAttributeCompressed) - msg(QObject::tr("parseGuidedSectionHeader: compressed GUIDed section without ProcessingRequired attribute"), index); + msg(UString("parseGuidedSectionHeader: compressed GUIDed section without ProcessingRequired attribute"), index); if (msgNoProcessingRequiredAttributeSigned) - msg(QObject::tr("parseGuidedSectionHeader: signed GUIDed section without ProcessingRequired attribute"), index); + msg(UString("parseGuidedSectionHeader: signed GUIDed section without ProcessingRequired attribute"), index); if (msgInvalidCrc) - msg(QObject::tr("parseGuidedSectionHeader: GUID defined section with invalid CRC32"), index); + msg(UString("parseGuidedSectionHeader: GUID defined section with invalid CRC32"), index); if (msgUnknownCertType) - msg(QObject::tr("parseGuidedSectionHeader: signed GUIDed section with unknown type"), index); + msg(UString("parseGuidedSectionHeader: signed GUIDed section with unknown type"), index); if (msgUnknownCertSubtype) - msg(QObject::tr("parseGuidedSectionHeader: signed GUIDed section with unknown subtype"), index); + msg(UString("parseGuidedSectionHeader: signed GUIDed section with unknown subtype"), index); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseFreeformGuidedSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse) +USTATUS FfsParser::parseFreeformGuidedSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse) { // Check sanity if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; // Get data from parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Obtain header fields UINT32 headerSize; @@ -2180,7 +2174,7 @@ STATUS FfsParser::parseFreeformGuidedSectionHeader(const QByteArray & section, c else if (pdata.ffsVersion == 3 && uint24ToUint32(sectionHeader->Size) == EFI_SECTION2_IS_USED) { // Check for extended header section const EFI_FREEFORM_SUBTYPE_GUID_SECTION* fsgSectionHeader = (const EFI_FREEFORM_SUBTYPE_GUID_SECTION*)(section2Header + 1); if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER2) + sizeof(EFI_FREEFORM_SUBTYPE_GUID_SECTION)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; headerSize = sizeof(EFI_COMMON_SECTION_HEADER2) + sizeof(EFI_FREEFORM_SUBTYPE_GUID_SECTION); guid = fsgSectionHeader->SubTypeGuid; type = section2Header->Type; @@ -2194,19 +2188,19 @@ STATUS FfsParser::parseFreeformGuidedSectionHeader(const QByteArray & section, c // Check sanity again if ((UINT32)section.size() < headerSize) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; - QByteArray header = section.left(headerSize); - QByteArray body = section.mid(headerSize); + UByteArray header = section.left(headerSize); + UByteArray body = section.mid(headerSize); // Get info - QString name = sectionTypeToQString(type) + QObject::tr(" section"); - QString info = QObject::tr("Type: %1h\nFull size: %2h (%3)\nHeader size: %4h (%5)\nBody size: %6h (%7)\nSubtype GUID: %8") - .hexarg2(type, 2) - .hexarg(section.size()).arg(section.size()) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .arg(guidToQString(guid)); + UString name = sectionTypeToUString(type) + (" section"); + UString info = usprintf("Type: %02Xh\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nSubtype GUID: ", + type, + section.size(), section.size(), + header.size(), header.size(), + body.size(), body.size()) + + guidToUString(guid); // Construct parsing data pdata.offset += parentOffset; @@ -2214,22 +2208,22 @@ STATUS FfsParser::parseFreeformGuidedSectionHeader(const QByteArray & section, c // Add tree item if (!preparse) { - index = model->addItem(Types::Section, type, name, QString(), info, header, body, QByteArray(), false, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Section, type, name, UString(), info, header, body, UByteArray(), false, parsingDataToUByteArray(pdata), parent); // Rename section - model->setName(index, guidToQString(guid)); + model->setName(index, guidToUString(guid)); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseVersionSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse) +USTATUS FfsParser::parseVersionSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse) { // Check sanity if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; // Get data from parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Obtain header fields UINT32 headerSize; @@ -2260,38 +2254,38 @@ STATUS FfsParser::parseVersionSectionHeader(const QByteArray & section, const UI // Check sanity again if ((UINT32)section.size() < headerSize) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; - QByteArray header = section.left(headerSize); - QByteArray body = section.mid(headerSize); + UByteArray header = section.left(headerSize); + UByteArray body = section.mid(headerSize); // Get info - QString name = sectionTypeToQString(type) + QObject::tr(" section"); - QString info = QObject::tr("Type: %1h\nFull size: %2h (%3)\nHeader size: %4h (%5)\nBody size: %6h (%7)\nBuild number: %8") - .hexarg2(type, 2) - .hexarg(section.size()).arg(section.size()) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .arg(buildNumber); + UString name = sectionTypeToUString(type) + (" section"); + UString info = ("Type: %02Xh\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nBuild number: %u", + type, + section.size(), section.size(), + header.size(), header.size(), + body.size(), body.size(), + buildNumber); // Construct parsing data pdata.offset += parentOffset; // Add tree item if (!preparse) { - index = model->addItem(Types::Section, type, name, QString(), info, header, body, QByteArray(), false, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Section, type, name, UString(), info, header, body, UByteArray(), false, parsingDataToUByteArray(pdata), parent); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parsePostcodeSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse) +USTATUS FfsParser::parsePostcodeSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse) { // Check sanity if ((UINT32)section.size() < sizeof(EFI_COMMON_SECTION_HEADER)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; // Get data from parent's parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Obtain header fields UINT32 headerSize; @@ -2322,39 +2316,39 @@ STATUS FfsParser::parsePostcodeSectionHeader(const QByteArray & section, const U // Check sanity again if ((UINT32)section.size() < headerSize) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; - QByteArray header = section.left(headerSize); - QByteArray body = section.mid(headerSize); + UByteArray header = section.left(headerSize); + UByteArray body = section.mid(headerSize); // Get info - QString name = sectionTypeToQString(type) + QObject::tr(" section"); - QString info = QObject::tr("Type: %1h\nFull size: %2h (%3)\nHeader size: %4h (%5)\nBody size: %6h (%7)\nPostcode: %8h") - .hexarg2(type, 2) - .hexarg(section.size()).arg(section.size()) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .hexarg(postCode); + UString name = sectionTypeToUString(type) + (" section"); + UString info = ("Type: %02Xh\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nPostcode: %Xh", + type, 2, + section.size(), section.size(), + header.size(), header.size(), + body.size(), body.size(), + postCode); // Construct parsing data pdata.offset += parentOffset; // Add tree item if (!preparse) { - index = model->addItem(Types::Section, sectionHeader->Type, name, QString(), info, header, body, QByteArray(), false, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Section, sectionHeader->Type, name, UString(), info, header, body, UByteArray(), false, parsingDataToUByteArray(pdata), parent); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseSectionBody(const QModelIndex & index) +USTATUS FfsParser::parseSectionBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; - QByteArray header = model->header(index); + return U_INVALID_PARAMETER; + UByteArray header = model->header(index); if ((UINT32)header.size() < sizeof(EFI_COMMON_SECTION_HEADER)) - return ERR_INVALID_SECTION; + return U_INVALID_SECTION; const EFI_COMMON_SECTION_HEADER* sectionHeader = (const EFI_COMMON_SECTION_HEADER*)(header.constData()); @@ -2380,130 +2374,130 @@ STATUS FfsParser::parseSectionBody(const QModelIndex & index) case PHOENIX_SECTION_POSTCODE: case INSYDE_SECTION_POSTCODE: default: - return ERR_SUCCESS; + return U_SUCCESS; } } -STATUS FfsParser::parseCompressedSectionBody(const QModelIndex & index) +USTATUS FfsParser::parseCompressedSectionBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get data from parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); UINT8 algorithm = pdata.section.compressed.compressionType; // Decompress section - QByteArray decompressed; - QByteArray efiDecompressed; - STATUS result = decompress(model->body(index), algorithm, decompressed, efiDecompressed); + UByteArray decompressed; + UByteArray efiDecompressed; + USTATUS result = decompress(model->body(index), algorithm, decompressed, efiDecompressed); if (result) { - msg(QObject::tr("parseCompressedSectionBody: decompression failed with error \"%1\"").arg(errorCodeToQString(result)), index); - return ERR_SUCCESS; + msg(UString("parseCompressedSectionBody: decompression failed with error ") + errorCodeToUString(result), index); + return U_SUCCESS; } // Check reported uncompressed size if (pdata.section.compressed.uncompressedSize != (UINT32)decompressed.size()) { - msg(QObject::tr("parseCompressedSectionBody: decompressed size stored in header %1h (%2) differs from actual %3h (%4)") - .hexarg(pdata.section.compressed.uncompressedSize) - .arg(pdata.section.compressed.uncompressedSize) - .hexarg(decompressed.size()) - .arg(decompressed.size()), index); - model->addInfo(index, QObject::tr("\nActual decompressed size: %1h (%2)").hexarg(decompressed.size()).arg(decompressed.size())); + msg(usprintf("parseCompressedSectionBody: decompressed size stored in header %Xh (%u) differs from actual %Xh (%u)", + pdata.section.compressed.uncompressedSize, + pdata.section.compressed.uncompressedSize, + decompressed.size(), + decompressed.size()), index); + model->addInfo(index, usprintf("\nActual decompressed size: %Xh (%u)", decompressed.size(), decompressed.size())); } // Check for undecided compression algorithm, this is a special case if (algorithm == COMPRESSION_ALGORITHM_UNDECIDED) { // Try preparse of sections decompressed with Tiano algorithm - if (ERR_SUCCESS == parseSections(decompressed, index, true)) { + if (U_SUCCESS == parseSections(decompressed, index, true)) { algorithm = COMPRESSION_ALGORITHM_TIANO; } // Try preparse of sections decompressed with EFI 1.1 algorithm - else if (ERR_SUCCESS == parseSections(efiDecompressed, index, true)) { + else if (U_SUCCESS == parseSections(efiDecompressed, index, true)) { algorithm = COMPRESSION_ALGORITHM_EFI11; decompressed = efiDecompressed; } else { - msg(QObject::tr("parseCompressedSectionBody: can't guess the correct decompression algorithm, both preparse steps are failed"), index); + msg(UString("parseCompressedSectionBody: can't guess the correct decompression algorithm, both preparse steps are failed"), index); } } // Add info - model->addInfo(index, QObject::tr("\nCompression algorithm: %1").arg(compressionTypeToQString(algorithm))); + model->addInfo(index, UString("\nCompression algorithm: ") + compressionTypeToUString(algorithm)); // Update data pdata.section.compressed.algorithm = algorithm; if (algorithm != COMPRESSION_ALGORITHM_NONE) model->setCompressed(index, true); - model->setParsingData(index, parsingDataToQByteArray(pdata)); + model->setParsingData(index, parsingDataToUByteArray(pdata)); // Parse decompressed data return parseSections(decompressed, index); } -STATUS FfsParser::parseGuidedSectionBody(const QModelIndex & index) +USTATUS FfsParser::parseGuidedSectionBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get data from parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); EFI_GUID guid = pdata.section.guidDefined.guid; // Check if section requires processing - QByteArray processed = model->body(index); - QByteArray efiDecompressed; - QString info; + UByteArray processed = model->body(index); + UByteArray efiDecompressed; + UString info; bool parseCurrentSection = true; UINT8 algorithm = COMPRESSION_ALGORITHM_NONE; // Tiano compressed section - if (QByteArray((const char*)&guid, sizeof(EFI_GUID)) == EFI_GUIDED_SECTION_TIANO) { + if (UByteArray((const char*)&guid, sizeof(EFI_GUID)) == EFI_GUIDED_SECTION_TIANO) { algorithm = EFI_STANDARD_COMPRESSION; - STATUS result = decompress(model->body(index), algorithm, processed, efiDecompressed); + USTATUS result = decompress(model->body(index), algorithm, processed, efiDecompressed); if (result) { parseCurrentSection = false; - msg(QObject::tr("parseGuidedSectionBody: decompression failed with error \"%1\"").arg(errorCodeToQString(result)), index); - return ERR_SUCCESS; + msg(UString("parseGuidedSectionBody: decompression failed with error ") + errorCodeToUString(result), index); + return U_SUCCESS; } // Check for undecided compression algorithm, this is a special case if (algorithm == COMPRESSION_ALGORITHM_UNDECIDED) { // Try preparse of sections decompressed with Tiano algorithm - if (ERR_SUCCESS == parseSections(processed, index, true)) { + if (U_SUCCESS == parseSections(processed, index, true)) { algorithm = COMPRESSION_ALGORITHM_TIANO; } // Try preparse of sections decompressed with EFI 1.1 algorithm - else if (ERR_SUCCESS == parseSections(efiDecompressed, index, true)) { + else if (U_SUCCESS == parseSections(efiDecompressed, index, true)) { algorithm = COMPRESSION_ALGORITHM_EFI11; processed = efiDecompressed; } else { - msg(QObject::tr("parseGuidedSectionBody: can't guess the correct decompression algorithm, both preparse steps are failed"), index); + msg(UString("parseGuidedSectionBody: can't guess the correct decompression algorithm, both preparse steps are failed"), index); parseCurrentSection = false; } } - info += QObject::tr("\nCompression algorithm: %1").arg(compressionTypeToQString(algorithm)); - info += QObject::tr("\nDecompressed size: %1h (%2)").hexarg(processed.length()).arg(processed.length()); + info += UString("\nCompression algorithm: ") + compressionTypeToUString(algorithm); + info += usprintf("\nDecompressed size: %Xh (%u)", processed.length(), processed.length()); } // LZMA compressed section - else if (QByteArray((const char*)&guid, sizeof(EFI_GUID)) == EFI_GUIDED_SECTION_LZMA) { + else if (UByteArray((const char*)&guid, sizeof(EFI_GUID)) == EFI_GUIDED_SECTION_LZMA) { algorithm = EFI_CUSTOMIZED_COMPRESSION; - STATUS result = decompress(model->body(index), algorithm, processed, efiDecompressed); + USTATUS result = decompress(model->body(index), algorithm, processed, efiDecompressed); if (result) { parseCurrentSection = false; - msg(QObject::tr("parseGuidedSectionBody: decompression failed with error \"%1\"").arg(errorCodeToQString(result)), index); - return ERR_SUCCESS; + msg(UString("parseGuidedSectionBody: decompression failed with error ") + errorCodeToUString(result), index); + return U_SUCCESS; } if (algorithm == COMPRESSION_ALGORITHM_LZMA) { - info += QObject::tr("\nCompression algorithm: LZMA"); - info += QObject::tr("\nDecompressed size: %1h (%2)").hexarg(processed.length()).arg(processed.length()); + info += UString("\nCompression algorithm: LZMA"); + info += usprintf("\nDecompressed size: %Xh (%u)", processed.length(), processed.length()); } else { - info += QObject::tr("\nCompression algorithm: unknown"); + info += UString("\nCompression algorithm: unknown"); parseCurrentSection = false; } } @@ -2514,41 +2508,41 @@ STATUS FfsParser::parseGuidedSectionBody(const QModelIndex & index) // Update data if (algorithm != COMPRESSION_ALGORITHM_NONE) model->setCompressed(index, true); - model->setParsingData(index, parsingDataToQByteArray(pdata)); + model->setParsingData(index, parsingDataToUByteArray(pdata)); if (!parseCurrentSection) { - msg(QObject::tr("parseGuidedSectionBody: GUID defined section can not be processed"), index); - return ERR_SUCCESS; + msg(UString("parseGuidedSectionBody: GUID defined section can not be processed"), index); + return U_SUCCESS; } return parseSections(processed, index); } -STATUS FfsParser::parseVersionSectionBody(const QModelIndex & index) +USTATUS FfsParser::parseVersionSectionBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Add info - model->addInfo(index, QObject::tr("\nVersion string: %1").arg(QString::fromUtf16((const CHAR16*)model->body(index).constData()))); + model->addInfo(index, UString("\nVersion string: ") + UString::fromUtf16((const CHAR16*)model->body(index).constData())); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseDepexSectionBody(const QModelIndex & index) +USTATUS FfsParser::parseDepexSectionBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; - QByteArray body = model->body(index); - QString parsed; + UByteArray body = model->body(index); + UString parsed; // Check data to be present if (body.size() < 2) { // 2 is a minimal sane value, i.e TRUE + END - msg(QObject::tr("parseDepexSectionBody: DEPEX section too short"), index); - return ERR_DEPEX_PARSE_FAILED; + msg(UString("parseDepexSectionBody: DEPEX section too short"), index); + return U_DEPEX_PARSE_FAILED; } const EFI_GUID * guid; @@ -2558,36 +2552,36 @@ STATUS FfsParser::parseDepexSectionBody(const QModelIndex & index) switch (*current) { case EFI_DEP_BEFORE: if (body.size() != 2 * EFI_DEP_OPCODE_SIZE + sizeof(EFI_GUID)) { - msg(QObject::tr("parseDepexSectionBody: DEPEX section too long for a section starting with BEFORE opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: DEPEX section too long for a section starting with BEFORE opcode"), index); + return U_SUCCESS; } guid = (const EFI_GUID*)(current + EFI_DEP_OPCODE_SIZE); - parsed += QObject::tr("\nBEFORE %1").arg(guidToQString(*guid)); + parsed += UString("\nBEFORE ") + guidToUString(*guid); current += EFI_DEP_OPCODE_SIZE + sizeof(EFI_GUID); if (*current != EFI_DEP_END){ - msg(QObject::tr("parseDepexSectionBody: DEPEX section ends with non-END opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: DEPEX section ends with non-END opcode"), index); + return U_SUCCESS; } - return ERR_SUCCESS; + return U_SUCCESS; case EFI_DEP_AFTER: if (body.size() != 2 * EFI_DEP_OPCODE_SIZE + sizeof(EFI_GUID)){ - msg(QObject::tr("parseDepexSectionBody: DEPEX section too long for a section starting with AFTER opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: DEPEX section too long for a section starting with AFTER opcode"), index); + return U_SUCCESS; } guid = (const EFI_GUID*)(current + EFI_DEP_OPCODE_SIZE); - parsed += QObject::tr("\nAFTER %1").arg(guidToQString(*guid)); + parsed += UString("\nAFTER ") + guidToUString(*guid); current += EFI_DEP_OPCODE_SIZE + sizeof(EFI_GUID); if (*current != EFI_DEP_END) { - msg(QObject::tr("parseDepexSectionBody: DEPEX section ends with non-END opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: DEPEX section ends with non-END opcode"), index); + return U_SUCCESS; } - return ERR_SUCCESS; + return U_SUCCESS; case EFI_DEP_SOR: if (body.size() <= 2 * EFI_DEP_OPCODE_SIZE) { - msg(QObject::tr("parseDepexSectionBody: DEPEX section too short for a section starting with SOR opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: DEPEX section too short for a section starting with SOR opcode"), index); + return U_SUCCESS; } - parsed += QObject::tr("\nSOR"); + parsed += UString("\nSOR"); current += EFI_DEP_OPCODE_SIZE; break; } @@ -2596,148 +2590,148 @@ STATUS FfsParser::parseDepexSectionBody(const QModelIndex & index) while (current - (const UINT8*)body.constData() < body.size()) { switch (*current) { case EFI_DEP_BEFORE: { - msg(QObject::tr("parseDepexSectionBody: misplaced BEFORE opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: misplaced BEFORE opcode"), index); + return U_SUCCESS; } case EFI_DEP_AFTER: { - msg(QObject::tr("parseDepexSectionBody: misplaced AFTER opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: misplaced AFTER opcode"), index); + return U_SUCCESS; } case EFI_DEP_SOR: { - msg(QObject::tr("parseDepexSectionBody: misplaced SOR opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: misplaced SOR opcode"), index); + return U_SUCCESS; } case EFI_DEP_PUSH: // Check that the rest of depex has correct size if ((UINT32)body.size() - (UINT32)(current - (const UINT8*)body.constData()) <= EFI_DEP_OPCODE_SIZE + sizeof(EFI_GUID)) { parsed.clear(); - msg(QObject::tr("parseDepexSectionBody: remains of DEPEX section too short for PUSH opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: remains of DEPEX section too short for PUSH opcode"), index); + return U_SUCCESS; } guid = (const EFI_GUID*)(current + EFI_DEP_OPCODE_SIZE); - parsed += QObject::tr("\nPUSH %1").arg(guidToQString(*guid)); + parsed += UString("\nPUSH ") + guidToUString(*guid); current += EFI_DEP_OPCODE_SIZE + sizeof(EFI_GUID); break; case EFI_DEP_AND: - parsed += QObject::tr("\nAND"); + parsed += UString("\nAND"); current += EFI_DEP_OPCODE_SIZE; break; case EFI_DEP_OR: - parsed += QObject::tr("\nOR"); + parsed += UString("\nOR"); current += EFI_DEP_OPCODE_SIZE; break; case EFI_DEP_NOT: - parsed += QObject::tr("\nNOT"); + parsed += UString("\nNOT"); current += EFI_DEP_OPCODE_SIZE; break; case EFI_DEP_TRUE: - parsed += QObject::tr("\nTRUE"); + parsed += UString("\nTRUE"); current += EFI_DEP_OPCODE_SIZE; break; case EFI_DEP_FALSE: - parsed += QObject::tr("\nFALSE"); + parsed += UString("\nFALSE"); current += EFI_DEP_OPCODE_SIZE; break; case EFI_DEP_END: - parsed += QObject::tr("\nEND"); + parsed += UString("\nEND"); current += EFI_DEP_OPCODE_SIZE; // Check that END is the last opcode if (current - (const UINT8*)body.constData() < body.size()) { parsed.clear(); - msg(QObject::tr("parseDepexSectionBody: DEPEX section ends with non-END opcode"), index); + msg(UString("parseDepexSectionBody: DEPEX section ends with non-END opcode"), index); } break; default: - msg(QObject::tr("parseDepexSectionBody: unknown opcode"), index); - return ERR_SUCCESS; + msg(UString("parseDepexSectionBody: unknown opcode"), index); + return U_SUCCESS; break; } } // Add info - model->addInfo(index, QObject::tr("\nParsed expression:%1").arg(parsed)); + model->addInfo(index, UString("\nParsed expression:") + parsed); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseUiSectionBody(const QModelIndex & index) +USTATUS FfsParser::parseUiSectionBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; - QString text = QString::fromUtf16((const CHAR16*)model->body(index).constData()); + UString text = UString::fromUtf16((const CHAR16*)model->body(index).constData()); // Add info - model->addInfo(index, QObject::tr("\nText: %1").arg(text)); + model->addInfo(index, UString("\nText: ") + text); // Rename parent file model->setText(model->findParentOfType(index, Types::File), text); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseAprioriRawSection(const QByteArray & body, QString & parsed) +USTATUS FfsParser::parseAprioriRawSection(const UByteArray & body, UString & parsed) { // Sanity check if (body.size() % sizeof(EFI_GUID)) { - msg(QObject::tr("parseAprioriRawSection: apriori file has size is not a multiple of 16")); + msg(UString("parseAprioriRawSection: apriori file has size is not a multiple of 16")); } parsed.clear(); UINT32 count = body.size() / sizeof(EFI_GUID); if (count > 0) { for (UINT32 i = 0; i < count; i++) { const EFI_GUID* guid = (const EFI_GUID*)body.constData() + i; - parsed += QObject::tr("\n%1").arg(guidToQString(*guid)); + parsed += guidToUString(*guid).prepend("\n"); } } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseRawSectionBody(const QModelIndex & index) +USTATUS FfsParser::parseRawSectionBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Check for apriori file - QModelIndex parentFile = model->findParentOfType(index, Types::File); + UModelIndex parentFile = model->findParentOfType(index, Types::File); // Get parent file parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parentFile); - QByteArray parentFileGuid((const char*)&pdata.file.guid, sizeof(EFI_GUID)); + PARSING_DATA pdata = parsingDataFromUModelIndex(parentFile); + UByteArray parentFileGuid((const char*)&pdata.file.guid, sizeof(EFI_GUID)); if (parentFileGuid == EFI_PEI_APRIORI_FILE_GUID) { // PEI apriori file // Parse apriori file list - QString str; - STATUS result = parseAprioriRawSection(model->body(index), str); + UString str; + USTATUS result = parseAprioriRawSection(model->body(index), str); if (!result && !str.isEmpty()) - model->addInfo(index, QObject::tr("\nFile list:%1").arg(str)); + model->addInfo(index, UString("\nFile list:") + str); // Set parent file text - model->setText(parentFile, QObject::tr("PEI apriori file")); + model->setText(parentFile, UString("PEI apriori file")); - return ERR_SUCCESS; + return U_SUCCESS; } else if (parentFileGuid == EFI_DXE_APRIORI_FILE_GUID) { // DXE apriori file // Parse apriori file list - QString str; - STATUS result = parseAprioriRawSection(model->body(index), str); + UString str; + USTATUS result = parseAprioriRawSection(model->body(index), str); if (!result && !str.isEmpty()) - model->addInfo(index, QObject::tr("\nFile list:%1").arg(str)); + model->addInfo(index, UString("\nFile list:") + str); // Set parent file text - model->setText(parentFile, QObject::tr("DXE apriori file")); + model->setText(parentFile, UString("DXE apriori file")); - return ERR_SUCCESS; + return U_SUCCESS; } else if (parentFileGuid == NVRAM_NVAR_EXTERNAL_DEFAULTS_FILE_GUID) { // Parse NVAR area parseNvarStore(index); // Set parent file text - model->setText(parentFile, QObject::tr("NVRAM external defaults")); + model->setText(parentFile, UString("NVRAM external defaults")); } // Parse as raw area @@ -2745,154 +2739,156 @@ STATUS FfsParser::parseRawSectionBody(const QModelIndex & index) } -STATUS FfsParser::parsePeImageSectionBody(const QModelIndex & index) +USTATUS FfsParser::parsePeImageSectionBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get section body - QByteArray body = model->body(index); + UByteArray body = model->body(index); if ((UINT32)body.size() < sizeof(EFI_IMAGE_DOS_HEADER)) { - msg(QObject::tr("parsePeImageSectionBody: section body size is smaller than DOS header size"), index); - return ERR_SUCCESS; + msg(UString("parsePeImageSectionBody: section body size is smaller than DOS header size"), index); + return U_SUCCESS; } - QByteArray info; + UByteArray info; const EFI_IMAGE_DOS_HEADER* dosHeader = (const EFI_IMAGE_DOS_HEADER*)body.constData(); if (dosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) { - info += QObject::tr("\nDOS signature: %1h, invalid").hexarg2(dosHeader->e_magic, 4); - msg(QObject::tr("parsePeImageSectionBody: PE32 image with invalid DOS signature"), index); + info += usprintf("\nDOS signature: %04Xh, invalid", dosHeader->e_magic); + msg(UString("parsePeImageSectionBody: PE32 image with invalid DOS signature"), index); model->addInfo(index, info); - return ERR_SUCCESS; + return U_SUCCESS; } const EFI_IMAGE_PE_HEADER* peHeader = (EFI_IMAGE_PE_HEADER*)(body.constData() + dosHeader->e_lfanew); if (body.size() < (UINT8*)peHeader - (UINT8*)dosHeader) { - info += QObject::tr("\nDOS header: invalid"); - msg(QObject::tr("parsePeImageSectionBody: PE32 image with invalid DOS header"), index); + info += UString("\nDOS header: invalid"); + msg(UString("parsePeImageSectionBody: PE32 image with invalid DOS header"), index); model->addInfo(index, info); - return ERR_SUCCESS; + return U_SUCCESS; } if (peHeader->Signature != EFI_IMAGE_PE_SIGNATURE) { - info += QObject::tr("\nPE signature: %1h, invalid").hexarg2(peHeader->Signature, 8); - msg(QObject::tr("parsePeImageSectionBody: PE32 image with invalid PE signature"), index); + info += usprintf("\nPE signature: %08Xh, invalid", peHeader->Signature); + msg(UString("parsePeImageSectionBody: PE32 image with invalid PE signature"), index); model->addInfo(index, info); - return ERR_SUCCESS; + return U_SUCCESS; } const EFI_IMAGE_FILE_HEADER* imageFileHeader = (const EFI_IMAGE_FILE_HEADER*)(peHeader + 1); if (body.size() < (UINT8*)imageFileHeader - (UINT8*)dosHeader) { - info += QObject::tr("\nPE header: invalid"); - msg(QObject::tr("parsePeImageSectionBody: PE32 image with invalid PE header"), index); + info += UString("\nPE header: invalid"); + msg(UString("parsePeImageSectionBody: PE32 image with invalid PE header"), index); model->addInfo(index, info); - return ERR_SUCCESS; + return U_SUCCESS; } - info += QObject::tr("\nDOS signature: %1h\nPE signature: %2h\nMachine type: %3\nNumber of sections: %4\nCharacteristics: %5h") - .hexarg2(dosHeader->e_magic, 4) - .hexarg2(peHeader->Signature, 8) - .arg(machineTypeToQString(imageFileHeader->Machine)) - .arg(imageFileHeader->NumberOfSections) - .hexarg2(imageFileHeader->Characteristics, 4); + info += usprintf("\nDOS signature: %04Xh\nPE signature: %08Xh", + dosHeader->e_magic, + peHeader->Signature) + + machineTypeToUString(imageFileHeader->Machine).prepend("\nMachine type: ") + + usprintf("\nNumber of sections: %u\nCharacteristics: %04Xh", + imageFileHeader->NumberOfSections, + imageFileHeader->Characteristics); EFI_IMAGE_OPTIONAL_HEADER_POINTERS_UNION optionalHeader; optionalHeader.H32 = (const EFI_IMAGE_OPTIONAL_HEADER32*)(imageFileHeader + 1); if (body.size() < (UINT8*)optionalHeader.H32 - (UINT8*)dosHeader) { - info += QObject::tr("\nPE optional header: invalid"); - msg(QObject::tr("parsePeImageSectionBody: PE32 image with invalid PE optional header"), index); + info += UString("\nPE optional header: invalid"); + msg(UString("parsePeImageSectionBody: PE32 image with invalid PE optional header"), index); model->addInfo(index, info); - return ERR_SUCCESS; + return U_SUCCESS; } if (optionalHeader.H32->Magic == EFI_IMAGE_PE_OPTIONAL_HDR32_MAGIC) { - info += QObject::tr("\nOptional header signature: %1h\nSubsystem: %2h\nAddress of entry point: %3h\nBase of code: %4h\nImage base: %5h") - .hexarg2(optionalHeader.H32->Magic, 4) - .hexarg2(optionalHeader.H32->Subsystem, 4) - .hexarg(optionalHeader.H32->AddressOfEntryPoint) - .hexarg(optionalHeader.H32->BaseOfCode) - .hexarg(optionalHeader.H32->ImageBase); + info += usprintf("\nOptional header signature: %04Xh\nSubsystem: %04Xh\nAddress of entry point: %Xh\nBase of code: %Xh\nImage base: %Xh", + optionalHeader.H32->Magic, + optionalHeader.H32->Subsystem, + optionalHeader.H32->AddressOfEntryPoint, + optionalHeader.H32->BaseOfCode, + optionalHeader.H32->ImageBase); } else if (optionalHeader.H32->Magic == EFI_IMAGE_PE_OPTIONAL_HDR64_MAGIC) { - info += QObject::tr("\nOptional header signature: %1h\nSubsystem: %2h\nAddress of entry point: %3h\nBase of code: %4h\nImage base: %5h") - .hexarg2(optionalHeader.H64->Magic, 4) - .hexarg2(optionalHeader.H64->Subsystem, 4) - .hexarg(optionalHeader.H64->AddressOfEntryPoint) - .hexarg(optionalHeader.H64->BaseOfCode) - .hexarg(optionalHeader.H64->ImageBase); + info += usprintf("\nOptional header signature: %04Xh\nSubsystem: %04Xh\nAddress of entry point: %Xh\nBase of code: %Xh\nImage base: %Xh", + optionalHeader.H64->Magic, + optionalHeader.H64->Subsystem, + optionalHeader.H64->AddressOfEntryPoint, + optionalHeader.H64->BaseOfCode, + optionalHeader.H64->ImageBase); } else { - info += QObject::tr("\nOptional header signature: %1h, unknown").hexarg2(optionalHeader.H32->Magic, 4); - msg(QObject::tr("parsePeImageSectionBody: PE32 image with invalid optional PE header signature"), index); + info += usprintf("\nOptional header signature: %04Xh, unknown", optionalHeader.H32->Magic); + msg(UString("parsePeImageSectionBody: PE32 image with invalid optional PE header signature"), index); } model->addInfo(index, info); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseTeImageSectionBody(const QModelIndex & index) +USTATUS FfsParser::parseTeImageSectionBody(const UModelIndex & index) { // Check sanity if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get section body - QByteArray body = model->body(index); + UByteArray body = model->body(index); if ((UINT32)body.size() < sizeof(EFI_IMAGE_TE_HEADER)) { - msg(QObject::tr("parsePeImageSectionBody: section body size is smaller than TE header size"), index); - return ERR_SUCCESS; + msg(("parsePeImageSectionBody: section body size is smaller than TE header size"), index); + return U_SUCCESS; } - QByteArray info; + UByteArray info; const EFI_IMAGE_TE_HEADER* teHeader = (const EFI_IMAGE_TE_HEADER*)body.constData(); if (teHeader->Signature != EFI_IMAGE_TE_SIGNATURE) { - info += QObject::tr("\nSignature: %1h, invalid").hexarg2(teHeader->Signature, 4); - msg(QObject::tr("parseTeImageSectionBody: TE image with invalid TE signature"), index); + info += usprintf("\nSignature: %04Xh, invalid", teHeader->Signature); + msg(UString("parseTeImageSectionBody: TE image with invalid TE signature"), index); } else { - info += QObject::tr("\nSignature: %1h\nMachine type: %2\nNumber of sections: %3\nSubsystem: %4h\nStripped size: %5h (%6)\nBase of code: %7h\nAddress of entry point: %8h\nImage base: %9h\nAdjusted image base: %10h") - .hexarg2(teHeader->Signature, 4) - .arg(machineTypeToQString(teHeader->Machine)) - .arg(teHeader->NumberOfSections) - .hexarg2(teHeader->Subsystem, 2) - .hexarg(teHeader->StrippedSize).arg(teHeader->StrippedSize) - .hexarg(teHeader->BaseOfCode) - .hexarg(teHeader->AddressOfEntryPoint) - .hexarg(teHeader->ImageBase) - .hexarg(teHeader->ImageBase + teHeader->StrippedSize - sizeof(EFI_IMAGE_TE_HEADER)); + info += usprintf("\nSignature: %04Xh", teHeader->Signature) + + machineTypeToUString(teHeader->Machine).prepend("\nMachine type: ") + + usprintf("\nNumber of sections: %u\nSubsystem: %02Xh\nStripped size: %Xh (%u)\n" + "Base of code: %Xh\nAddress of entry point: %Xh\nImage base: %Xh\nAdjusted image base: %Xh", + teHeader->NumberOfSections, + teHeader->Subsystem, + teHeader->StrippedSize, teHeader->StrippedSize, + teHeader->BaseOfCode, + teHeader->AddressOfEntryPoint, + teHeader->ImageBase, + teHeader->ImageBase + teHeader->StrippedSize - sizeof(EFI_IMAGE_TE_HEADER)); } // Get data from parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); pdata.section.teImage.imageBase = teHeader->ImageBase; pdata.section.teImage.adjustedImageBase = teHeader->ImageBase + teHeader->StrippedSize - sizeof(EFI_IMAGE_TE_HEADER); // Update parsing data - model->setParsingData(index, parsingDataToQByteArray(pdata)); + model->setParsingData(index, parsingDataToUByteArray(pdata)); // Add TE info model->addInfo(index, info); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::performSecondPass(const QModelIndex & index) +USTATUS FfsParser::performSecondPass(const UModelIndex & index) { // Sanity check if (!index.isValid() || !lastVtf.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Check for compressed lastVtf if (model->compressed(lastVtf)) { - msg(QObject::tr("performSecondPass: the last VTF appears inside compressed item, the image may be damaged"), lastVtf); - return ERR_SUCCESS; + msg(UString("performSecondPass: the last VTF appears inside compressed item, the image may be damaged"), lastVtf); + return U_SUCCESS; } // Get parsing data for the last VTF - PARSING_DATA pdata = parsingDataFromQModelIndex(lastVtf); + PARSING_DATA pdata = parsingDataFromUModelIndex(lastVtf); // Calculate address difference const UINT32 vtfSize = model->header(lastVtf).size() + model->body(lastVtf).size() + model->tail(lastVtf).size(); @@ -2901,19 +2897,19 @@ STATUS FfsParser::performSecondPass(const QModelIndex & index) // Apply address information to index and all it's child items addMemoryAddressesRecursive(index, diff); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::addMemoryAddressesRecursive(const QModelIndex & index, const UINT32 diff) +USTATUS FfsParser::addMemoryAddressesRecursive(const UModelIndex & index, const UINT32 diff) { // Sanity check if (!index.isValid()) - return ERR_SUCCESS; + return U_SUCCESS; // Set address value for non-compressed data if (!model->compressed(index)) { // Get parsing data for the current item - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); // Check address sanity if ((const UINT64)diff + pdata.offset <= 0xFFFFFFFFUL) { @@ -2921,11 +2917,11 @@ STATUS FfsParser::addMemoryAddressesRecursive(const QModelIndex & index, const U pdata.address = diff + pdata.offset; UINT32 headerSize = model->header(index).size(); if (headerSize) { - model->addInfo(index, QObject::tr("\nHeader memory address: %1h").hexarg2(pdata.address, 8)); - model->addInfo(index, QObject::tr("\nData memory address: %1h").hexarg2(pdata.address + headerSize, 8)); + model->addInfo(index, usprintf("\nHeader memory address: %08Xh", pdata.address)); + model->addInfo(index, usprintf("\nData memory address: %08Xh", pdata.address + headerSize)); } else { - model->addInfo(index, QObject::tr("\nMemory address: %1h").hexarg2(pdata.address, 8)); + model->addInfo(index, usprintf("\nMemory address: %08Xh", pdata.address)); } // Special case of uncompressed TE image sections @@ -2938,13 +2934,13 @@ STATUS FfsParser::addMemoryAddressesRecursive(const QModelIndex & index, const U pdata.section.teImage.revision = 2; } else { - msg(QObject::tr("addMemoryAddressesRecursive: image base is neither original nor adjusted, it's likely a part of backup PEI volume or DXE volume, but can also be damaged"), index); + msg(UString("addMemoryAddressesRecursive: image base is neither original nor adjusted, it's likely a part of backup PEI volume or DXE volume, but can also be damaged"), index); pdata.section.teImage.revision = 0; } } // Set modified parsing data - model->setParsingData(index, parsingDataToQByteArray(pdata)); + model->setParsingData(index, parsingDataToUByteArray(pdata)); } } @@ -2953,51 +2949,51 @@ STATUS FfsParser::addMemoryAddressesRecursive(const QModelIndex & index, const U addMemoryAddressesRecursive(index.child(i, 0), diff); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::addOffsetsRecursive(const QModelIndex & index) +USTATUS FfsParser::addOffsetsRecursive(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parsing data for the current item - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); // Add current offset if the element is not compressed // or it's compressed, but it's parent isn't if ((!model->compressed(index)) || (index.parent().isValid() && !model->compressed(index.parent()))) { - model->addInfo(index, QObject::tr("Offset: %1h\n").hexarg(pdata.offset), false); + model->addInfo(index, usprintf("Offset: %Xh\n", pdata.offset), false); } //TODO: show FIT file fixed attribute correctly - model->addInfo(index, QObject::tr("\nCompressed: %1").arg(model->compressed(index) ? QObject::tr("Yes") : QObject::tr("No"))); - model->addInfo(index, QObject::tr("\nFixed: %1").arg(model->fixed(index) ? QObject::tr("Yes") : QObject::tr("No"))); + model->addInfo(index, usprintf("\nCompressed: %s", model->compressed(index) ? "Yes" : "No")); + model->addInfo(index, usprintf("\nFixed: %s", model->fixed(index) ? "Yes" : "No")); // Process child items for (int i = 0; i < model->rowCount(index); i++) { addOffsetsRecursive(index.child(i, 0)); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseNvarStore(const QModelIndex & index) +USTATUS FfsParser::parseNvarStore(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parsing data for the current item - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); UINT32 parentOffset = pdata.offset + model->header(index).size(); // Get item data - const QByteArray data = model->body(index); + const UByteArray data = model->body(index); // Rename parent file - model->setText(model->findParentOfType(index, Types::File), QObject::tr("NVAR store")); + model->setText(model->findParentOfType(index, Types::File), UString("NVAR store")); UINT32 offset = 0; UINT32 guidsInStore = 0; @@ -3022,14 +3018,14 @@ STATUS FfsParser::parseNvarStore(const QModelIndex & index) UINT32 extendedHeaderSize = 0; UINT8 extendedAttributes = 0; UINT64 timestamp = 0; - QByteArray hash; + UByteArray hash; UINT8 subtype = Subtypes::FullNvarEntry; - QString name; - QString text; - QByteArray header; - QByteArray body; - QByteArray tail; + UString name; + UString text; + UByteArray header; + UByteArray body; + UByteArray tail; UINT32 guidAreaSize = guidsInStore * sizeof(EFI_GUID); UINT32 unparsedSize = (UINT32)data.size() - offset - guidAreaSize; @@ -3043,48 +3039,47 @@ STATUS FfsParser::parseNvarStore(const QModelIndex & index) unparsedSize < entryHeader->Size) { // Check if the data left is a free space or a padding - QByteArray padding = data.mid(offset, unparsedSize); + UByteArray padding = data.mid(offset, unparsedSize); UINT8 type; if ((UINT32)padding.count(emptyByte) == unparsedSize) { // It's a free space - name = QObject::tr("Free space"); + name = ("Free space"); type = Types::FreeSpace; subtype = 0; } else { // Nothing is parsed yet, but the file is not empty if (!offset) { - msg(QObject::tr("parseNvarStore: file can't be parsed as NVAR variables store"), index); - return ERR_SUCCESS; + msg(UString("parseNvarStore: file can't be parsed as NVAR variables store"), index); + return U_SUCCESS; } // It's a padding - name = QObject::tr("Padding"); + name = UString("Padding"); type = Types::Padding; subtype = getPaddingType(padding); } // Get info - QString info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + UString info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = parentOffset + offset; // Add tree item - model->addItem(type, subtype, name, QString(), info, QByteArray(), padding, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(type, subtype, name, UString(), info, UByteArray(), padding, UByteArray(), false, parsingDataToUByteArray(pdata), index); // Add GUID store area - QByteArray guidArea = data.right(guidAreaSize); + UByteArray guidArea = data.right(guidAreaSize); // Get info - name = QObject::tr("GUID store area"); - info = QObject::tr("Full size: %1h (%2)\nGUIDs in store: %3") - .hexarg(guidArea.size()).arg(guidArea.size()) - .arg(guidsInStore); + name = UString("GUID store area"); + info = usprintf("Full size: %Xh (%u)\nGUIDs in store: %u", + guidArea.size(), guidArea.size(), + guidsInStore); // Construct parsing data pdata.offset = parentOffset + offset + padding.size(); // Add tree item - model->addItem(Types::Padding, getPaddingType(guidArea), name, QString(), info, QByteArray(), guidArea, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::Padding, getPaddingType(guidArea), name, UString(), info, UByteArray(), guidArea, UByteArray(), false, parsingDataToUByteArray(pdata), index); - return ERR_SUCCESS; + return U_SUCCESS; } // Contruct generic header and body @@ -3170,11 +3165,11 @@ STATUS FfsParser::parseNvarStore(const QModelIndex & index) // Entry is data-only (nameless and GUIDless entry or link) if (entryHeader->Attributes & NVRAM_NVAR_ENTRY_DATA_ONLY) { // Data-only attribute is set isInvalidLink = true; - QModelIndex nvarIndex; + UModelIndex nvarIndex; // Search prevously added entries for a link to this variable //TODO:replace with linked lists for (int i = 0; i < model->rowCount(index); i++) { nvarIndex = index.child(i, 0); - PARSING_DATA nvarPdata = parsingDataFromQModelIndex(nvarIndex); + PARSING_DATA nvarPdata = parsingDataFromUModelIndex(nvarIndex); if (nvarPdata.nvar.isValid && nvarPdata.nvar.next + nvarPdata.offset - parentOffset == offset) { // Previous link is present and valid isInvalidLink = false; break; @@ -3201,17 +3196,17 @@ STATUS FfsParser::parseNvarStore(const QModelIndex & index) CHAR8* namePtr = (CHAR8*)(entryHeader + 1) + nameOffset; UINT32 nameSize = 0; if (entryHeader->Attributes & NVRAM_NVAR_ENTRY_ASCII_NAME) { // Name is stored as ASCII string of CHAR8s - text = QString(namePtr); + text = UString(namePtr); nameSize = text.length() + 1; } else { // Name is stored as UCS2 string of CHAR16s - text = QString::fromUtf16((CHAR16*)namePtr); + text = UString::fromUtf16((CHAR16*)namePtr); nameSize = (text.length() + 1) * 2; } // Get entry GUID if (entryHeader->Attributes & NVRAM_NVAR_ENTRY_GUID) { // GUID is strored in the variable itself - name = guidToQString(*(EFI_GUID*)(entryHeader + 1)); + name = guidToUString(*(EFI_GUID*)(entryHeader + 1)); } // GUID is stored in GUID list at the end of the store else { @@ -3221,7 +3216,7 @@ STATUS FfsParser::parseNvarStore(const QModelIndex & index) // The list begins at the end of the store and goes backwards const EFI_GUID* guidPtr = (const EFI_GUID*)(data.constData() + data.size()) - 1 - guidIndex; - name = guidToQString(*guidPtr); + name = guidToUString(*guidPtr); hasGuidIndex = true; } @@ -3230,59 +3225,58 @@ STATUS FfsParser::parseNvarStore(const QModelIndex & index) body = body.mid(nameOffset + nameSize); } parsing_done: - QString info; + UString info; // Rename invalid entries according to their types pdata.nvar.isValid = TRUE; if (isInvalid) { - name = QObject::tr("Invalid"); + name = UString("Invalid"); subtype = Subtypes::InvalidNvarEntry; pdata.nvar.isValid = FALSE; } else if (isInvalidLink) { - name = QObject::tr("Invalid link"); + name = UString("Invalid link"); subtype = Subtypes::InvalidLinkNvarEntry; pdata.nvar.isValid = FALSE; } else // Add GUID info for valid entries - info += QObject::tr("Variable GUID: %1\n").arg(name); + info += UString("Variable GUID: ") + name + UString("\n"); // Add GUID index information if (hasGuidIndex) - info += QObject::tr("GUID index: %1\n").arg(guidIndex); + info += usprintf("GUID index: %u\n", guidIndex); // Add header, body and extended data info - info += QObject::tr("Full size: %1h (%2)\nHeader size: %3h (%4)\nBody size: %5h (%6)") - .hexarg(entryHeader->Size).arg(entryHeader->Size) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()); + info += usprintf("Full size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)", + entryHeader->Size, entryHeader->Size, + header.size(), header.size(), + body.size(), body.size()); // Add attributes info - info += QObject::tr("\nAttributes: %1h").hexarg2(entryHeader->Attributes, 2); + info += usprintf("\nAttributes: %02Xh", entryHeader->Attributes); // Translate attributes to text if (entryHeader->Attributes && entryHeader->Attributes != 0xFF) - info += QObject::tr(" (%1)").arg(nvarAttributesToQString(entryHeader->Attributes)); + info += nvarAttributesToUString(entryHeader->Attributes).prepend(" (").append(")"); // Add next node info if (!isInvalid && entryHeader->Next != lastVariableFlag) - info += QObject::tr("\nNext node at offset: %1h").hexarg(parentOffset + offset + entryHeader->Next); + info += usprintf("\nNext node at offset: %Xh", parentOffset + offset + entryHeader->Next); // Add extended header info if (hasExtendedHeader) { - info += QObject::tr("\nExtended header size: %1h (%2)\nExtended attributes: %3h (%4)") - .hexarg(extendedHeaderSize).arg(extendedHeaderSize) - .hexarg2(extendedAttributes, 2) - .arg(nvarExtendedAttributesToQString(extendedAttributes)); + info += usprintf("\nExtended header size: %Xh (%u)\nExtended attributes: %Xh (", + extendedHeaderSize, extendedHeaderSize, + extendedAttributes) + nvarExtendedAttributesToUString(extendedAttributes).append(")"); // Checksum if (hasChecksum) - info += QObject::tr("\nChecksum: %1h%2").hexarg2(storedChecksum, 2) - .arg(calculatedChecksum ? QObject::tr(", invalid, should be %1h").hexarg2(0x100 - calculatedChecksum, 2) : QObject::tr(", valid")); + info += usprintf("\nChecksum: %02Xh", storedChecksum) + + (calculatedChecksum ? usprintf(", invalid, should be %02Xh", 0x100 - calculatedChecksum) : UString(", valid")); // Authentication data if (hasTimestampAndHash) { - info += QObject::tr("\nTimestamp: %1h\nHash: %2") - .hexarg(timestamp).arg(QString(hash.toHex().toUpper())); + info += usprintf("\nTimestamp: %Xh\nHash: ", + timestamp) + hash.toHex().toUpper(); } } @@ -3290,14 +3284,14 @@ parsing_done: pdata.offset = parentOffset + offset; // Add tree item - QModelIndex varIndex = model->addItem(Types::NvarEntry, subtype, name, text, info, header, body, tail, false, parsingDataToQByteArray(pdata), index); + UModelIndex varIndex = model->addItem(Types::NvarEntry, subtype, name, text, info, header, body, tail, false, parsingDataToUByteArray(pdata), index); // Show messages - if (msgUnknownExtDataFormat) msg(QObject::tr("parseNvarStore: unknown extended data format"), varIndex); - if (msgExtHeaderTooLong) msg(QObject::tr("parseNvarStore: extended header size (%1h) is greater than body size (%2h)") - .hexarg(extendedHeaderSize).hexarg(body.size()), varIndex); - if (msgExtDataTooShort) msg(QObject::tr("parseNvarStore: extended header size (%1h) is too small for timestamp and hash") - .hexarg(tail.size()), varIndex); + if (msgUnknownExtDataFormat) msg(UString("parseNvarStore: unknown extended data format"), varIndex); + if (msgExtHeaderTooLong) msg(usprintf("parseNvarStore: extended header size (%Xh) is greater than body size (%Xh)", + extendedHeaderSize, body.size()), varIndex); + if (msgExtDataTooShort) msg(usprintf("parseNvarStore: extended header size (%Xh) is too small for timestamp and hash", + tail.size()), varIndex); // Try parsing the entry data as NVAR storage if it begins with NVAR signature if ((subtype == Subtypes::DataNvarEntry || subtype == Subtypes::FullNvarEntry) @@ -3308,44 +3302,43 @@ parsing_done: offset += entryHeader->Size; } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseNvramVolumeBody(const QModelIndex & index) +USTATUS FfsParser::parseNvramVolumeBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); UINT32 parentOffset = pdata.offset + model->header(index).size(); // Get item data - QByteArray data = model->body(index); + UByteArray data = model->body(index); // Search for first store - STATUS result; + USTATUS result; UINT32 prevStoreOffset; result = findNextStore(index, data, parentOffset, 0, prevStoreOffset); if (result) return result; // First store is not at the beginning of volume body - QString name; - QString info; + UString name; + UString info; if (prevStoreOffset > 0) { // Get info - QByteArray padding = data.left(prevStoreOffset); - name = QObject::tr("Padding"); - info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + UByteArray padding = data.left(prevStoreOffset); + name = UString("Padding"); + info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = parentOffset; // Add tree item - model->addItem(Types::Padding, getPaddingType(padding), name, QString(), info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); + model->addItem(Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); } // Search for and parse all stores @@ -3358,44 +3351,42 @@ STATUS FfsParser::parseNvramVolumeBody(const QModelIndex & index) if (storeOffset > prevStoreOffset + prevStoreSize) { UINT32 paddingOffset = prevStoreOffset + prevStoreSize; UINT32 paddingSize = storeOffset - paddingOffset; - QByteArray padding = data.mid(paddingOffset, paddingSize); + UByteArray padding = data.mid(paddingOffset, paddingSize); // Get info - name = QObject::tr("Padding"); - info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + name = UString("Padding"); + info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = parentOffset + paddingOffset; // Add tree item - model->addItem(Types::Padding, getPaddingType(padding), name, QString(), info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); + model->addItem(Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); } // Get store size UINT32 storeSize = 0; result = getStoreSize(data, storeOffset, storeSize); if (result) { - msg(QObject::tr("parseNvramVolumeBody: getStoreSize failed with error \"%1\"").arg(errorCodeToQString(result)), index); + msg(UString("parseNvramVolumeBody: getStoreSize failed with error ") + errorCodeToUString(result), index); return result; } // Check that current store is fully present in input if (storeSize > (UINT32)data.size() || storeOffset + storeSize > (UINT32)data.size()) { // Mark the rest as padding and finish parsing - QByteArray padding = data.mid(storeOffset); + UByteArray padding = data.mid(storeOffset); // Get info - name = QObject::tr("Padding"); - info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + name = ("Padding"); + info = ("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = parentOffset + storeOffset; // Add tree item - QModelIndex paddingIndex = model->addItem(Types::Padding, getPaddingType(padding), name, QString(), info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); - msg(QObject::tr("parseNvramVolumeBody: one of stores inside overlaps the end of data"), paddingIndex); + UModelIndex paddingIndex = model->addItem(Types::Padding, getPaddingType(padding), name, UString(), info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); + msg(UString("parseNvramVolumeBody: one of stores inside overlaps the end of data"), paddingIndex); // Update variables prevStoreOffset = storeOffset; @@ -3403,12 +3394,12 @@ STATUS FfsParser::parseNvramVolumeBody(const QModelIndex & index) break; } - QByteArray store = data.mid(storeOffset, storeSize); + UByteArray store = data.mid(storeOffset, storeSize); // Parse current store header - QModelIndex storeIndex; + UModelIndex storeIndex; result = parseStoreHeader(store, parentOffset + storeOffset, index, storeIndex); if (result) - msg(QObject::tr("parseNvramVolumeBody: store header parsing failed with error \"%1\"").arg(errorCodeToQString(result)), index); + msg(UString("parseNvramVolumeBody: store header parsing failed with error ") + errorCodeToUString(result), index); // Go to next store prevStoreOffset = storeOffset; @@ -3419,42 +3410,41 @@ STATUS FfsParser::parseNvramVolumeBody(const QModelIndex & index) // Padding/free space at the end storeOffset = prevStoreOffset + prevStoreSize; if ((UINT32)data.size() > storeOffset) { - QByteArray padding = data.mid(storeOffset); + UByteArray padding = data.mid(storeOffset); UINT8 type; UINT8 subtype; if (padding.count(pdata.emptyByte) == padding.size()) { // It's a free space - name = QObject::tr("Free space"); + name = UString("Free space"); type = Types::FreeSpace; subtype = 0; } else { // Nothing is parsed yet, but the file is not empty if (!storeOffset) { - msg(QObject::tr("parseNvramVolumeBody: can't be parsed as NVRAM volume"), index); - return ERR_SUCCESS; + msg(UString("parseNvramVolumeBody: can't be parsed as NVRAM volume"), index); + return U_SUCCESS; } // It's a padding - name = QObject::tr("Padding"); + name = UString("Padding"); type = Types::Padding; subtype = getPaddingType(padding); } // Add info - info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = parentOffset + storeOffset; // Add tree item - model->addItem(type, subtype, name, QString(), info, QByteArray(), padding, QByteArray(), true, parsingDataToQByteArray(pdata), index); + model->addItem(type, subtype, name, UString(), info, UByteArray(), padding, UByteArray(), true, parsingDataToUByteArray(pdata), index); } // Parse bodies for (int i = 0; i < model->rowCount(index); i++) { - QModelIndex current = index.child(i, 0); + UModelIndex current = index.child(i, 0); switch (model->type(current)) { case Types::VssStore: case Types::FdcStore: parseVssStoreBody(current); break; @@ -3464,15 +3454,15 @@ STATUS FfsParser::parseNvramVolumeBody(const QModelIndex & index) } } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::findNextStore(const QModelIndex & index, const QByteArray & volume, const UINT32 parentOffset, const UINT32 storeOffset, UINT32 & nextStoreOffset) +USTATUS FfsParser::findNextStore(const UModelIndex & index, const UByteArray & volume, const UINT32 parentOffset, const UINT32 storeOffset, UINT32 & nextStoreOffset) { UINT32 dataSize = volume.size(); if (dataSize < sizeof(UINT32)) - return ERR_STORES_NOT_FOUND; + return U_STORES_NOT_FOUND; UINT32 offset = storeOffset; for (; offset < dataSize - sizeof(UINT32); offset++) { @@ -3480,11 +3470,11 @@ STATUS FfsParser::findNextStore(const QModelIndex & index, const QByteArray & vo 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; if (vssHeader->Format != NVRAM_VSS_VARIABLE_STORE_FORMATTED) { - msg(QObject::tr("findNextStore: VSS store candidate at offset %1h skipped, has invalid format %2h").hexarg(parentOffset + offset).hexarg2(vssHeader->Format, 2), index); + msg(usprintf("findNextStore: VSS store candidate at offset %Xh skipped, has invalid format %02Xh", parentOffset + offset, vssHeader->Format), index); continue; } if (vssHeader->Size == 0 || vssHeader->Size == 0xFFFFFFFF) { - msg(QObject::tr("findNextStore: VSS store candidate at offset %1h skipped, has invalid size %2h").hexarg(parentOffset + offset).hexarg2(vssHeader->Size, 8), index); + msg(usprintf("findNextStore: VSS store candidate at offset %Xh skipped, has invalid size %Xh", parentOffset + offset, vssHeader->Size), index); continue; } // All checks passed, store found @@ -3493,7 +3483,7 @@ STATUS FfsParser::findNextStore(const QModelIndex & index, const QByteArray & vo else if (*currentPos == NVRAM_FDC_VOLUME_SIGNATURE) { //FDC signature found const FDC_VOLUME_HEADER* fdcHeader = (const FDC_VOLUME_HEADER*)currentPos; if (fdcHeader->Size == 0 || fdcHeader->Size == 0xFFFFFFFF) { - msg(QObject::tr("findNextStore: FDC store candidate at offset %1h skipped, has invalid size %2h").hexarg(parentOffset + offset).hexarg2(fdcHeader->Size, 8), index); + msg(usprintf("findNextStore: FDC store candidate at offset %Xh skipped, has invalid size %Xh", parentOffset + offset, fdcHeader->Size), index); continue; } // All checks passed, store found @@ -3502,7 +3492,7 @@ STATUS FfsParser::findNextStore(const QModelIndex & index, const QByteArray & vo 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; if (fsysHeader->Size == 0 || fsysHeader->Size == 0xFFFF) { - msg(QObject::tr("findNextStore: Fsys store candidate at offset %1h skipped, has invalid size %2h").hexarg(parentOffset + offset).hexarg2(fsysHeader->Size, 4), index); + msg(usprintf("findNextStore: Fsys store candidate at offset %Xh skipped, has invalid size %Xh", parentOffset + offset, fsysHeader->Size), index); continue; } // All checks passed, store found @@ -3514,11 +3504,11 @@ STATUS FfsParser::findNextStore(const QModelIndex & index, const QByteArray & vo const EVSA_STORE_ENTRY* evsaHeader = (const EVSA_STORE_ENTRY*)(currentPos - 1); if (evsaHeader->Header.Type != NVRAM_EVSA_ENTRY_TYPE_STORE) { - msg(QObject::tr("findNextStore: EVSA store candidate at offset %1h skipped, has invalid type %2h").hexarg(parentOffset + offset - 4).hexarg2(evsaHeader->Header.Type, 2), index); + msg(usprintf("findNextStore: EVSA store candidate at offset %Xh skipped, has invalid type %02Xh", parentOffset + offset - 4, evsaHeader->Header.Type), index); continue; } if (evsaHeader->StoreSize == 0 || evsaHeader->StoreSize == 0xFFFFFFFF) { - msg(QObject::tr("findNextStore: EVSA store candidate at offset %1h skipped, has invalid size %2h").hexarg(parentOffset + offset).hexarg2(evsaHeader->StoreSize, 8), index); + msg(usprintf("findNextStore: EVSA store candidate at offset %Xh skipped, has invalid size %Xh", parentOffset + offset, evsaHeader->StoreSize), index); continue; } // All checks passed, store found @@ -3526,7 +3516,7 @@ STATUS FfsParser::findNextStore(const QModelIndex & index, const QByteArray & vo break; } else if (*currentPos == NVRAM_MAIN_STORE_VOLUME_GUID_DATA1 || *currentPos == EDKII_WORKING_BLOCK_SIGNATURE_GUID_DATA1) { //Possible FTW block signature found - QByteArray guid = QByteArray(volume.constData() + offset, sizeof(EFI_GUID)); + UByteArray guid = UByteArray(volume.constData() + offset, sizeof(EFI_GUID)); if (guid != NVRAM_MAIN_STORE_VOLUME_GUID && guid != EDKII_WORKING_BLOCK_SIGNATURE_GUID) // Check the whole signature continue; @@ -3534,14 +3524,14 @@ STATUS FfsParser::findNextStore(const QModelIndex & index, const QByteArray & vo 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 == 0 || ftwHeader->WriteQueueSize == 0xFFFFFFFF) { - msg(QObject::tr("findNextStore: FTW block candidate at offset %1h skipped, has invalid body size %2h").hexarg(parentOffset + offset).hexarg2(ftwHeader->WriteQueueSize, 8), index); + msg(usprintf("findNextStore: FTW block candidate at offset %Xh skipped, has invalid body size %Xh", parentOffset + offset, ftwHeader->WriteQueueSize), index); continue; } } 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; if (ftw64Header->WriteQueueSize == 0 || ftw64Header->WriteQueueSize >= 0xFFFFFFFF) { - msg(QObject::tr("findNextStore: FTW block candidate at offset %1h skipped, has invalid body size %2h").hexarg(parentOffset + offset).hexarg2(ftw64Header->WriteQueueSize, 16), index); + msg(usprintf("findNextStore: FTW block candidate at offset %Xh skipped, has invalid body size %Xh", parentOffset + offset, ftw64Header->WriteQueueSize), index); continue; } } @@ -3552,7 +3542,7 @@ STATUS FfsParser::findNextStore(const QModelIndex & index, const QByteArray & vo break; } else if (*currentPos == NVRAM_PHOENIX_FLASH_MAP_SIGNATURE_PART1) {// Phoenix SCT flash map - QByteArray signature = QByteArray(volume.constData() + offset, NVRAM_PHOENIX_FLASH_MAP_SIGNATURE_LENGTH); + UByteArray signature = UByteArray(volume.constData() + offset, NVRAM_PHOENIX_FLASH_MAP_SIGNATURE_LENGTH); if (signature != NVRAM_PHOENIX_FLASH_MAP_SIGNATURE) // Check the whole signature continue; @@ -3624,14 +3614,14 @@ STATUS FfsParser::findNextStore(const QModelIndex & index, const QByteArray & vo } // No more stores found if (offset >= dataSize - sizeof(UINT32)) - return ERR_STORES_NOT_FOUND; + return U_STORES_NOT_FOUND; nextStoreOffset = offset; - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::getStoreSize(const QByteArray & data, const UINT32 storeOffset, UINT32 & storeSize) +USTATUS FfsParser::getStoreSize(const UByteArray & data, const UINT32 storeOffset, UINT32 & storeSize) { const UINT32* signature = (const UINT32*)(data.constData() + storeOffset); if (*signature == NVRAM_VSS_STORE_SIGNATURE || *signature == NVRAM_APPLE_SVS_STORE_SIGNATURE) { @@ -3679,17 +3669,17 @@ STATUS FfsParser::getStoreSize(const QByteArray & data, const UINT32 storeOffset const INTEL_MICROCODE_HEADER* ucodeHeader = (const INTEL_MICROCODE_HEADER*)signature; storeSize = ucodeHeader->TotalSize; } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseVssStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseVssStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check store size if (dataSize < sizeof(VSS_VARIABLE_STORE_HEADER)) { - msg(QObject::tr("parseVssStoreHeader: volume body is too small even for VSS store header"), parent); - return ERR_SUCCESS; + msg(UString("parseVssStoreHeader: volume body is too small even for VSS store header"), parent); + return U_SUCCESS; } // Get VSS store header @@ -3697,48 +3687,48 @@ STATUS FfsParser::parseVssStoreHeader(const QByteArray & store, const UINT32 par // Check store size if (dataSize < vssStoreHeader->Size) { - msg(QObject::tr("parseVssStoreHeader: VSS store size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(vssStoreHeader->Size).arg(vssStoreHeader->Size) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseVssStoreHeader: VSS store size %Xh (%u) is greater than volume body size %Xh (%u)", + vssStoreHeader->Size, vssStoreHeader->Size, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body - QByteArray header = store.left(sizeof(VSS_VARIABLE_STORE_HEADER)); - QByteArray body = store.mid(sizeof(VSS_VARIABLE_STORE_HEADER), vssStoreHeader->Size - sizeof(VSS_VARIABLE_STORE_HEADER)); + UByteArray header = store.left(sizeof(VSS_VARIABLE_STORE_HEADER)); + UByteArray body = store.mid(sizeof(VSS_VARIABLE_STORE_HEADER), vssStoreHeader->Size - sizeof(VSS_VARIABLE_STORE_HEADER)); // Add info bool isSvsStore = (vssStoreHeader->Signature == NVRAM_APPLE_SVS_STORE_SIGNATURE); - QString name = isSvsStore ? QObject::tr("SVS store") : QObject::tr("VSS store"); - QString info = QObject::tr("Signature: %1\nFull size: %2h (%3)\nHeader size: %4h (%5)\nBody size: %6h (%7)\nFormat: %8h\nState: %9h\nUnknown: %10h") - .arg(isSvsStore ? QObject::tr("$SVS") : QObject::tr("$VSS")) - .hexarg(vssStoreHeader->Size).arg(vssStoreHeader->Size) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .hexarg2(vssStoreHeader->Format, 2) - .hexarg2(vssStoreHeader->State, 2) - .hexarg2(vssStoreHeader->Unknown, 4); + UString name = isSvsStore ? UString("SVS store") : UString("VSS store"); + UString info = usprintf("Signature: %s\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nFormat: %02Xh\nState: %02Xh\nUnknown: %04Xh", + isSvsStore ? "$SVS" : "$VSS", + vssStoreHeader->Size, vssStoreHeader->Size, + header.size(), header.size(), + body.size(), body.size(), + vssStoreHeader->Format, + vssStoreHeader->State, + vssStoreHeader->Unknown); // Add correct offset pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::VssStore, 0, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::VssStore, 0, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseFtwStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseFtwStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check store size if (dataSize < sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64)) { - msg(QObject::tr("parseFtwStoreHeader: volume body is too small even for FTW store header"), parent); - return ERR_SUCCESS; + msg(UString("parseFtwStoreHeader: volume body is too small even for FTW store header"), parent); + return U_SUCCESS; } // Get FTW block headers @@ -3757,56 +3747,55 @@ STATUS FfsParser::parseFtwStoreHeader(const QByteArray & store, const UINT32 par has32bitHeader = false; } if (dataSize < ftwBlockSize) { - msg(QObject::tr("parseFtwStoreHeader: FTW store size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(ftwBlockSize).arg(ftwBlockSize) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseFtwStoreHeader: FTW store size %Xh (%u) is greater than volume body size %Xh (%u)", + ftwBlockSize, ftwBlockSize, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body UINT32 headerSize = has32bitHeader ? sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32) : sizeof(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER64); - QByteArray header = store.left(headerSize); - QByteArray body = store.mid(headerSize, ftwBlockSize - headerSize); + UByteArray header = store.left(headerSize); + UByteArray body = store.mid(headerSize, ftwBlockSize - headerSize); // Check block header checksum - QByteArray crcHeader = header; + UByteArray crcHeader = header; EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32* crcFtwBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER32*)header.data(); crcFtwBlockHeader->Crc = pdata.emptyByte ? 0xFFFFFFFF : 0; crcFtwBlockHeader->State = pdata.emptyByte ? 0xFF : 0; UINT32 calculatedCrc = crc32(0, (const UINT8*)crcFtwBlockHeader, headerSize); // Add info - QString name = QObject::tr("FTW store"); - QString info = QObject::tr("Signature: %1\nFull size: %2h (%3)\nHeader size: %4h (%5)\nBody size: %6h (%7)\nState: %8h\nHeader CRC32: %9") - .arg(guidToQString(ftw32BlockHeader->Signature)) - .hexarg(ftwBlockSize).arg(ftwBlockSize) - .hexarg(headerSize).arg(headerSize) - .hexarg(body.size()).arg(body.size()) - .hexarg2(ftw32BlockHeader->State, 2) - .arg(ftw32BlockHeader->Crc == calculatedCrc ? - QObject::tr("%1h, valid").hexarg2(ftw32BlockHeader->Crc, 8) : - QObject::tr("%1h, invalid, should be %2h").hexarg2(ftw32BlockHeader->Crc, 8).hexarg2(calculatedCrc, 8)); + UString name("FTW store"); + UString info = guidToUString(ftw32BlockHeader->Signature).prepend("Signature:") + + usprintf("\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nState: %02Xh\nHeader CRC32: ", + ftwBlockSize, ftwBlockSize, + headerSize, headerSize, + body.size(), body.size(), + ftw32BlockHeader->State) + + (ftw32BlockHeader->Crc == calculatedCrc ? usprintf("%08Xh, valid", ftw32BlockHeader->Crc) : + usprintf("%08Xh, invalid, should be %08Xh", ftw32BlockHeader->Crc, calculatedCrc)); // Add correct offset pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::FtwStore, 0, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::FtwStore, 0, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseFdcStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseFdcStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check store size if (dataSize < sizeof(FDC_VOLUME_HEADER)) { - msg(QObject::tr("parseFdcStoreHeader: volume body is too small even for FDC store header"), parent); - return ERR_SUCCESS; + msg(UString("parseFdcStoreHeader: volume body is too small even for FDC store header"), parent); + return U_SUCCESS; } // Get Fdc store header @@ -3814,10 +3803,10 @@ STATUS FfsParser::parseFdcStoreHeader(const QByteArray & store, const UINT32 par // Check store size if (dataSize < fdcStoreHeader->Size) { - msg(QObject::tr("parseFdcStoreHeader: FDC store size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(fdcStoreHeader->Size).arg(fdcStoreHeader->Size) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseFdcStoreHeader: FDC store size %Xh (%u) is greater than volume body size %Xh (%u)", + fdcStoreHeader->Size, fdcStoreHeader->Size, + dataSize, dataSize), parent); + return U_SUCCESS; } // Determine internal volume header size @@ -3841,25 +3830,25 @@ STATUS FfsParser::parseFdcStoreHeader(const QByteArray & store, const UINT32 par // Check sanity of combined header size if (dataSize < headerSize) { - msg(QObject::tr("parseFdcStoreHeader: FDC store header size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg2(fdcStoreHeader->Size, 8).arg(fdcStoreHeader->Size) - .hexarg2(dataSize, 8).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseFdcStoreHeader: FDC store header size %Xh (%u) is greater than volume body size %Xh (%u)", + fdcStoreHeader->Size,fdcStoreHeader->Size, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body - QByteArray header = store.left(headerSize); - QByteArray body = store.mid(headerSize, fdcStoreHeader->Size - headerSize); + UByteArray header = store.left(headerSize); + UByteArray body = store.mid(headerSize, fdcStoreHeader->Size - headerSize); // Add info - QString name = QObject::tr("FDC store"); - QString info = QObject::tr("Signature: _FDC\nFull size: %1h (%2)\nHeader size: %3h (%4)\nBody size: %5h (%6)") - .hexarg(fdcStoreHeader->Size).arg(fdcStoreHeader->Size) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()); + UString name("FDC store"); + UString info = usprintf("Signature: _FDC\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)", + fdcStoreHeader->Size, fdcStoreHeader->Size, + header.size(), header.size(), + body.size(), body.size()); // TODO: add internal headers info @@ -3867,19 +3856,19 @@ STATUS FfsParser::parseFdcStoreHeader(const QByteArray & store, const UINT32 par pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::FdcStore, 0, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::FdcStore, 0, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseFsysStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseFsysStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check store size if (dataSize < sizeof(APPLE_FSYS_STORE_HEADER)) { - msg(QObject::tr("parseFsysStoreHeader: volume body is too small even for Fsys store header"), parent); - return ERR_SUCCESS; + msg(UString("parseFsysStoreHeader: volume body is too small even for Fsys store header"), parent); + return U_SUCCESS; } // Get Fsys store header @@ -3887,18 +3876,18 @@ STATUS FfsParser::parseFsysStoreHeader(const QByteArray & store, const UINT32 pa // Check store size if (dataSize < fsysStoreHeader->Size) { - msg(QObject::tr("parseFsysStoreHeader: Fsys store size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(fsysStoreHeader->Size).arg(fsysStoreHeader->Size) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseFsysStoreHeader: Fsys store size %Xh (%u) is greater than volume body size %Xh (%u)", + fsysStoreHeader->Size, fsysStoreHeader->Size, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body - QByteArray header = store.left(sizeof(APPLE_FSYS_STORE_HEADER)); - QByteArray body = store.mid(sizeof(APPLE_FSYS_STORE_HEADER), fsysStoreHeader->Size - sizeof(APPLE_FSYS_STORE_HEADER) - sizeof(UINT32)); + UByteArray header = store.left(sizeof(APPLE_FSYS_STORE_HEADER)); + UByteArray body = store.mid(sizeof(APPLE_FSYS_STORE_HEADER), fsysStoreHeader->Size - sizeof(APPLE_FSYS_STORE_HEADER) - sizeof(UINT32)); // Check store checksum UINT32 storedCrc = *(UINT32*)store.right(sizeof(UINT32)).constBegin(); @@ -3906,33 +3895,33 @@ STATUS FfsParser::parseFsysStoreHeader(const QByteArray & store, const UINT32 pa // Add info bool isGaidStore = (fsysStoreHeader->Signature == NVRAM_APPLE_GAID_STORE_SIGNATURE); - QString name = isGaidStore ? QObject::tr("Gaid store") : QObject::tr("Fsys store"); - QString info = QObject::tr("Signature: %1\nFull size: %2h (%3)\nHeader size: %4h (%5)\nBody size: %6h (%7)\nUnknown0: %9h\nUnknown1: %10h\nCRC32: %11") - .arg(isGaidStore ? QObject::tr("Gaid") : QObject::tr("Fsys")) - .hexarg(fsysStoreHeader->Size).arg(fsysStoreHeader->Size) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .hexarg2(fsysStoreHeader->Unknown0, 2) - .hexarg2(fsysStoreHeader->Unknown1, 8) - .arg(storedCrc == calculatedCrc ? QObject::tr("%1h, valid").hexarg2(storedCrc, 8) : QObject::tr("%1h, invalid, should be %2h").hexarg2(storedCrc, 8).hexarg2(calculatedCrc, 8)); + UString name = isGaidStore ? UString("Gaid store") : UString("Fsys store"); + UString info = usprintf("Signature: %s\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nUnknown0: %02Xh\nUnknown1: %08Xh\nCRC32: ", + isGaidStore ? "Gaid" : "Fsys", + fsysStoreHeader->Size, fsysStoreHeader->Size, + header.size(), header.size(), + body.size(), body.size(), + fsysStoreHeader->Unknown0, + fsysStoreHeader->Unknown1) + + (storedCrc == calculatedCrc ? usprintf("%08Xh, valid", storedCrc) : usprintf("%08Xh, invalid, should be %08Xh", storedCrc, calculatedCrc)); // Add correct offset pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::FsysStore, 0, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::FsysStore, 0, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseEvsaStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseEvsaStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check dataSize if (dataSize < sizeof(EVSA_STORE_ENTRY)) { - msg(QObject::tr("parseEvsaStoreHeader: volume body is too small even for EVSA store header"), parent); - return ERR_SUCCESS; + msg(UString("parseEvsaStoreHeader: volume body is too small even for EVSA store header"), parent); + return U_SUCCESS; } // Get EVSA store header @@ -3940,51 +3929,49 @@ STATUS FfsParser::parseEvsaStoreHeader(const QByteArray & store, const UINT32 pa // Check store size if (dataSize < evsaStoreHeader->StoreSize) { - msg(QObject::tr("parseEvsaStoreHeader: EVSA store size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(evsaStoreHeader->StoreSize).arg(evsaStoreHeader->StoreSize) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseEvsaStoreHeader: EVSA store size %Xh (%u) is greater than volume body size %Xh (%u)", + evsaStoreHeader->StoreSize, evsaStoreHeader->StoreSize, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body - QByteArray header = store.left(evsaStoreHeader->Header.Size); - QByteArray body = store.mid(evsaStoreHeader->Header.Size, evsaStoreHeader->StoreSize - evsaStoreHeader->Header.Size); + UByteArray header = store.left(evsaStoreHeader->Header.Size); + UByteArray body = store.mid(evsaStoreHeader->Header.Size, evsaStoreHeader->StoreSize - evsaStoreHeader->Header.Size); // Recalculate checksum UINT8 calculated = calculateChecksum8(((const UINT8*)evsaStoreHeader) + 2, evsaStoreHeader->Header.Size - 2); // Add info - QString name = QObject::tr("EVSA store"); - QString info = QObject::tr("Signature: EVSA\nFull size: %1h (%2)\nHeader size: %3h (%4)\nBody size: %5h (%6)\nType: %7h\nChecksum: %8\nAttributes: %9h") - .hexarg(evsaStoreHeader->StoreSize).arg(evsaStoreHeader->StoreSize) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .hexarg2(evsaStoreHeader->Header.Type, 2) - .arg(evsaStoreHeader->Header.Checksum == calculated ? - QObject::tr("%1h, valid").hexarg2(calculated, 2) : - QObject::tr("%1h, invalid, should be %2h").hexarg2(evsaStoreHeader->Header.Checksum, 2).hexarg2(calculated, 2)) - .hexarg2(evsaStoreHeader->Attributes, 8); + UString name("EVSA store"); + UString info = usprintf("Signature: EVSA\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nType: %02Xh\nAttributes: %08Xh\nChecksum: ", + evsaStoreHeader->StoreSize, evsaStoreHeader->StoreSize, + header.size(), header.size(), + body.size(), body.size(), + evsaStoreHeader->Header.Type, + evsaStoreHeader->Attributes) + + (evsaStoreHeader->Header.Checksum == calculated ? usprintf("%02Xh, valid", calculated) : usprintf("%02Xh, invalid, should be %02Xh", evsaStoreHeader->Header.Checksum, calculated)); // Add correct offset pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::EvsaStore, 0, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::EvsaStore, 0, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseFlashMapStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseFlashMapStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check data size if (dataSize < sizeof(PHOENIX_FLASH_MAP_HEADER)) { - msg(QObject::tr("parseFlashMapStoreHeader: volume body is too small even for FlashMap block header"), parent); - return ERR_SUCCESS; + msg(UString("parseFlashMapStoreHeader: volume body is too small even for FlashMap block header"), parent); + return U_SUCCESS; } // Get FlashMap block header @@ -3993,88 +3980,88 @@ STATUS FfsParser::parseFlashMapStoreHeader(const QByteArray & store, const UINT3 // Check store size UINT32 flashMapSize = sizeof(PHOENIX_FLASH_MAP_HEADER) + flashMapHeader->NumEntries * sizeof(PHOENIX_FLASH_MAP_ENTRY); if (dataSize < flashMapSize) { - msg(QObject::tr("parseFlashMapStoreHeader: FlashMap block size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(flashMapSize).arg(flashMapSize) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseFlashMapStoreHeader: FlashMap block size %Xh (%u) is greater than volume body size %Xh (%u)", + flashMapSize, flashMapSize, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body - QByteArray header = store.left(sizeof(PHOENIX_FLASH_MAP_HEADER)); - QByteArray body = store.mid(sizeof(PHOENIX_FLASH_MAP_HEADER), flashMapSize - sizeof(PHOENIX_FLASH_MAP_HEADER)); + UByteArray header = store.left(sizeof(PHOENIX_FLASH_MAP_HEADER)); + UByteArray body = store.mid(sizeof(PHOENIX_FLASH_MAP_HEADER), flashMapSize - sizeof(PHOENIX_FLASH_MAP_HEADER)); // Add info - QString name = QObject::tr("Phoenix SCT flash map"); - QString info = QObject::tr("Signature: _FLASH_MAP\nFull size: %1h (%2)\nHeader size: %3h (%4)\nBody size: %5h (%6)\nNumber of entries: %7") - .hexarg(flashMapSize).arg(flashMapSize) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .arg(flashMapHeader->NumEntries); + UString name("Phoenix SCT flash map"); + UString info = usprintf("Signature: _FLASH_MAP\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\nNumber of entries: %u", + flashMapSize, flashMapSize, + header.size(), header.size(), + body.size(), body.size(), + flashMapHeader->NumEntries); // Add correct offset pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::FlashMapStore, 0, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::FlashMapStore, 0, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseCmdbStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseCmdbStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check store size if (dataSize < sizeof(PHOENIX_CMDB_HEADER)) { - msg(QObject::tr("parseCmdbStoreHeader: volume body is too small even for CMDB store header"), parent); - return ERR_SUCCESS; + msg(UString("parseCmdbStoreHeader: volume body is too small even for CMDB store header"), parent); + return U_SUCCESS; } UINT32 cmdbSize = NVRAM_PHOENIX_CMDB_SIZE; if (dataSize < cmdbSize) { - msg(QObject::tr("parseCmdbStoreHeader: CMDB store size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(cmdbSize).arg(cmdbSize) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseCmdbStoreHeader: CMDB store size %Xh (%u) is greater than volume body size %Xh (%u)", + cmdbSize, cmdbSize, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get store header const PHOENIX_CMDB_HEADER* cmdbHeader = (const PHOENIX_CMDB_HEADER*)store.constData(); // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body - QByteArray header = store.left(cmdbHeader->TotalSize); - QByteArray body = store.mid(cmdbHeader->TotalSize, cmdbSize - cmdbHeader->TotalSize); + UByteArray header = store.left(cmdbHeader->TotalSize); + UByteArray body = store.mid(cmdbHeader->TotalSize, cmdbSize - cmdbHeader->TotalSize); // Add info - QString name = QObject::tr("CMDB store"); - QString info = QObject::tr("Signature: CMDB\nFull size: %1h (%2)\nHeader size: %3h (%4)\nBody size: %5h (%6)") - .hexarg(cmdbSize).arg(cmdbSize) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()); + UString name("CMDB store"); + UString info = usprintf("Signature: CMDB\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)", + cmdbSize, cmdbSize, + header.size(), header.size(), + body.size(), body.size()); // Add correct offset pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::CmdbStore, 0, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::CmdbStore, 0, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseSlicPubkeyHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseSlicPubkeyHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check data size if (dataSize < sizeof(OEM_ACTIVATION_PUBKEY)) { - msg(QObject::tr("parseSlicPubkeyHeader: volume body is too small even for SLIC pubkey header"), parent); - return ERR_SUCCESS; + msg(UString("parseSlicPubkeyHeader: volume body is too small even for SLIC pubkey header"), parent); + return U_SUCCESS; } // Get SLIC pubkey header @@ -4082,47 +4069,47 @@ STATUS FfsParser::parseSlicPubkeyHeader(const QByteArray & store, const UINT32 p // Check store size if (dataSize < pubkeyHeader->Size) { - msg(QObject::tr("parseSlicPubkeyHeader: SLIC pubkey size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(pubkeyHeader->Size).arg(pubkeyHeader->Size) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseSlicPubkeyHeader: SLIC pubkey size %Xh (%u) is greater than volume body size %Xh (%u)", + pubkeyHeader->Size, pubkeyHeader->Size, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body - QByteArray header = store.left(sizeof(OEM_ACTIVATION_PUBKEY)); + UByteArray header = store.left(sizeof(OEM_ACTIVATION_PUBKEY)); // Add info - QString name = QObject::tr("SLIC pubkey"); - QString info = QObject::tr("Type: 0h\nFull size: %1h (%2)\nHeader size: %3h (%4)\nBody size: 0h (0)\n" - "Key type :%5h\nVersion: %6h\nAlgorithm: %7h\nMagic: RSA1\nBit length: %8h\nExponent:%9h") - .hexarg(pubkeyHeader->Size).arg(pubkeyHeader->Size) - .hexarg(header.size()).arg(header.size()) - .hexarg2(pubkeyHeader->KeyType, 2) - .hexarg2(pubkeyHeader->Version, 2) - .hexarg2(pubkeyHeader->Algorithm, 8) - .hexarg2(pubkeyHeader->BitLength, 8) - .hexarg2(pubkeyHeader->Exponent, 8); + UString name("SLIC pubkey"); + UString info = usprintf("Type: 0h\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: 0h (0)\n" + "Key type :%02Xh\nVersion: %02Xh\nAlgorithm: %08Xh\nMagic: RSA1\nBit length: %08Xh\nExponent:%08Xh", + pubkeyHeader->Size, pubkeyHeader->Size, + header.size(), header.size(), + pubkeyHeader->KeyType, + pubkeyHeader->Version, + pubkeyHeader->Algorithm, + pubkeyHeader->BitLength, + pubkeyHeader->Exponent); // Add correct offset pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::SlicData, Subtypes::PubkeySlicData, name, QString(), info, header, QByteArray(), QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::SlicData, Subtypes::PubkeySlicData, name, UString(), info, header, UByteArray(), UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseSlicMarkerHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseSlicMarkerHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check data size if (dataSize < sizeof(OEM_ACTIVATION_MARKER)) { - msg(QObject::tr("parseSlicMarkerHeader: volume body is too small even for SLIC marker header"), parent); - return ERR_SUCCESS; + msg(UString("parseSlicMarkerHeader: volume body is too small even for SLIC marker header"), parent); + return U_SUCCESS; } // Get SLIC marker header @@ -4130,46 +4117,46 @@ STATUS FfsParser::parseSlicMarkerHeader(const QByteArray & store, const UINT32 p // Check store size if (dataSize < markerHeader->Size) { - msg(QObject::tr("parseSlicMarkerHeader: SLIC marker size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(markerHeader->Size).arg(markerHeader->Size) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseSlicMarkerHeader: SLIC marker size %Xh (%u) is greater than volume body size %Xh (%u)", + markerHeader->Size, markerHeader->Size, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body - QByteArray header = store.left(sizeof(OEM_ACTIVATION_MARKER)); + UByteArray header = store.left(sizeof(OEM_ACTIVATION_MARKER)); // Add info - QString name = QObject::tr("SLIC marker"); - QString info = QObject::tr("Type: 1h\nFull size: %1h (%2)\nHeader size: %3h (%4)\nBody size: 0h (0)\n" - "Version :%5h\nOEM ID: %6\nOEM table ID: %7\nWindows flag: WINDOWS\nSLIC version: %8h") - .hexarg(markerHeader->Size).arg(markerHeader->Size) - .hexarg(header.size()).arg(header.size()) - .hexarg2(markerHeader->Version, 8) - .arg(QString::fromLatin1((const char*)&(markerHeader->OemId), sizeof(markerHeader->OemId))) - .arg(QString::fromLatin1((const char*)&(markerHeader->OemTableId), sizeof(markerHeader->OemTableId))) - .hexarg2(markerHeader->SlicVersion, 8); + UString name("SLIC marker"); + UString info = usprintf("Type: 1h\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: 0h (0)\n" + "Version :%08Xh\nOEM ID: %s\nOEM table ID: %s\nWindows flag: WINDOWS\nSLIC version: %08Xh", + markerHeader->Size, markerHeader->Size, + header.size(), header.size(), + markerHeader->Version, + (const char*)&(markerHeader->OemId), + (const char*)&(markerHeader->OemTableId), + markerHeader->SlicVersion); // Add correct offset pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::SlicData, Subtypes::MarkerSlicData, name, QString(), info, header, QByteArray(), QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::SlicData, Subtypes::MarkerSlicData, name, UString(), info, header, UByteArray(), UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseIntelMicrocodeHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseIntelMicrocodeHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); // Check data size if (dataSize < sizeof(INTEL_MICROCODE_HEADER)) { - msg(QObject::tr("parseIntelMicrocodeHeader: volume body is too small even for Intel microcode header"), parent); - return ERR_SUCCESS; + msg(UString("parseIntelMicrocodeHeader: volume body is too small even for Intel microcode header"), parent); + return U_SUCCESS; } // Get Intel microcode header @@ -4177,51 +4164,51 @@ STATUS FfsParser::parseIntelMicrocodeHeader(const QByteArray & store, const UINT // Check store size if (dataSize < ucodeHeader->TotalSize) { - msg(QObject::tr("parseIntelMicrocodeHeader: Intel microcode size %1h (%2) is greater than volume body size %3h (%4)") - .hexarg(ucodeHeader->TotalSize).arg(ucodeHeader->TotalSize) - .hexarg(dataSize).arg(dataSize), parent); - return ERR_SUCCESS; + msg(usprintf("parseIntelMicrocodeHeader: Intel microcode size %Xh (%u) is greater than volume body size %Xh (%u)", + ucodeHeader->TotalSize, ucodeHeader->TotalSize, + dataSize, dataSize), parent); + return U_SUCCESS; } // Get parsing data - PARSING_DATA pdata = parsingDataFromQModelIndex(parent); + PARSING_DATA pdata = parsingDataFromUModelIndex(parent); // Construct header and body - QByteArray header = store.left(sizeof(INTEL_MICROCODE_HEADER)); - QByteArray body = store.mid(sizeof(INTEL_MICROCODE_HEADER), ucodeHeader->DataSize); + UByteArray header = store.left(sizeof(INTEL_MICROCODE_HEADER)); + UByteArray body = store.mid(sizeof(INTEL_MICROCODE_HEADER), ucodeHeader->DataSize); //TODO: recalculate checksum // Add info - QString name = QObject::tr("Intel microcode"); - QString info = QObject::tr("Revision: 1h\nFull size: %1h (%2)\nHeader size: %3h (%4)\nBody size: %5h (%6)\n" - "Date: %7h\nCPU signature: %8h\nChecksum: %9h\nLoader revision: %10h\nCPU flags: %11h") - .hexarg(ucodeHeader->TotalSize).arg(ucodeHeader->TotalSize) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .hexarg2(ucodeHeader->Date, 8) - .hexarg2(ucodeHeader->CpuSignature, 8) - .hexarg2(ucodeHeader->Checksum, 8) - .hexarg2(ucodeHeader->LoaderRevision, 8) - .hexarg2(ucodeHeader->CpuFlags, 8); + UString name("Intel microcode"); + UString info = usprintf("Revision: 1h\nFull size: %Xh (%u)\nHeader size: %Xh (%u)\nBody size: %Xh (%u)\n" + "Date: %08Xh\nCPU signature: %08Xh\nChecksum: %08Xh\nLoader revision: %08Xh\nCPU flags: %08Xh", + ucodeHeader->TotalSize, ucodeHeader->TotalSize, + header.size(), header.size(), + body.size(), body.size(), + ucodeHeader->Date, + ucodeHeader->CpuSignature, + ucodeHeader->Checksum, + ucodeHeader->LoaderRevision, + ucodeHeader->CpuFlags); // Add correct offset pdata.offset = parentOffset; // Add tree item - index = model->addItem(Types::Microcode, Subtypes::IntelMicrocode, name, QString(), info, header, body, QByteArray(), true, parsingDataToQByteArray(pdata), parent); + index = model->addItem(Types::Microcode, Subtypes::IntelMicrocode, name, UString(), info, header, body, UByteArray(), true, parsingDataToUByteArray(pdata), parent); - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index) +USTATUS FfsParser::parseStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index) { const UINT32 dataSize = (const UINT32)store.size(); const UINT32* signature = (const UINT32*)store.constData(); // Check store size if (dataSize < sizeof(UINT32)) { - msg(QObject::tr("parseStoreHeader: volume body is too small even for store signature"), parent); - return ERR_SUCCESS; + msg(UString("parseStoreHeader: volume body is too small even for store signature"), parent); + return U_SUCCESS; } // Check signature and run parser function needed @@ -4257,26 +4244,26 @@ STATUS FfsParser::parseStoreHeader(const QByteArray & store, const UINT32 parent else if (*signature == INTEL_MICROCODE_HEADER_VERSION) return parseIntelMicrocodeHeader(store, parentOffset, parent, index); - msg(QObject::tr("parseStoreHeader: don't know how to parse a header with signature %1h").hexarg2(*signature, 8), parent); - return ERR_SUCCESS; + msg(usprintf("parseStoreHeader: don't know how to parse a header with signature %08Xh", *signature), parent); + return U_SUCCESS; } -STATUS FfsParser::parseVssStoreBody(const QModelIndex & index) +USTATUS FfsParser::parseVssStoreBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parsing data for the current item - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); UINT32 parentOffset = pdata.offset + model->header(index).size(); - const QByteArray data = model->body(index); + const UByteArray data = model->body(index); // Check that the is enough space for variable header const UINT32 dataSize = (UINT32)data.size(); if (dataSize < sizeof(VSS_VARIABLE_HEADER)) { - msg(QObject::tr("parseVssStoreBody: store body is too small even for VSS variable header"), index); - return ERR_SUCCESS; + msg(UString("parseVssStoreBody: store body is too small even for VSS variable header"), index); + return U_SUCCESS; } UINT32 offset = 0; @@ -4294,12 +4281,12 @@ STATUS FfsParser::parseVssStoreBody(const QModelIndex & index) UINT32 pubKeyIndex = 0; UINT8 subtype = 0; - QString name; - QString text; + UString name; + UString text; EFI_GUID* variableGuid; CHAR16* variableName; - QByteArray header; - QByteArray body; + UByteArray header; + UByteArray body; UINT32 unparsedSize = dataSize - offset; @@ -4377,78 +4364,72 @@ STATUS FfsParser::parseVssStoreBody(const QModelIndex & index) // Can't parse further, add the last element and break the loop if (!variableSize) { // Check if the data left is a free space or a padding - QByteArray padding = data.mid(offset, unparsedSize); + UByteArray padding = data.mid(offset, unparsedSize); UINT8 type; if (padding.count(pdata.emptyByte) == padding.size()) { // It's a free space - name = QObject::tr("Free space"); + name = UString("Free space"); type = Types::FreeSpace; subtype = 0; } else { // Nothing is parsed yet, but the store is not empty if (!offset) { - msg(QObject::tr("parseVssStoreBody: store can't be parsed as VSS store"), index); - return ERR_SUCCESS; + msg(UString("parseVssStoreBody: store can't be parsed as VSS store"), index); + return U_SUCCESS; } // It's a padding - name = QObject::tr("Padding"); + name = UString("Padding"); type = Types::Padding; subtype = getPaddingType(padding); } // Get info - QString info = QObject::tr("Full size: %1h (%2)") - .hexarg(padding.size()).arg(padding.size()); + UString info = usprintf("Full size: %Xh (%u)", padding.size(), padding.size()); // Construct parsing data pdata.offset = parentOffset + offset; // Add tree item - model->addItem(type, subtype, name, QString(), info, QByteArray(), padding, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(type, subtype, name, UString(), info, UByteArray(), padding, UByteArray(), false, parsingDataToUByteArray(pdata), index); - return ERR_SUCCESS; + return U_SUCCESS; } - QString info; + UString info; // Rename invalid variables if (isInvalid) { - name = QObject::tr("Invalid"); + name = UString("Invalid"); } else { // Add GUID and text for valid variables - name = guidToQString(*variableGuid); - info += QObject::tr("Variable GUID: %1\n").arg(name); - text = QString::fromUtf16(variableName); + name = guidToUString(*variableGuid); + info += UString("Variable GUID: ") + name + UString("\n"); + text = UString::fromUtf16(variableName); } - // Add header, body and extended data info - info += QObject::tr("Full size: %1h (%2)\nHeader size %3h (%4)\nBody size: %5h (%6)") - .hexarg(variableSize).arg(variableSize) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()); - - // Add state info - info += QObject::tr("\nState: %1h").hexarg2(variableHeader->State, 2); - - // Add attributes info - info += QObject::tr("\nAttributes: %1h (%2)").hexarg2(variableHeader->Attributes, 8).arg(vssAttributesToQString(variableHeader->Attributes)); + // Add info + info += usprintf("Full size: %Xh (%u)\nHeader size %Xh (%u)\nBody size: %Xh (%u)\nState: %02Xh\nAttributes: %08Xh (", + variableSize, variableSize, + header.size(), header.size(), + body.size(), body.size(), + variableHeader->State, + variableHeader->Attributes) + vssAttributesToUString(variableHeader->Attributes).append(")"); // Set subtype and add related info if (isInvalid) subtype = Subtypes::InvalidVssEntry; else if (isAuthenticated) { subtype = Subtypes::AuthVssEntry; - info += QObject::tr("\nMonotonic counter: %1h\nTimestamp: %2\nPubKey index: %3") - .hexarg(monotonicCounter).arg(efiTimeToQString(timestamp)).arg(pubKeyIndex); - + info += usprintf("\nMonotonic counter: %Xh\nTimestamp:", monotonicCounter) + efiTimeToUString(timestamp) + + usprintf("\nPubKey index: %u", pubKeyIndex); } else if (isAppleCrc32) { subtype = Subtypes::AppleVssEntry; - info += QObject::tr("\nData checksum: %1h%2").hexarg2(storedCrc32, 8) - .arg(storedCrc32 == calculatedCrc32 ? QObject::tr(", valid") : QObject::tr(", invalid, should be %1h").hexarg2(calculatedCrc32,8)); + info += usprintf("\nData checksum: %08X", storedCrc32) + + (storedCrc32 == calculatedCrc32 ? UString(", valid") : usprintf(", invalid, should be %08Xh", calculatedCrc32)); } else subtype = Subtypes::StandardVssEntry; @@ -4457,25 +4438,25 @@ STATUS FfsParser::parseVssStoreBody(const QModelIndex & index) pdata.offset = parentOffset + offset; // Add tree item - model->addItem(Types::VssEntry, subtype, name, text, info, header, body, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::VssEntry, subtype, name, text, info, header, body, UByteArray(), false, parsingDataToUByteArray(pdata), index); // Move to next variable offset += variableSize; } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseFsysStoreBody(const QModelIndex & index) +USTATUS FfsParser::parseFsysStoreBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parsing data for the current item - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); UINT32 parentOffset = pdata.offset + model->header(index).size(); - const QByteArray data = model->body(index); + const UByteArray data = model->body(index); // Check that the is enough space for variable header const UINT32 dataSize = (UINT32)data.size(); @@ -4493,36 +4474,34 @@ STATUS FfsParser::parseFsysStoreBody(const QModelIndex & index) variableSize = nameSize + sizeof(UINT8); } - QByteArray name; + UByteArray name; if (variableSize) { name = data.mid(offset + sizeof(UINT8), nameSize); // Check for EOF variable if (nameSize == 3 && name[0] == 'E' && name[1] == 'O' && name[2] == 'F') { // There is no data afterward, add EOF variable and free space and return - QByteArray header = data.mid(offset, sizeof(UINT8) + nameSize); - QString info = QObject::tr("Full size: %1h (%2)") - .hexarg(header.size()).arg(header.size()); + UByteArray header = data.mid(offset, sizeof(UINT8) + nameSize); + UString info = usprintf("Full size: %Xh (%u)", header.size(), header.size()); // Add correct offset to parsing data pdata.offset = parentOffset + offset; // Add EOF tree item - model->addItem(Types::FsysEntry, 0, name, QString(), info, header, QByteArray(), QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::FsysEntry, 0, name, UString(), info, header, UByteArray(), UByteArray(), false, parsingDataToUByteArray(pdata), index); // Add free space offset += header.size(); unparsedSize = dataSize - offset; - QByteArray body = data.mid(offset); - info = QObject::tr("Full size: %1h (%2)") - .hexarg(body.size()).arg(body.size()); + UByteArray body = data.mid(offset); + info = usprintf("Full size: %Xh (%u)", body.size(), body.size()); // Add correct offset to parsing data pdata.offset = parentOffset + offset; // Add free space tree item - model->addItem(Types::FreeSpace, 0, QObject::tr("Free space"), QString(), info, QByteArray(), body, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::FreeSpace, 0, UString("Free space"), UString(), info, UByteArray(), body, UByteArray(), false, parsingDataToUByteArray(pdata), index); - return ERR_SUCCESS; + return U_SUCCESS; } } @@ -4533,71 +4512,70 @@ STATUS FfsParser::parseFsysStoreBody(const QModelIndex & index) } else { // Last variable is bad, add the rest as padding and return - QByteArray body = data.mid(offset); - QString info = QObject::tr("Full size: %1h (%2)") - .hexarg(body.size()).arg(body.size()); + UByteArray body = data.mid(offset); + UString info = usprintf("Full size: %Xh (%u)", body.size(), body.size()); // Add correct offset to parsing data pdata.offset = parentOffset + offset; // Add free space tree item - model->addItem(Types::Padding, getPaddingType(body), QObject::tr("Padding"), QString(), info, QByteArray(), body, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::Padding, getPaddingType(body), UString("Padding"), UString(), info, UByteArray(), body, UByteArray(), false, parsingDataToUByteArray(pdata), index); // Show message - msg(QObject::tr("parseFsysStoreBody: next variable appears too big, added as padding"), index); + msg(UString("parseFsysStoreBody: next variable appears too big, added as padding"), index); - return ERR_SUCCESS; + return U_SUCCESS; } // Construct header and body - QByteArray header = data.mid(offset, sizeof(UINT8) + nameSize + sizeof(UINT16)); - QByteArray body = data.mid(offset + sizeof(UINT8) + nameSize + sizeof(UINT16), dataSize); + UByteArray header = data.mid(offset, sizeof(UINT8) + nameSize + sizeof(UINT16)); + UByteArray body = data.mid(offset + sizeof(UINT8) + nameSize + sizeof(UINT16), dataSize); // Add info - QString info = QObject::tr("Full size: %1h (%2)\nHeader size %3h (%4)\nBody size: %5h (%6)") - .hexarg(variableSize).arg(variableSize) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()); + UString info = usprintf("Full size: %Xh (%u)\nHeader size %Xh (%u)\nBody size: %Xh (%u)", + variableSize, variableSize, + header.size(), header.size(), + body.size(), body.size()); // Add correct offset to parsing data pdata.offset = parentOffset + offset; // Add tree item - model->addItem(Types::FsysEntry, 0, name, QString(), info, header, body, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::FsysEntry, 0, name, UString(), info, header, body, UByteArray(), false, parsingDataToUByteArray(pdata), index); // Move to next variable offset += variableSize; } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseEvsaStoreBody(const QModelIndex & index) +USTATUS FfsParser::parseEvsaStoreBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parsing data for the current item - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); UINT32 parentOffset = pdata.offset + model->header(index).size(); - const QByteArray data = model->body(index); + const UByteArray data = model->body(index); // Check that the is enough space for entry header const UINT32 dataSize = (UINT32)data.size(); UINT32 offset = 0; std::map guidMap; - std::map nameMap; + std::map nameMap; // Parse all entries UINT32 unparsedSize = dataSize; while (unparsedSize) { UINT32 variableSize = 0; - QString name; - QString info; - QByteArray header; - QByteArray body; + UString name; + UString info; + UByteArray header; + UByteArray body; UINT8 subtype; UINT8 calculated; @@ -4606,16 +4584,15 @@ STATUS FfsParser::parseEvsaStoreBody(const QModelIndex & index) // Check entry size variableSize = sizeof(EVSA_ENTRY_HEADER); if (unparsedSize < variableSize || unparsedSize < entryHeader->Size) { - QByteArray body = data.mid(offset); - QString info = QObject::tr("Full size: %1h (%2)") - .hexarg(body.size()).arg(body.size()); + UByteArray body = data.mid(offset); + UString info = usprintf("Full size: %Xh (%u)", body.size(), body.size()); // Checke type - QString name = QObject::tr("Free space"); + UString name("Free space"); UINT8 type = Types::FreeSpace; UINT8 subtype = 0; if (getPaddingType(body) == Subtypes::DataPadding) { - name = QObject::tr("Padding"); + name = UString("Padding"); type = Types::Padding; subtype = Subtypes::DataPadding; } @@ -4624,11 +4601,11 @@ STATUS FfsParser::parseEvsaStoreBody(const QModelIndex & index) pdata.offset = parentOffset + offset; // Add free space tree item - QModelIndex itemIndex = model->addItem(type, subtype, name, QString(), info, QByteArray(), body, QByteArray(), false, parsingDataToQByteArray(pdata), index); + UModelIndex itemIndex = model->addItem(type, subtype, name, UString(), info, UByteArray(), body, UByteArray(), false, parsingDataToUByteArray(pdata), index); // Show message if (type == Types::Padding) - msg(QObject::tr("parseEvsaStoreBody: variable parsing failed, rest of unparsed store added as padding"), itemIndex); + msg(UString("parseEvsaStoreBody: variable parsing failed, rest of unparsed store added as padding"), itemIndex); break; } @@ -4644,17 +4621,15 @@ STATUS FfsParser::parseEvsaStoreBody(const QModelIndex & index) header = data.mid(offset, sizeof(EVSA_GUID_ENTRY)); body = data.mid(offset + sizeof(EVSA_GUID_ENTRY), guidHeader->Header.Size - sizeof(EVSA_GUID_ENTRY)); EFI_GUID guid = *(EFI_GUID*)body.constData(); - name = guidToQString(guid); - info = QObject::tr("GUID: %1\nFull size: %2h (%3)\nHeader size %4h (%5)\nBody size: %6h (%7)\nType: %8h\nChecksum: %9\nGuidId: %10h") - .arg(name) - .hexarg(variableSize).arg(variableSize) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .hexarg2(guidHeader->Header.Type, 2) - .arg(guidHeader->Header.Checksum == calculated ? - QObject::tr("%1h, valid").hexarg2(calculated, 2) : - QObject::tr("%1h, invalid, should be %2h").hexarg2(guidHeader->Header.Checksum, 2).hexarg2(calculated, 2)) - .hexarg2(guidHeader->GuidId, 4); + name = guidToUString(guid); + info = UString("GUID: ") + name + usprintf("\nFull size: %Xh (%u)\nHeader size %Xh (%u)\nBody size: %Xh (%u)\nType: %02Xh\nChecksum: %02Xh", + variableSize, variableSize, + header.size(), header.size(), + body.size(), body.size(), + guidHeader->Header.Type, + guidHeader->Header.Checksum) + + (guidHeader->Header.Checksum == calculated ? UString(", valid") : usprintf(", invalid, should be %02Xh", calculated)) + + usprintf("\nGuidId: %04Xh", guidHeader->GuidId); subtype = Subtypes::GuidEvsaEntry; guidMap.insert(std::pair(guidHeader->GuidId, guid)); } @@ -4664,19 +4639,17 @@ STATUS FfsParser::parseEvsaStoreBody(const QModelIndex & index) const EVSA_NAME_ENTRY* nameHeader = (const EVSA_NAME_ENTRY*)entryHeader; header = data.mid(offset, sizeof(EVSA_NAME_ENTRY)); body = data.mid(offset + sizeof(EVSA_NAME_ENTRY), nameHeader->Header.Size - sizeof(EVSA_NAME_ENTRY)); - name = QString::fromUtf16((const CHAR16*)body.constData()); - info = QObject::tr("Name: %1\nFull size: %2h (%3)\nHeader size %4h (%5)\nBody size: %6h (%7)\nType: %8h\nChecksum: %9\nVarId: %10h") - .arg(name) - .hexarg(variableSize).arg(variableSize) - .hexarg(header.size()).arg(header.size()) - .hexarg(body.size()).arg(body.size()) - .hexarg2(nameHeader->Header.Type, 2) - .arg(nameHeader->Header.Checksum == calculated ? - QObject::tr("%1h, valid").hexarg2(calculated, 2) : - QObject::tr("%1h, invalid, should be %2h").hexarg2(nameHeader->Header.Checksum, 2).hexarg2(calculated, 2)) - .hexarg2(nameHeader->VarId, 4); + name = UString::fromUtf16((const CHAR16*)body.constData()); + info = UString("GUID: ") + name + usprintf("\nFull size: %Xh (%u)\nHeader size %Xh (%u)\nBody size: %Xh (%u)\nType: %02Xh\nChecksum: %02Xh", + variableSize, variableSize, + header.size(), header.size(), + body.size(), body.size(), + nameHeader->Header.Type, + nameHeader->Header.Checksum) + + (nameHeader->Header.Checksum == calculated ? UString(", valid") : usprintf(", invalid, should be %02Xh", calculated)) + + usprintf("\nVarId: %04Xh", nameHeader->VarId); subtype = Subtypes::NameEvsaEntry; - nameMap.insert(std::pair(nameHeader->VarId, name)); + nameMap.insert(std::pair(nameHeader->VarId, name)); } // Data entry else if (entryHeader->Type == NVRAM_EVSA_ENTRY_TYPE_DATA1 || @@ -4695,32 +4668,32 @@ STATUS FfsParser::parseEvsaStoreBody(const QModelIndex & index) header = data.mid(offset, headerSize); body = data.mid(offset + headerSize, dataSize); - name = QObject::tr("Data"); - info = QObject::tr("Full size: %1h (%2)\nHeader size %3h (%4)\nBody size: %5h (%6)\nType: %7h\nChecksum: %8\nVarId: %9h\nGuidId: %10h\nAttributes: %11h (%12)") - .hexarg(variableSize).arg(variableSize) - .hexarg(headerSize).arg(headerSize) - .hexarg(dataSize).arg(dataSize) - .hexarg2(dataHeader->Header.Type, 2) - .arg(dataHeader->Header.Checksum == calculated ? - QObject::tr("%1h, valid").hexarg2(calculated, 2) : - QObject::tr("%1h, invalid, should be %2h").hexarg2(dataHeader->Header.Checksum, 2).hexarg2(calculated, 2)) - .hexarg2(dataHeader->VarId, 4) - .hexarg2(dataHeader->GuidId, 4) - .hexarg2(dataHeader->Attributes, 8).arg(evsaAttributesToQString(dataHeader->Attributes)); + name = UString("Data"); + info = usprintf("Full size: %Xh (%u)\nHeader size %Xh (%u)\nBody size: %Xh (%u)\nType: %02Xh\nChecksum: %02Xh", + variableSize, variableSize, + headerSize, headerSize, + dataSize, dataSize, + dataHeader->Header.Type, + dataHeader->Header.Checksum) + + (dataHeader->Header.Checksum == calculated ? UString("valid") : usprintf(", invalid, should be %02Xh", calculated)) + + usprintf("\nVarId: %04Xh\nGuidId: %04Xh\nAttributes: %08Xh (", + dataHeader->VarId, + dataHeader->GuidId, + dataHeader->Attributes) + + evsaAttributesToUString(dataHeader->Attributes).append(")"); subtype = Subtypes::DataEvsaEntry; } // Unknown entry or free space else { - QByteArray body = data.mid(offset); - QString info = QObject::tr("Full size: %1h (%2)") - .hexarg(body.size()).arg(body.size()); + UByteArray body = data.mid(offset); + UString info = usprintf("Full size: %Xh (%u)", body.size(), body.size()); // Check type - QString name = QObject::tr("Free space"); + UString name("Free space"); UINT8 type = Types::FreeSpace; UINT8 subtype = 0; if (getPaddingType(body) == Subtypes::DataPadding) { - name = QObject::tr("Padding"); + name = UString("Padding"); type = Types::Padding; subtype = Subtypes::DataPadding; } @@ -4729,11 +4702,11 @@ STATUS FfsParser::parseEvsaStoreBody(const QModelIndex & index) pdata.offset = parentOffset + offset; // Add free space tree item - QModelIndex itemIndex = model->addItem(type, subtype, name, QString(), info, QByteArray(), body, QByteArray(), false, parsingDataToQByteArray(pdata), index); + UModelIndex itemIndex = model->addItem(type, subtype, name, UString(), info, UByteArray(), body, UByteArray(), false, parsingDataToUByteArray(pdata), index); // Show message if (type == Types::Padding) - msg(QObject::tr("parseEvsaStoreBody: unknown variable of type %1h found at offset %2h, the rest of unparsed store added as padding").hexarg2(entryHeader->Type, 2).hexarg(offset), itemIndex); + msg(usprintf("parseEvsaStoreBody: unknown variable of type %02Xh found at offset %Xh, the rest of unparsed store added as padding",entryHeader->Type, offset), itemIndex); break; } @@ -4741,7 +4714,7 @@ STATUS FfsParser::parseEvsaStoreBody(const QModelIndex & index) pdata.offset = parentOffset + offset; // Add tree item - model->addItem(Types::EvsaEntry, subtype, name, QString(), info, header, body, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::EvsaEntry, subtype, name, UString(), info, header, body, UByteArray(), false, parsingDataToUByteArray(pdata), index); // Move to next variable offset += variableSize; @@ -4750,61 +4723,61 @@ STATUS FfsParser::parseEvsaStoreBody(const QModelIndex & index) // Reparse all data variables to detect invalid ones and assign name and test to valid ones for (int i = 0; i < model->rowCount(index); i++) { - QModelIndex current = index.child(i, 0); + UModelIndex current = index.child(i, 0); if (model->subtype(current) == Subtypes::DataEvsaEntry) { - QByteArray header = model->header(current); + UByteArray header = model->header(current); const EVSA_DATA_ENTRY* dataHeader = (const EVSA_DATA_ENTRY*)header.constData(); - QString guid; + UString guid; if (guidMap.count(dataHeader->GuidId)) - guid = guidToQString(guidMap[dataHeader->GuidId]); - QString name; + guid = guidToUString(guidMap[dataHeader->GuidId]); + UString name; if (nameMap.count(dataHeader->VarId)) name = nameMap[dataHeader->VarId]; // Check for variable validity if (guid.isEmpty() && name.isEmpty()) { // Both name and guid aren't found model->setSubtype(current, Subtypes::InvalidEvsaEntry); - model->setName(current, QObject::tr("Invalid")); - msg(QObject::tr("parseEvsaStoreBody: data variable with invalid GuidId and invalid VarId"), current); + model->setName(current, UString("Invalid")); + msg(UString("parseEvsaStoreBody: data variable with invalid GuidId and invalid VarId"), current); } else if (guid.isEmpty()) { // Guid not found model->setSubtype(current, Subtypes::InvalidEvsaEntry); - model->setName(current, QObject::tr("Invalid")); - msg(QObject::tr("parseEvsaStoreBody: data variable with invalid GuidId"), current); + model->setName(current, UString("Invalid")); + msg(UString("parseEvsaStoreBody: data variable with invalid GuidId"), current); } else if (name.isEmpty()) { // Name not found model->setSubtype(current, Subtypes::InvalidEvsaEntry); - model->setName(current, QObject::tr("Invalid")); - msg(QObject::tr("parseEvsaStoreBody: data variable with invalid VarId"), current); + model->setName(current, UString("Invalid")); + msg(UString("parseEvsaStoreBody: data variable with invalid VarId"), current); } else { // Variable is OK, rename it if (dataHeader->Header.Type == NVRAM_EVSA_ENTRY_TYPE_DATA_INVALID) { model->setSubtype(current, Subtypes::InvalidEvsaEntry); - model->setName(current, QObject::tr("Invalid")); + model->setName(current, UString("Invalid")); } else { model->setName(current, guid); } model->setText(current, name); - model->addInfo(current, QObject::tr("GUID: %1\nName: %2\n").arg(guid).arg(name), false); + model->addInfo(current, guid.prepend("GUID: ") + name.prepend("\nName: "), false); } } } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS FfsParser::parseFlashMapBody(const QModelIndex & index) +USTATUS FfsParser::parseFlashMapBody(const UModelIndex & index) { // Sanity check if (!index.isValid()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get parsing data for the current item - PARSING_DATA pdata = parsingDataFromQModelIndex(index); + PARSING_DATA pdata = parsingDataFromUModelIndex(index); UINT32 parentOffset = pdata.offset + model->header(index).size(); - const QByteArray data = model->body(index); + const UByteArray data = model->body(index); const UINT32 dataSize = (UINT32)data.size(); @@ -4817,36 +4790,35 @@ STATUS FfsParser::parseFlashMapBody(const QModelIndex & index) // Check entry size if (unparsedSize < sizeof(PHOENIX_FLASH_MAP_ENTRY)) { // Last variable is bad, add the rest as padding and return - QByteArray body = data.mid(offset); - QString info = QObject::tr("Full size: %1h (%2)") - .hexarg(body.size()).arg(body.size()); + UByteArray body = data.mid(offset); + UString info = usprintf("Full size: %Xh (%u)", body.size(), body.size()); // Add correct offset to parsing data pdata.offset = parentOffset + offset; // Add free space tree item - model->addItem(Types::Padding, getPaddingType(body), QObject::tr("Padding"), QString(), info, QByteArray(), body, QByteArray(), false, parsingDataToQByteArray(pdata), index); + model->addItem(Types::Padding, getPaddingType(body), UString("Padding"), UString(), info, UByteArray(), body, UByteArray(), false, parsingDataToUByteArray(pdata), index); // Show message if (unparsedSize < entryHeader->Size) - msg(QObject::tr("parseFlashMapBody: next entry appears too big, added as padding"), index); + msg(UString("parseFlashMapBody: next entry appears too big, added as padding"), index); break; } - QString name = guidToQString(entryHeader->Guid); + UString name = guidToUString(entryHeader->Guid); // Construct header - QByteArray header = data.mid(offset, sizeof(PHOENIX_FLASH_MAP_ENTRY)); + UByteArray header = data.mid(offset, sizeof(PHOENIX_FLASH_MAP_ENTRY)); // Add info - QString info = QObject::tr("Entry GUID: %1\nFull size: 24h (36)\nHeader size: 24h (36)\nBody size: 0h (0)\nEntry type: %2h\nData type: %3h\nMemory address: %4h\nSize: %5h\nOffset: %6h") - .arg(name) - .hexarg2(entryHeader->EntryType, 4) - .hexarg2(entryHeader->DataType, 4) - .hexarg2(entryHeader->PhysicalAddress, 8) - .hexarg2(entryHeader->Size, 8) - .hexarg2(entryHeader->Offset, 8); + UString info = UString("Entry GUID: ") + name + usprintf("\nFull size: 24h (36)\nHeader size: 24h (36)\nBody size: 0h (0)\n" + "Entry type: %04Xh\nData type: %04Xh\nMemory address: %08Xh\nSize: %08Xh\nOffset: %08Xh", + entryHeader->EntryType, + entryHeader->DataType, + entryHeader->PhysicalAddress, + entryHeader->Size, + entryHeader->Offset); // Add correct offset to parsing data pdata.offset = parentOffset + offset; @@ -4863,12 +4835,12 @@ STATUS FfsParser::parseFlashMapBody(const QModelIndex & index) } // Add tree item - model->addItem(Types::FlashMapEntry, subtype, name, flashMapGuidToQString(entryHeader->Guid), info, header, QByteArray(), QByteArray(), true, parsingDataToQByteArray(pdata), index); + model->addItem(Types::FlashMapEntry, subtype, name, flashMapGuidToUString(entryHeader->Guid), info, header, UByteArray(), UByteArray(), true, parsingDataToUByteArray(pdata), index); // Move to next variable offset += sizeof(PHOENIX_FLASH_MAP_ENTRY); unparsedSize = dataSize - offset; } - return ERR_SUCCESS; + return U_SUCCESS; } diff --git a/common/ffsparser.h b/common/ffsparser.h index e160e82..5e4be11 100644 --- a/common/ffsparser.h +++ b/common/ffsparser.h @@ -15,10 +15,9 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include -#include -#include -#include - +#include "ustring.h" +#include "ubytearray.h" +#include "umodelindex.h" #include "basetypes.h" #include "treemodel.h" #include "utility.h" @@ -43,95 +42,95 @@ public: ~FfsParser() {} // Returns messages - std::vector > getMessages() const { return messagesVector; } + std::vector > getMessages() const { return messagesVector; } // Clears messages void clearMessages() { messagesVector.clear(); } // Firmware image parsing - STATUS parse(const QByteArray &buffer); + USTATUS parse(const UByteArray &buffer); // Retuns index of the last VTF after parsing is done - const QModelIndex getLastVtf() {return lastVtf;}; + const UModelIndex getLastVtf() {return lastVtf;}; private: TreeModel *model; - std::vector > messagesVector; - void msg(const QString & message, const QModelIndex &index = QModelIndex()) { - messagesVector.push_back(std::pair(message, index)); + std::vector > messagesVector; + void msg(const UString message, const UModelIndex index = UModelIndex()) { + messagesVector.push_back(std::pair(message, index)); }; - QModelIndex lastVtf; + UModelIndex lastVtf; UINT32 capsuleOffsetFixup; - STATUS parseRawArea(const QModelIndex & index); - STATUS parseVolumeHeader(const QByteArray & volume, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseVolumeBody(const QModelIndex & index); - STATUS parseFileHeader(const QByteArray & file, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseFileBody(const QModelIndex & index); - STATUS parseSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse = false); - STATUS parseSectionBody(const QModelIndex & index); + USTATUS parseRawArea(const UModelIndex & index); + USTATUS parseVolumeHeader(const UByteArray & volume, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseVolumeBody(const UModelIndex & index); + USTATUS parseFileHeader(const UByteArray & file, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseFileBody(const UModelIndex & index); + USTATUS parseSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse = false); + USTATUS parseSectionBody(const UModelIndex & index); - STATUS parseIntelImage(const QByteArray & intelImage, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & root); - STATUS parseGbeRegion(const QByteArray & gbe, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseMeRegion(const QByteArray & me, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseBiosRegion(const QByteArray & bios, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parsePdrRegion(const QByteArray & pdr, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseGeneralRegion(const UINT8 subtype, const QByteArray & region, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); + USTATUS parseIntelImage(const UByteArray & intelImage, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & root); + USTATUS parseGbeRegion(const UByteArray & gbe, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseMeRegion(const UByteArray & me, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseBiosRegion(const UByteArray & bios, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parsePdrRegion(const UByteArray & pdr, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseGeneralRegion(const UINT8 subtype, const UByteArray & region, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); - STATUS parsePadFileBody(const QModelIndex & index); - STATUS parseVolumeNonUefiData(const QByteArray & data, const UINT32 parentOffset, const QModelIndex & index); + USTATUS parsePadFileBody(const UModelIndex & index); + USTATUS parseVolumeNonUefiData(const UByteArray & data, const UINT32 parentOffset, const UModelIndex & index); - STATUS parseSections(const QByteArray & sections, const QModelIndex & index, const bool preparse = false); - STATUS parseCommonSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse); - STATUS parseCompressedSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse); - STATUS parseGuidedSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse); - STATUS parseFreeformGuidedSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse); - STATUS parseVersionSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse); - STATUS parsePostcodeSectionHeader(const QByteArray & section, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index, const bool preparse); + USTATUS parseSections(const UByteArray & sections, const UModelIndex & index, const bool preparse = false); + USTATUS parseCommonSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse); + USTATUS parseCompressedSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse); + USTATUS parseGuidedSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse); + USTATUS parseFreeformGuidedSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse); + USTATUS parseVersionSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse); + USTATUS parsePostcodeSectionHeader(const UByteArray & section, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index, const bool preparse); - STATUS parseCompressedSectionBody(const QModelIndex & index); - STATUS parseGuidedSectionBody(const QModelIndex & index); - STATUS parseVersionSectionBody(const QModelIndex & index); - STATUS parseDepexSectionBody(const QModelIndex & index); - STATUS parseUiSectionBody(const QModelIndex & index); - STATUS parseRawSectionBody(const QModelIndex & index); - STATUS parsePeImageSectionBody(const QModelIndex & index); - STATUS parseTeImageSectionBody(const QModelIndex & index); + USTATUS parseCompressedSectionBody(const UModelIndex & index); + USTATUS parseGuidedSectionBody(const UModelIndex & index); + USTATUS parseVersionSectionBody(const UModelIndex & index); + USTATUS parseDepexSectionBody(const UModelIndex & index); + USTATUS parseUiSectionBody(const UModelIndex & index); + USTATUS parseRawSectionBody(const UModelIndex & index); + USTATUS parsePeImageSectionBody(const UModelIndex & index); + USTATUS parseTeImageSectionBody(const UModelIndex & index); - UINT8 getPaddingType(const QByteArray & padding); - STATUS parseAprioriRawSection(const QByteArray & body, QString & parsed); - STATUS findNextVolume(const QModelIndex & index, const QByteArray & bios, const UINT32 parentOffset, const UINT32 volumeOffset, UINT32 & nextVolumeOffset); - STATUS getVolumeSize(const QByteArray & bios, const UINT32 volumeOffset, UINT32 & volumeSize, UINT32 & bmVolumeSize); - UINT32 getFileSize(const QByteArray & volume, const UINT32 fileOffset, const UINT8 ffsVersion); - UINT32 getSectionSize(const QByteArray & file, const UINT32 sectionOffset, const UINT8 ffsVersion); + UINT8 getPaddingType(const UByteArray & padding); + USTATUS parseAprioriRawSection(const UByteArray & body, UString & parsed); + USTATUS findNextVolume(const UModelIndex & index, const UByteArray & bios, const UINT32 parentOffset, const UINT32 volumeOffset, UINT32 & nextVolumeOffset); + USTATUS getVolumeSize(const UByteArray & bios, const UINT32 volumeOffset, UINT32 & volumeSize, UINT32 & bmVolumeSize); + UINT32 getFileSize(const UByteArray & volume, const UINT32 fileOffset, const UINT8 ffsVersion); + UINT32 getSectionSize(const UByteArray & file, const UINT32 sectionOffset, const UINT8 ffsVersion); - STATUS performFirstPass(const QByteArray & imageFile, QModelIndex & index); - STATUS performSecondPass(const QModelIndex & index); - STATUS addOffsetsRecursive(const QModelIndex & index); - STATUS addMemoryAddressesRecursive(const QModelIndex & index, const UINT32 diff); + USTATUS performFirstPass(const UByteArray & imageFile, UModelIndex & index); + USTATUS performSecondPass(const UModelIndex & index); + USTATUS addOffsetsRecursive(const UModelIndex & index); + USTATUS addMemoryAddressesRecursive(const UModelIndex & index, const UINT32 diff); // NVRAM parsing - STATUS parseNvramVolumeBody(const QModelIndex & index); - STATUS findNextStore(const QModelIndex & index, const QByteArray & volume, const UINT32 parentOffset, const UINT32 storeOffset, UINT32 & nextStoreOffset); - STATUS getStoreSize(const QByteArray & data, const UINT32 storeOffset, UINT32 & storeSize); - STATUS parseStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); + USTATUS parseNvramVolumeBody(const UModelIndex & index); + USTATUS findNextStore(const UModelIndex & index, const UByteArray & volume, const UINT32 parentOffset, const UINT32 storeOffset, UINT32 & nextStoreOffset); + USTATUS getStoreSize(const UByteArray & data, const UINT32 storeOffset, UINT32 & storeSize); + USTATUS parseStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); - STATUS parseNvarStore(const QModelIndex & index); - STATUS parseVssStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseFtwStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseFdcStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseFsysStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseEvsaStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseFlashMapStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseCmdbStoreHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseSlicPubkeyHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseSlicMarkerHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); - STATUS parseIntelMicrocodeHeader(const QByteArray & store, const UINT32 parentOffset, const QModelIndex & parent, QModelIndex & index); + USTATUS parseNvarStore(const UModelIndex & index); + USTATUS parseVssStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseFtwStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseFdcStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseFsysStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseEvsaStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseFlashMapStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseCmdbStoreHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseSlicPubkeyHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseSlicMarkerHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); + USTATUS parseIntelMicrocodeHeader(const UByteArray & store, const UINT32 parentOffset, const UModelIndex & parent, UModelIndex & index); - STATUS parseVssStoreBody(const QModelIndex & index); - STATUS parseFsysStoreBody(const QModelIndex & index); - STATUS parseEvsaStoreBody(const QModelIndex & index); - STATUS parseFlashMapBody(const QModelIndex & index); + USTATUS parseVssStoreBody(const UModelIndex & index); + USTATUS parseFsysStoreBody(const UModelIndex & index); + USTATUS parseEvsaStoreBody(const UModelIndex & index); + USTATUS parseFlashMapBody(const UModelIndex & index); }; #endif // FFSPARSER_H diff --git a/common/ffsreport.cpp b/common/ffsreport.cpp index b1ca61c..3f9638c 100644 --- a/common/ffsreport.cpp +++ b/common/ffsreport.cpp @@ -13,53 +13,49 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "ffsreport.h" -std::vector FfsReport::generate() +std::vector FfsReport::generate() { - std::vector report; + std::vector report; // Check model pointer if (!model) { - report.push_back(QObject::tr("ERROR: Invalid model pointer provided.")); + report.push_back(UString("ERROR: Invalid model pointer provided")); return report; } // Check root index to be valid - QModelIndex root = model->index(0,0); + UModelIndex root = model->index(0,0); if (!root.isValid()) { - report.push_back(QObject::tr("ERROR: Model root index is invalid.")); + report.push_back(UString("ERROR: Model root index is invalid")); return report; } // Generate report recursive - report.push_back(QObject::tr(" Type | Subtype | Size | CRC32 | Name ")); - STATUS result = generateRecursive(report, root); + report.push_back(UString(" Type | Subtype | Size | CRC32 | Name ")); + USTATUS result = generateRecursive(report, root); if (result) { - report.push_back(QObject::tr("ERROR: generateRecursive returned %1.") - .arg(errorCodeToQString(result))); + report.push_back(UString("ERROR: generateRecursive returned ") + errorCodeToUString(result)); } return report; } -STATUS FfsReport::generateRecursive(std::vector & report, QModelIndex index, UINT32 level) +USTATUS FfsReport::generateRecursive(std::vector & report, UModelIndex index, UINT32 level) { if (!index.isValid()) - return ERR_SUCCESS; //Nothing to report for invalid index + return U_SUCCESS; //Nothing to report for invalid index // Calculate item CRC32 - QByteArray data = model->header(index) + model->body(index) + model->tail(index); + UByteArray data = model->header(index) + model->body(index) + model->tail(index); UINT32 crc = crc32(0, (const UINT8*)data.constData(), data.size()); // Information on current item - QString text = model->text(index); - report.push_back(QObject::tr("%1 | %2 | %3 | %4 | %5 %6 %7") - .arg(itemTypeToQString(model->type(index)), 16, QChar(' ')) - .arg(itemSubtypeToQString(model->type(index), model->subtype(index)), 24, QChar(' ')) - .hexarg2(data.size(), 8) - .hexarg2(crc, 8) - .arg(' ', level, QChar('-')) - .arg(model->name(index)) - .arg(text.isEmpty() ? "" : text.prepend("| ")) + UString text = model->text(index); + report.push_back( + UString(" ") + itemTypeToUString(model->type(index)).leftJustified(16) + + UString("| ") + itemSubtypeToUString(model->type(index), model->subtype(index)).leftJustified(22) + + usprintf("| %08X | %08X | ", data.size(), crc) + + UString(level, '-') + UString(" ") + model->name(index) + (text.isEmpty() ? UString("") : UString(" | ") + text) ); // Information on child items @@ -67,5 +63,5 @@ STATUS FfsReport::generateRecursive(std::vector & report, QModelIndex i generateRecursive(report, index.child(i,0), level + 1); } - return ERR_SUCCESS; + return U_SUCCESS; } diff --git a/common/ffsreport.h b/common/ffsreport.h index 9432fda..5d671c6 100644 --- a/common/ffsreport.h +++ b/common/ffsreport.h @@ -16,11 +16,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include -#include -#include -#include -#include - +#include "../common/ubytearray.h" +#include "../common/ustring.h" +#include "../common/umodelindex.h" #include "basetypes.h" #include "treemodel.h" #include "ffs.h" @@ -33,12 +31,12 @@ public: FfsReport(TreeModel * treeModel) : model(treeModel) {} ~FfsReport() {}; - std::vector generate(); + std::vector generate(); private: TreeModel* model; - STATUS generateRecursive(std::vector & report, QModelIndex index, UINT32 level = 0); + USTATUS generateRecursive(std::vector & report, UModelIndex index, UINT32 level = 0); }; diff --git a/common/fitparser.cpp b/common/fitparser.cpp index 8ec00c5..a01c1dc 100644 --- a/common/fitparser.cpp +++ b/common/fitparser.cpp @@ -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 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 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; } \ No newline at end of file diff --git a/common/fitparser.h b/common/fitparser.h index f9cbad7..4ebf663 100644 --- a/common/fitparser.h +++ b/common/fitparser.h @@ -15,10 +15,9 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include -#include -#include -#include - +#include "ustring.h" +#include "ubytearray.h" +#include "umodelindex.h" #include "treemodel.h" #include "utility.h" #include "parsingdata.h" @@ -36,25 +35,25 @@ public: ~FitParser() {} // Returns messages - std::vector > getMessages() const { return messagesVector; }; + std::vector > getMessages() const { return messagesVector; }; // Clears messages void clearMessages() { messagesVector.clear(); } - STATUS parse(const QModelIndex & index, const QModelIndex & lastVtf); - std::vector > getFitTable() const { return fitTable; } + USTATUS parse(const UModelIndex & index, const UModelIndex & lastVtf); + std::vector > getFitTable() const { return fitTable; } private: TreeModel *model; - std::vector > messagesVector; - QModelIndex lastVtf; - std::vector > fitTable; + std::vector > messagesVector; + UModelIndex lastVtf; + std::vector > fitTable; - STATUS findFitRecursive(const QModelIndex & index, QModelIndex & found, UINT32 & fitOffset); - QString fitEntryTypeToQString(UINT8 type); + USTATUS findFitRecursive(const UModelIndex & index, UModelIndex & found, UINT32 & fitOffset); + UString fitEntryTypeToUString(UINT8 type); // Message helper - void msg(const QString & message, const QModelIndex &index = QModelIndex()) { - messagesVector.push_back(std::pair(message, index)); + void msg(const UString & message, const UModelIndex &index = UModelIndex()) { + messagesVector.push_back(std::pair(message, index)); } }; diff --git a/common/me.h b/common/me.h index 7197065..60b8245 100644 --- a/common/me.h +++ b/common/me.h @@ -18,8 +18,8 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // Make sure we use right packing rules #pragma pack(push, 1) -const QByteArray ME_VERSION_SIGNATURE("\x24\x4D\x41\x4E", 4); //$MAN -const QByteArray ME_VERSION_SIGNATURE2("\x24\x4D\x4E\x32", 4); //$MN2 +const UByteArray ME_VERSION_SIGNATURE("\x24\x4D\x41\x4E", 4); //$MAN +const UByteArray ME_VERSION_SIGNATURE2("\x24\x4D\x4E\x32", 4); //$MN2 typedef struct ME_VERSION_ { UINT32 signature; diff --git a/common/nvram.cpp b/common/nvram.cpp index cb3540d..c279d56 100644 --- a/common/nvram.cpp +++ b/common/nvram.cpp @@ -11,100 +11,99 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. */ -#include #include "nvram.h" -QString nvarAttributesToQString(const UINT8 attributes) +UString nvarAttributesToUString(const UINT8 attributes) { if (attributes == 0x00 || attributes == 0xFF) - return QString(); + return UString(); - QString str; - if (attributes & NVRAM_NVAR_ENTRY_RUNTIME) str += QObject::tr(", Runtime"); - if (attributes & NVRAM_NVAR_ENTRY_ASCII_NAME) str += QObject::tr(", AsciiName"); - if (attributes & NVRAM_NVAR_ENTRY_GUID) str += QObject::tr(", Guid"); - if (attributes & NVRAM_NVAR_ENTRY_DATA_ONLY) str += QObject::tr(", DataOnly"); - if (attributes & NVRAM_NVAR_ENTRY_EXT_HEADER) str += QObject::tr(", ExtHeader"); - if (attributes & NVRAM_NVAR_ENTRY_HW_ERROR_RECORD) str += QObject::tr(", HwErrorRecord"); - if (attributes & NVRAM_NVAR_ENTRY_AUTH_WRITE) str += QObject::tr(", AuthWrite"); - if (attributes & NVRAM_NVAR_ENTRY_VALID) str += QObject::tr(", Valid"); + UString str; + if (attributes & NVRAM_NVAR_ENTRY_RUNTIME) str += UString(", Runtime"); + if (attributes & NVRAM_NVAR_ENTRY_ASCII_NAME) str += UString(", AsciiName"); + if (attributes & NVRAM_NVAR_ENTRY_GUID) str += UString(", Guid"); + if (attributes & NVRAM_NVAR_ENTRY_DATA_ONLY) str += UString(", DataOnly"); + if (attributes & NVRAM_NVAR_ENTRY_EXT_HEADER) str += UString(", ExtHeader"); + if (attributes & NVRAM_NVAR_ENTRY_HW_ERROR_RECORD) str += UString(", HwErrorRecord"); + if (attributes & NVRAM_NVAR_ENTRY_AUTH_WRITE) str += UString(", AuthWrite"); + if (attributes & NVRAM_NVAR_ENTRY_VALID) str += UString(", Valid"); return str.mid(2); // Remove first comma and space } -QString nvarExtendedAttributesToQString(const UINT8 attributes) +UString nvarExtendedAttributesToUString(const UINT8 attributes) { - QString str; - if (attributes & NVRAM_NVAR_ENTRY_EXT_CHECKSUM) str += QObject::tr(", Checksum"); - if (attributes & NVRAM_NVAR_ENTRY_EXT_AUTH_WRITE) str += QObject::tr(", AuthWrite"); - if (attributes & NVRAM_NVAR_ENTRY_EXT_TIME_BASED) str += QObject::tr(", TimeBasedAuthWrite"); - if (attributes & NVRAM_NVAR_ENTRY_EXT_UNKNOWN_MASK) str += QObject::tr(", Unknown"); + UString str; + if (attributes & NVRAM_NVAR_ENTRY_EXT_CHECKSUM) str += UString(", Checksum"); + if (attributes & NVRAM_NVAR_ENTRY_EXT_AUTH_WRITE) str += UString(", AuthWrite"); + if (attributes & NVRAM_NVAR_ENTRY_EXT_TIME_BASED) str += UString(", TimeBasedAuthWrite"); + if (attributes & NVRAM_NVAR_ENTRY_EXT_UNKNOWN_MASK) str += UString(", Unknown"); return str.mid(2); // Remove first comma and space } -extern QString vssAttributesToQString(const UINT32 attributes) +extern UString vssAttributesToUString(const UINT32 attributes) { - QString str; - if (attributes & NVRAM_VSS_VARIABLE_NON_VOLATILE) str += QObject::tr(", NonVolatile"); - if (attributes & NVRAM_VSS_VARIABLE_BOOTSERVICE_ACCESS) str += QObject::tr(", BootService"); - if (attributes & NVRAM_VSS_VARIABLE_RUNTIME_ACCESS) str += QObject::tr(", Runtime"); - if (attributes & NVRAM_VSS_VARIABLE_HARDWARE_ERROR_RECORD) str += QObject::tr(", HwErrorRecord"); - if (attributes & NVRAM_VSS_VARIABLE_AUTHENTICATED_WRITE_ACCESS) str += QObject::tr(", AuthWrite"); - if (attributes & NVRAM_VSS_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) str += QObject::tr(", TimeBasedAuthWrite"); - if (attributes & NVRAM_VSS_VARIABLE_APPEND_WRITE) str += QObject::tr(", AppendWrite"); - if (attributes & NVRAM_VSS_VARIABLE_APPLE_DATA_CHECKSUM) str += QObject::tr(", AppleChecksum"); - if (attributes & NVRAM_VSS_VARIABLE_UNKNOWN_MASK) str += QObject::tr(", Unknown"); + UString str; + if (attributes & NVRAM_VSS_VARIABLE_NON_VOLATILE) str += UString(", NonVolatile"); + if (attributes & NVRAM_VSS_VARIABLE_BOOTSERVICE_ACCESS) str += UString(", BootService"); + if (attributes & NVRAM_VSS_VARIABLE_RUNTIME_ACCESS) str += UString(", Runtime"); + if (attributes & NVRAM_VSS_VARIABLE_HARDWARE_ERROR_RECORD) str += UString(", HwErrorRecord"); + if (attributes & NVRAM_VSS_VARIABLE_AUTHENTICATED_WRITE_ACCESS) str += UString(", AuthWrite"); + if (attributes & NVRAM_VSS_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) str += UString(", TimeBasedAuthWrite"); + if (attributes & NVRAM_VSS_VARIABLE_APPEND_WRITE) str += UString(", AppendWrite"); + if (attributes & NVRAM_VSS_VARIABLE_APPLE_DATA_CHECKSUM) str += UString(", AppleChecksum"); + if (attributes & NVRAM_VSS_VARIABLE_UNKNOWN_MASK) str += UString(", Unknown"); return str.mid(2); // Remove first comma and space } -QString evsaAttributesToQString(const UINT32 attributes) +UString evsaAttributesToUString(const UINT32 attributes) { - QString str; - if (attributes & NVRAM_EVSA_DATA_NON_VOLATILE) str += QObject::tr(", NonVolatile"); - if (attributes & NVRAM_EVSA_DATA_BOOTSERVICE_ACCESS) str += QObject::tr(", BootService"); - if (attributes & NVRAM_EVSA_DATA_RUNTIME_ACCESS) str += QObject::tr(", Runtime"); - if (attributes & NVRAM_EVSA_DATA_HARDWARE_ERROR_RECORD) str += QObject::tr(", HwErrorRecord"); - if (attributes & NVRAM_EVSA_DATA_AUTHENTICATED_WRITE_ACCESS) str += QObject::tr(", AuthWrite"); - if (attributes & NVRAM_EVSA_DATA_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) str += QObject::tr(", TimeBasedAuthWrite"); - if (attributes & NVRAM_EVSA_DATA_APPEND_WRITE) str += QObject::tr(", AppendWrite"); - if (attributes & NVRAM_EVSA_DATA_EXTENDED_HEADER) str += QObject::tr(", ExtendedHeader"); - if (attributes & NVRAM_EVSA_DATA_UNKNOWN_MASK) str += QObject::tr(", Unknown"); + UString str; + if (attributes & NVRAM_EVSA_DATA_NON_VOLATILE) str += UString(", NonVolatile"); + if (attributes & NVRAM_EVSA_DATA_BOOTSERVICE_ACCESS) str += UString(", BootService"); + if (attributes & NVRAM_EVSA_DATA_RUNTIME_ACCESS) str += UString(", Runtime"); + if (attributes & NVRAM_EVSA_DATA_HARDWARE_ERROR_RECORD) str += UString(", HwErrorRecord"); + if (attributes & NVRAM_EVSA_DATA_AUTHENTICATED_WRITE_ACCESS) str += UString(", AuthWrite"); + if (attributes & NVRAM_EVSA_DATA_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) str += UString(", TimeBasedAuthWrite"); + if (attributes & NVRAM_EVSA_DATA_APPEND_WRITE) str += UString(", AppendWrite"); + if (attributes & NVRAM_EVSA_DATA_EXTENDED_HEADER) str += UString(", ExtendedHeader"); + if (attributes & NVRAM_EVSA_DATA_UNKNOWN_MASK) str += UString(", Unknown"); return str.mid(2); // Remove first comma and space } -QString efiTimeToQString(const EFI_TIME & time) +UString efiTimeToUString(const EFI_TIME & time) { - return QObject::tr("%1-%2-%3T%4:%5:%6.%7") - .arg(time.Year, 4, 10, QLatin1Char('0')) - .arg(time.Month, 2, 10, QLatin1Char('0')) - .arg(time.Day, 2, 10, QLatin1Char('0')) - .arg(time.Hour, 2, 10, QLatin1Char('0')) - .arg(time.Minute, 2, 10, QLatin1Char('0')) - .arg(time.Second, 2, 10, QLatin1Char('0')) - .arg(time.Nanosecond); + return usprintf("%04u-%02u-%02uT%02u:%02u:%02u.%u", + time.Year, + time.Month, + time.Day, + time.Hour, + time.Minute, + time.Second, + time.Nanosecond); } -QString flashMapGuidToQString(const EFI_GUID & guid) +UString flashMapGuidToUString(const EFI_GUID & guid) { - const QByteArray baGuid((const char*)&guid, sizeof(EFI_GUID)); - if (baGuid == NVRAM_PHOENIX_FLASH_MAP_VOLUME_HEADER) return QObject::tr("Volume header"); - if (baGuid == NVRAM_PHOENIX_FLASH_MAP_MICROCODES_GUID) return QObject::tr("Microcodes"); - if (baGuid == NVRAM_PHOENIX_FLASH_MAP_CMDB_GUID) return QObject::tr("CMDB"); + const UByteArray baGuid((const char*)&guid, sizeof(EFI_GUID)); + if (baGuid == NVRAM_PHOENIX_FLASH_MAP_VOLUME_HEADER) return UString("Volume header"); + if (baGuid == NVRAM_PHOENIX_FLASH_MAP_MICROCODES_GUID) return UString("Microcodes"); + if (baGuid == NVRAM_PHOENIX_FLASH_MAP_CMDB_GUID) return UString("CMDB"); if (baGuid == NVRAM_PHOENIX_FLASH_MAP_PUBKEY1_GUID - || baGuid == NVRAM_PHOENIX_FLASH_MAP_PUBKEY2_GUID) return QObject::tr("SLIC pubkey"); + || baGuid == NVRAM_PHOENIX_FLASH_MAP_PUBKEY2_GUID) return UString("SLIC pubkey"); if (baGuid == NVRAM_PHOENIX_FLASH_MAP_MARKER1_GUID - || baGuid == NVRAM_PHOENIX_FLASH_MAP_MARKER2_GUID) return QObject::tr("SLIC marker"); + || baGuid == NVRAM_PHOENIX_FLASH_MAP_MARKER2_GUID) return UString("SLIC marker"); if (baGuid == NVRAM_PHOENIX_FLASH_MAP_EVSA1_GUID || baGuid == NVRAM_PHOENIX_FLASH_MAP_EVSA2_GUID || baGuid == NVRAM_PHOENIX_FLASH_MAP_EVSA3_GUID || baGuid == NVRAM_PHOENIX_FLASH_MAP_EVSA4_GUID || baGuid == NVRAM_PHOENIX_FLASH_MAP_EVSA5_GUID || baGuid == NVRAM_PHOENIX_FLASH_MAP_EVSA6_GUID - || baGuid == NVRAM_PHOENIX_FLASH_MAP_EVSA7_GUID) return QObject::tr("EVSA store"); - if (baGuid == NVRAM_PHOENIX_FLASH_MAP_SELF_GUID) return QObject::tr("Flash map"); - return QString(); + || baGuid == NVRAM_PHOENIX_FLASH_MAP_EVSA7_GUID) return UString("EVSA store"); + if (baGuid == NVRAM_PHOENIX_FLASH_MAP_SELF_GUID) return UString("Flash map"); + return UString(); } diff --git a/common/nvram.h b/common/nvram.h index 322e73c..7a26f74 100644 --- a/common/nvram.h +++ b/common/nvram.h @@ -15,8 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #ifndef NVRAM_H #define NVRAM_H -#include -#include +#include "ubytearray.h" +#include "ustring.h" #include "basetypes.h" // Make sure we use right packing rules @@ -27,16 +27,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // // CEF5B9A3-476D-497F-9FDC-E98143E0422C -const QByteArray NVRAM_NVAR_STORE_FILE_GUID +const UByteArray NVRAM_NVAR_STORE_FILE_GUID ("\xA3\xB9\xF5\xCE\x6D\x47\x7F\x49\x9F\xDC\xE9\x81\x43\xE0\x42\x2C", 16); // 9221315B-30BB-46B5-813E-1B1BF4712BD3 -const QByteArray NVRAM_NVAR_EXTERNAL_DEFAULTS_FILE_GUID +const UByteArray NVRAM_NVAR_EXTERNAL_DEFAULTS_FILE_GUID ("\x5B\x31\x21\x92\xBB\x30\xB5\x46\x81\x3E\x1B\x1B\xF4\x71\x2B\xD3", 16); -extern QString nvarAttributesToQString(const UINT8 attributes); -extern QString nvarExtendedAttributesToQString(const UINT8 attributes); -extern QString efiTimeToQString(const EFI_TIME & time); +extern UString nvarAttributesToUString(const UINT8 attributes); +extern UString nvarExtendedAttributesToUString(const UINT8 attributes); +extern UString efiTimeToUString(const EFI_TIME & time); typedef struct NVAR_ENTRY_HEADER_ { UINT32 Signature; // NVAR @@ -68,11 +68,11 @@ typedef struct NVAR_ENTRY_HEADER_ { // // FFF12B8D-7696-4C8B-A985-2747075B4F50 -const QByteArray NVRAM_MAIN_STORE_VOLUME_GUID +const UByteArray NVRAM_MAIN_STORE_VOLUME_GUID ("\x8D\x2B\xF1\xFF\x96\x76\x8B\x4C\xA9\x85\x27\x47\x07\x5B\x4F\x50", 16); // 00504624-8A59-4EEB-BD0F-6B36E96128E0 -const QByteArray NVRAM_ADDITIONAL_STORE_VOLUME_GUID +const UByteArray NVRAM_ADDITIONAL_STORE_VOLUME_GUID ("\x24\x46\x50\x00\x59\x8A\xEB\x4E\xBD\x0F\x6B\x36\xE9\x61\x28\xE0", 16); #define NVRAM_VSS_STORE_SIGNATURE 0x53535624 // $VSS @@ -156,7 +156,7 @@ typedef struct VSS_AUTH_VARIABLE_HEADER_ { #define NVRAM_VSS_VARIABLE_APPLE_DATA_CHECKSUM 0x80000000 #define NVRAM_VSS_VARIABLE_UNKNOWN_MASK 0x7FFFFF80 -extern QString vssAttributesToQString(const UINT32 attributes); +extern UString vssAttributesToUString(const UINT32 attributes); // // _FDC region @@ -179,7 +179,7 @@ typedef struct FDC_VOLUME_HEADER_ { #define EFI_FAULT_TOLERANT_WORKING_BLOCK_INVALID 0x2 // 9E58292B-7C68-497D-0ACE6500FD9F1B95 -const QByteArray EDKII_WORKING_BLOCK_SIGNATURE_GUID +const UByteArray EDKII_WORKING_BLOCK_SIGNATURE_GUID ("\x2B\x29\x58\x9E\x68\x7C\x7D\x49\x0A\xCE\x65\x00\xFD\x9F\x1B\x95", 16); #define NVRAM_MAIN_STORE_VOLUME_GUID_DATA1 0xFFF12B8D @@ -292,7 +292,7 @@ typedef struct EVSA_DATA_ENTRY_EXTENDED_ { //UINT8 Data[]; } EVSA_DATA_ENTRY_EXTENDED; -extern QString evsaAttributesToQString(const UINT32 attributes); +extern UString evsaAttributesToUString(const UINT32 attributes); // // Phoenix SCT Flash Map @@ -302,7 +302,7 @@ extern QString evsaAttributesToQString(const UINT32 attributes); #define NVRAM_PHOENIX_FLASH_MAP_SIGNATURE_LENGTH 10 // _FLASH_MAP -const QByteArray NVRAM_PHOENIX_FLASH_MAP_SIGNATURE +const UByteArray NVRAM_PHOENIX_FLASH_MAP_SIGNATURE ("\x5F\x46\x4C\x41\x53\x48\x5F\x4D\x41\x50", 10); typedef struct PHOENIX_FLASH_MAP_HEADER_ { @@ -323,66 +323,66 @@ typedef struct PHOENIX_FLASH_MAP_ENTRY_ { #define NVRAM_PHOENIX_FLASH_MAP_ENTRY_TYPE_VOLUME 0x0000 #define NVRAM_PHOENIX_FLASH_MAP_ENTRY_TYPE_DATA_BLOCK 0x0001 -extern QString flashMapGuidToQString(const EFI_GUID & guid); +extern UString flashMapGuidToUString(const EFI_GUID & guid); // B091E7D2-05A0-4198-94F0-74B7B8C55459 -const QByteArray NVRAM_PHOENIX_FLASH_MAP_VOLUME_HEADER +const UByteArray NVRAM_PHOENIX_FLASH_MAP_VOLUME_HEADER ("\xD2\xE7\x91\xB0\xA0\x05\x98\x41\x94\xF0\x74\xB7\xB8\xC5\x54\x59", 16); // FD3F690E-B4B0-4D68-89DB-19A1A3318F90 -const QByteArray NVRAM_PHOENIX_FLASH_MAP_MICROCODES_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_MICROCODES_GUID ("\x0E\x69\x3F\xFD\xB0\xB4\x68\x4D\x89\xDB\x19\xA1\xA3\x31\x8F\x90", 16); // 46310243-7B03-4132-BE44-2243FACA7CDD -const QByteArray NVRAM_PHOENIX_FLASH_MAP_CMDB_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_CMDB_GUID ("\x43\x02\x31\x46\x03\x7B\x32\x41\xBE\x44\x22\x43\xFA\xCA\x7C\xDD", 16); // 1B2C4952-D778-4B64-BDA1-15A36F5FA545 -const QByteArray NVRAM_PHOENIX_FLASH_MAP_PUBKEY1_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_PUBKEY1_GUID ("\x52\x49\x2C\x1B\x78\xD7\x64\x4B\xBD\xA1\x15\xA3\x6F\x5F\xA5\x45", 16); // 127C1C4E-9135-46E3-B006-F9808B0559A5 -const QByteArray NVRAM_PHOENIX_FLASH_MAP_MARKER1_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_MARKER1_GUID ("\x4E\x1C\x7C\x12\x35\x91\xE3\x46\xB0\x06\xF9\x80\x8B\x05\x59\xA5", 16); // 7CE75114-8272-45AF-B536-761BD38852CE -const QByteArray NVRAM_PHOENIX_FLASH_MAP_PUBKEY2_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_PUBKEY2_GUID ("\x14\x51\xE7\x7C\x72\x82\xAF\x45\xB5\x36\x76\x1B\xD3\x88\x52\xCE", 16); // 071A3DBE-CFF4-4B73-83F0-598C13DCFDD5 -const QByteArray NVRAM_PHOENIX_FLASH_MAP_MARKER2_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_MARKER2_GUID ("\xBE\x3D\x1A\x07\xF4\xCF\x73\x4B\x83\xF0\x59\x8C\x13\xDC\xFD\xD5", 16); // FACFB110-7BFD-4EFB-873E-88B6B23B97EA -const QByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA1_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA1_GUID ("\x10\xB1\xCF\xFA\xFD\x7B\xFB\x4E\x87\x3E\x88\xB6\xB2\x3B\x97\xEA", 16); // E68DC11A-A5F4-4AC3-AA2E-29E298BFF645 -const QByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA2_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA2_GUID ("\x1A\xC1\x8D\xE6\xF4\xA5\xC3\x4A\xAA\x2E\x29\xE2\x98\xBF\xF6\x45", 16); // 4B3828AE-0ACE-45B6-8CDB-DAFC28BBF8C5 -const QByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA3_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA3_GUID ("\xAE\x28\x38\x4B\xCE\x0A\xB6\x45\x8C\xDB\xDA\xFC\x28\xBB\xF8\xC5", 16); // C22E6B8A-8159-49A3-B353-E84B79DF19C0 -const QByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA4_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA4_GUID ("\x8A\x6B\x2E\xC2\x59\x81\xA3\x49\xB3\x53\xE8\x4B\x79\xDF\x19\xC0", 16); // B6B5FAB9-75C4-4AAE-8314-7FFFA7156EAA -const QByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA5_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA5_GUID ("\xB9\xFA\xB5\xB6\xC4\x75\xAE\x4A\x83\x14\x7F\xFF\xA7\x15\x6E\xAA", 16); // 919B9699-8DD0-4376-AA0B-0E54CCA47D8F -const QByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA6_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA6_GUID ("\x99\x96\x9B\x91\xD0\x8D\x76\x43\xAA\x0B\x0E\x54\xCC\xA4\x7D\x8F", 16); // 58A90A52-929F-44F8-AC35-A7E1AB18AC91 -const QByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA7_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_EVSA7_GUID ("\x52\x0A\xA9\x58\x9F\x92\xF8\x44\xAC\x35\xA7\xE1\xAB\x18\xAC\x91", 16); // 8CB71915-531F-4AF5-82BF-A09140817BAA -const QByteArray NVRAM_PHOENIX_FLASH_MAP_SELF_GUID +const UByteArray NVRAM_PHOENIX_FLASH_MAP_SELF_GUID ("\x15\x19\xB7\x8C\x1F\x53\xF5\x4A\x82\xBF\xA0\x91\x40\x81\x7B\xAA", 16); // diff --git a/common/peimage.cpp b/common/peimage.cpp index 47f3d70..534d0c8 100644 --- a/common/peimage.cpp +++ b/common/peimage.cpp @@ -11,27 +11,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. */ -#include - #include "peimage.h" -QString machineTypeToQString(UINT16 machineType) +UString machineTypeToUString(UINT16 machineType) { switch (machineType) { - case EFI_IMAGE_FILE_MACHINE_AMD64: return QObject::tr("x86-64"); - case EFI_IMAGE_FILE_MACHINE_ARM: return QObject::tr("ARM"); - case EFI_IMAGE_FILE_MACHINE_ARMNT: return QObject::tr("ARMv7"); - case EFI_IMAGE_FILE_MACHINE_APPLE_ARM: return QObject::tr("Apple ARM"); - case EFI_IMAGE_FILE_MACHINE_AARCH64: return QObject::tr("AARCH64"); - case EFI_IMAGE_FILE_MACHINE_EBC: return QObject::tr("EBC"); - case EFI_IMAGE_FILE_MACHINE_I386: return QObject::tr("x86"); - case EFI_IMAGE_FILE_MACHINE_IA64: return QObject::tr("IA64"); - case EFI_IMAGE_FILE_MACHINE_POWERPC: return QObject::tr("PowerPC"); - case EFI_IMAGE_FILE_MACHINE_POWERPCFP: return QObject::tr("PowerPC FP"); - case EFI_IMAGE_FILE_MACHINE_THUMB: return QObject::tr("ARM Thumb"); - case EFI_IMAGE_FILE_MACHINE_RISCV32: return QObject::tr("RISC-V 32-bit"); - case EFI_IMAGE_FILE_MACHINE_RISCV64: return QObject::tr("RISC-V 64-bit"); - case EFI_IMAGE_FILE_MACHINE_RISCV128: return QObject::tr("RISC-V 128-bit"); - default: return QObject::tr("Unknown %1h").hexarg2(machineType, 4); + case EFI_IMAGE_FILE_MACHINE_AMD64: return UString("x86-64"); + case EFI_IMAGE_FILE_MACHINE_ARM: return UString("ARM"); + case EFI_IMAGE_FILE_MACHINE_ARMNT: return UString("ARMv7"); + case EFI_IMAGE_FILE_MACHINE_APPLE_ARM: return UString("Apple ARM"); + case EFI_IMAGE_FILE_MACHINE_AARCH64: return UString("AARCH64"); + case EFI_IMAGE_FILE_MACHINE_EBC: return UString("EBC"); + case EFI_IMAGE_FILE_MACHINE_I386: return UString("x86"); + case EFI_IMAGE_FILE_MACHINE_IA64: return UString("IA64"); + case EFI_IMAGE_FILE_MACHINE_POWERPC: return UString("PowerPC"); + case EFI_IMAGE_FILE_MACHINE_POWERPCFP: return UString("PowerPC FP"); + case EFI_IMAGE_FILE_MACHINE_THUMB: return UString("ARM Thumb"); + case EFI_IMAGE_FILE_MACHINE_RISCV32: return UString("RISC-V 32-bit"); + case EFI_IMAGE_FILE_MACHINE_RISCV64: return UString("RISC-V 64-bit"); + case EFI_IMAGE_FILE_MACHINE_RISCV128: return UString("RISC-V 128-bit"); + default: return usprintf("Unknown (%04Xh)", machineType); } } \ No newline at end of file diff --git a/common/peimage.h b/common/peimage.h index 5eaa44a..0d5b1e7 100644 --- a/common/peimage.h +++ b/common/peimage.h @@ -1,737 +1,739 @@ -/* peimage.h - -Copyright (c) 2015, Nikolaj Schlej. All rights reserved. -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. -Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved. -This program and the accompanying materials -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 -http://opensource.org/licenses/bsd-license.php. - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -*/ - -#ifndef PEIMAGE_H -#define PEIMAGE_H - -#include -#include "basetypes.h" - -extern QString machineTypeToQString(UINT16 machineType); - -// Make sure we use right packing rules -#pragma pack(push, 1) - -// -// PE32+ Subsystem type for EFI images -// -#define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION 10 -#define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 -#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 -#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13 - -// -// PE32+ Machine type for EFI images -// -#define EFI_IMAGE_FILE_MACHINE_I386 0x014c // x86 -#define EFI_IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM little endian -#define EFI_IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM or Thumb (interworking) -#define EFI_IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARMv7 (or higher) Thumb mode only -#define EFI_IMAGE_FILE_MACHINE_APPLE_ARM 0x01c6 // Apple ARM -#define EFI_IMAGE_FILE_MACHINE_POWERPC 0x01f0 // Power PC little endian -#define EFI_IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 // Power PC with floating point support -#define EFI_IMAGE_FILE_MACHINE_IA64 0x0200 // Itanium -#define EFI_IMAGE_FILE_MACHINE_EBC 0x0ebc // EFI Byte Code -#define EFI_IMAGE_FILE_MACHINE_AMD64 0x8664 // x86-64 -#define EFI_IMAGE_FILE_MACHINE_AARCH64 0xaa64 // ARMv8 in 64-bit mode -#define EFI_IMAGE_FILE_MACHINE_RISCV32 0x5032 // RISC-V 32-bit -#define EFI_IMAGE_FILE_MACHINE_RISCV64 0x5064 // RISC-V 64-bit -#define EFI_IMAGE_FILE_MACHINE_RISCV128 0x5128 // RISC-V 128-bit -// -// EXE file formats -// -#define EFI_IMAGE_DOS_SIGNATURE 0x5A4D // MZ -#define EFI_IMAGE_PE_SIGNATURE 0x00004550 // PE - -// -// PE images can start with an optional DOS header, so if an image is run -// under DOS it can print an error message. -// -typedef struct { - UINT16 e_magic; // Magic number - UINT16 e_cblp; // Bytes on last page of file - UINT16 e_cp; // Pages in file - UINT16 e_crlc; // Relocations - UINT16 e_cparhdr; // Size of header in paragraphs - UINT16 e_minalloc; // Minimum extra paragraphs needed - UINT16 e_maxalloc; // Maximum extra paragraphs needed - UINT16 e_ss; // Initial (relative) SS value - UINT16 e_sp; // Initial SP value - UINT16 e_csum; // Checksum - UINT16 e_ip; // Initial IP value - UINT16 e_cs; // Initial (relative) CS value - UINT16 e_lfarlc; // File address of relocation table - UINT16 e_ovno; // Overlay number - UINT16 e_res[4]; // Reserved words - UINT16 e_oemid; // OEM identifier (for e_oeminfo) - UINT16 e_oeminfo; // OEM information; e_oemid specific - UINT16 e_res2[10]; // Reserved words - UINT32 e_lfanew; // File address of new header -} EFI_IMAGE_DOS_HEADER; - -// -// COFF File Header (Object and Image) -// -typedef struct { - UINT16 Machine; - UINT16 NumberOfSections; - UINT32 TimeDateStamp; - UINT32 PointerToSymbolTable; - UINT32 NumberOfSymbols; - UINT16 SizeOfOptionalHeader; - UINT16 Characteristics; -} EFI_IMAGE_FILE_HEADER; - -// -// Size of EFI_IMAGE_FILE_HEADER. -// -#define EFI_IMAGE_SIZEOF_FILE_HEADER 20 - -// -// Characteristics -// -#define EFI_IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file -#define EFI_IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved external references) -#define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line numbers stripped from file -#define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file -#define EFI_IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed -#define EFI_IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine -#define EFI_IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file -#define EFI_IMAGE_FILE_SYSTEM 0x1000 // System File -#define EFI_IMAGE_FILE_DLL 0x2000 // File is a DLL -#define EFI_IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed - -// -// Header Data Directories. -// -typedef struct { - UINT32 VirtualAddress; - UINT32 Size; -} EFI_IMAGE_DATA_DIRECTORY; - -// -// Directory Entries -// -#define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0 -#define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1 -#define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2 -#define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 -#define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4 -#define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5 -#define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6 -#define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 -#define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 -#define EFI_IMAGE_DIRECTORY_ENTRY_TLS 9 -#define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 - -#define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16 - -// -// EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC means PE32 and -// EFI_IMAGE_OPTIONAL_HEADER32 must be used. -// The data structures only vary after NT additional fields -// -#define EFI_IMAGE_PE_OPTIONAL_HDR32_MAGIC 0x10b - -// -// Optional Header Standard Fields for PE32 -// -typedef struct { - // - // Standard fields. - // - UINT16 Magic; - UINT8 MajorLinkerVersion; - UINT8 MinorLinkerVersion; - UINT32 SizeOfCode; - UINT32 SizeOfInitializedData; - UINT32 SizeOfUninitializedData; - UINT32 AddressOfEntryPoint; - UINT32 BaseOfCode; - UINT32 BaseOfData; // PE32 contains this additional field, which is absent in PE32+. - // - // Optional Header Windows-Specific Fields. - // - UINT32 ImageBase; - UINT32 SectionAlignment; - UINT32 FileAlignment; - UINT16 MajorOperatingSystemVersion; - UINT16 MinorOperatingSystemVersion; - UINT16 MajorImageVersion; - UINT16 MinorImageVersion; - UINT16 MajorSubsystemVersion; - UINT16 MinorSubsystemVersion; - UINT32 Win32VersionValue; - UINT32 SizeOfImage; - UINT32 SizeOfHeaders; - UINT32 CheckSum; - UINT16 Subsystem; - UINT16 DllCharacteristics; - UINT32 SizeOfStackReserve; - UINT32 SizeOfStackCommit; - UINT32 SizeOfHeapReserve; - UINT32 SizeOfHeapCommit; - UINT32 LoaderFlags; - UINT32 NumberOfRvaAndSizes; - EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]; -} EFI_IMAGE_OPTIONAL_HEADER32; - -// -// EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC means PE32+ and -// EFI_IMAGE_OPTIONAL_HEADER64 must be used. -// The data structures only vary after NT additional fields -// -#define EFI_IMAGE_PE_OPTIONAL_HDR64_MAGIC 0x20b - -// -// Optional Header Standard Fields for PE32+. -// -typedef struct { - // - // Standard fields. - // - UINT16 Magic; - UINT8 MajorLinkerVersion; - UINT8 MinorLinkerVersion; - UINT32 SizeOfCode; - UINT32 SizeOfInitializedData; - UINT32 SizeOfUninitializedData; - UINT32 AddressOfEntryPoint; - UINT32 BaseOfCode; - // - // Optional Header Windows-Specific Fields. - // - UINT64 ImageBase; - UINT32 SectionAlignment; - UINT32 FileAlignment; - UINT16 MajorOperatingSystemVersion; - UINT16 MinorOperatingSystemVersion; - UINT16 MajorImageVersion; - UINT16 MinorImageVersion; - UINT16 MajorSubsystemVersion; - UINT16 MinorSubsystemVersion; - UINT32 Win32VersionValue; - UINT32 SizeOfImage; - UINT32 SizeOfHeaders; - UINT32 CheckSum; - UINT16 Subsystem; - UINT16 DllCharacteristics; - UINT64 SizeOfStackReserve; - UINT64 SizeOfStackCommit; - UINT64 SizeOfHeapReserve; - UINT64 SizeOfHeapCommit; - UINT32 LoaderFlags; - UINT32 NumberOfRvaAndSizes; - EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]; -} EFI_IMAGE_OPTIONAL_HEADER64; - -// Union for pointers to either PE32 or PE32+ headers -typedef union _EFI_IMAGE_OPTIONAL_HEADER_POINTERS_UNION { - const EFI_IMAGE_OPTIONAL_HEADER32* H32; - const EFI_IMAGE_OPTIONAL_HEADER64* H64; -} EFI_IMAGE_OPTIONAL_HEADER_POINTERS_UNION; - -typedef struct -{ - UINT32 Signature; - //EFI_IMAGE_FILE_HEADER FileHeader; - //EFI_IMAGE_OPTIONAL_HEADER OptionalHeader; -} EFI_IMAGE_PE_HEADER; - -// -// Other Windows Subsystem Values -// -#define EFI_IMAGE_SUBSYSTEM_UNKNOWN 0 -#define EFI_IMAGE_SUBSYSTEM_NATIVE 1 -#define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2 -#define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3 -#define EFI_IMAGE_SUBSYSTEM_OS2_CUI 5 -#define EFI_IMAGE_SUBSYSTEM_POSIX_CUI 7 - -// -// Length of ShortName -// -#define EFI_IMAGE_SIZEOF_SHORT_NAME 8 - -// -// Section Table. This table immediately follows the optional header. -// -typedef struct { - UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME]; - union { - UINT32 PhysicalAddress; - UINT32 VirtualSize; - } Misc; - UINT32 VirtualAddress; - UINT32 SizeOfRawData; - UINT32 PointerToRawData; - UINT32 PointerToRelocations; - UINT32 PointerToLinenumbers; - UINT16 NumberOfRelocations; - UINT16 NumberOfLinenumbers; - UINT32 Characteristics; -} EFI_IMAGE_SECTION_HEADER; - -// -// Size of EFI_IMAGE_SECTION_HEADER -// -#define EFI_IMAGE_SIZEOF_SECTION_HEADER 40 - -// -// Section Flags Values -// -#define EFI_IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved -#define EFI_IMAGE_SCN_CNT_CODE 0x00000020 -#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 -#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 - -#define EFI_IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved -#define EFI_IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information -#define EFI_IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image -#define EFI_IMAGE_SCN_LNK_COMDAT 0x00001000 - -#define EFI_IMAGE_SCN_ALIGN_1BYTES 0x00100000 -#define EFI_IMAGE_SCN_ALIGN_2BYTES 0x00200000 -#define EFI_IMAGE_SCN_ALIGN_4BYTES 0x00300000 -#define EFI_IMAGE_SCN_ALIGN_8BYTES 0x00400000 -#define EFI_IMAGE_SCN_ALIGN_16BYTES 0x00500000 -#define EFI_IMAGE_SCN_ALIGN_32BYTES 0x00600000 -#define EFI_IMAGE_SCN_ALIGN_64BYTES 0x00700000 - -#define EFI_IMAGE_SCN_MEM_DISCARDABLE 0x02000000 -#define EFI_IMAGE_SCN_MEM_NOT_CACHED 0x04000000 -#define EFI_IMAGE_SCN_MEM_NOT_PAGED 0x08000000 -#define EFI_IMAGE_SCN_MEM_SHARED 0x10000000 -#define EFI_IMAGE_SCN_MEM_EXECUTE 0x20000000 -#define EFI_IMAGE_SCN_MEM_READ 0x40000000 -#define EFI_IMAGE_SCN_MEM_WRITE 0x80000000 - -// -// Size of a Symbol Table Record -// -#define EFI_IMAGE_SIZEOF_SYMBOL 18 - -// -// Symbols have a section number of the section in which they are -// defined. Otherwise, section numbers have the following meanings: -// -#define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0 ///< Symbol is undefined or is common -#define EFI_IMAGE_SYM_ABSOLUTE (UINT16) -1 ///< Symbol is an absolute value -#define EFI_IMAGE_SYM_DEBUG (UINT16) -2 ///< Symbol is a special debug item - -// -// Symbol Type (fundamental) values. -// -#define EFI_IMAGE_SYM_TYPE_NULL 0 // no type -#define EFI_IMAGE_SYM_TYPE_VOID 1 // no valid type -#define EFI_IMAGE_SYM_TYPE_CHAR 2 // type character -#define EFI_IMAGE_SYM_TYPE_SHORT 3 // type short integer -#define EFI_IMAGE_SYM_TYPE_INT 4 -#define EFI_IMAGE_SYM_TYPE_LONG 5 -#define EFI_IMAGE_SYM_TYPE_FLOAT 6 -#define EFI_IMAGE_SYM_TYPE_DOUBLE 7 -#define EFI_IMAGE_SYM_TYPE_STRUCT 8 -#define EFI_IMAGE_SYM_TYPE_UNION 9 -#define EFI_IMAGE_SYM_TYPE_ENUM 10 // enumeration -#define EFI_IMAGE_SYM_TYPE_MOE 11 // member of enumeration -#define EFI_IMAGE_SYM_TYPE_BYTE 12 -#define EFI_IMAGE_SYM_TYPE_WORD 13 -#define EFI_IMAGE_SYM_TYPE_UINT 14 -#define EFI_IMAGE_SYM_TYPE_DWORD 15 - -// -// Symbol Type (derived) values -// -#define EFI_IMAGE_SYM_DTYPE_NULL 0 // no derived type -#define EFI_IMAGE_SYM_DTYPE_POINTER 1 -#define EFI_IMAGE_SYM_DTYPE_FUNCTION 2 -#define EFI_IMAGE_SYM_DTYPE_ARRAY 3 - -// -// Storage classes -// -#define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION ((UINT8) -1) -#define EFI_IMAGE_SYM_CLASS_NULL 0 -#define EFI_IMAGE_SYM_CLASS_AUTOMATIC 1 -#define EFI_IMAGE_SYM_CLASS_EXTERNAL 2 -#define EFI_IMAGE_SYM_CLASS_STATIC 3 -#define EFI_IMAGE_SYM_CLASS_REGISTER 4 -#define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF 5 -#define EFI_IMAGE_SYM_CLASS_LABEL 6 -#define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL 7 -#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8 -#define EFI_IMAGE_SYM_CLASS_ARGUMENT 9 -#define EFI_IMAGE_SYM_CLASS_STRUCT_TAG 10 -#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION 11 -#define EFI_IMAGE_SYM_CLASS_UNION_TAG 12 -#define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION 13 -#define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC 14 -#define EFI_IMAGE_SYM_CLASS_ENUM_TAG 15 -#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16 -#define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM 17 -#define EFI_IMAGE_SYM_CLASS_BIT_FIELD 18 -#define EFI_IMAGE_SYM_CLASS_BLOCK 100 -#define EFI_IMAGE_SYM_CLASS_FUNCTION 101 -#define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT 102 -#define EFI_IMAGE_SYM_CLASS_FILE 103 -#define EFI_IMAGE_SYM_CLASS_SECTION 104 -#define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL 105 - -// -// Type packing constants -// -#define EFI_IMAGE_N_BTMASK 017 -#define EFI_IMAGE_N_TMASK 060 -#define EFI_IMAGE_N_TMASK1 0300 -#define EFI_IMAGE_N_TMASK2 0360 -#define EFI_IMAGE_N_BTSHFT 4 -#define EFI_IMAGE_N_TSHIFT 2 - -// -// Communal selection types -// -#define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES 1 -#define EFI_IMAGE_COMDAT_SELECT_ANY 2 -#define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3 -#define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4 -#define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5 - -// -// The following values only be referred in PeCoff, not defined in PECOFF -// -#define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1 -#define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2 -#define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3 - -// -// Relocation format -// -typedef struct { - UINT32 VirtualAddress; - UINT32 SymbolTableIndex; - UINT16 Type; -} EFI_IMAGE_RELOCATION; - -// -// Size of EFI_IMAGE_RELOCATION -// -#define EFI_IMAGE_SIZEOF_RELOCATION 10 - -// -// I386 relocation types -// -#define EFI_IMAGE_REL_I386_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary -#define EFI_IMAGE_REL_I386_DIR16 0x0001 // Direct 16-bit reference to the symbols virtual address -#define EFI_IMAGE_REL_I386_REL16 0x0002 // PC-relative 16-bit reference to the symbols virtual address -#define EFI_IMAGE_REL_I386_DIR32 0x0006 // Direct 32-bit reference to the symbols virtual address -#define EFI_IMAGE_REL_I386_DIR32NB 0x0007 // Direct 32-bit reference to the symbols virtual address, base not included -#define EFI_IMAGE_REL_I386_SEG12 0x0009 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address -#define EFI_IMAGE_REL_I386_SECTION 0x000A -#define EFI_IMAGE_REL_I386_SECREL 0x000B -#define EFI_IMAGE_REL_I386_REL32 0x0014 // PC-relative 32-bit reference to the symbols virtual address - - -// -// x64 relocation types -// -#define EFI_IMAGE_REL_AMD64_ABSOLUTE 0x0000 -#define EFI_IMAGE_REL_AMD64_ADDR64 0x0001 -#define EFI_IMAGE_REL_AMD64_ADDR32 0x0002 -#define EFI_IMAGE_REL_AMD64_ADDR32NB 0x0003 -#define EFI_IMAGE_REL_AMD64_REL32 0x0004 -#define EFI_IMAGE_REL_AMD64_REL32_1 0x0005 -#define EFI_IMAGE_REL_AMD64_REL32_2 0x0006 -#define EFI_IMAGE_REL_AMD64_REL32_3 0x0007 -#define EFI_IMAGE_REL_AMD64_REL32_4 0x0008 -#define EFI_IMAGE_REL_AMD64_REL32_5 0x0009 -#define EFI_IMAGE_REL_AMD64_SECTION 0x000A -#define EFI_IMAGE_REL_AMD64_SECREL 0x000B -#define EFI_IMAGE_REL_AMD64_SECREL7 0x000C -#define EFI_IMAGE_REL_AMD64_TOKEN 0x000D -#define EFI_IMAGE_REL_AMD64_SREL32 0x000E -#define EFI_IMAGE_REL_AMD64_PAIR 0x000F -#define EFI_IMAGE_REL_AMD64_SSPAN32 0x0010 - -// -// RISC-V relocation types -// -#define EFI_IMAGE_REL_BASED_RISCV_HI20 0x0005 -#define EFI_IMAGE_REL_BASED_RISCV_LO12I 0x0007 -#define EFI_IMAGE_REL_BASED_RISCV_LO12S 0x0008 - -// -// Based relocation format -// -typedef struct { - UINT32 VirtualAddress; - UINT32 SizeOfBlock; -} EFI_IMAGE_BASE_RELOCATION; - -// -// Size of EFI_IMAGE_BASE_RELOCATION -// -#define EFI_IMAGE_SIZEOF_BASE_RELOCATION 8 - -// -// Based relocation types -// -#define EFI_IMAGE_REL_BASED_ABSOLUTE 0 -#define EFI_IMAGE_REL_BASED_HIGH 1 -#define EFI_IMAGE_REL_BASED_LOW 2 -#define EFI_IMAGE_REL_BASED_HIGHLOW 3 -#define EFI_IMAGE_REL_BASED_HIGHADJ 4 -#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5 -#define EFI_IMAGE_REL_BASED_ARM_MOV32A 5 -#define EFI_IMAGE_REL_BASED_ARM_MOV32T 7 -#define EFI_IMAGE_REL_BASED_IA64_IMM64 9 -#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16 9 -#define EFI_IMAGE_REL_BASED_DIR64 10 - -// -// Line number format -// -typedef struct { - union { - UINT32 SymbolTableIndex; // Symbol table index of function name if line number is 0 - UINT32 VirtualAddress; // Virtual address of line number - } Type; - UINT16 Linenumber; // Line number -} EFI_IMAGE_LINENUMBER; - -// -// Size of EFI_IMAGE_LINENUMBER -// -#define EFI_IMAGE_SIZEOF_LINENUMBER 6 - -// -// Archive format -// -#define EFI_IMAGE_ARCHIVE_START_SIZE 8 -#define EFI_IMAGE_ARCHIVE_START "!\n" -#define EFI_IMAGE_ARCHIVE_END "`\n" -#define EFI_IMAGE_ARCHIVE_PAD "\n" -#define EFI_IMAGE_ARCHIVE_LINKER_MEMBER "/ " -#define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER "// " - -// -// Archive Member Headers -// -typedef struct { - UINT8 Name[16]; // File member name - `/' terminated - UINT8 Date[12]; // File member date - decimal - UINT8 UserID[6]; // File member user id - decimal - UINT8 GroupID[6]; // File member group id - decimal - UINT8 Mode[8]; // File member mode - octal - UINT8 Size[10]; // File member size - decimal - UINT8 EndHeader[2]; // String to end header. (0x60 0x0A) -} EFI_IMAGE_ARCHIVE_MEMBER_HEADER; - -// -// Size of EFI_IMAGE_ARCHIVE_MEMBER_HEADER -// -#define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60 - -// -// DLL Support -// - -// -// Export Directory Table -// -typedef struct { - UINT32 Characteristics; - UINT32 TimeDateStamp; - UINT16 MajorVersion; - UINT16 MinorVersion; - UINT32 Name; - UINT32 Base; - UINT32 NumberOfFunctions; - UINT32 NumberOfNames; - UINT32 AddressOfFunctions; - UINT32 AddressOfNames; - UINT32 AddressOfNameOrdinals; -} EFI_IMAGE_EXPORT_DIRECTORY; - -// -// Hint/Name Table -// -typedef struct { - UINT16 Hint; - UINT8 Name[1]; -} EFI_IMAGE_IMPORT_BY_NAME; - -// -// Import Address Table RVA (Thunk Table) -// -typedef struct { - union { - UINT32 Function; - UINT32 Ordinal; - EFI_IMAGE_IMPORT_BY_NAME *AddressOfData; - } u1; -} EFI_IMAGE_THUNK_DATA; - -#define EFI_IMAGE_ORDINAL_FLAG 0x80000000 // Flag for PE32. -#define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0) -#define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff) - -// -// Import Directory Table -// -typedef struct { - UINT32 Characteristics; - UINT32 TimeDateStamp; - UINT32 ForwarderChain; - UINT32 Name; - EFI_IMAGE_THUNK_DATA *FirstThunk; -} EFI_IMAGE_IMPORT_DESCRIPTOR; - -// -// Debug Directory Format -// -typedef struct { - UINT32 Characteristics; - UINT32 TimeDateStamp; - UINT16 MajorVersion; - UINT16 MinorVersion; - UINT32 Type; - UINT32 SizeOfData; - UINT32 RVA; // The address of the debug data when loaded, relative to the image base - UINT32 FileOffset; // The file pointer to the debug data -} EFI_IMAGE_DEBUG_DIRECTORY_ENTRY; - -#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 // The Visual C++ debug information. - -// -// Debug Data Structure defined in Microsoft C++ -// -#define CODEVIEW_SIGNATURE_NB10 0x3031424E // NB10 -typedef struct { - UINT32 Signature; - UINT32 Unknown; - UINT32 Unknown2; - UINT32 Unknown3; - // - // Filename of .PDB goes here - // -} EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY; - -// -// Debug Data Structure defined in Microsoft C++ -// -#define CODEVIEW_SIGNATURE_RSDS 0x53445352 // RSDS -typedef struct { - UINT32 Signature; - UINT32 Unknown; - UINT32 Unknown2; - UINT32 Unknown3; - UINT32 Unknown4; - UINT32 Unknown5; - // - // Filename of .PDB goes here - // -} EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY; - -// -// Debug Data Structure defined by Apple Mach-O to COFF utility. -// -#define CODEVIEW_SIGNATURE_MTOC 0x434F544D // MTOC -typedef struct { - UINT32 Signature; - UINT8 MachOUuid[16]; - // - // Filename of .DLL (Mach-O with debug info) goes here - // -} EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY; - -// -// Resource format -// -typedef struct { - UINT32 Characteristics; - UINT32 TimeDateStamp; - UINT16 MajorVersion; - UINT16 MinorVersion; - UINT16 NumberOfNamedEntries; - UINT16 NumberOfIdEntries; - // - // Array of EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY entries goes here - // -} EFI_IMAGE_RESOURCE_DIRECTORY; - -// -// Resource directory entry format -// -typedef struct { - union { - struct { - UINT32 NameOffset : 31; - UINT32 NameIsString : 1; - } s; - UINT32 Id; - } u1; - union { - UINT32 OffsetToData; - struct { - UINT32 OffsetToDirectory : 31; - UINT32 DataIsDirectory : 1; - } s; - } u2; -} EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY; - -// -// Resource directory entry for string -// -typedef struct { - UINT16 Length; - CHAR16 String[1]; -} EFI_IMAGE_RESOURCE_DIRECTORY_STRING; - -// -// Resource directory entry for data array -// -typedef struct { - UINT32 OffsetToData; - UINT32 Size; - UINT32 CodePage; - UINT32 Reserved; -} EFI_IMAGE_RESOURCE_DATA_ENTRY; - -// -// Header format for TE images, defined in the PI Specification 1.0. -// -typedef struct { - UINT16 Signature; // The signature for TE format = "VZ" - UINT16 Machine; // From original file header - UINT8 NumberOfSections; // From original file header - UINT8 Subsystem; // From original optional header - UINT16 StrippedSize; // Number of bytes we removed from header - UINT32 AddressOfEntryPoint; // Offset to entry point -- from original optional header - UINT32 BaseOfCode; // From original image -- required for ITP debug - UINT64 ImageBase; // From original file header - EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; // Only base relocation and debug directory -} EFI_IMAGE_TE_HEADER; - -#define EFI_IMAGE_TE_SIGNATURE 0x5A56 // VZ - -// -// Data directory indexes in our TE image header -// -#define EFI_IMAGE_TE_DIRECTORY_ENTRY_BASERELOC 0 -#define EFI_IMAGE_TE_DIRECTORY_ENTRY_DEBUG 1 - -// Restore previous packing rules -#pragma pack(pop) -#endif // PEIMAGE_H +/* peimage.h + +Copyright (c) 2015, Nikolaj Schlej. All rights reserved. +Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. +Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved. +This program and the accompanying materials +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 +http://opensource.org/licenses/bsd-license.php. + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +*/ + +#ifndef PEIMAGE_H +#define PEIMAGE_H + +#include "ustring.h" +#include "basetypes.h" + +extern UString machineTypeToUString(UINT16 machineType); + +// Make sure we use right packing rules +#pragma pack(push, 1) + +// +// PE32+ Subsystem type for EFI images +// +#define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION 10 +#define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11 +#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12 +#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13 + +// +// PE32+ Machine type for EFI images +// +#define EFI_IMAGE_FILE_MACHINE_I386 0x014c // x86 +#define EFI_IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM little endian +#define EFI_IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM or Thumb (interworking) +#define EFI_IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARMv7 (or higher) Thumb mode only +#define EFI_IMAGE_FILE_MACHINE_APPLE_ARM 0x01c6 // Apple ARM +#define EFI_IMAGE_FILE_MACHINE_POWERPC 0x01f0 // Power PC little endian +#define EFI_IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 // Power PC with floating point support +#define EFI_IMAGE_FILE_MACHINE_IA64 0x0200 // Itanium +#define EFI_IMAGE_FILE_MACHINE_EBC 0x0ebc // EFI Byte Code +#define EFI_IMAGE_FILE_MACHINE_AMD64 0x8664 // x86-64 +#define EFI_IMAGE_FILE_MACHINE_AARCH64 0xaa64 // ARMv8 in 64-bit mode +#define EFI_IMAGE_FILE_MACHINE_RISCV32 0x5032 // RISC-V 32-bit +#define EFI_IMAGE_FILE_MACHINE_RISCV64 0x5064 // RISC-V 64-bit +#define EFI_IMAGE_FILE_MACHINE_RISCV128 0x5128 // RISC-V 128-bit + +// +// EXE file formats +// +#define EFI_IMAGE_DOS_SIGNATURE 0x5A4D // MZ +#define EFI_IMAGE_PE_SIGNATURE 0x00004550 // PE + +// +// PE images can start with an optional DOS header, so if an image is run +// under DOS it can print an error message. +// +typedef struct { + UINT16 e_magic; // Magic number + UINT16 e_cblp; // Bytes on last page of file + UINT16 e_cp; // Pages in file + UINT16 e_crlc; // Relocations + UINT16 e_cparhdr; // Size of header in paragraphs + UINT16 e_minalloc; // Minimum extra paragraphs needed + UINT16 e_maxalloc; // Maximum extra paragraphs needed + UINT16 e_ss; // Initial (relative) SS value + UINT16 e_sp; // Initial SP value + UINT16 e_csum; // Checksum + UINT16 e_ip; // Initial IP value + UINT16 e_cs; // Initial (relative) CS value + UINT16 e_lfarlc; // File address of relocation table + UINT16 e_ovno; // Overlay number + UINT16 e_res[4]; // Reserved words + UINT16 e_oemid; // OEM identifier (for e_oeminfo) + UINT16 e_oeminfo; // OEM information; e_oemid specific + UINT16 e_res2[10]; // Reserved words + UINT32 e_lfanew; // File address of new header +} EFI_IMAGE_DOS_HEADER; + +// +// COFF File Header (Object and Image) +// +typedef struct { + UINT16 Machine; + UINT16 NumberOfSections; + UINT32 TimeDateStamp; + UINT32 PointerToSymbolTable; + UINT32 NumberOfSymbols; + UINT16 SizeOfOptionalHeader; + UINT16 Characteristics; +} EFI_IMAGE_FILE_HEADER; + +// +// Size of EFI_IMAGE_FILE_HEADER. +// +#define EFI_IMAGE_SIZEOF_FILE_HEADER 20 + +// +// Characteristics +// +#define EFI_IMAGE_FILE_RELOCS_STRIPPED 0x0001 // Relocation info stripped from file +#define EFI_IMAGE_FILE_EXECUTABLE_IMAGE 0x0002 // File is executable (i.e. no unresolved external references) +#define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004 // Line numbers stripped from file +#define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008 // Local symbols stripped from file +#define EFI_IMAGE_FILE_BYTES_REVERSED_LO 0x0080 // Bytes of machine word are reversed +#define EFI_IMAGE_FILE_32BIT_MACHINE 0x0100 // 32 bit word machine +#define EFI_IMAGE_FILE_DEBUG_STRIPPED 0x0200 // Debugging info stripped from file in .DBG file +#define EFI_IMAGE_FILE_SYSTEM 0x1000 // System File +#define EFI_IMAGE_FILE_DLL 0x2000 // File is a DLL +#define EFI_IMAGE_FILE_BYTES_REVERSED_HI 0x8000 // Bytes of machine word are reversed + +// +// Header Data Directories. +// +typedef struct { + UINT32 VirtualAddress; + UINT32 Size; +} EFI_IMAGE_DATA_DIRECTORY; + +// +// Directory Entries +// +#define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0 +#define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1 +#define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2 +#define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 +#define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4 +#define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5 +#define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6 +#define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 +#define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 +#define EFI_IMAGE_DIRECTORY_ENTRY_TLS 9 +#define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 + +#define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16 + +// +// EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC means PE32 and +// EFI_IMAGE_OPTIONAL_HEADER32 must be used. +// The data structures only vary after NT additional fields +// +#define EFI_IMAGE_PE_OPTIONAL_HDR32_MAGIC 0x10b + +// +// Optional Header Standard Fields for PE32 +// +typedef struct { + // + // Standard fields. + // + UINT16 Magic; + UINT8 MajorLinkerVersion; + UINT8 MinorLinkerVersion; + UINT32 SizeOfCode; + UINT32 SizeOfInitializedData; + UINT32 SizeOfUninitializedData; + UINT32 AddressOfEntryPoint; + UINT32 BaseOfCode; + UINT32 BaseOfData; // PE32 contains this additional field, which is absent in PE32+. + // + // Optional Header Windows-Specific Fields. + // + UINT32 ImageBase; + UINT32 SectionAlignment; + UINT32 FileAlignment; + UINT16 MajorOperatingSystemVersion; + UINT16 MinorOperatingSystemVersion; + UINT16 MajorImageVersion; + UINT16 MinorImageVersion; + UINT16 MajorSubsystemVersion; + UINT16 MinorSubsystemVersion; + UINT32 Win32VersionValue; + UINT32 SizeOfImage; + UINT32 SizeOfHeaders; + UINT32 CheckSum; + UINT16 Subsystem; + UINT16 DllCharacteristics; + UINT32 SizeOfStackReserve; + UINT32 SizeOfStackCommit; + UINT32 SizeOfHeapReserve; + UINT32 SizeOfHeapCommit; + UINT32 LoaderFlags; + UINT32 NumberOfRvaAndSizes; + EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]; +} EFI_IMAGE_OPTIONAL_HEADER32; + +// +// EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC means PE32+ and +// EFI_IMAGE_OPTIONAL_HEADER64 must be used. +// The data structures only vary after NT additional fields +// +#define EFI_IMAGE_PE_OPTIONAL_HDR64_MAGIC 0x20b + +// +// Optional Header Standard Fields for PE32+. +// +typedef struct { + // + // Standard fields. + // + UINT16 Magic; + UINT8 MajorLinkerVersion; + UINT8 MinorLinkerVersion; + UINT32 SizeOfCode; + UINT32 SizeOfInitializedData; + UINT32 SizeOfUninitializedData; + UINT32 AddressOfEntryPoint; + UINT32 BaseOfCode; + // + // Optional Header Windows-Specific Fields. + // + UINT64 ImageBase; + UINT32 SectionAlignment; + UINT32 FileAlignment; + UINT16 MajorOperatingSystemVersion; + UINT16 MinorOperatingSystemVersion; + UINT16 MajorImageVersion; + UINT16 MinorImageVersion; + UINT16 MajorSubsystemVersion; + UINT16 MinorSubsystemVersion; + UINT32 Win32VersionValue; + UINT32 SizeOfImage; + UINT32 SizeOfHeaders; + UINT32 CheckSum; + UINT16 Subsystem; + UINT16 DllCharacteristics; + UINT64 SizeOfStackReserve; + UINT64 SizeOfStackCommit; + UINT64 SizeOfHeapReserve; + UINT64 SizeOfHeapCommit; + UINT32 LoaderFlags; + UINT32 NumberOfRvaAndSizes; + EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES]; +} EFI_IMAGE_OPTIONAL_HEADER64; + +// Union for pointers to either PE32 or PE32+ headers +typedef union _EFI_IMAGE_OPTIONAL_HEADER_POINTERS_UNION { + const EFI_IMAGE_OPTIONAL_HEADER32* H32; + const EFI_IMAGE_OPTIONAL_HEADER64* H64; +} EFI_IMAGE_OPTIONAL_HEADER_POINTERS_UNION; + +typedef struct +{ + UINT32 Signature; + //EFI_IMAGE_FILE_HEADER FileHeader; + //EFI_IMAGE_OPTIONAL_HEADER OptionalHeader; +} EFI_IMAGE_PE_HEADER; + +// +// Other Windows Subsystem Values +// +#define EFI_IMAGE_SUBSYSTEM_UNKNOWN 0 +#define EFI_IMAGE_SUBSYSTEM_NATIVE 1 +#define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2 +#define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3 +#define EFI_IMAGE_SUBSYSTEM_OS2_CUI 5 +#define EFI_IMAGE_SUBSYSTEM_POSIX_CUI 7 + +// +// Length of ShortName +// +#define EFI_IMAGE_SIZEOF_SHORT_NAME 8 + +// +// Section Table. This table immediately follows the optional header. +// +typedef struct { + UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME]; + union { + UINT32 PhysicalAddress; + UINT32 VirtualSize; + } Misc; + UINT32 VirtualAddress; + UINT32 SizeOfRawData; + UINT32 PointerToRawData; + UINT32 PointerToRelocations; + UINT32 PointerToLinenumbers; + UINT16 NumberOfRelocations; + UINT16 NumberOfLinenumbers; + UINT32 Characteristics; +} EFI_IMAGE_SECTION_HEADER; + +// +// Size of EFI_IMAGE_SECTION_HEADER +// +#define EFI_IMAGE_SIZEOF_SECTION_HEADER 40 + +// +// Section Flags Values +// +#define EFI_IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved +#define EFI_IMAGE_SCN_CNT_CODE 0x00000020 +#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 +#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 + +#define EFI_IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved +#define EFI_IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information +#define EFI_IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image +#define EFI_IMAGE_SCN_LNK_COMDAT 0x00001000 + +#define EFI_IMAGE_SCN_ALIGN_1BYTES 0x00100000 +#define EFI_IMAGE_SCN_ALIGN_2BYTES 0x00200000 +#define EFI_IMAGE_SCN_ALIGN_4BYTES 0x00300000 +#define EFI_IMAGE_SCN_ALIGN_8BYTES 0x00400000 +#define EFI_IMAGE_SCN_ALIGN_16BYTES 0x00500000 +#define EFI_IMAGE_SCN_ALIGN_32BYTES 0x00600000 +#define EFI_IMAGE_SCN_ALIGN_64BYTES 0x00700000 + +#define EFI_IMAGE_SCN_MEM_DISCARDABLE 0x02000000 +#define EFI_IMAGE_SCN_MEM_NOT_CACHED 0x04000000 +#define EFI_IMAGE_SCN_MEM_NOT_PAGED 0x08000000 +#define EFI_IMAGE_SCN_MEM_SHARED 0x10000000 +#define EFI_IMAGE_SCN_MEM_EXECUTE 0x20000000 +#define EFI_IMAGE_SCN_MEM_READ 0x40000000 +#define EFI_IMAGE_SCN_MEM_WRITE 0x80000000 + +// +// Size of a Symbol Table Record +// +#define EFI_IMAGE_SIZEOF_SYMBOL 18 + +// +// Symbols have a section number of the section in which they are +// defined. Otherwise, section numbers have the following meanings: +// +#define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0 ///< Symbol is undefined or is common +#define EFI_IMAGE_SYM_ABSOLUTE (UINT16) -1 ///< Symbol is an absolute value +#define EFI_IMAGE_SYM_DEBUG (UINT16) -2 ///< Symbol is a special debug item + +// +// Symbol Type (fundamental) values. +// +#define EFI_IMAGE_SYM_TYPE_NULL 0 // no type +#define EFI_IMAGE_SYM_TYPE_VOID 1 // no valid type +#define EFI_IMAGE_SYM_TYPE_CHAR 2 // type character +#define EFI_IMAGE_SYM_TYPE_SHORT 3 // type short integer +#define EFI_IMAGE_SYM_TYPE_INT 4 +#define EFI_IMAGE_SYM_TYPE_LONG 5 +#define EFI_IMAGE_SYM_TYPE_FLOAT 6 +#define EFI_IMAGE_SYM_TYPE_DOUBLE 7 +#define EFI_IMAGE_SYM_TYPE_STRUCT 8 +#define EFI_IMAGE_SYM_TYPE_UNION 9 +#define EFI_IMAGE_SYM_TYPE_ENUM 10 // enumeration +#define EFI_IMAGE_SYM_TYPE_MOE 11 // member of enumeration +#define EFI_IMAGE_SYM_TYPE_BYTE 12 +#define EFI_IMAGE_SYM_TYPE_WORD 13 +#define EFI_IMAGE_SYM_TYPE_UINT 14 +#define EFI_IMAGE_SYM_TYPE_DWORD 15 + +// +// Symbol Type (derived) values +// +#define EFI_IMAGE_SYM_DTYPE_NULL 0 // no derived type +#define EFI_IMAGE_SYM_DTYPE_POINTER 1 +#define EFI_IMAGE_SYM_DTYPE_FUNCTION 2 +#define EFI_IMAGE_SYM_DTYPE_ARRAY 3 + +// +// Storage classes +// +#define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION ((UINT8) -1) +#define EFI_IMAGE_SYM_CLASS_NULL 0 +#define EFI_IMAGE_SYM_CLASS_AUTOMATIC 1 +#define EFI_IMAGE_SYM_CLASS_EXTERNAL 2 +#define EFI_IMAGE_SYM_CLASS_STATIC 3 +#define EFI_IMAGE_SYM_CLASS_REGISTER 4 +#define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF 5 +#define EFI_IMAGE_SYM_CLASS_LABEL 6 +#define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL 7 +#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8 +#define EFI_IMAGE_SYM_CLASS_ARGUMENT 9 +#define EFI_IMAGE_SYM_CLASS_STRUCT_TAG 10 +#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION 11 +#define EFI_IMAGE_SYM_CLASS_UNION_TAG 12 +#define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION 13 +#define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC 14 +#define EFI_IMAGE_SYM_CLASS_ENUM_TAG 15 +#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16 +#define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM 17 +#define EFI_IMAGE_SYM_CLASS_BIT_FIELD 18 +#define EFI_IMAGE_SYM_CLASS_BLOCK 100 +#define EFI_IMAGE_SYM_CLASS_FUNCTION 101 +#define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT 102 +#define EFI_IMAGE_SYM_CLASS_FILE 103 +#define EFI_IMAGE_SYM_CLASS_SECTION 104 +#define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL 105 + +// +// Type packing constants +// +#define EFI_IMAGE_N_BTMASK 017 +#define EFI_IMAGE_N_TMASK 060 +#define EFI_IMAGE_N_TMASK1 0300 +#define EFI_IMAGE_N_TMASK2 0360 +#define EFI_IMAGE_N_BTSHFT 4 +#define EFI_IMAGE_N_TSHIFT 2 + +// +// Communal selection types +// +#define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES 1 +#define EFI_IMAGE_COMDAT_SELECT_ANY 2 +#define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3 +#define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4 +#define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5 + +// +// The following values only be referred in PeCoff, not defined in PECOFF +// +#define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1 +#define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2 +#define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3 + +// +// Relocation format +// +typedef struct { + UINT32 VirtualAddress; + UINT32 SymbolTableIndex; + UINT16 Type; +} EFI_IMAGE_RELOCATION; + +// +// Size of EFI_IMAGE_RELOCATION +// +#define EFI_IMAGE_SIZEOF_RELOCATION 10 + +// +// I386 relocation types +// +#define EFI_IMAGE_REL_I386_ABSOLUTE 0x0000 // Reference is absolute, no relocation is necessary +#define EFI_IMAGE_REL_I386_DIR16 0x0001 // Direct 16-bit reference to the symbols virtual address +#define EFI_IMAGE_REL_I386_REL16 0x0002 // PC-relative 16-bit reference to the symbols virtual address +#define EFI_IMAGE_REL_I386_DIR32 0x0006 // Direct 32-bit reference to the symbols virtual address +#define EFI_IMAGE_REL_I386_DIR32NB 0x0007 // Direct 32-bit reference to the symbols virtual address, base not included +#define EFI_IMAGE_REL_I386_SEG12 0x0009 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address +#define EFI_IMAGE_REL_I386_SECTION 0x000A +#define EFI_IMAGE_REL_I386_SECREL 0x000B +#define EFI_IMAGE_REL_I386_REL32 0x0014 // PC-relative 32-bit reference to the symbols virtual address + + +// +// x64 relocation types +// +#define EFI_IMAGE_REL_AMD64_ABSOLUTE 0x0000 +#define EFI_IMAGE_REL_AMD64_ADDR64 0x0001 +#define EFI_IMAGE_REL_AMD64_ADDR32 0x0002 +#define EFI_IMAGE_REL_AMD64_ADDR32NB 0x0003 +#define EFI_IMAGE_REL_AMD64_REL32 0x0004 +#define EFI_IMAGE_REL_AMD64_REL32_1 0x0005 +#define EFI_IMAGE_REL_AMD64_REL32_2 0x0006 +#define EFI_IMAGE_REL_AMD64_REL32_3 0x0007 +#define EFI_IMAGE_REL_AMD64_REL32_4 0x0008 +#define EFI_IMAGE_REL_AMD64_REL32_5 0x0009 +#define EFI_IMAGE_REL_AMD64_SECTION 0x000A +#define EFI_IMAGE_REL_AMD64_SECREL 0x000B +#define EFI_IMAGE_REL_AMD64_SECREL7 0x000C +#define EFI_IMAGE_REL_AMD64_TOKEN 0x000D +#define EFI_IMAGE_REL_AMD64_SREL32 0x000E +#define EFI_IMAGE_REL_AMD64_PAIR 0x000F +#define EFI_IMAGE_REL_AMD64_SSPAN32 0x0010 + +// +// RISC-V relocation types +// +#define EFI_IMAGE_REL_BASED_RISCV_HI20 0x0005 +#define EFI_IMAGE_REL_BASED_RISCV_LO12I 0x0007 +#define EFI_IMAGE_REL_BASED_RISCV_LO12S 0x0008 + + +// +// Based relocation format +// +typedef struct { + UINT32 VirtualAddress; + UINT32 SizeOfBlock; +} EFI_IMAGE_BASE_RELOCATION; + +// +// Size of EFI_IMAGE_BASE_RELOCATION +// +#define EFI_IMAGE_SIZEOF_BASE_RELOCATION 8 + +// +// Based relocation types +// +#define EFI_IMAGE_REL_BASED_ABSOLUTE 0 +#define EFI_IMAGE_REL_BASED_HIGH 1 +#define EFI_IMAGE_REL_BASED_LOW 2 +#define EFI_IMAGE_REL_BASED_HIGHLOW 3 +#define EFI_IMAGE_REL_BASED_HIGHADJ 4 +#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5 +#define EFI_IMAGE_REL_BASED_ARM_MOV32A 5 +#define EFI_IMAGE_REL_BASED_ARM_MOV32T 7 +#define EFI_IMAGE_REL_BASED_IA64_IMM64 9 +#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16 9 +#define EFI_IMAGE_REL_BASED_DIR64 10 + +// +// Line number format +// +typedef struct { + union { + UINT32 SymbolTableIndex; // Symbol table index of function name if line number is 0 + UINT32 VirtualAddress; // Virtual address of line number + } Type; + UINT16 Linenumber; // Line number +} EFI_IMAGE_LINENUMBER; + +// +// Size of EFI_IMAGE_LINENUMBER +// +#define EFI_IMAGE_SIZEOF_LINENUMBER 6 + +// +// Archive format +// +#define EFI_IMAGE_ARCHIVE_START_SIZE 8 +#define EFI_IMAGE_ARCHIVE_START "!\n" +#define EFI_IMAGE_ARCHIVE_END "`\n" +#define EFI_IMAGE_ARCHIVE_PAD "\n" +#define EFI_IMAGE_ARCHIVE_LINKER_MEMBER "/ " +#define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER "// " + +// +// Archive Member Headers +// +typedef struct { + UINT8 Name[16]; // File member name - `/' terminated + UINT8 Date[12]; // File member date - decimal + UINT8 UserID[6]; // File member user id - decimal + UINT8 GroupID[6]; // File member group id - decimal + UINT8 Mode[8]; // File member mode - octal + UINT8 Size[10]; // File member size - decimal + UINT8 EndHeader[2]; // String to end header. (0x60 0x0A) +} EFI_IMAGE_ARCHIVE_MEMBER_HEADER; + +// +// Size of EFI_IMAGE_ARCHIVE_MEMBER_HEADER +// +#define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60 + +// +// DLL Support +// + +// +// Export Directory Table +// +typedef struct { + UINT32 Characteristics; + UINT32 TimeDateStamp; + UINT16 MajorVersion; + UINT16 MinorVersion; + UINT32 Name; + UINT32 Base; + UINT32 NumberOfFunctions; + UINT32 NumberOfNames; + UINT32 AddressOfFunctions; + UINT32 AddressOfNames; + UINT32 AddressOfNameOrdinals; +} EFI_IMAGE_EXPORT_DIRECTORY; + +// +// Hint/Name Table +// +typedef struct { + UINT16 Hint; + UINT8 Name[1]; +} EFI_IMAGE_IMPORT_BY_NAME; + +// +// Import Address Table RVA (Thunk Table) +// +typedef struct { + union { + UINT32 Function; + UINT32 Ordinal; + EFI_IMAGE_IMPORT_BY_NAME *AddressOfData; + } u1; +} EFI_IMAGE_THUNK_DATA; + +#define EFI_IMAGE_ORDINAL_FLAG 0x80000000 // Flag for PE32. +#define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0) +#define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff) + +// +// Import Directory Table +// +typedef struct { + UINT32 Characteristics; + UINT32 TimeDateStamp; + UINT32 ForwarderChain; + UINT32 Name; + EFI_IMAGE_THUNK_DATA *FirstThunk; +} EFI_IMAGE_IMPORT_DESCRIPTOR; + +// +// Debug Directory Format +// +typedef struct { + UINT32 Characteristics; + UINT32 TimeDateStamp; + UINT16 MajorVersion; + UINT16 MinorVersion; + UINT32 Type; + UINT32 SizeOfData; + UINT32 RVA; // The address of the debug data when loaded, relative to the image base + UINT32 FileOffset; // The file pointer to the debug data +} EFI_IMAGE_DEBUG_DIRECTORY_ENTRY; + +#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 // The Visual C++ debug information. + +// +// Debug Data Structure defined in Microsoft C++ +// +#define CODEVIEW_SIGNATURE_NB10 0x3031424E // NB10 +typedef struct { + UINT32 Signature; + UINT32 Unknown; + UINT32 Unknown2; + UINT32 Unknown3; + // + // Filename of .PDB goes here + // +} EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY; + +// +// Debug Data Structure defined in Microsoft C++ +// +#define CODEVIEW_SIGNATURE_RSDS 0x53445352 // RSDS +typedef struct { + UINT32 Signature; + UINT32 Unknown; + UINT32 Unknown2; + UINT32 Unknown3; + UINT32 Unknown4; + UINT32 Unknown5; + // + // Filename of .PDB goes here + // +} EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY; + +// +// Debug Data Structure defined by Apple Mach-O to COFF utility. +// +#define CODEVIEW_SIGNATURE_MTOC 0x434F544D // MTOC +typedef struct { + UINT32 Signature; + UINT8 MachOUuid[16]; + // + // Filename of .DLL (Mach-O with debug info) goes here + // +} EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY; + +// +// Resource format +// +typedef struct { + UINT32 Characteristics; + UINT32 TimeDateStamp; + UINT16 MajorVersion; + UINT16 MinorVersion; + UINT16 NumberOfNamedEntries; + UINT16 NumberOfIdEntries; + // + // Array of EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY entries goes here + // +} EFI_IMAGE_RESOURCE_DIRECTORY; + +// +// Resource directory entry format +// +typedef struct { + union { + struct { + UINT32 NameOffset : 31; + UINT32 NameIsString : 1; + } s; + UINT32 Id; + } u1; + union { + UINT32 OffsetToData; + struct { + UINT32 OffsetToDirectory : 31; + UINT32 DataIsDirectory : 1; + } s; + } u2; +} EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY; + +// +// Resource directory entry for string +// +typedef struct { + UINT16 Length; + CHAR16 String[1]; +} EFI_IMAGE_RESOURCE_DIRECTORY_STRING; + +// +// Resource directory entry for data array +// +typedef struct { + UINT32 OffsetToData; + UINT32 Size; + UINT32 CodePage; + UINT32 Reserved; +} EFI_IMAGE_RESOURCE_DATA_ENTRY; + +// +// Header format for TE images, defined in the PI Specification 1.0. +// +typedef struct { + UINT16 Signature; // The signature for TE format = "VZ" + UINT16 Machine; // From original file header + UINT8 NumberOfSections; // From original file header + UINT8 Subsystem; // From original optional header + UINT16 StrippedSize; // Number of bytes we removed from header + UINT32 AddressOfEntryPoint; // Offset to entry point -- from original optional header + UINT32 BaseOfCode; // From original image -- required for ITP debug + UINT64 ImageBase; // From original file header + EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; // Only base relocation and debug directory +} EFI_IMAGE_TE_HEADER; + +#define EFI_IMAGE_TE_SIGNATURE 0x5A56 // VZ + +// +// Data directory indexes in our TE image header +// +#define EFI_IMAGE_TE_DIRECTORY_ENTRY_BASERELOC 0 +#define EFI_IMAGE_TE_DIRECTORY_ENTRY_DEBUG 1 + +// Restore previous packing rules +#pragma pack(pop) +#endif // PEIMAGE_H diff --git a/common/treeitem.cpp b/common/treeitem.cpp index 0997c85..a0fefe0 100644 --- a/common/treeitem.cpp +++ b/common/treeitem.cpp @@ -11,14 +11,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. */ -#include #include "treeitem.h" #include "types.h" TreeItem::TreeItem(const UINT8 type, const UINT8 subtype, - const QString & name, const QString & text, const QString & info, - const QByteArray & header, const QByteArray & body, const QByteArray & tail, - const BOOLEAN fixed, const BOOLEAN compressed, const QByteArray & parsingData, + const UString & name, const UString & text, const UString & info, + const UByteArray & header, const UByteArray & body, const UByteArray & tail, + const BOOLEAN fixed, const BOOLEAN compressed, const UByteArray & parsingData, TreeItem *parent) : itemAction(Actions::NoAction), itemType(type), @@ -41,18 +40,18 @@ UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem) { int index = childItems.indexOf(item); if (index == -1) - return ERR_ITEM_NOT_FOUND; + return U_ITEM_NOT_FOUND; childItems.insert(index, newItem); - return ERR_SUCCESS; + return U_SUCCESS; } UINT8 TreeItem::insertChildAfter(TreeItem *item, TreeItem *newItem) { int index = childItems.indexOf(item); if (index == -1) - return ERR_ITEM_NOT_FOUND; + return U_ITEM_NOT_FOUND; childItems.insert(index + 1, newItem); - return ERR_SUCCESS; + return U_SUCCESS; } QVariant TreeItem::data(int column) const @@ -62,11 +61,11 @@ QVariant TreeItem::data(int column) const case 0: // Name return itemName; case 1: // Action - return actionTypeToQString(itemAction); + return actionTypeToUString(itemAction); case 2: // Type - return itemTypeToQString(itemType); + return itemTypeToUString(itemType); case 3: // Subtype - return itemSubtypeToQString(itemType, itemSubtype); + return itemSubtypeToUString(itemType, itemSubtype); case 4: // Text return itemText; default: diff --git a/common/treeitem.h b/common/treeitem.h index 9fc4c66..265d507 100644 --- a/common/treeitem.h +++ b/common/treeitem.h @@ -14,19 +14,19 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #ifndef TREEITEM_H #define TREEITEM_H -#include #include -#include #include +#include "ubytearray.h" +#include "ustring.h" #include "basetypes.h" class TreeItem { public: - TreeItem(const UINT8 type, const UINT8 subtype, const QString &name, const QString &text, const QString &info, - const QByteArray & header, const QByteArray & body, const QByteArray & tail, - const BOOLEAN fixed, const BOOLEAN compressed, const QByteArray & parsingData, + TreeItem(const UINT8 type, const UINT8 subtype, const UString &name, const UString &text, const UString &info, + const UByteArray & header, const UByteArray & body, const UByteArray & tail, + const BOOLEAN fixed, const BOOLEAN compressed, const UByteArray & parsingData, TreeItem *parent = 0); ~TreeItem() { qDeleteAll(childItems); } @@ -45,8 +45,8 @@ public: TreeItem *parent() { return parentItem; } // Reading operations for item parameters - QString name() const { return itemName; } - void setName(const QString &text) { itemName = text; } + UString name() const { return itemName; } + void setName(const UString &text) { itemName = text; } UINT8 type() const { return itemType; } void setType(const UINT8 type) { itemType = type; } @@ -54,25 +54,25 @@ public: UINT8 subtype() const { return itemSubtype; } void setSubtype(const UINT8 subtype) { itemSubtype = subtype; } - QString text() const { return itemText; } - void setText(const QString &text) { itemText = text; } + UString text() const { return itemText; } + void setText(const UString &text) { itemText = text; } - QByteArray header() const { return itemHeader; } + UByteArray header() const { return itemHeader; } bool hasEmptyHeader() const { return itemHeader.isEmpty(); } - QByteArray body() const { return itemBody; }; + UByteArray body() const { return itemBody; }; bool hasEmptyBody() const { return itemBody.isEmpty(); } - QByteArray tail() const { return itemTail; }; + UByteArray tail() const { return itemTail; }; bool hasEmptyTail() const { return itemTail.isEmpty(); } - QByteArray parsingData() const { return itemParsingData; } + UByteArray parsingData() const { return itemParsingData; } bool hasEmptyParsingData() const { return itemParsingData.isEmpty(); } - void setParsingData(const QByteArray & data) { itemParsingData = data; } + void setParsingData(const UByteArray & data) { itemParsingData = data; } - QString info() const { return itemInfo; } - void addInfo(const QString &info, const BOOLEAN append) { if (append) itemInfo.append(info); else itemInfo.prepend(info); } - void setInfo(const QString &info) { itemInfo = info; } + UString info() const { return itemInfo; } + void addInfo(const UString &info, const BOOLEAN append) { if (append) itemInfo.append(info); else itemInfo.prepend(info); } + void setInfo(const UString &info) { itemInfo = info; } UINT8 action() const {return itemAction; } void setAction(const UINT8 action) { itemAction = action; } @@ -88,13 +88,13 @@ private: UINT8 itemAction; UINT8 itemType; UINT8 itemSubtype; - QString itemName; - QString itemText; - QString itemInfo; - QByteArray itemHeader; - QByteArray itemBody; - QByteArray itemTail; - QByteArray itemParsingData; + UString itemName; + UString itemText; + UString itemInfo; + UByteArray itemHeader; + UByteArray itemBody; + UByteArray itemTail; + UByteArray itemParsingData; bool itemFixed; bool itemCompressed; TreeItem* parentItem; diff --git a/common/treemodel.cpp b/common/treemodel.cpp index 8046c20..f4222f7 100644 --- a/common/treemodel.cpp +++ b/common/treemodel.cpp @@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. TreeModel::TreeModel(QObject *parent) : QAbstractItemModel(parent) { - rootItem = new TreeItem(Types::Root, 0, QString(), QString(), QString(), QByteArray(), QByteArray(), QByteArray(), TRUE, FALSE, QByteArray()); + rootItem = new TreeItem(Types::Root, 0, UString(), UString(), UString(), UByteArray(), UByteArray(), UByteArray(), TRUE, FALSE, UByteArray()); } TreeModel::~TreeModel() @@ -25,7 +25,7 @@ TreeModel::~TreeModel() delete rootItem; } -int TreeModel::columnCount(const QModelIndex &parent) const +int TreeModel::columnCount(const UModelIndex &parent) const { if (parent.isValid()) return static_cast(parent.internalPointer())->columnCount(); @@ -33,7 +33,7 @@ int TreeModel::columnCount(const QModelIndex &parent) const return rootItem->columnCount(); } -QVariant TreeModel::data(const QModelIndex &index, int role) const +QVariant TreeModel::data(const UModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); @@ -49,7 +49,7 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const return item->info(); } -Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const +Qt::ItemFlags TreeModel::flags(const UModelIndex &index) const { if (!index.isValid()) return 0; @@ -79,10 +79,10 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation, return QVariant(); } -QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const +UModelIndex TreeModel::index(int row, int column, const UModelIndex &parent) const { if (!hasIndex(row, column, parent)) - return QModelIndex(); + return UModelIndex(); TreeItem *parentItem; @@ -95,27 +95,27 @@ QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) con if (childItem) return createIndex(row, column, childItem); else - return QModelIndex(); + return UModelIndex(); } -QModelIndex TreeModel::parent(const QModelIndex &index) const +UModelIndex TreeModel::parent(const UModelIndex &index) const { if (!index.isValid()) - return QModelIndex(); + return UModelIndex(); TreeItem *childItem = static_cast(index.internalPointer()); if (childItem == rootItem) - return QModelIndex(); + return UModelIndex(); TreeItem *parentItem = childItem->parent(); if (parentItem == rootItem) - return QModelIndex(); + return UModelIndex(); return createIndex(parentItem->row(), 0, parentItem); } -int TreeModel::rowCount(const QModelIndex &parent) const +int TreeModel::rowCount(const UModelIndex &parent) const { TreeItem *parentItem; if (parent.column() > 0) @@ -129,7 +129,7 @@ int TreeModel::rowCount(const QModelIndex &parent) const return parentItem->childCount(); } -UINT8 TreeModel::type(const QModelIndex &index) const +UINT8 TreeModel::type(const UModelIndex &index) const { if (!index.isValid()) return 0; @@ -137,7 +137,7 @@ UINT8 TreeModel::type(const QModelIndex &index) const return item->type(); } -UINT8 TreeModel::subtype(const QModelIndex &index) const +UINT8 TreeModel::subtype(const UModelIndex &index) const { if (!index.isValid()) return 0; @@ -145,15 +145,15 @@ UINT8 TreeModel::subtype(const QModelIndex &index) const return item->subtype(); } -QByteArray TreeModel::header(const QModelIndex &index) const +UByteArray TreeModel::header(const UModelIndex &index) const { if (!index.isValid()) - return QByteArray(); + return UByteArray(); TreeItem *item = static_cast(index.internalPointer()); return item->header(); } -bool TreeModel::hasEmptyHeader(const QModelIndex &index) const +bool TreeModel::hasEmptyHeader(const UModelIndex &index) const { if (!index.isValid()) return true; @@ -161,15 +161,15 @@ bool TreeModel::hasEmptyHeader(const QModelIndex &index) const return item->hasEmptyHeader(); } -QByteArray TreeModel::body(const QModelIndex &index) const +UByteArray TreeModel::body(const UModelIndex &index) const { if (!index.isValid()) - return QByteArray(); + return UByteArray(); TreeItem *item = static_cast(index.internalPointer()); return item->body(); } -bool TreeModel::hasEmptyBody(const QModelIndex &index) const +bool TreeModel::hasEmptyBody(const UModelIndex &index) const { if (!index.isValid()) return true; @@ -177,15 +177,15 @@ bool TreeModel::hasEmptyBody(const QModelIndex &index) const return item->hasEmptyBody(); } -QByteArray TreeModel::tail(const QModelIndex &index) const +UByteArray TreeModel::tail(const UModelIndex &index) const { if (!index.isValid()) - return QByteArray(); + return UByteArray(); TreeItem *item = static_cast(index.internalPointer()); return item->tail(); } -bool TreeModel::hasEmptyTail(const QModelIndex &index) const +bool TreeModel::hasEmptyTail(const UModelIndex &index) const { if (!index.isValid()) return true; @@ -193,15 +193,15 @@ bool TreeModel::hasEmptyTail(const QModelIndex &index) const return item->hasEmptyTail(); } -QByteArray TreeModel::parsingData(const QModelIndex &index) const +UByteArray TreeModel::parsingData(const UModelIndex &index) const { if (!index.isValid()) - return QByteArray(); + return UByteArray(); TreeItem *item = static_cast(index.internalPointer()); return item->parsingData(); } -bool TreeModel::hasEmptyParsingData(const QModelIndex &index) const +bool TreeModel::hasEmptyParsingData(const UModelIndex &index) const { if (!index.isValid()) return true; @@ -209,31 +209,31 @@ bool TreeModel::hasEmptyParsingData(const QModelIndex &index) const return item->hasEmptyParsingData(); } -QString TreeModel::name(const QModelIndex &index) const +UString TreeModel::name(const UModelIndex &index) const { if (!index.isValid()) - return QString(); + return UString(); TreeItem *item = static_cast(index.internalPointer()); return item->name(); } -QString TreeModel::text(const QModelIndex &index) const +UString TreeModel::text(const UModelIndex &index) const { if (!index.isValid()) - return QString(); + return UString(); TreeItem *item = static_cast(index.internalPointer()); return item->text(); } -QString TreeModel::info(const QModelIndex &index) const +UString TreeModel::info(const UModelIndex &index) const { if (!index.isValid()) - return QString(); + return UString(); TreeItem *item = static_cast(index.internalPointer()); return item->info(); } -UINT8 TreeModel::action(const QModelIndex &index) const +UINT8 TreeModel::action(const UModelIndex &index) const { if (!index.isValid()) return Actions::NoAction; @@ -241,7 +241,7 @@ UINT8 TreeModel::action(const QModelIndex &index) const return item->action(); } -bool TreeModel::fixed(const QModelIndex &index) const +bool TreeModel::fixed(const UModelIndex &index) const { if (!index.isValid()) return false; @@ -249,7 +249,7 @@ bool TreeModel::fixed(const QModelIndex &index) const return item->fixed(); } -bool TreeModel::compressed(const QModelIndex &index) const +bool TreeModel::compressed(const UModelIndex &index) const { if (!index.isValid()) return false; @@ -257,7 +257,7 @@ bool TreeModel::compressed(const QModelIndex &index) const return item->compressed(); } -void TreeModel::setFixed(const QModelIndex &index, const bool fixed) +void TreeModel::setFixed(const UModelIndex &index, const bool fixed) { if (!index.isValid()) return; @@ -281,7 +281,7 @@ void TreeModel::setFixed(const QModelIndex &index, const bool fixed) emit dataChanged(index, index); } -void TreeModel::setCompressed(const QModelIndex &index, const bool compressed) +void TreeModel::setCompressed(const UModelIndex &index, const bool compressed) { if (!index.isValid()) return; @@ -293,7 +293,7 @@ void TreeModel::setCompressed(const QModelIndex &index, const bool compressed) } -void TreeModel::setSubtype(const QModelIndex & index, const UINT8 subtype) +void TreeModel::setSubtype(const UModelIndex & index, const UINT8 subtype) { if (!index.isValid()) return; @@ -303,7 +303,7 @@ void TreeModel::setSubtype(const QModelIndex & index, const UINT8 subtype) emit dataChanged(index, index); } -void TreeModel::setName(const QModelIndex &index, const QString &data) +void TreeModel::setName(const UModelIndex &index, const UString &data) { if (!index.isValid()) return; @@ -313,7 +313,7 @@ void TreeModel::setName(const QModelIndex &index, const QString &data) emit dataChanged(index, index); } -void TreeModel::setType(const QModelIndex &index, const UINT8 data) +void TreeModel::setType(const UModelIndex &index, const UINT8 data) { if (!index.isValid()) return; @@ -323,7 +323,7 @@ void TreeModel::setType(const QModelIndex &index, const UINT8 data) emit dataChanged(index, index); } -void TreeModel::setText(const QModelIndex &index, const QString &data) +void TreeModel::setText(const UModelIndex &index, const UString &data) { if (!index.isValid()) return; @@ -333,7 +333,7 @@ void TreeModel::setText(const QModelIndex &index, const QString &data) emit dataChanged(index, index); } -void TreeModel::setInfo(const QModelIndex &index, const QString &data) +void TreeModel::setInfo(const UModelIndex &index, const UString &data) { if (!index.isValid()) return; @@ -343,7 +343,7 @@ void TreeModel::setInfo(const QModelIndex &index, const QString &data) emit dataChanged(index, index); } -void TreeModel::addInfo(const QModelIndex &index, const QString &data, const bool append) +void TreeModel::addInfo(const UModelIndex &index, const UString &data, const bool append) { if (!index.isValid()) return; @@ -353,7 +353,7 @@ void TreeModel::addInfo(const QModelIndex &index, const QString &data, const boo emit dataChanged(index, index); } -void TreeModel::setAction(const QModelIndex &index, const UINT8 action) +void TreeModel::setAction(const UModelIndex &index, const UINT8 action) { if (!index.isValid()) return; @@ -363,7 +363,7 @@ void TreeModel::setAction(const QModelIndex &index, const UINT8 action) emit dataChanged(index, index); } -void TreeModel::setParsingData(const QModelIndex &index, const QByteArray &data) +void TreeModel::setParsingData(const UModelIndex &index, const UByteArray &data) { if (!index.isValid()) return; @@ -373,11 +373,11 @@ void TreeModel::setParsingData(const QModelIndex &index, const QByteArray &data) emit dataChanged(this->index(0, 0), index); } -QModelIndex TreeModel::addItem(const UINT8 type, const UINT8 subtype, - const QString & name, const QString & text, const QString & info, - const QByteArray & header, const QByteArray & body, const QByteArray & tail, - const bool fixed, const QByteArray & parsingData, - const QModelIndex & parent, const UINT8 mode) +UModelIndex TreeModel::addItem(const UINT8 type, const UINT8 subtype, + const UString & name, const UString & text, const UString & info, + const UByteArray & header, const UByteArray & body, const UByteArray & tail, + const bool fixed, const UByteArray & parsingData, + const UModelIndex & parent, const UINT8 mode) { TreeItem *item = 0; TreeItem *parentItem = 0; @@ -418,23 +418,23 @@ QModelIndex TreeModel::addItem(const UINT8 type, const UINT8 subtype, } else { delete newItem; - return QModelIndex(); + return UModelIndex(); } emit layoutChanged(); - QModelIndex created = createIndex(newItem->row(), parentColumn, newItem); + UModelIndex created = createIndex(newItem->row(), parentColumn, newItem); setFixed(created, fixed); // Non-trivial logic requires additional call return created; } -QModelIndex TreeModel::findParentOfType(const QModelIndex& index, UINT8 type) const +UModelIndex TreeModel::findParentOfType(const UModelIndex& index, UINT8 type) const { if (!index.isValid()) - return QModelIndex(); + return UModelIndex(); TreeItem *item; - QModelIndex parent = index; + UModelIndex parent = index; for (item = static_cast(parent.internalPointer()); item != NULL && item != rootItem && item->type() != type; @@ -443,5 +443,5 @@ QModelIndex TreeModel::findParentOfType(const QModelIndex& index, UINT8 type) co if (item != NULL && item != rootItem) return parent; - return QModelIndex(); + return UModelIndex(); } \ No newline at end of file diff --git a/common/treemodel.h b/common/treemodel.h index 8448177..58ed9d2 100644 --- a/common/treemodel.h +++ b/common/treemodel.h @@ -15,12 +15,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define TREEMODEL_H #include -#include -#include #include +#include +#include "ustring.h" +#include "ubytearray.h" #include "basetypes.h" #include "types.h" +#include "umodelindex.h" class TreeItem; @@ -32,52 +34,52 @@ public: TreeModel(QObject *parent = 0); ~TreeModel(); - QVariant data(const QModelIndex &index, int role) const; - Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant data(const UModelIndex &index, int role) const; + Qt::ItemFlags flags(const UModelIndex &index) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &index) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; + UModelIndex index(int row, int column, + const UModelIndex &parent = UModelIndex()) const; + UModelIndex parent(const UModelIndex &index) const; + int rowCount(const UModelIndex &parent = UModelIndex()) const; + int columnCount(const UModelIndex &parent = UModelIndex()) const; - void setAction(const QModelIndex &index, const UINT8 action); - void setType(const QModelIndex &index, const UINT8 type); - void setSubtype(const QModelIndex &index, const UINT8 subtype); - void setName(const QModelIndex &index, const QString &name); - void setText(const QModelIndex &index, const QString &text); - void setInfo(const QModelIndex &index, const QString &info); - void addInfo(const QModelIndex &index, const QString &info, const bool append = TRUE); - void setParsingData(const QModelIndex &index, const QByteArray &data); - void setFixed(const QModelIndex &index, const bool fixed); - void setCompressed(const QModelIndex &index, const bool compressed); + void setAction(const UModelIndex &index, const UINT8 action); + void setType(const UModelIndex &index, const UINT8 type); + void setSubtype(const UModelIndex &index, const UINT8 subtype); + void setName(const UModelIndex &index, const UString &name); + void setText(const UModelIndex &index, const UString &text); + void setInfo(const UModelIndex &index, const UString &info); + void addInfo(const UModelIndex &index, const UString &info, const bool append = TRUE); + void setParsingData(const UModelIndex &index, const UByteArray &data); + void setFixed(const UModelIndex &index, const bool fixed); + void setCompressed(const UModelIndex &index, const bool compressed); - QString name(const QModelIndex &index) const; - QString text(const QModelIndex &index) const; - QString info(const QModelIndex &index) const; - UINT8 type(const QModelIndex &index) const; - UINT8 subtype(const QModelIndex &index) const; - QByteArray header(const QModelIndex &index) const; - bool hasEmptyHeader(const QModelIndex &index) const; - QByteArray body(const QModelIndex &index) const; - bool hasEmptyBody(const QModelIndex &index) const; - QByteArray tail(const QModelIndex &index) const; - bool hasEmptyTail(const QModelIndex &index) const; - QByteArray parsingData(const QModelIndex &index) const; - bool hasEmptyParsingData(const QModelIndex &index) const; - UINT8 action(const QModelIndex &index) const; - bool fixed(const QModelIndex &index) const; + UString name(const UModelIndex &index) const; + UString text(const UModelIndex &index) const; + UString info(const UModelIndex &index) const; + UINT8 type(const UModelIndex &index) const; + UINT8 subtype(const UModelIndex &index) const; + UByteArray header(const UModelIndex &index) const; + bool hasEmptyHeader(const UModelIndex &index) const; + UByteArray body(const UModelIndex &index) const; + bool hasEmptyBody(const UModelIndex &index) const; + UByteArray tail(const UModelIndex &index) const; + bool hasEmptyTail(const UModelIndex &index) const; + UByteArray parsingData(const UModelIndex &index) const; + bool hasEmptyParsingData(const UModelIndex &index) const; + UINT8 action(const UModelIndex &index) const; + bool fixed(const UModelIndex &index) const; - bool compressed(const QModelIndex &index) const; + bool compressed(const UModelIndex &index) const; - QModelIndex addItem(const UINT8 type, const UINT8 subtype, - const QString & name, const QString & text, const QString & info, - const QByteArray & header, const QByteArray & body, const QByteArray & tail, - const bool fixed, const QByteArray & parsingData = QByteArray(), - const QModelIndex & parent = QModelIndex(), const UINT8 mode = CREATE_MODE_APPEND); + UModelIndex addItem(const UINT8 type, const UINT8 subtype, + const UString & name, const UString & text, const UString & info, + const UByteArray & header, const UByteArray & body, const UByteArray & tail, + const bool fixed, const UByteArray & parsingData = UByteArray(), + const UModelIndex & parent = UModelIndex(), const UINT8 mode = CREATE_MODE_APPEND); - QModelIndex findParentOfType(const QModelIndex & index, UINT8 type) const; + UModelIndex findParentOfType(const UModelIndex & index, UINT8 type) const; private: TreeItem *rootItem; diff --git a/common/types.cpp b/common/types.cpp index 613e787..ac90a58 100644 --- a/common/types.cpp +++ b/common/types.cpp @@ -10,62 +10,60 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. */ -#include -#include +#include "ustring.h" #include "types.h" #include "ffs.h" -QString regionTypeToQString(const UINT8 type) -{ - switch (type) - { - case Subtypes::DescriptorRegion: return QObject::tr("Descriptor"); - case Subtypes::BiosRegion: return QObject::tr("BIOS"); - case Subtypes::MeRegion: return QObject::tr("ME"); - case Subtypes::GbeRegion: return QObject::tr("GbE"); - case Subtypes::PdrRegion: return QObject::tr("PDR"); - case Subtypes::Reserved1Region: return QObject::tr("Reserved1"); - case Subtypes::Reserved2Region: return QObject::tr("Reserved2"); - case Subtypes::Reserved3Region: return QObject::tr("Reserved3"); - case Subtypes::EcRegion: return QObject::tr("EC"); - case Subtypes::Reserved4Region: return QObject::tr("Reserved4"); - }; - - return QObject::tr("Unknown"); -} - -QString itemTypeToQString(const UINT8 type) +UString regionTypeToUString(const UINT8 type) { switch (type) { - case Types::Root: return QObject::tr("Root"); - case Types::Image: return QObject::tr("Image"); - case Types::Capsule: return QObject::tr("Capsule"); - case Types::Region: return QObject::tr("Region"); - case Types::Volume: return QObject::tr("Volume"); - case Types::Padding: return QObject::tr("Padding"); - case Types::File: return QObject::tr("File"); - case Types::Section: return QObject::tr("Section"); - case Types::FreeSpace: return QObject::tr("Free space"); - case Types::VssStore: return QObject::tr("VSS store"); - case Types::FtwStore: return QObject::tr("FTW store"); - case Types::FdcStore: return QObject::tr("FDC store"); - case Types::FsysStore: return QObject::tr("Fsys store"); - case Types::EvsaStore: return QObject::tr("EVSA store"); - case Types::CmdbStore: return QObject::tr("CMDB store"); - case Types::FlashMapStore: return QObject::tr("FlashMap store"); - case Types::NvarEntry: return QObject::tr("NVAR entry"); - case Types::VssEntry: return QObject::tr("VSS entry"); - case Types::FsysEntry: return QObject::tr("Fsys entry"); - case Types::EvsaEntry: return QObject::tr("EVSA entry"); - case Types::FlashMapEntry: return QObject::tr("FlashMap entry"); - case Types::Microcode: return QObject::tr("Microcode"); - case Types::SlicData: return QObject::tr("SLIC data"); - } + case Subtypes::DescriptorRegion: return UString("Descriptor"); + case Subtypes::BiosRegion: return UString("BIOS"); + case Subtypes::MeRegion: return UString("ME"); + case Subtypes::GbeRegion: return UString("GbE"); + case Subtypes::PdrRegion: return UString("PDR"); + case Subtypes::Reserved1Region: return UString("Reserved1"); + case Subtypes::Reserved2Region: return UString("Reserved2"); + case Subtypes::Reserved3Region: return UString("Reserved3"); + case Subtypes::EcRegion: return UString("EC"); + case Subtypes::Reserved4Region: return UString("Reserved4"); + }; - return QObject::tr("Unknown"); + return UString("Unknown"); } -QString itemSubtypeToQString(const UINT8 type, const UINT8 subtype) +UString itemTypeToUString(const UINT8 type) +{ + switch (type) { + case Types::Root: return UString("Root"); + case Types::Image: return UString("Image"); + case Types::Capsule: return UString("Capsule"); + case Types::Region: return UString("Region"); + case Types::Volume: return UString("Volume"); + case Types::Padding: return UString("Padding"); + case Types::File: return UString("File"); + case Types::Section: return UString("Section"); + case Types::FreeSpace: return UString("Free space"); + case Types::VssStore: return UString("VSS store"); + case Types::FtwStore: return UString("FTW store"); + case Types::FdcStore: return UString("FDC store"); + case Types::FsysStore: return UString("Fsys store"); + case Types::EvsaStore: return UString("EVSA store"); + case Types::CmdbStore: return UString("CMDB store"); + case Types::FlashMapStore: return UString("FlashMap store"); + case Types::NvarEntry: return UString("NVAR entry"); + case Types::VssEntry: return UString("VSS entry"); + case Types::FsysEntry: return UString("Fsys entry"); + case Types::EvsaEntry: return UString("EVSA entry"); + case Types::FlashMapEntry: return UString("FlashMap entry"); + case Types::Microcode: return UString("Microcode"); + case Types::SlicData: return UString("SLIC data"); + } + + return UString("Unknown"); +} + +UString itemSubtypeToUString(const UINT8 type, const UINT8 subtype) { switch (type) { case Types::Root: @@ -78,89 +76,89 @@ QString itemSubtypeToQString(const UINT8 type, const UINT8 subtype) case Types::FlashMapStore: case Types::CmdbStore: case Types::FsysEntry: - case Types::SlicData: return QString(); + case Types::SlicData: return UString(); case Types::Image: - if (subtype == Subtypes::IntelImage) return QObject::tr("Intel"); - if (subtype == Subtypes::UefiImage) return QObject::tr("UEFI"); + if (subtype == Subtypes::IntelImage) return UString("Intel"); + if (subtype == Subtypes::UefiImage) return UString("UEFI"); break; case Types::Padding: - if (subtype == Subtypes::ZeroPadding) return QObject::tr("Empty (0x00)"); - if (subtype == Subtypes::OnePadding) return QObject::tr("Empty (0xFF)"); - if (subtype == Subtypes::DataPadding) return QObject::tr("Non-empty"); + if (subtype == Subtypes::ZeroPadding) return UString("Empty (0x00)"); + if (subtype == Subtypes::OnePadding) return UString("Empty (0xFF)"); + if (subtype == Subtypes::DataPadding) return UString("Non-empty"); break; case Types::Volume: - if (subtype == Subtypes::UnknownVolume) return QObject::tr("Unknown"); - if (subtype == Subtypes::Ffs2Volume) return QObject::tr("FFSv2"); - if (subtype == Subtypes::Ffs3Volume) return QObject::tr("FFSv3"); - if (subtype == Subtypes::NvramVolume) return QObject::tr("NVRAM"); + if (subtype == Subtypes::UnknownVolume) return UString("Unknown"); + if (subtype == Subtypes::Ffs2Volume) return UString("FFSv2"); + if (subtype == Subtypes::Ffs3Volume) return UString("FFSv3"); + if (subtype == Subtypes::NvramVolume) return UString("NVRAM"); break; case Types::Capsule: - if (subtype == Subtypes::AptioSignedCapsule) return QObject::tr("Aptio signed"); - if (subtype == Subtypes::AptioUnsignedCapsule) return QObject::tr("Aptio unsigned"); - if (subtype == Subtypes::UefiCapsule) return QObject::tr("UEFI 2.0"); - if (subtype == Subtypes::ToshibaCapsule) return QObject::tr("Toshiba"); + if (subtype == Subtypes::AptioSignedCapsule) return UString("Aptio signed"); + if (subtype == Subtypes::AptioUnsignedCapsule) return UString("Aptio unsigned"); + if (subtype == Subtypes::UefiCapsule) return UString("UEFI 2.0"); + if (subtype == Subtypes::ToshibaCapsule) return UString("Toshiba"); break; - case Types::Region: return regionTypeToQString(subtype); - case Types::File: return fileTypeToQString(subtype); - case Types::Section: return sectionTypeToQString(subtype); + case Types::Region: return regionTypeToUString(subtype); + case Types::File: return fileTypeToUString(subtype); + case Types::Section: return sectionTypeToUString(subtype); case Types::NvarEntry: - if (subtype == Subtypes::InvalidNvarEntry) return QObject::tr("Invalid"); - if (subtype == Subtypes::InvalidLinkNvarEntry) return QObject::tr("Invalid link"); - if (subtype == Subtypes::LinkNvarEntry) return QObject::tr("Link"); - if (subtype == Subtypes::DataNvarEntry) return QObject::tr("Data"); - if (subtype == Subtypes::FullNvarEntry) return QObject::tr("Full"); + if (subtype == Subtypes::InvalidNvarEntry) return UString("Invalid"); + if (subtype == Subtypes::InvalidLinkNvarEntry) return UString("Invalid link"); + if (subtype == Subtypes::LinkNvarEntry) return UString("Link"); + if (subtype == Subtypes::DataNvarEntry) return UString("Data"); + if (subtype == Subtypes::FullNvarEntry) return UString("Full"); break; case Types::VssEntry: - if (subtype == Subtypes::InvalidVssEntry) return QObject::tr("Invalid"); - if (subtype == Subtypes::StandardVssEntry) return QObject::tr("Standard"); - if (subtype == Subtypes::AppleVssEntry) return QObject::tr("Apple"); - if (subtype == Subtypes::AuthVssEntry) return QObject::tr("Auth"); + if (subtype == Subtypes::InvalidVssEntry) return UString("Invalid"); + if (subtype == Subtypes::StandardVssEntry) return UString("Standard"); + if (subtype == Subtypes::AppleVssEntry) return UString("Apple"); + if (subtype == Subtypes::AuthVssEntry) return UString("Auth"); break; case Types::EvsaEntry: - if (subtype == Subtypes::InvalidEvsaEntry) return QObject::tr("Invalid"); - if (subtype == Subtypes::UnknownEvsaEntry) return QObject::tr("Unknown"); - if (subtype == Subtypes::GuidEvsaEntry) return QObject::tr("GUID"); - if (subtype == Subtypes::NameEvsaEntry) return QObject::tr("Name"); - if (subtype == Subtypes::DataEvsaEntry) return QObject::tr("Data"); + if (subtype == Subtypes::InvalidEvsaEntry) return UString("Invalid"); + if (subtype == Subtypes::UnknownEvsaEntry) return UString("Unknown"); + if (subtype == Subtypes::GuidEvsaEntry) return UString("GUID"); + if (subtype == Subtypes::NameEvsaEntry) return UString("Name"); + if (subtype == Subtypes::DataEvsaEntry) return UString("Data"); break; case Types::FlashMapEntry: - if (subtype == Subtypes::VolumeFlashMapEntry) return QObject::tr("Volume"); - if (subtype == Subtypes::DataFlashMapEntry) return QObject::tr("Data"); + if (subtype == Subtypes::VolumeFlashMapEntry) return UString("Volume"); + if (subtype == Subtypes::DataFlashMapEntry) return UString("Data"); break; case Types::Microcode: - if (subtype == Subtypes::IntelMicrocode) return QObject::tr("Intel"); - if (subtype == Subtypes::AmdMicrocode) return QObject::tr("AMD"); + if (subtype == Subtypes::IntelMicrocode) return UString("Intel"); + if (subtype == Subtypes::AmdMicrocode) return UString("AMD"); break; } - return QObject::tr("Unknown"); + return UString("Unknown"); } -QString compressionTypeToQString(const UINT8 algorithm) +UString compressionTypeToUString(const UINT8 algorithm) { switch (algorithm) { - case COMPRESSION_ALGORITHM_NONE: return QObject::tr("None"); - case COMPRESSION_ALGORITHM_EFI11: return QObject::tr("EFI 1.1"); - case COMPRESSION_ALGORITHM_TIANO: return QObject::tr("Tiano"); - case COMPRESSION_ALGORITHM_UNDECIDED: return QObject::tr("Undecided Tiano/EFI 1.1"); - case COMPRESSION_ALGORITHM_LZMA: return QObject::tr("LZMA"); - case COMPRESSION_ALGORITHM_IMLZMA: return QObject::tr("Intel modified LZMA"); + case COMPRESSION_ALGORITHM_NONE: return UString("None"); + case COMPRESSION_ALGORITHM_EFI11: return UString("EFI 1.1"); + case COMPRESSION_ALGORITHM_TIANO: return UString("Tiano"); + case COMPRESSION_ALGORITHM_UNDECIDED: return UString("Undecided Tiano/EFI 1.1"); + case COMPRESSION_ALGORITHM_LZMA: return UString("LZMA"); + case COMPRESSION_ALGORITHM_IMLZMA: return UString("Intel modified LZMA"); } - return QObject::tr("Unknown"); + return UString("Unknown"); } -QString actionTypeToQString(const UINT8 action) +UString actionTypeToUString(const UINT8 action) { switch (action) { - case Actions::NoAction: return QString(); - case Actions::Create: return QObject::tr("Create"); - case Actions::Insert: return QObject::tr("Insert"); - case Actions::Replace: return QObject::tr("Replace"); - case Actions::Remove: return QObject::tr("Remove"); - case Actions::Rebuild: return QObject::tr("Rebuild"); - case Actions::Rebase: return QObject::tr("Rebase"); + case Actions::NoAction: return UString(); + case Actions::Create: return UString("Create"); + case Actions::Insert: return UString("Insert"); + case Actions::Replace: return UString("Replace"); + case Actions::Remove: return UString("Remove"); + case Actions::Rebuild: return UString("Rebuild"); + case Actions::Rebase: return UString("Rebase"); } - return QObject::tr("Unknown"); + return UString("Unknown"); } \ No newline at end of file diff --git a/common/types.h b/common/types.h index e232da3..b114f3a 100644 --- a/common/types.h +++ b/common/types.h @@ -138,11 +138,11 @@ namespace Subtypes { }; }; -// *ToQString conversion routines -extern QString actionTypeToQString(const UINT8 action); -extern QString itemTypeToQString(const UINT8 type); -extern QString itemSubtypeToQString(const UINT8 type, const UINT8 subtype); -extern QString compressionTypeToQString(const UINT8 algorithm); -extern QString regionTypeToQString(const UINT8 type); +// *ToUString conversion routines +extern UString actionTypeToUString(const UINT8 action); +extern UString itemTypeToUString(const UINT8 type); +extern UString itemSubtypeToUString(const UINT8 type, const UINT8 subtype); +extern UString compressionTypeToUString(const UINT8 algorithm); +extern UString regionTypeToUString(const UINT8 type); #endif // TYPES_H diff --git a/common/ubytearray.h b/common/ubytearray.h new file mode 100644 index 0000000..ad81bb6 --- /dev/null +++ b/common/ubytearray.h @@ -0,0 +1,67 @@ +/* ubytearray.h + +Copyright (c) 2016, Nikolaj Schlej. All rights reserved. +This program and the accompanying materials +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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +*/ + +#ifndef UBYTEARRAY_H +#define UBYTEARRAY_H + +#ifdef QT_CORE_LIB +// Use Qt class, if Qt is available +#include +#define UByteArray QByteArray +#else +// Use own implementation +#include +#include +#include + +class UByteArray +{ +public: + UByteArray() : d() {} + UByteArray(const UByteArray & ba) : d(ba.d) {} + UByteArray(const std::basic_string & bs) : d(bs) {} + UByteArray(const std::vector & bc) : d(bc.data(), bc.size()) {} + UByteArray(const char* bytes, int32_t size) : d(bytes, size) {} + ~UByteArray() {} + + bool isEmpty() const { return d.length() == 0; } + + char* data() { return &(d.front()); /* Feels dirty, but works for all basic_string implementations I know, is fully OK in C++11 and later*/ } + const char* data() const { return d.c_str(); } + const char* constData() const { return d.c_str(); } + void clear() { d.clear(); } + + int32_t size() const { return d.size(); } + int32_t count(char ch) const { return std::count(d.cbegin(), d.cend(), ch); } + char at(uint32_t i) const { return d.at(i); } + char operator[](uint32_t i) const { return d[i]; } + char& operator[](uint32_t i) { return d[i]; } + + bool startsWith(const UByteArray & ba) const { return 0 == d.find(ba.d, 0); } + int indexOf(const UByteArray & ba, int from = 0) const { return d.find(ba.d, from); } + int lastIndexOf(const UByteArray & ba, int from = 0) const { return d.rfind(ba.d, from); } + + UByteArray left(int32_t len) const { return d.substr(0, len); } + UByteArray right(int32_t len) const { return d.substr(d.size() - 1 - len, len); }; + UByteArray mid(int32_t pos, int32_t len = -1) const { return d.substr(pos, len); }; + + UByteArray &operator=(const UByteArray & ba) { d = ba.d; return *this; } + bool operator== (const UByteArray & ba) const { return d == ba.d; } + bool operator!= (const UByteArray & ba) const { return d != ba.d; } + inline void swap(UByteArray &other) { std::swap(d, other.d); } + +private: + std::basic_string d; +}; + +#endif // QT_CORE_LIB +#endif // UBYTEARRAY_H \ No newline at end of file diff --git a/common/umodelindex.h b/common/umodelindex.h new file mode 100644 index 0000000..0e860a5 --- /dev/null +++ b/common/umodelindex.h @@ -0,0 +1,23 @@ +/* umodelindex.h + +Copyright (c) 2016, Nikolaj Schlej. All rights reserved. +This program and the accompanying materials +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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +*/ + +#ifndef UMODELINDEX_H +#define UMODELINDEX_H + +#ifdef QT_CORE_LIB +// Use Qt class, if Qt is available +#include +#define UModelIndex QModelIndex +#else +// Use own implementation +#endif // QT_CORE_LIB +#endif // UMODELINDEX_H diff --git a/common/ustring.cpp b/common/ustring.cpp new file mode 100644 index 0000000..ccc0284 --- /dev/null +++ b/common/ustring.cpp @@ -0,0 +1,25 @@ +/* ustring.cpp + +Copyright (c) 2016, Nikolaj Schlej. All rights reserved. +This program and the accompanying materials +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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +*/ + +#include "ustring.h" +#include + +UString usprintf(const char* fmt, ...) +{ + UString msg; + va_list vl; + va_start(vl, fmt); + msg = msg.vsprintf(fmt, vl); + va_end(vl); + return msg; +}; + diff --git a/common/ustring.h b/common/ustring.h new file mode 100644 index 0000000..635bf62 --- /dev/null +++ b/common/ustring.h @@ -0,0 +1,34 @@ +/* ustring.h + +Copyright (c) 2016, Nikolaj Schlej. All rights reserved. +This program and the accompanying materials +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 +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +*/ + +#ifndef USTRING_H +#define USTRING_H + +//TODO: modify properly + +#ifdef QT_CORE_LIB +// Use Qt class, if Qt is available +#include +#define UString QString +#else +// Use own implementation +#include "../bstrlib/bstrwrap.h" +class UString : public CBString { +}; + +#endif // QT_CORE_LIB + +UString usprintf(const char* fmt, ...); + + + +#endif // USTRING_H diff --git a/common/utility.cpp b/common/utility.cpp index 3b9e44e..4425f5c 100644 --- a/common/utility.cpp +++ b/common/utility.cpp @@ -10,7 +10,7 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. */ -#include + #include "treemodel.h" #include "utility.h" #include "ffs.h" @@ -20,7 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "LZMA/LzmaDecompress.h" // Returns either new parsing data instance or obtains it from index -PARSING_DATA parsingDataFromQModelIndex(const QModelIndex & index) +PARSING_DATA parsingDataFromUModelIndex(const UModelIndex & index) { if (index.isValid()) { TreeModel* model = (TreeModel*)index.model(); @@ -39,64 +39,64 @@ PARSING_DATA parsingDataFromQModelIndex(const QModelIndex & index) } // Converts parsing data to byte array -QByteArray parsingDataToQByteArray(const PARSING_DATA & pdata) +UByteArray parsingDataToUByteArray(const PARSING_DATA & pdata) { - return QByteArray((const char*)&pdata, sizeof(PARSING_DATA)); + return UByteArray((const char*)&pdata, sizeof(PARSING_DATA)); } // Returns text representation of error code -QString errorCodeToQString(UINT8 errorCode) +UString errorCodeToUString(UINT8 errorCode) { switch (errorCode) { - case ERR_SUCCESS: return QObject::tr("Success"); - case ERR_NOT_IMPLEMENTED: return QObject::tr("Not implemented"); - case ERR_INVALID_PARAMETER: return QObject::tr("Function called with invalid parameter"); - case ERR_BUFFER_TOO_SMALL: return QObject::tr("Buffer too small"); - case ERR_OUT_OF_RESOURCES: return QObject::tr("Out of resources"); - case ERR_OUT_OF_MEMORY: return QObject::tr("Out of memory"); - case ERR_FILE_OPEN: return QObject::tr("File can't be opened"); - case ERR_FILE_READ: return QObject::tr("File can't be read"); - case ERR_FILE_WRITE: return QObject::tr("File can't be written"); - case ERR_ITEM_NOT_FOUND: return QObject::tr("Item not found"); - case ERR_UNKNOWN_ITEM_TYPE: return QObject::tr("Unknown item type"); - case ERR_INVALID_FLASH_DESCRIPTOR: return QObject::tr("Invalid flash descriptor"); - case ERR_INVALID_REGION: return QObject::tr("Invalid region"); - case ERR_EMPTY_REGION: return QObject::tr("Empty region"); - case ERR_BIOS_REGION_NOT_FOUND: return QObject::tr("BIOS region not found"); - case ERR_VOLUMES_NOT_FOUND: return QObject::tr("UEFI volumes not found"); - case ERR_INVALID_VOLUME: return QObject::tr("Invalid UEFI volume"); - case ERR_VOLUME_REVISION_NOT_SUPPORTED: return QObject::tr("Volume revision not supported"); - //case ERR_VOLUME_GROW_FAILED: return QObject::tr("Volume grow failed"); - case ERR_UNKNOWN_FFS: return QObject::tr("Unknown file system"); - case ERR_INVALID_FILE: return QObject::tr("Invalid file"); - case ERR_INVALID_SECTION: return QObject::tr("Invalid section"); - case ERR_UNKNOWN_SECTION: return QObject::tr("Unknown section"); - case ERR_STANDARD_COMPRESSION_FAILED: return QObject::tr("Standard compression failed"); - case ERR_CUSTOMIZED_COMPRESSION_FAILED: return QObject::tr("Customized compression failed"); - case ERR_STANDARD_DECOMPRESSION_FAILED: return QObject::tr("Standard decompression failed"); - case ERR_CUSTOMIZED_DECOMPRESSION_FAILED: return QObject::tr("Customized decompression failed"); - case ERR_UNKNOWN_COMPRESSION_TYPE: return QObject::tr("Unknown compression type"); - case ERR_UNKNOWN_EXTRACT_MODE: return QObject::tr("Unknown extract mode"); - case ERR_UNKNOWN_REPLACE_MODE: return QObject::tr("Unknown replace mode"); - //case ERR_UNKNOWN_INSERT_MODE: return QObject::tr("Unknown insert mode"); - case ERR_UNKNOWN_IMAGE_TYPE: return QObject::tr("Unknown executable image type"); - case ERR_UNKNOWN_PE_OPTIONAL_HEADER_TYPE: return QObject::tr("Unknown PE optional header type"); - case ERR_UNKNOWN_RELOCATION_TYPE: return QObject::tr("Unknown relocation type"); - //case ERR_GENERIC_CALL_NOT_SUPPORTED: return QObject::tr("Generic call not supported"); - //case ERR_VOLUME_BASE_NOT_FOUND: return QObject::tr("Volume base address not found"); - //case ERR_PEI_CORE_ENTRY_POINT_NOT_FOUND: return QObject::tr("PEI core entry point not found"); - case ERR_COMPLEX_BLOCK_MAP: return QObject::tr("Block map structure too complex for correct analysis"); - case ERR_DIR_ALREADY_EXIST: return QObject::tr("Directory already exists"); - case ERR_DIR_CREATE: return QObject::tr("Directory can't be created"); - //case ERR_UNKNOWN_PATCH_TYPE: return QObject::tr("Unknown patch type"); - //case ERR_PATCH_OFFSET_OUT_OF_BOUNDS: return QObject::tr("Patch offset out of bounds"); - //case ERR_INVALID_SYMBOL: return QObject::tr("Invalid symbol"); - //case ERR_NOTHING_TO_PATCH: return QObject::tr("Nothing to patch"); - case ERR_DEPEX_PARSE_FAILED: return QObject::tr("Dependency expression parsing failed"); - case ERR_TRUNCATED_IMAGE: return QObject::tr("Image is truncated"); - case ERR_INVALID_CAPSULE: return QObject::tr("Invalid capsule"); - case ERR_STORES_NOT_FOUND: return QObject::tr("Stores not found"); - default: return QObject::tr("Unknown error %1").arg(errorCode); + case U_SUCCESS: return UString("Success"); + case U_NOT_IMPLEMENTED: return UString("Not implemented"); + case U_INVALID_PARAMETER: return UString("Function called with invalid parameter"); + case U_BUFFER_TOO_SMALL: return UString("Buffer too small"); + case U_OUT_OF_RESOURCES: return UString("Out of resources"); + case U_OUT_OF_MEMORY: return UString("Out of memory"); + case U_FILE_OPEN: return UString("File can't be opened"); + case U_FILE_READ: return UString("File can't be read"); + case U_FILE_WRITE: return UString("File can't be written"); + case U_ITEM_NOT_FOUND: return UString("Item not found"); + case U_UNKNOWN_ITEM_TYPE: return UString("Unknown item type"); + case U_INVALID_FLASH_DESCRIPTOR: return UString("Invalid flash descriptor"); + case U_INVALID_REGION: return UString("Invalid region"); + case U_EMPTY_REGION: return UString("Empty region"); + case U_BIOS_REGION_NOT_FOUND: return UString("BIOS region not found"); + case U_VOLUMES_NOT_FOUND: return UString("UEFI volumes not found"); + case U_INVALID_VOLUME: return UString("Invalid UEFI volume"); + case U_VOLUME_REVISION_NOT_SUPPORTED: return UString("Volume revision not supported"); + //case U_VOLUME_GROW_FAILED: return UString("Volume grow failed"); + case U_UNKNOWN_FFS: return UString("Unknown file system"); + case U_INVALID_FILE: return UString("Invalid file"); + case U_INVALID_SECTION: return UString("Invalid section"); + case U_UNKNOWN_SECTION: return UString("Unknown section"); + case U_STANDARD_COMPRESSION_FAILED: return UString("Standard compression failed"); + case U_CUSTOMIZED_COMPRESSION_FAILED: return UString("Customized compression failed"); + case U_STANDARD_DECOMPRESSION_FAILED: return UString("Standard decompression failed"); + case U_CUSTOMIZED_DECOMPRESSION_FAILED: return UString("Customized decompression failed"); + case U_UNKNOWN_COMPRESSION_TYPE: return UString("Unknown compression type"); + case U_UNKNOWN_EXTRACT_MODE: return UString("Unknown extract mode"); + case U_UNKNOWN_REPLACE_MODE: return UString("Unknown replace mode"); + //case U_UNKNOWN_INSERT_MODE: return UString("Unknown insert mode"); + case U_UNKNOWN_IMAGE_TYPE: return UString("Unknown executable image type"); + case U_UNKNOWN_PE_OPTIONAL_HEADER_TYPE: return UString("Unknown PE optional header type"); + case U_UNKNOWN_RELOCATION_TYPE: return UString("Unknown relocation type"); + //case U_GENERIC_CALL_NOT_SUPPORTED: return UString("Generic call not supported"); + //case U_VOLUME_BASE_NOT_FOUND: return UString("Volume base address not found"); + //case U_PEI_CORE_ENTRY_POINT_NOT_FOUND: return UString("PEI core entry point not found"); + case U_COMPLEX_BLOCK_MAP: return UString("Block map structure too complex for correct analysis"); + case U_DIR_ALREADY_EXIST: return UString("Directory already exists"); + case U_DIR_CREATE: return UString("Directory can't be created"); + //case U_UNKNOWN_PATCH_TYPE: return UString("Unknown patch type"); + //case U_PATCH_OFFSET_OUT_OF_BOUNDS: return UString("Patch offset out of bounds"); + //case U_INVALID_SYMBOL: return UString("Invalid symbol"); + //case U_NOTHING_TO_PATCH: return UString("Nothing to patch"); + case U_DEPEX_PARSE_FAILED: return UString("Dependency expression parsing failed"); + case U_TRUNCATED_IMAGE: return UString("Image is truncated"); + case U_INVALID_CAPSULE: return UString("Invalid capsule"); + case U_STORES_NOT_FOUND: return UString("Stores not found"); + default: return usprintf("Unknown error %02X", errorCode); } } @@ -152,7 +152,7 @@ UINT32 crc32(UINT32 initial, const UINT8* buffer, const UINT32 length) } // Compression routines -STATUS decompress(const QByteArray & compressedData, UINT8 & algorithm, QByteArray & decompressedData, QByteArray & efiDecompressedData) +USTATUS decompress(const UByteArray & compressedData, UINT8 & algorithm, UByteArray & decompressedData, UByteArray & efiDecompressedData) { const UINT8* data; UINT32 dataSize; @@ -168,7 +168,7 @@ STATUS decompress(const QByteArray & compressedData, UINT8 & algorithm, QByteArr case EFI_NOT_COMPRESSED: decompressedData = compressedData; algorithm = COMPRESSION_ALGORITHM_NONE; - return ERR_SUCCESS; + return U_SUCCESS; case EFI_STANDARD_COMPRESSION: { // Set default algorithm to unknown algorithm = COMPRESSION_ALGORITHM_UNKNOWN; @@ -180,11 +180,11 @@ STATUS decompress(const QByteArray & compressedData, UINT8 & algorithm, QByteArr // Check header to be valid header = (const EFI_TIANO_HEADER*)data; if (header->CompSize + sizeof(EFI_TIANO_HEADER) != dataSize) - return ERR_STANDARD_DECOMPRESSION_FAILED; + return U_STANDARD_DECOMPRESSION_FAILED; // Get info function is the same for both algorithms - if (ERR_SUCCESS != EfiTianoGetInfo(data, dataSize, &decompressedSize, &scratchSize)) - return ERR_STANDARD_DECOMPRESSION_FAILED; + if (U_SUCCESS != EfiTianoGetInfo(data, dataSize, &decompressedSize, &scratchSize)) + return U_STANDARD_DECOMPRESSION_FAILED; // Allocate memory decompressed = (UINT8*)malloc(decompressedSize); @@ -194,31 +194,31 @@ STATUS decompress(const QByteArray & compressedData, UINT8 & algorithm, QByteArr if (decompressed) free(decompressed); if (efiDecompressed) free(efiDecompressed); if (scratch) free(scratch); - return ERR_STANDARD_DECOMPRESSION_FAILED; + return U_STANDARD_DECOMPRESSION_FAILED; } // Decompress section data using both algorithms - STATUS result = ERR_SUCCESS; + USTATUS result = U_SUCCESS; // Try Tiano - STATUS TianoResult = TianoDecompress(data, dataSize, decompressed, decompressedSize, scratch, scratchSize); + USTATUS TianoResult = TianoDecompress(data, dataSize, decompressed, decompressedSize, scratch, scratchSize); // Try EFI 1.1 - STATUS EfiResult = EfiDecompress(data, dataSize, efiDecompressed, decompressedSize, scratch, scratchSize); + USTATUS EfiResult = EfiDecompress(data, dataSize, efiDecompressed, decompressedSize, scratch, scratchSize); - if (EfiResult == ERR_SUCCESS && TianoResult == ERR_SUCCESS) { // Both decompressions are OK + if (EfiResult == U_SUCCESS && TianoResult == U_SUCCESS) { // Both decompressions are OK algorithm = COMPRESSION_ALGORITHM_UNDECIDED; - decompressedData = QByteArray((const char*)decompressed, decompressedSize); - efiDecompressedData = QByteArray((const char*)efiDecompressed, decompressedSize); + decompressedData = UByteArray((const char*)decompressed, decompressedSize); + efiDecompressedData = UByteArray((const char*)efiDecompressed, decompressedSize); } - else if (TianoResult == ERR_SUCCESS) { // Only Tiano is OK + else if (TianoResult == U_SUCCESS) { // Only Tiano is OK algorithm = COMPRESSION_ALGORITHM_TIANO; - decompressedData = QByteArray((const char*)decompressed, decompressedSize); + decompressedData = UByteArray((const char*)decompressed, decompressedSize); } - else if (EfiResult == ERR_SUCCESS) { // Only EFI 1.1 is OK + else if (EfiResult == U_SUCCESS) { // Only EFI 1.1 is OK algorithm = COMPRESSION_ALGORITHM_EFI11; - decompressedData = QByteArray((const char*)efiDecompressed, decompressedSize); + decompressedData = UByteArray((const char*)efiDecompressed, decompressedSize); } else { // Both decompressions failed - result = ERR_STANDARD_DECOMPRESSION_FAILED; + result = U_STANDARD_DECOMPRESSION_FAILED; } free(decompressed); @@ -235,47 +235,47 @@ STATUS decompress(const QByteArray & compressedData, UINT8 & algorithm, QByteArr dataSize = compressedData.size(); // Get info - if (ERR_SUCCESS != LzmaGetInfo(data, dataSize, &decompressedSize)) - return ERR_CUSTOMIZED_DECOMPRESSION_FAILED; + if (U_SUCCESS != LzmaGetInfo(data, dataSize, &decompressedSize)) + return U_CUSTOMIZED_DECOMPRESSION_FAILED; // Allocate memory decompressed = (UINT8*)malloc(decompressedSize); if (!decompressed) { - return ERR_STANDARD_DECOMPRESSION_FAILED; + return U_STANDARD_DECOMPRESSION_FAILED; } // Decompress section data - if (ERR_SUCCESS != LzmaDecompress(data, dataSize, decompressed)) { + if (U_SUCCESS != LzmaDecompress(data, dataSize, decompressed)) { // Intel modified LZMA workaround // Decompress section data once again data += sizeof(UINT32); // Get info again - if (ERR_SUCCESS != LzmaGetInfo(data, dataSize, &decompressedSize)) { + if (U_SUCCESS != LzmaGetInfo(data, dataSize, &decompressedSize)) { free(decompressed); - return ERR_CUSTOMIZED_DECOMPRESSION_FAILED; + return U_CUSTOMIZED_DECOMPRESSION_FAILED; } // Decompress section data again - if (ERR_SUCCESS != LzmaDecompress(data, dataSize, decompressed)) { + if (U_SUCCESS != LzmaDecompress(data, dataSize, decompressed)) { free(decompressed); - return ERR_CUSTOMIZED_DECOMPRESSION_FAILED; + return U_CUSTOMIZED_DECOMPRESSION_FAILED; } else { algorithm = COMPRESSION_ALGORITHM_IMLZMA; - decompressedData = QByteArray((const char*)decompressed, decompressedSize); + decompressedData = UByteArray((const char*)decompressed, decompressedSize); } } else { algorithm = COMPRESSION_ALGORITHM_LZMA; - decompressedData = QByteArray((const char*)decompressed, decompressedSize); + decompressedData = UByteArray((const char*)decompressed, decompressedSize); } free(decompressed); - return ERR_SUCCESS; + return U_SUCCESS; default: algorithm = COMPRESSION_ALGORITHM_UNKNOWN; - return ERR_UNKNOWN_COMPRESSION_TYPE; + return U_UNKNOWN_COMPRESSION_TYPE; } } diff --git a/common/utility.h b/common/utility.h index f594311..7378924 100644 --- a/common/utility.h +++ b/common/utility.h @@ -14,25 +14,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #ifndef UTILITY_H #define UTILITY_H -#include -#include +#include "ustring.h" +#include "umodelindex.h" #include "basetypes.h" #include "parsingdata.h" // Returns either new parsing data instance or obtains it from index -PARSING_DATA parsingDataFromQModelIndex(const QModelIndex & index); +PARSING_DATA parsingDataFromUModelIndex(const UModelIndex & index); // Converts parsing data to byte array -QByteArray parsingDataToQByteArray(const PARSING_DATA & pdata); +UByteArray parsingDataToUByteArray(const PARSING_DATA & pdata); -// Converts error code to QString -extern QString errorCodeToQString(UINT8 errorCode); +// Converts error code to UString +extern UString errorCodeToUString(UINT8 errorCode); // Decompression routine -extern STATUS decompress(const QByteArray & compressed, UINT8 & algorithm, QByteArray & decompressed, QByteArray & efiDecompressed); +extern USTATUS decompress(const UByteArray & compressed, UINT8 & algorithm, UByteArray & decompressed, UByteArray & efiDecompressed); // Compression routine -//STATUS compress(const QByteArray & decompressed, QByteArray & compressed, const UINT8 & algorithm); +//USTATUS compress(const UByteArray & decompressed, UByteArray & compressed, const UINT8 & algorithm); // CRC32 calculation routine extern UINT32 crc32(UINT32 initial, const UINT8* buffer, const UINT32 length);