From 0114a72fa57d3b4830eca9014cae840e3df27c05 Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Sat, 9 Jul 2016 10:01:41 +0200 Subject: [PATCH] Build fixes for Windows builds - now to test in OSX and Linux --- UEFIDump/uefidump.cpp | 9 +++---- UEFIFind/uefifind.cpp | 50 ++++++++++++-------------------------- UEFIFind/uefifind.h | 6 ++--- UEFIFind/uefifind_main.cpp | 20 +++++++-------- common/ffsparser.cpp | 4 +-- common/ustring.h | 1 + common/utility.cpp | 17 +++++++------ 7 files changed, 46 insertions(+), 61 deletions(-) diff --git a/UEFIDump/uefidump.cpp b/UEFIDump/uefidump.cpp index a66631d..df26ede 100644 --- a/UEFIDump/uefidump.cpp +++ b/UEFIDump/uefidump.cpp @@ -159,15 +159,14 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index) UString orgName = uniqueItemName(index); UString name = orgName; bool nameFound = false; - for (int i = 0; i < 0x10000; ++i) { - if (isExistOnFs(name)) { - name = orgName + UString("_") + usprintf("%04X", i); - } - else { + for (int i = 1; i < 1000; ++i) { + if (!isExistOnFs(name + UString("_info.txt"))) { nameFound = true; break; } + name = orgName + UString("_") + usprintf("%03d", i); } + if (!nameFound) return U_INVALID_PARAMETER; //TODO: replace with proper errorCode diff --git a/UEFIFind/uefifind.cpp b/UEFIFind/uefifind.cpp index 91eec33..ba6a376 100644 --- a/UEFIFind/uefifind.cpp +++ b/UEFIFind/uefifind.cpp @@ -27,20 +27,20 @@ UEFIFind::~UEFIFind() model = NULL; } -STATUS UEFIFind::init(const QString & path) +USTATUS UEFIFind::init(const QString & path) { - STATUS result; + USTATUS result; fileInfo = QFileInfo(path); if (!fileInfo.exists()) - return ERR_FILE_OPEN; + return U_FILE_OPEN; QFile inputFile; inputFile.setFileName(path); if (!inputFile.open(QFile::ReadOnly)) - return ERR_FILE_OPEN; + return U_FILE_OPEN; QByteArray buffer = inputFile.readAll(); inputFile.close(); @@ -50,42 +50,24 @@ STATUS UEFIFind::init(const QString & path) return result; initDone = true; - return ERR_SUCCESS; + return U_SUCCESS; } -QString UEFIFind::guidToQString(const UINT8* guid) -{ - const UINT32 u32 = *(const UINT32*)guid; - const UINT16 u16_1 = *(const UINT16*)(guid + 4); - const UINT16 u16_2 = *(const UINT16*)(guid + 6); - const UINT8 u8_1 = *(const UINT8*)(guid + 8); - const UINT8 u8_2 = *(const UINT8*)(guid + 9); - const UINT8 u8_3 = *(const UINT8*)(guid + 10); - const UINT8 u8_4 = *(const UINT8*)(guid + 11); - const UINT8 u8_5 = *(const UINT8*)(guid + 12); - const UINT8 u8_6 = *(const UINT8*)(guid + 13); - const UINT8 u8_7 = *(const UINT8*)(guid + 14); - const UINT8 u8_8 = *(const UINT8*)(guid + 15); - - return QString("%1-%2-%3-%4%5-%6%7%8%9%10%11").hexarg2(u32, 8).hexarg2(u16_1, 4).hexarg2(u16_2, 4).hexarg2(u8_1, 2).hexarg2(u8_2, 2) - .hexarg2(u8_3, 2).hexarg2(u8_4, 2).hexarg2(u8_5, 2).hexarg2(u8_6, 2).hexarg2(u8_7, 2).hexarg2(u8_8, 2); -} - -STATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result) +USTATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result) { QModelIndex root = model->index(0, 0); std::set > files; result.clear(); - STATUS returned = findFileRecursive(root, hexPattern, mode, files); + USTATUS returned = findFileRecursive(root, hexPattern, mode, files); if (returned) return returned; if (count) { if (!files.empty()) result.append(QString("%1\n").arg(files.size())); - return ERR_SUCCESS; + return U_SUCCESS; } for (std::set >::const_iterator citer = files.cbegin(); citer != files.cend(); ++citer) { @@ -93,30 +75,30 @@ STATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPat std::pair indexes = *citer; if (!model->hasEmptyHeader(indexes.first)) data = model->header(indexes.first).left(16); - result.append(guidToQString((const UINT8*)data.constData())); + result.append(guidToUString(*(const EFI_GUID*)data.constData())); // Special case of freeform subtype GUID files if (indexes.second.isValid() && model->subtype(indexes.second) == EFI_SECTION_FREEFORM_SUBTYPE_GUID) { data = model->header(indexes.second).left(sizeof(EFI_FREEFORM_SUBTYPE_GUID_SECTION)); - result.append(" ").append(guidToQString((const UINT8*)data.constData() + sizeof(EFI_COMMON_SECTION_HEADER))); + result.append(" ").append(guidToUString(*(const EFI_GUID*)(data.constData() + sizeof(EFI_COMMON_SECTION_HEADER)))); } result.append("\n"); } - return ERR_SUCCESS; + return U_SUCCESS; } -STATUS UEFIFind::findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, std::set > & files) +USTATUS UEFIFind::findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, std::set > & files) { if (!index.isValid()) - return ERR_SUCCESS; + return U_SUCCESS; if (hexPattern.isEmpty()) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Check for "all substrings" pattern if (hexPattern.count('.') == hexPattern.length()) - return ERR_SUCCESS; + return U_SUCCESS; bool hasChildren = (model->rowCount(index) > 0); for (int i = 0; i < model->rowCount(index); i++) { @@ -157,5 +139,5 @@ STATUS UEFIFind::findFileRecursive(const QModelIndex index, const QString & hexP offset = regexp.indexIn(hexBody, offset + 1); } - return ERR_SUCCESS; + return U_SUCCESS; } \ No newline at end of file diff --git a/UEFIFind/uefifind.h b/UEFIFind/uefifind.h index 4b76a82..69cd1a5 100644 --- a/UEFIFind/uefifind.h +++ b/UEFIFind/uefifind.h @@ -34,11 +34,11 @@ public: explicit UEFIFind(); ~UEFIFind(); - STATUS init(const QString & path); - STATUS find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result); + USTATUS init(const QString & path); + USTATUS find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result); private: - STATUS findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, std::set > & files); + USTATUS findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, std::set > & files); QString guidToQString(const UINT8* guid); FfsParser* ffsParser; diff --git a/UEFIFind/uefifind_main.cpp b/UEFIFind/uefifind_main.cpp index 079e8d2..a6a991d 100644 --- a/UEFIFind/uefifind_main.cpp +++ b/UEFIFind/uefifind_main.cpp @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) else if (a.arguments().at(1) == QString("all")) mode = SEARCH_MODE_ALL; else - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Get result type bool count; @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) else if (a.arguments().at(2) == QString("count")) count = true; else - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Parse input file result = w.init(a.arguments().at(4)); @@ -58,26 +58,26 @@ int main(int argc, char *argv[]) // Nothing is found if (found.isEmpty()) - return ERR_ITEM_NOT_FOUND; + return U_ITEM_NOT_FOUND; // Print result std::cout << found.toStdString(); - return ERR_SUCCESS; + return U_SUCCESS; } else if (a.arguments().length() == 4) { // Get search mode if (a.arguments().at(1) != QString("file")) - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; // Open patterns file QFileInfo fileInfo(a.arguments().at(2)); if (!fileInfo.exists()) - return ERR_FILE_OPEN; + return U_FILE_OPEN; QFile patternsFile; patternsFile.setFileName(a.arguments().at(2)); if (!patternsFile.open(QFile::ReadOnly)) - return ERR_FILE_OPEN; + return U_FILE_OPEN; // Parse input file result = w.init(a.arguments().at(3)); @@ -143,15 +143,15 @@ int main(int argc, char *argv[]) // Nothing is found if (!somethingFound) - return ERR_ITEM_NOT_FOUND; + return U_ITEM_NOT_FOUND; - return ERR_SUCCESS; + return U_SUCCESS; } else { std::cout << "UEFIFind 0.10.6" << std::endl << std::endl << "Usage: UEFIFind {header | body | all} {list | count} pattern imagefile" << std::endl << " or UEFIFind file patternsfile imagefile" << std::endl; - return ERR_INVALID_PARAMETER; + return U_INVALID_PARAMETER; } } diff --git a/common/ffsparser.cpp b/common/ffsparser.cpp index a584b53..21ae946 100644 --- a/common/ffsparser.cpp +++ b/common/ffsparser.cpp @@ -4086,7 +4086,7 @@ USTATUS FfsParser::parseSlicPubkeyHeader(const UByteArray & store, const UINT32 // Add info 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", + "Key type: %02Xh\nVersion: %02Xh\nAlgorithm: %08Xh\nMagic: RSA1\nBit length: %08Xh\nExponent: %08Xh", pubkeyHeader->Size, pubkeyHeader->Size, header.size(), header.size(), pubkeyHeader->KeyType, @@ -4134,7 +4134,7 @@ USTATUS FfsParser::parseSlicMarkerHeader(const UByteArray & store, const UINT32 // Add info 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", + "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, diff --git a/common/ustring.h b/common/ustring.h index 3c6afa4..171c7ec 100644 --- a/common/ustring.h +++ b/common/ustring.h @@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // Use Qt class, if Qt is available #include #define UString QString +#define findreplace replace #else // Use Bstrlib #define BSTRLIB_DOESNT_THROW_EXCEPTIONS diff --git a/common/utility.cpp b/common/utility.cpp index 49529be..a678200 100644 --- a/common/utility.cpp +++ b/common/utility.cpp @@ -52,7 +52,7 @@ UString uniqueItemName(const UModelIndex & index) return UString("Invalid index"); // Get model from index - const TreeModel* model = index.model(); + const TreeModel* model = (const TreeModel*)index.model(); // Get data from parsing data PARSING_DATA pdata = parsingDataFromUModelIndex(index); @@ -64,7 +64,7 @@ UString uniqueItemName(const UModelIndex & index) // Default name UString name = itemName; switch (model->type(index)) { - case Types::Volume: + case Types::Volume: if (pdata.volume.hasExtendedHeader) name = guidToUString(pdata.volume.extendedHeaderGuid); break; case Types::NvarEntry: @@ -72,19 +72,22 @@ UString uniqueItemName(const UModelIndex & index) case Types::FsysEntry: case Types::EvsaEntry: case Types::FlashMapEntry: - case Types::File: - name = itemText.isEmpty() ? itemName : itemText; + case Types::File: + name = itemText.isEmpty() ? itemName : itemName + '_' + itemText; break; case Types::Section: { // Get parent file name UModelIndex fileIndex = model->findParentOfType(index, Types::File); UString fileText = model->text(fileIndex); - name = fileText.isEmpty() ? model->name(fileIndex) : fileText; - // Append section subtype name - name += '_' + itemName; + name = fileText.isEmpty() ? model->name(fileIndex) : model->name(fileIndex) + '_' + fileText; } break; } + UString subtypeString = itemSubtypeToUString(model->type(index), model->subtype(index)); + name = itemTypeToUString(model->type(index)) + + (subtypeString.length() ? ('_' + subtypeString) : UString()) + + '_' + name; + name.findreplace(' ', '_'); name.findreplace('/', '_'); name.findreplace('-', '_');