UE 0.11.0

- default behavior changed to only generate header.bin and body.bin for
leaf items, add "all" after file name to extract everything
This commit is contained in:
Nikolaj Schlej 2016-06-20 21:20:47 +02:00
parent ee3a256206
commit eb2d7c36f5
3 changed files with 39 additions and 31 deletions

View File

@ -22,10 +22,10 @@ FfsDumper::~FfsDumper()
{
}
STATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const QString & guid)
STATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const bool dumpAll, const QString & guid)
{
dumped = false;
UINT8 result = recursiveDump(root, path, guid);
UINT8 result = recursiveDump(root, path, dumpAll, guid);
if (result)
return result;
else if (!dumped)
@ -33,7 +33,7 @@ STATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const QSt
return ERR_SUCCESS;
}
STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, const QString & guid)
STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, const bool dumpAll, const QString & guid)
{
if (!index.isValid())
return ERR_INVALID_PARAMETER;
@ -50,29 +50,32 @@ STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path,
return ERR_DIR_CREATE;
QFile file;
if (!model->header(index).isEmpty()) {
file.setFileName(QObject::tr("%1/header.bin").arg(path));
if (!file.open(QFile::WriteOnly))
return ERR_FILE_OPEN;
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));
if (!file.open(QFile::WriteOnly))
return ERR_FILE_OPEN;
file.write(model->header(index));
file.close();
file.write(model->header(index));
file.close();
}
if (!model->body(index).isEmpty()) {
file.setFileName(QObject::tr("%1/body.bin").arg(path));
if (!file.open(QFile::WriteOnly))
return ERR_FILE_OPEN;
file.write(model->body(index));
file.close();
}
}
if (!model->body(index).isEmpty()) {
file.setFileName(QObject::tr("%1/body.bin").arg(path));
if (!file.open(QFile::WriteOnly))
return ERR_FILE_OPEN;
file.write(model->body(index));
file.close();
}
// 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));
.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));
if (!file.open(QFile::Text | QFile::WriteOnly))
return ERR_FILE_OPEN;
@ -90,7 +93,7 @@ STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path,
useText = !model->text(childIndex).isEmpty();
QString childPath = QString("%1/%2 %3").arg(path).arg(i).arg(useText ? model->text(childIndex) : model->name(childIndex));
result = recursiveDump(childIndex, childPath, guid);
result = recursiveDump(childIndex, childPath, dumpAll, guid);
if (result)
return result;
}

View File

@ -30,10 +30,10 @@ public:
explicit FfsDumper(TreeModel * treeModel);
~FfsDumper();
STATUS dump(const QModelIndex & root, const QString & path, const QString & guid = QString());
STATUS dump(const QModelIndex & root, const QString & path, const bool dumpAll = false, const QString & guid = QString());
private:
STATUS recursiveDump(const QModelIndex & root, const QString & path, const QString & guid);
STATUS recursiveDump(const QModelIndex & root, const QString & path, const bool dumpAll, const QString & guid);
TreeModel* model;
bool dumped;
};

View File

@ -97,14 +97,17 @@ int main(int argc, char *argv[])
// Create ffsDumper
FfsDumper ffsDumper(&model);
// Dump everyting
// Dump all non-leaf elements
if (a.arguments().length() == 2) {
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != ERR_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 { // Dump specific files
UINT32 returned = 0;
for (int i = 2; i < a.arguments().length(); i++) {
result = ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), a.arguments().at(i));
result = ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), true, a.arguments().at(i));
if (result)
returned |= (1 << (i - 1));
}
@ -112,9 +115,11 @@ int main(int argc, char *argv[])
}
}
else { // Show version and usage information
std::cout << "UEFIExtract 0.10.9" << std::endl << std::endl
<< "Usage: UEFIExtract imagefile [FileGUID_1 FileGUID_2 ... FileGUID_31]" << std::endl
<< "Return value is a bit mask where 0 at position N means that file with GUID_N was found and unpacked, 1 otherwise" << std::endl;
std::cout << "UEFIExtract 0.11.0" << std::endl << std::endl
<< "Usage: UEFIExtract imagefile - dumps only leaf tree items into .dump folder" << std::endl
<< " UEFIExtract imagefile all - dumps all tree items"
<< " UIFIExtract imagefile GUID_1 GUID_2 ... GUID_31 - dumps an FFS file(s) with specific GUID(s)"
<< "Return value is a bit mask where 0 at position N means that file with GUID_N was found and unpacked, 1 otherwise" << std::endl;
return 1;
}
}