UE 0.10.8 / UF 0.10.6

- removed usage of QSet, QPair and Q_FOREACH
- removed dependency from QObject for FfsDumper and UEFIFind classes
This commit is contained in:
Nikolaj Schlej 2016-03-01 09:12:37 +01:00
parent 4a7bacb270
commit f729dd58b7
6 changed files with 30 additions and 39 deletions

View File

@ -13,8 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "ffsdumper.h" #include "ffsdumper.h"
FfsDumper::FfsDumper(TreeModel* treeModel, QObject *parent) FfsDumper::FfsDumper(TreeModel* treeModel)
: QObject(parent), model(treeModel), dumped(false) : model(treeModel), dumped(false)
{ {
} }
@ -51,7 +51,7 @@ STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path,
QFile file; QFile file;
if (!model->header(index).isEmpty()) { if (!model->header(index).isEmpty()) {
file.setFileName(tr("%1/header.bin").arg(path)); file.setFileName(QObject::tr("%1/header.bin").arg(path));
if (!file.open(QFile::WriteOnly)) if (!file.open(QFile::WriteOnly))
return ERR_FILE_OPEN; return ERR_FILE_OPEN;
@ -60,7 +60,7 @@ STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path,
} }
if (!model->body(index).isEmpty()) { if (!model->body(index).isEmpty()) {
file.setFileName(tr("%1/body.bin").arg(path)); file.setFileName(QObject::tr("%1/body.bin").arg(path));
if (!file.open(QFile::WriteOnly)) if (!file.open(QFile::WriteOnly))
return ERR_FILE_OPEN; return ERR_FILE_OPEN;
@ -68,12 +68,12 @@ STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path,
file.close(); file.close();
} }
QString info = tr("Type: %1\nSubtype: %2\n%3%4") QString info = QObject::tr("Type: %1\nSubtype: %2\n%3%4")
.arg(itemTypeToQString(model->type(index))) .arg(itemTypeToQString(model->type(index)))
.arg(itemSubtypeToQString(model->type(index), model->subtype(index))) .arg(itemSubtypeToQString(model->type(index), model->subtype(index)))
.arg(model->text(index).isEmpty() ? tr("") : tr("Text: %1\n").arg(model->text(index))) .arg(model->text(index).isEmpty() ? QObject::tr("") : QObject::tr("Text: %1\n").arg(model->text(index)))
.arg(model->info(index)); .arg(model->info(index));
file.setFileName(tr("%1/info.txt").arg(path)); file.setFileName(QObject::tr("%1/info.txt").arg(path));
if (!file.open(QFile::Text | QFile::WriteOnly)) if (!file.open(QFile::Text | QFile::WriteOnly))
return ERR_FILE_OPEN; return ERR_FILE_OPEN;

View File

@ -19,18 +19,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <QByteArray> #include <QByteArray>
#include <QString> #include <QString>
#include <QModelIndex> #include <QModelIndex>
#include <QFileInfo>
#include "../common/basetypes.h" #include "../common/basetypes.h"
#include "../common/treemodel.h" #include "../common/treemodel.h"
#include "../common/ffs.h" #include "../common/ffs.h"
class FfsDumper : public QObject class FfsDumper
{ {
Q_OBJECT
public: public:
explicit FfsDumper(TreeModel * treeModel, QObject *parent = 0); explicit FfsDumper(TreeModel * treeModel);
~FfsDumper(); ~FfsDumper();
STATUS dump(const QModelIndex & root, const QString & path, const QString & guid = QString()); STATUS dump(const QModelIndex & root, const QString & path, const QString & guid = QString());

View File

@ -11,8 +11,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/ */
#include <QCoreApplication> #include <QCoreApplication>
#include <QVector>
#include <QPair>
#include <QString> #include <QString>
#include <QFileInfo> #include <QFileInfo>
@ -53,10 +51,9 @@ int main(int argc, char *argv[])
if (result) if (result)
return result; return result;
QVector<QPair<QString, QModelIndex> > messages = ffsParser.getMessages(); std::vector<std::pair<QString, QModelIndex> > messages = ffsParser.getMessages();
QPair<QString, QModelIndex> msg; for (size_t i = 0; i < messages.size(); i++) {
foreach(msg, messages) { std::cout << messages[i].first.toLatin1().constData() << std::endl;
std::cout << msg.first.toLatin1().constData() << std::endl;
} }
FfsDumper ffsDumper(&model); FfsDumper ffsDumper(&model);
@ -75,7 +72,7 @@ int main(int argc, char *argv[])
} }
} }
else { else {
std::cout << "UEFIExtract 0.10.7" << std::endl << std::endl std::cout << "UEFIExtract 0.10.8" << std::endl << std::endl
<< "Usage: UEFIExtract imagefile [FileGUID_1 FileGUID_2 ... FileGUID_31]" << 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; << "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; return 1;

View File

@ -13,11 +13,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "uefifind.h" #include "uefifind.h"
UEFIFind::UEFIFind(QObject *parent) : UEFIFind::UEFIFind()
QObject(parent)
{ {
model = new TreeModel(); model = new TreeModel();
ffsParser = new FfsParser(model, this); ffsParser = new FfsParser(model);
initDone = false; initDone = false;
} }
@ -75,7 +74,7 @@ QString UEFIFind::guidToQString(const UINT8* guid)
STATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result) STATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result)
{ {
QModelIndex root = model->index(0, 0); QModelIndex root = model->index(0, 0);
QSet<QPair<QModelIndex, QModelIndex> > files; std::set<std::pair<QModelIndex, QModelIndex> > files;
result.clear(); result.clear();
@ -84,14 +83,14 @@ STATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPat
return returned; return returned;
if (count) { if (count) {
if (files.count()) if (!files.empty())
result.append(QString("%1\n").arg(files.count())); result.append(QString("%1\n").arg(files.size()));
return ERR_SUCCESS; return ERR_SUCCESS;
} }
QPair<QModelIndex, QModelIndex> indexes; for (std::set<std::pair<QModelIndex, QModelIndex> >::const_iterator citer = files.cbegin(); citer != files.cend(); ++citer) {
Q_FOREACH(indexes, files) {
QByteArray data(16, '\x00'); QByteArray data(16, '\x00');
std::pair<QModelIndex, QModelIndex> indexes = *citer;
if (!model->hasEmptyHeader(indexes.first)) if (!model->hasEmptyHeader(indexes.first))
data = model->header(indexes.first).left(16); data = model->header(indexes.first).left(16);
result.append(guidToQString((const UINT8*)data.constData())); result.append(guidToQString((const UINT8*)data.constData()));
@ -107,7 +106,7 @@ STATUS UEFIFind::find(const UINT8 mode, const bool count, const QString & hexPat
return ERR_SUCCESS; return ERR_SUCCESS;
} }
STATUS UEFIFind::findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, QSet<QPair<QModelIndex, QModelIndex> > & files) STATUS UEFIFind::findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, std::set<std::pair<QModelIndex, QModelIndex> > & files)
{ {
if (!index.isValid()) if (!index.isValid())
return ERR_SUCCESS; return ERR_SUCCESS;
@ -146,12 +145,12 @@ STATUS UEFIFind::findFileRecursive(const QModelIndex index, const QString & hexP
if (model->type(index) != Types::File) { if (model->type(index) != Types::File) {
QModelIndex ffs = model->findParentOfType(index, Types::File); QModelIndex ffs = model->findParentOfType(index, Types::File);
if (model->type(index) == Types::Section && model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID) if (model->type(index) == Types::Section && model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID)
files.insert(QPair<QModelIndex, QModelIndex>(ffs, index)); files.insert(std::pair<QModelIndex, QModelIndex>(ffs, index));
else else
files.insert(QPair<QModelIndex, QModelIndex>(ffs, QModelIndex())); files.insert(std::pair<QModelIndex, QModelIndex>(ffs, QModelIndex()));
} }
else else
files.insert(QPair<QModelIndex, QModelIndex>(index, QModelIndex())); files.insert(std::pair<QModelIndex, QModelIndex>(index, QModelIndex()));
break; break;
} }

View File

@ -14,13 +14,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef __UEFIFIND_H__ #ifndef __UEFIFIND_H__
#define __UEFIFIND_H__ #define __UEFIFIND_H__
#include <set>
#include <QObject> #include <QObject>
#include <QByteArray> #include <QByteArray>
#include <QString> #include <QString>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QPair>
#include <QSet>
#include <QString> #include <QString>
#include <QUuid> #include <QUuid>
@ -28,19 +28,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "../common/ffsparser.h" #include "../common/ffsparser.h"
#include "../common/ffs.h" #include "../common/ffs.h"
class UEFIFind : public QObject class UEFIFind
{ {
Q_OBJECT
public: public:
explicit UEFIFind(QObject *parent = 0); explicit UEFIFind();
~UEFIFind(); ~UEFIFind();
STATUS init(const QString & path); STATUS init(const QString & path);
STATUS find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result); STATUS find(const UINT8 mode, const bool count, const QString & hexPattern, QString & result);
private: private:
STATUS findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, QSet<QPair<QModelIndex, QModelIndex> > & files); STATUS findFileRecursive(const QModelIndex index, const QString & hexPattern, const UINT8 mode, std::set<std::pair<QModelIndex, QModelIndex> > & files);
QString guidToQString(const UINT8* guid); QString guidToQString(const UINT8* guid);
FfsParser* ffsParser; FfsParser* ffsParser;

View File

@ -148,7 +148,7 @@ int main(int argc, char *argv[])
return ERR_SUCCESS; return ERR_SUCCESS;
} }
else { else {
std::cout << "UEFIFind 0.10.5" << std::endl << std::endl << std::cout << "UEFIFind 0.10.6" << std::endl << std::endl <<
"Usage: UEFIFind {header | body | all} {list | count} pattern imagefile" << std::endl << "Usage: UEFIFind {header | body | all} {list | count} pattern imagefile" << std::endl <<
" or UEFIFind file patternsfile imagefile" << std::endl; " or UEFIFind file patternsfile imagefile" << std::endl;
return ERR_INVALID_PARAMETER; return ERR_INVALID_PARAMETER;