UEFIExtract 0.3.0

- added filtering by FFS file GUID, only specified files can now be
unpacked
This commit is contained in:
Nikolaj Schlej 2014-08-15 13:24:03 +02:00
parent 754f9c5b13
commit 701717c554
5 changed files with 99 additions and 64 deletions

View file

@ -24,9 +24,9 @@ UEFIExtract::~UEFIExtract()
delete ffsEngine;
}
UINT8 UEFIExtract::extractAll(QString path)
UINT8 UEFIExtract::init(const QString & path)
{
QFileInfo fileInfo = QFileInfo(path);
fileInfo = QFileInfo(path);
if (!fileInfo.exists())
return ERR_FILE_OPEN;
@ -44,8 +44,14 @@ UINT8 UEFIExtract::extractAll(QString path)
if (result)
return result;
return ERR_SUCCESS;
}
UINT8 UEFIExtract::extract(QString guid)
{
QModelIndex rootIndex = ffsEngine->treeModel()->index(0, 0);
result = ffsEngine->dump(rootIndex, fileInfo.fileName().append(".dump"));
UINT8 result = ffsEngine->dump(rootIndex, fileInfo.fileName().append(".dump"), guid);
if (result)
return result;

View file

@ -31,10 +31,13 @@ public:
explicit UEFIExtract(QObject *parent = 0);
~UEFIExtract();
UINT8 extractAll(QString path);
UINT8 init(const QString & path);
UINT8 extract(QString guid = QString());
private:
FfsEngine* ffsEngine;
QFileInfo fileInfo;
};
#endif

View file

@ -26,7 +26,10 @@ int main(int argc, char *argv[])
UEFIExtract w;
UINT8 result = ERR_SUCCESS;
if (a.arguments().length() > 1 ) {
result = w.extractAll(a.arguments().at(1));
w.init(a.arguments().at(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;
@ -39,10 +42,27 @@ int main(int argc, char *argv[])
break;
}
}
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;
}
}
}
}
else {
result = ERR_INVALID_PARAMETER;
std::cout << "UEFIExtract 0.2.2" << std::endl << std::endl <<
"Usage: uefiextract imagefile\n" << std::endl;
std::cout << "UEFIExtract 0.3.0" << std::endl << std::endl <<
"Usage: uefiextract imagefile [FileGUID_1 FileGUID_2 ...]\n" << std::endl;
}
return result;

View file

@ -3432,12 +3432,17 @@ UINT32 FfsEngine::crc32(UINT32 initial, const UINT8* buffer, UINT32 length)
return(crc32 ^ 0xFFFFFFFF);
}
UINT8 FfsEngine::dump(const QModelIndex & index, const QString path)
UINT8 FfsEngine::dump(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) {
if (dir.cd(path))
return ERR_DIR_ALREADY_EXIST;
@ -3471,12 +3476,13 @@ UINT8 FfsEngine::dump(const QModelIndex & index, const QString path)
return ERR_FILE_OPEN;
file.write(info.toLatin1());
file.close();
}
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);
result = dump(childIndex, childPath, guid);
if (result)
return result;
}

View file

@ -94,7 +94,7 @@ public:
UINT8 replace(const QModelIndex & index, const QByteArray & object, const UINT8 mode);
UINT8 remove(const QModelIndex & index);
UINT8 rebuild(const QModelIndex & index);
UINT8 dump(const QModelIndex & index, const QString path);
UINT8 dump(const QModelIndex & index, const QString & path, const QString & filter = QString());
UINT8 patch(const QModelIndex & index, const QVector<PatchData> & patches);
// Search routines