UEFIExtract 0.3.1

- added return value as bit mask
This commit is contained in:
Nikolaj Schlej 2014-08-16 15:54:42 +02:00
parent 701717c554
commit af63fe9852
4 changed files with 41 additions and 45 deletions

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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