diff --git a/UEFIExtract/uefiextract.cpp b/UEFIExtract/uefiextract.cpp index 3570764..1fd2557 100644 --- a/UEFIExtract/uefiextract.cpp +++ b/UEFIExtract/uefiextract.cpp @@ -40,20 +40,10 @@ UINT8 UEFIExtract::init(const QString & path) QByteArray buffer = inputFile.readAll(); inputFile.close(); - UINT8 result = ffsEngine->parseImageFile(buffer); - if (result) - return result; - - return ERR_SUCCESS; + return ffsEngine->parseImageFile(buffer); } UINT8 UEFIExtract::extract(QString guid) { - QModelIndex rootIndex = ffsEngine->treeModel()->index(0, 0); - - UINT8 result = ffsEngine->dump(rootIndex, fileInfo.fileName().append(".dump"), guid); - if (result) - return result; - - return ERR_SUCCESS; + return ffsEngine->dump(ffsEngine->treeModel()->index(0, 0), fileInfo.fileName().append(".dump"), guid); } \ No newline at end of file diff --git a/UEFIExtract/uefiextract_main.cpp b/UEFIExtract/uefiextract_main.cpp index b08b055..a8b1c17 100644 --- a/UEFIExtract/uefiextract_main.cpp +++ b/UEFIExtract/uefiextract_main.cpp @@ -25,45 +25,36 @@ int main(int argc, char *argv[]) UEFIExtract w; UINT8 result = ERR_SUCCESS; + UINT32 returned = 0; + + if (a.arguments().length() > 32) { + std::cout << "Too many arguments" << std::endl; + return 1; + } + if (a.arguments().length() > 1 ) { - w.init(a.arguments().at(1)); + if (w.init(a.arguments().at(1))) + return 1; if (a.arguments().length() == 2) { result = w.extract(); - switch (result) { - case ERR_DIR_ALREADY_EXIST: - std::cout << "Dump directory already exist, please remove it" << std::endl; - break; - case ERR_DIR_CREATE: - std::cout << "Can't create directory" << std::endl; - break; - case ERR_FILE_OPEN: - std::cout << "Can't create file" << std::endl; - break; - } + if (result) + return 2; } else { for (int i = 2; i < a.arguments().length(); i++) { result = w.extract(a.arguments().at(i)); - switch (result) { - case ERR_DIR_ALREADY_EXIST: - std::cout << "Dump directory already exist, please remove it" << std::endl; - break; - case ERR_DIR_CREATE: - std::cout << "Can't create directory" << std::endl; - break; - case ERR_FILE_OPEN: - std::cout << "Can't create file" << std::endl; - break; - } + if (result) + returned |= (1 << (i - 1)); } + return returned; } + } else { - result = ERR_INVALID_PARAMETER; - std::cout << "UEFIExtract 0.3.0" << std::endl << std::endl << - "Usage: uefiextract imagefile [FileGUID_1 FileGUID_2 ...]\n" << std::endl; - } - - return result; + std::cout << "UEFIExtract 0.3.1" << std::endl << std::endl << + "Usage: uefiextract imagefile [FileGUID_1 FileGUID_2 ... FileGUID_31]" << std::endl << + "Returned value is a bit mask where 0 on position N meant File with GUID_N was found and unpacked, 1 otherwise" << std::endl; + return 1; + } } \ No newline at end of file diff --git a/ffsengine.cpp b/ffsengine.cpp index 68241a3..4911284 100644 --- a/ffsengine.cpp +++ b/ffsengine.cpp @@ -193,7 +193,7 @@ void FfsEngine::msg(const QString & message, const QModelIndex & index) #ifndef _CONSOLE messageItems.enqueue(MessageListItem(message, NULL, 0, index)); #else - std::cout << message.toLatin1().constData() << std::endl; + std::cout << message.toLatin1().constData() << std::endl; #endif } @@ -3433,12 +3433,22 @@ UINT32 FfsEngine::crc32(UINT32 initial, const UINT8* buffer, UINT32 length) } UINT8 FfsEngine::dump(const QModelIndex & index, const QString & path, const QString & guid) +{ + dumped = false; + UINT8 result = recursiveDump(index, path, guid); + if (result) + return result; + else if (!dumped) + return ERR_ITEM_NOT_FOUND; + return ERR_SUCCESS; +} + +UINT8 FfsEngine::recursiveDump(const QModelIndex & index, const QString & path, const QString & guid) { if (!index.isValid()) return ERR_INVALID_PARAMETER; QDir dir; - if (guid.isEmpty() || guidToQString(*(EFI_GUID*)model->header(index).constData()) == guid || guidToQString(*(EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) { @@ -3476,13 +3486,14 @@ UINT8 FfsEngine::dump(const QModelIndex & index, const QString & path, const QSt return ERR_FILE_OPEN; file.write(info.toLatin1()); file.close(); - } + dumped = true; + } UINT8 result; for (int i = 0; i < model->rowCount(index); i++) { QModelIndex childIndex = index.child(i, 0); QString childPath = tr("%1/%2 %3").arg(path).arg(i).arg(model->textString(childIndex).isEmpty() ? model->nameString(childIndex) : model->textString(childIndex)); - result = dump(childIndex, childPath, guid); + result = recursiveDump(childIndex, childPath, guid); if (result) return result; } diff --git a/ffsengine.h b/ffsengine.h index 8d4a3c8..336bb92 100644 --- a/ffsengine.h +++ b/ffsengine.h @@ -141,6 +141,10 @@ private: // Internal operations bool hasIntersection(const UINT32 begin1, const UINT32 end1, const UINT32 begin2, const UINT32 end2); UINT32 crc32(UINT32 initial, const UINT8* buffer, UINT32 length); + + // Recursive dump + bool dumped; + UINT8 recursiveDump(const QModelIndex & index, const QString & path, const QString & filter); }; #endif