From c9db871c126e058146fe09bca7726dba5c8521a7 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Fri, 13 Jul 2018 00:17:08 +0300 Subject: [PATCH] Rough attempt to deglue UEFIExtract from Qt --- UEFIDump/CMakeLists.txt | 1 + UEFIDump/uefidump.cpp | 32 +-------- UEFIExtract/CMakeLists.txt | 58 ++++++++++++++++ UEFIExtract/ffsdumper.cpp | 104 ++++++++++++++------------- UEFIExtract/ffsdumper.h | 17 ++--- UEFIExtract/uefiextract.pro | 55 --------------- UEFIExtract/uefiextract_main.cpp | 116 ++++++++++++++----------------- common/filesystem.h | 51 ++++++++++++++ unixbuild.sh | 2 +- 9 files changed, 227 insertions(+), 209 deletions(-) create mode 100644 UEFIExtract/CMakeLists.txt delete mode 100644 UEFIExtract/uefiextract.pro create mode 100644 common/filesystem.h diff --git a/UEFIDump/CMakeLists.txt b/UEFIDump/CMakeLists.txt index 0663fc8..945509f 100644 --- a/UEFIDump/CMakeLists.txt +++ b/UEFIDump/CMakeLists.txt @@ -50,6 +50,7 @@ SET(PROJECT_HEADERS ../common/sha256.h ../common/bstrlib/bstrlib.h ../common/bstrlib/bstrwrap.h + ../common/filesystem.h ../version.h ) diff --git a/UEFIDump/uefidump.cpp b/UEFIDump/uefidump.cpp index df2849d..c72bba7 100644 --- a/UEFIDump/uefidump.cpp +++ b/UEFIDump/uefidump.cpp @@ -14,41 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "uefidump.h" #include "../common/ffs.h" #include "../common/utility.h" +#include "../common/filesystem.h" #include #include #include #include -#include - -#ifdef WIN32 -#include -bool isExistOnFs(const UString & path) { - struct _stat buf; - return (_stat((const char*)path.toLocal8Bit(), &buf) == 0); -} - -bool makeDirectory(const UString & dir) { - return (_mkdir((const char*)dir.toLocal8Bit()) == 0); -} - -bool changeDirectory(const UString & dir) { - return (_chdir((const char*)dir.toLocal8Bit()) == 0); -} -#else -#include -bool isExistOnFs(const UString & path) { - struct stat buf; - return (stat((const char*)path.toLocal8Bit(), &buf) == 0); -} - -bool makeDirectory(const UString & dir) { - return (mkdir((const char*)dir.toLocal8Bit(), ACCESSPERMS) == 0); -} - -bool changeDirectory(const UString & dir) { - return (chdir((const char*)dir.toLocal8Bit()) == 0); -} -#endif USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, const UString & guid) { diff --git a/UEFIExtract/CMakeLists.txt b/UEFIExtract/CMakeLists.txt new file mode 100644 index 0000000..c26f5ac --- /dev/null +++ b/UEFIExtract/CMakeLists.txt @@ -0,0 +1,58 @@ +PROJECT(UEFIExtract) + +SET(PROJECT_SOURCES + uefiextract_main.cpp + ffsdumper.cpp + ../common/guiddatabase.cpp + ../common/types.cpp + ../common/descriptor.cpp + ../common/ffs.cpp + ../common/nvram.cpp + ../common/nvramparser.cpp + ../common/ffsparser.cpp + ../common/ffsreport.cpp + ../common/peimage.cpp + ../common/treeitem.cpp + ../common/treemodel.cpp + ../common/utility.cpp + ../common/LZMA/LzmaDecompress.c + ../common/LZMA/SDK/C/LzmaDec.c + ../common/Tiano/EfiTianoDecompress.c + ../common/ustring.cpp + ../common/sha256.c + ../common/bstrlib/bstrlib.c + ../common/bstrlib/bstrwrap.cpp +) + +SET(PROJECT_HEADERS + ffsdumper.h + ../common/guiddatabase.h + ../common/basetypes.h + ../common/descriptor.h + ../common/gbe.h + ../common/me.h + ../common/ffs.h + ../common/nvram.h + ../common/nvramparser.h + ../common/ffsparser.h + ../common/ffsreport.h + ../common/peimage.h + ../common/types.h + ../common/treeitem.h + ../common/treemodel.h + ../common/utility.h + ../common/LZMA/LzmaDecompress.h + ../common/Tiano/EfiTianoDecompress.h + ../common/ubytearray.h + ../common/ustring.h + ../common/bootguard.h + ../common/sha256.h + ../common/filesystem.h + ../common/bstrlib/bstrlib.h + ../common/bstrlib/bstrwrap.h + ../version.h +) + +ADD_DEFINITIONS(-DU_ENABLE_NVRAM_PARSING_SUPPORT) + +ADD_EXECUTABLE(UEFIExtract ${PROJECT_SOURCES} ${PROJECT_HEADERS}) \ No newline at end of file diff --git a/UEFIExtract/ffsdumper.cpp b/UEFIExtract/ffsdumper.cpp index 0b52894..b8dd12c 100644 --- a/UEFIExtract/ffsdumper.cpp +++ b/UEFIExtract/ffsdumper.cpp @@ -13,13 +13,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "ffsdumper.h" -USTATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const DumpMode dumpMode, const UINT8 sectionType, const QString & guid) +#include + +USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid) { dumped = false; - counter = 0; + counterHeader = counterBody = counterRaw = counterInfo = 0; - QDir dir; - if (dir.cd(path)) + if (changeDirectory(path)) return U_DIR_ALREADY_EXIST; UINT8 result = recursiveDump(root, path, dumpMode, sectionType, guid); @@ -30,49 +31,50 @@ USTATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const Du return U_SUCCESS; } -USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, const DumpMode dumpMode, const UINT8 sectionType, const QString & guid) +USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid) { if (!index.isValid()) return U_INVALID_PARAMETER; - QDir dir; if (guid.isEmpty() || (model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID && guidToUString(*(const EFI_GUID*)(model->header(index).constData() + sizeof(EFI_COMMON_SECTION_HEADER))) == 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) && !dir.mkpath(path)) + if (!changeDirectory(path) && !makeDirectory(path)) return U_DIR_CREATE; - QFile file; + counterHeader = counterBody = counterRaw = counterInfo = 0; + + std::ofstream file; if (dumpMode == DUMP_ALL || model->rowCount(index) == 0) { // Dump if leaf item or dumpAll is true if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER) { if (!model->header(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) { - if (counter == 0) - file.setFileName(QObject::tr("%1/header.bin").arg(path)); + UString filename; + if (counterHeader == 0) + filename = usprintf("%s/header.bin", (const char *)path.toLocal8Bit()); else - file.setFileName(QObject::tr("%1/header_%2.bin").arg(path).arg(counter)); - counter++; - if (!file.open(QFile::WriteOnly)) - return U_FILE_OPEN; - - file.write(model->header(index)); + filename = usprintf("%s/header_%d.bin", (const char *)path.toLocal8Bit(), counterHeader); + counterHeader++; + file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary); + const UByteArray &data = model->header(index); + file.write(data.constData(), data.size()); file.close(); } } if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY) { if (!model->body(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) { - if (counter == 0) - file.setFileName(QObject::tr("%1/body.bin").arg(path)); + UString filename; + if (counterBody == 0) + filename = usprintf("%s/body.bin", (const char *)path.toLocal8Bit()); else - file.setFileName(QObject::tr("%1/body_%2.bin").arg(path).arg(counter)); - counter++; - if (!file.open(QFile::WriteOnly)) - return U_FILE_OPEN; - - file.write(model->body(index)); + filename = usprintf("%s/body_%d.bin", (const char *)path.toLocal8Bit(), counterBody); + counterBody++; + file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary); + const UByteArray &data = model->body(index); + file.write(data.constData(), data.size()); file.close(); } } @@ -81,16 +83,19 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path UModelIndex fileIndex = model->findParentOfType(index, Types::File); if (!fileIndex.isValid()) fileIndex = index; - if (counter == 0) - file.setFileName(QObject::tr("%1/file.ffs").arg(path)); + UString filename; + if (counterRaw == 0) + filename = usprintf("%s/file.ffs", (const char *)path.toLocal8Bit()); else - file.setFileName(QObject::tr("%1/file_%2.ffs").arg(path).arg(counter)); - counter++; - if (!file.open(QFile::WriteOnly)) - return U_FILE_OPEN; - file.write(model->header(fileIndex)); - file.write(model->body(fileIndex)); - file.write(model->tail(fileIndex)); + filename = usprintf("%s/file_%d.bin", (const char *)path.toLocal8Bit(), counterRaw); + counterRaw++; + file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary); + const UByteArray &headerData = model->header(index); + const UByteArray &bodyData = model->body(index); + const UByteArray &tailData = model->tail(index); + file.write(headerData.constData(), headerData.size()); + file.write(bodyData.constData(), bodyData.size()); + file.write(tailData.constData(), tailData.size()); file.close(); } } @@ -98,20 +103,20 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path // Always dump info unless explicitly prohibited if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_INFO) && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) { - QString info = QObject::tr("Type: %1\nSubtype: %2\n%3%4\n") - .arg(itemTypeToUString(model->type(index))) - .arg(itemSubtypeToUString(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)); - if (counter == 0) - file.setFileName(QObject::tr("%1/info.txt").arg(path)); + UString info = usprintf("Type: %s\nSubtype: %s\n%s%s\n", + (const char *)itemTypeToUString(model->type(index)).toLocal8Bit(), + (const char *)itemSubtypeToUString(model->type(index), model->subtype(index)).toLocal8Bit(), + (const char *)(model->text(index).isEmpty() ? UString("") : + usprintf("Text: %s\n", (const char *)model->text(index).toLocal8Bit())).toLocal8Bit(), + (const char *)model->info(index).toLocal8Bit()); + UString filename; + if (counterInfo == 0) + filename = usprintf("%s/info.txt", (const char *)path.toLocal8Bit()); else - file.setFileName(QObject::tr("%1/info_%2.txt").arg(path).arg(counter)); - counter++; - if (!file.open(QFile::Text | QFile::WriteOnly)) - return U_FILE_OPEN; - - file.write(info.toLatin1()); + filename = usprintf("%s/info_%d.txt", (const char *)path.toLocal8Bit(), counterInfo); + counterInfo++; + file.open((const char *)filename.toLocal8Bit()); + file << (const char *)info.toLocal8Bit(); file.close(); } @@ -120,14 +125,15 @@ USTATUS 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 = path; + UString childPath = path; if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT) - childPath = QString("%1/%2 %3").arg(path).arg(i).arg(useText ? model->text(childIndex) : model->name(childIndex)); + childPath = usprintf("%s/%d %s", (const char *)path.toLocal8Bit(), i, + (const char *)(useText ? model->text(childIndex) : model->name(childIndex)).toLocal8Bit()); result = recursiveDump(childIndex, childPath, dumpMode, sectionType, guid); if (result) return result; diff --git a/UEFIExtract/ffsdumper.h b/UEFIExtract/ffsdumper.h index 870bff4..b09be31 100644 --- a/UEFIExtract/ffsdumper.h +++ b/UEFIExtract/ffsdumper.h @@ -14,15 +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 "../common/basetypes.h" +#include "../common/ustring.h" #include "../common/treemodel.h" #include "../common/ffs.h" +#include "../common/filesystem.h" class FfsDumper { @@ -38,15 +34,16 @@ public: static const UINT8 IgnoreSectionType = 0xFF; - explicit FfsDumper(TreeModel * treeModel) : model(treeModel), dumped(false), counter(0) {} + explicit FfsDumper(TreeModel * treeModel) : model(treeModel), dumped(false), + counterHeader(0), counterBody(0), counterRaw(0), counterInfo(0) {} ~FfsDumper() {}; - USTATUS dump(const QModelIndex & root, const QString & path, const DumpMode dumpMode = DUMP_CURRENT, const UINT8 sectionType = IgnoreSectionType, const QString & guid = QString()); + USTATUS dump(const UModelIndex & root, const UString & path, const DumpMode dumpMode = DUMP_CURRENT, const UINT8 sectionType = IgnoreSectionType, const UString & guid = UString()); private: - USTATUS recursiveDump(const QModelIndex & root, const QString & path, const DumpMode dumpMode, const UINT8 sectionType, const QString & guid); + USTATUS recursiveDump(const UModelIndex & root, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid); TreeModel* model; bool dumped; - int counter; + int counterHeader, counterBody, counterRaw, counterInfo; }; #endif // FFSDUMPER_H diff --git a/UEFIExtract/uefiextract.pro b/UEFIExtract/uefiextract.pro deleted file mode 100644 index 2830f2c..0000000 --- a/UEFIExtract/uefiextract.pro +++ /dev/null @@ -1,55 +0,0 @@ -QT += core -QT -= gui - -TARGET = UEFIExtract -TEMPLATE = app -CONFIG += console -CONFIG -= app_bundle -DEFINES += "U_ENABLE_NVRAM_PARSING_SUPPORT" - -SOURCES += \ - uefiextract_main.cpp \ - ffsdumper.cpp \ - ../common/guiddatabase.cpp \ - ../common/types.cpp \ - ../common/descriptor.cpp \ - ../common/ffs.cpp \ - ../common/nvram.cpp \ - ../common/nvramparser.cpp \ - ../common/ffsparser.cpp \ - ../common/ffsreport.cpp \ - ../common/peimage.cpp \ - ../common/treeitem.cpp \ - ../common/treemodel.cpp \ - ../common/utility.cpp \ - ../common/LZMA/LzmaDecompress.c \ - ../common/LZMA/SDK/C/LzmaDec.c \ - ../common/Tiano/EfiTianoDecompress.c \ - ../common/ustring.cpp \ - ../common/sha256.c - -HEADERS += \ - ffsdumper.h \ - ../common/guiddatabase.h \ - ../common/basetypes.h \ - ../common/descriptor.h \ - ../common/gbe.h \ - ../common/me.h \ - ../common/ffs.h \ - ../common/nvram.h \ - ../common/nvramparser.h \ - ../common/ffsparser.h \ - ../common/ffsreport.h \ - ../common/peimage.h \ - ../common/types.h \ - ../common/treeitem.h \ - ../common/treemodel.h \ - ../common/utility.h \ - ../common/LZMA/LzmaDecompress.h \ - ../common/Tiano/EfiTianoDecompress.h \ - ../common/ubytearray.h \ - ../common/ustring.h \ - ../common/bootguard.h \ - ../common/sha256.h \ - ../version.h - diff --git a/UEFIExtract/uefiextract_main.cpp b/UEFIExtract/uefiextract_main.cpp index a909eb0..afb58ab 100644 --- a/UEFIExtract/uefiextract_main.cpp +++ b/UEFIExtract/uefiextract_main.cpp @@ -7,13 +7,16 @@ 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 -#include -#include #include +#include +#include +#include #include "../version.h" +#include "../common/basetypes.h" +#include "../common/ustring.h" +#include "../common/filesystem.h" #include "../common/ffsparser.h" #include "../common/ffsreport.h" #include "ffsdumper.h" @@ -27,26 +30,17 @@ enum ReadType { int main(int argc, char *argv[]) { - QCoreApplication a(argc, argv); - a.setOrganizationName("LongSoft"); - a.setOrganizationDomain("longsoft.me"); - a.setApplicationName("UEFIExtract"); - - if (a.arguments().length() > 1) { + if (argc > 1) { // Check that input file exists - QString path = a.arguments().at(1); - QFileInfo fileInfo(path); - if (!fileInfo.exists()) + UString path = argv[1]; + if (!isExistOnFs(path)) return U_FILE_OPEN; // Open the input file - QFile inputFile; - inputFile.setFileName(path); - if (!inputFile.open(QFile::ReadOnly)) - return U_FILE_OPEN; - - // Read and close the file - QByteArray buffer = inputFile.readAll(); + std::ifstream inputFile; + inputFile.open(argv[1], std::ios::in | std::ios::binary); + std::vector buffer(std::istreambuf_iterator(inputFile), + (std::istreambuf_iterator())); inputFile.close(); // Create model and ffsParser @@ -58,24 +52,24 @@ int main(int argc, char *argv[]) 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; + std::cout << (const char *)messages[i].first.toLocal8Bit() << std::endl; } // Get last VTF - std::vector, QModelIndex > > fitTable = ffsParser.getFitTable(); + std::vector, UModelIndex > > fitTable = ffsParser.getFitTable(); if (fitTable.size()) { std::cout << "---------------------------------------------------------------------------" << std::endl; std::cout << " Address | Size | Ver | CS | Type / Info " << std::endl; std::cout << "---------------------------------------------------------------------------" << std::endl; for (size_t i = 0; i < fitTable.size(); i++) { - std::cout << fitTable[i].first[0].toLatin1().constData() << " | " - << fitTable[i].first[1].toLatin1().constData() << " | " - << fitTable[i].first[2].toLatin1().constData() << " | " - << fitTable[i].first[3].toLatin1().constData() << " | " - << fitTable[i].first[4].toLatin1().constData() << " | " - << fitTable[i].first[5].toLatin1().constData() << std::endl; + std::cout << (const char *)fitTable[i].first[0].toLocal8Bit() << " | " + << (const char *)fitTable[i].first[1].toLocal8Bit() << " | " + << (const char *)fitTable[i].first[2].toLocal8Bit() << " | " + << (const char *)fitTable[i].first[3].toLocal8Bit() << " | " + << (const char *)fitTable[i].first[4].toLocal8Bit() << " | " + << (const char *)fitTable[i].first[5].toLocal8Bit() << std::endl; } } @@ -84,27 +78,27 @@ int main(int argc, char *argv[]) FfsDumper ffsDumper(&model); // Dump only leaf elements, no report - if (a.arguments().length() == 3 && a.arguments().at(2) == QString("dump")) { - return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS); + if (argc == 3 && !std::strcmp(argv[2], "dump")) { + return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS); } - else if (a.arguments().length() > 3 || - (a.arguments().length() == 3 && a.arguments().at(2) != QString("all") && a.arguments().at(2) != QString("report"))) { // Dump specific files, without report - std::vector inputs, outputs; + else if (argc > 3 || + (argc == 3 && std::strcmp(argv[2], "all") != 0 && std::strcmp(argv[2], "report") != 0)) { // Dump specific files, without report + std::vector inputs, outputs; std::vector modes; std::vector sectionTypes; ReadType readType = READ_INPUT; - for (int i = 2; i < a.arguments().length(); i++) { - QString arg = a.arguments().at(i); - if (arg == QString("-i")) { + for (int i = 2; i < argc; i++) { + const char *arg = argv[i]; + if (!std::strcmp(arg, "-i")) { readType = READ_INPUT; continue; - } else if (arg == QString("-o")) { + } else if (!std::strcmp(arg, "-o")) { readType = READ_OUTPUT; continue; - } else if (arg == QString("-m")) { + } else if (!std::strcmp(arg, "-m")) { readType = READ_MODE; continue; - } else if (arg == QString("-t")) { + } else if (!std::strcmp(arg, "-t")) { readType = READ_SECTION; continue; } @@ -114,22 +108,22 @@ int main(int argc, char *argv[]) } else if (readType == READ_OUTPUT) { outputs.push_back(arg); } else if (readType == READ_MODE) { - if (arg == QString("all")) + if (!std::strcmp(arg, "all")) modes.push_back(FfsDumper::DUMP_ALL); - else if (arg == QString("body")) + else if (!std::strcmp(arg, "body")) modes.push_back(FfsDumper::DUMP_BODY); - else if (arg == QString("header")) + else if (!std::strcmp(arg, "header")) modes.push_back(FfsDumper::DUMP_HEADER); - else if (arg == QString("info")) + else if (!std::strcmp(arg, "info")) modes.push_back(FfsDumper::DUMP_INFO); - else if (arg == QString("file")) + else if (!std::strcmp(arg, "file")) modes.push_back(FfsDumper::DUMP_FILE); else return U_INVALID_PARAMETER; } else if (readType == READ_SECTION) { - bool converted; - UINT8 sectionType = (UINT8)arg.toUShort(&converted, 16); - if (!converted) + char *converted = const_cast(arg); + UINT8 sectionType = (UINT8)std::strtol(arg, &converted, 16); + if (converted == arg) return U_INVALID_PARAMETER; sectionTypes.push_back(sectionType); } @@ -141,12 +135,12 @@ int main(int argc, char *argv[]) USTATUS lastError = U_SUCCESS; for (size_t i = 0; i < inputs.size(); i++) { - QString outPath = outputs.empty() ? fileInfo.fileName().append(".dump") : outputs[i]; + UString outPath = outputs.empty() ? path + UString(".dump") : outputs[i]; FfsDumper::DumpMode mode = modes.empty() ? FfsDumper::DUMP_ALL : modes[i]; UINT8 type = sectionTypes.empty() ? FfsDumper::IgnoreSectionType : sectionTypes[i]; result = ffsDumper.dump(model.index(0, 0), outPath, mode, type, inputs[i]); if (result) { - std::cout << "Guid " << inputs[i].toStdString() << " failed with " << result << " code!" << std::endl; + std::cout << "Guid " << (const char *)inputs[i].toLocal8Bit() << " failed with " << result << " code!" << std::endl; lastError = result; } } @@ -156,26 +150,22 @@ 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")); - if (file.open(QFile::Text | QFile::WriteOnly)) { - for (size_t i = 0; i < report.size(); i++) { - file.write(report[i].toLatin1().append('\n')); - } - file.close(); - } + std::ofstream file; + file.open((const char *)(path + UString(".report.txt")).toLocal8Bit()); + for (size_t i = 0; i < report.size(); i++) + file << (const char *)report[i].toLocal8Bit() << '\n'; } // Dump all non-leaf elements, with report, default - if (a.arguments().length() == 2) { - return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS); + if (argc == 2) { + return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS); } - else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("all")) { // Dump every elementm with report - return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), FfsDumper::DUMP_ALL) != U_SUCCESS); + else if (argc == 3 && !std::strcmp(argv[2], "all")) { // Dump every elementm with report + return (ffsDumper.dump(model.index(0, 0), path + UString(".dump"), FfsDumper::DUMP_ALL) != U_SUCCESS); } - else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("report")) { // Skip dumping + else if (argc == 3 && !std::strcmp(argv[2], "report")) { // Skip dumping return 0; } } diff --git a/common/filesystem.h b/common/filesystem.h new file mode 100644 index 0000000..904cab6 --- /dev/null +++ b/common/filesystem.h @@ -0,0 +1,51 @@ +/* filesystem.h + +Copyright (c) 2015, 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 FILESYSTEM_H +#define FILESYSTEM_H + +#include "basetypes.h" +#include "ustring.h" +#include + +#ifdef WIN32 +#include +static inline bool isExistOnFs(const UString & path) { + struct _stat buf; + return (_stat((const char*)path.toLocal8Bit(), &buf) == 0); +} + +static inline bool makeDirectory(const UString & dir) { + return (_mkdir((const char*)dir.toLocal8Bit()) == 0); +} + +static inline bool changeDirectory(const UString & dir) { + return (_chdir((const char*)dir.toLocal8Bit()) == 0); +} +#else +#include +static inline bool isExistOnFs(const UString & path) { + struct stat buf; + return (stat((const char*)path.toLocal8Bit(), &buf) == 0); +} + +static inline bool makeDirectory(const UString & dir) { + return (mkdir((const char*)dir.toLocal8Bit(), ACCESSPERMS) == 0); +} + +static inline bool changeDirectory(const UString & dir) { + return (chdir((const char*)dir.toLocal8Bit()) == 0); +} +#endif + +#endif diff --git a/unixbuild.sh b/unixbuild.sh index ef72aba..fcfde94 100755 --- a/unixbuild.sh +++ b/unixbuild.sh @@ -114,7 +114,7 @@ mkdir -p dist || exit 1 build_tool UEFITool "$UEFITOOL_VER" uefitool.pro build_tool UEFIDump "$UEFITOOL_VER" "" -build_tool UEFIExtract "$UEFITOOL_VER" uefiextract.pro +build_tool UEFIExtract "$UEFITOOL_VER" "" build_tool UEFIFind "$UEFITOOL_VER" uefifind.pro exit 0