LessQt, part 1

- added wrappers over Qt classes for seamless replacement if Qt is not available
- added bstrlib as submodule
- only UEFIExtract works with this changes for now, others will followa bit later
This commit is contained in:
Nikolaj Schlej 2016-06-26 05:54:21 +02:00
parent 71ce2a07b2
commit bf8632c063
32 changed files with 2891 additions and 2774 deletions

View file

@ -22,48 +22,48 @@ FfsDumper::~FfsDumper()
{
}
STATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const bool dumpAll, const QString & guid)
USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const bool dumpAll, const UString & guid)
{
dumped = false;
UINT8 result = recursiveDump(root, path, dumpAll, guid);
if (result)
return result;
else if (!dumped)
return ERR_ITEM_NOT_FOUND;
return ERR_SUCCESS;
return U_ITEM_NOT_FOUND;
return U_SUCCESS;
}
STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, const bool dumpAll, const QString & guid)
USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path, const bool dumpAll, const UString & guid)
{
if (!index.isValid())
return ERR_INVALID_PARAMETER;
return U_INVALID_PARAMETER;
QDir dir;
if (guid.isEmpty() ||
guidToQString(*(const EFI_GUID*)model->header(index).constData()) == guid ||
guidToQString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) {
guidToUString(*(const EFI_GUID*)model->header(index).constData()) == guid ||
guidToUString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) {
if (dir.cd(path))
return ERR_DIR_ALREADY_EXIST;
return U_DIR_ALREADY_EXIST;
if (!dir.mkpath(path))
return ERR_DIR_CREATE;
return U_DIR_CREATE;
QFile file;
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));
file.setFileName(path + UString("/header.bin"));
if (!file.open(QFile::WriteOnly))
return ERR_FILE_OPEN;
return U_FILE_OPEN;
file.write(model->header(index));
file.close();
}
if (!model->body(index).isEmpty()) {
file.setFileName(QObject::tr("%1/body.bin").arg(path));
file.setFileName(path + UString("/body.bin"));
if (!file.open(QFile::WriteOnly))
return ERR_FILE_OPEN;
return U_FILE_OPEN;
file.write(model->body(index));
file.close();
@ -71,14 +71,13 @@ STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path,
}
// 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));
file.setFileName(QObject::tr("%1/info.txt").arg(path));
UString info = UString("Type: ") + itemTypeToUString(model->type(index)) + UString("\n")
+ UString("Subtype: ") + itemSubtypeToUString(model->type(index), model->subtype(index)) + UString("\n")
+ (model->text(index).isEmpty() ? UString("") : UString("Text: ") + model->text(index) + UString("\n"))
+ model->info(index) + UString("\n");
file.setFileName(path + UString("/info.txt"));
if (!file.open(QFile::Text | QFile::WriteOnly))
return ERR_FILE_OPEN;
return U_FILE_OPEN;
file.write(info.toLatin1());
file.close();
@ -87,16 +86,16 @@ STATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path,
UINT8 result;
for (int i = 0; i < model->rowCount(index); i++) {
QModelIndex childIndex = index.child(i, 0);
UModelIndex childIndex = index.child(i, 0);
bool useText = FALSE;
if (model->type(childIndex) != Types::Volume)
useText = !model->text(childIndex).isEmpty();
QString childPath = QString("%1/%2 %3").arg(path).arg(i).arg(useText ? model->text(childIndex) : model->name(childIndex));
UString childPath = path + usprintf("/%u ", i) + (useText ? model->text(childIndex) : model->name(childIndex));
result = recursiveDump(childIndex, childPath, dumpAll, guid);
if (result)
return result;
}
return ERR_SUCCESS;
return U_SUCCESS;
}

View file

@ -14,12 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef FFSDUMPER_H
#define FFSDUMPER_H
#include <QObject>
#include <QDir>
#include <QByteArray>
#include <QString>
#include <QModelIndex>
#include <QDir>
#include "../common/ubytearray.h"
#include "../common/ustring.h"
#include "../common/umodelindex.h"
#include "../common/basetypes.h"
#include "../common/treemodel.h"
#include "../common/ffs.h"
@ -30,10 +29,10 @@ public:
explicit FfsDumper(TreeModel * treeModel);
~FfsDumper();
STATUS dump(const QModelIndex & root, const QString & path, const bool dumpAll = false, const QString & guid = QString());
USTATUS dump(const UModelIndex & root, const UString & path, const bool dumpAll = false, const UString & guid = UString());
private:
STATUS recursiveDump(const QModelIndex & root, const QString & path, const bool dumpAll, const QString & guid);
USTATUS recursiveDump(const UModelIndex & root, const UString & path, const bool dumpAll, const UString & guid);
TreeModel* model;
bool dumped;
};

View file

@ -6,7 +6,8 @@ TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
SOURCES += uefiextract_main.cpp \
SOURCES += \
uefiextract_main.cpp \
ffsdumper.cpp \
../common/types.cpp \
../common/descriptor.cpp \
@ -22,8 +23,12 @@ SOURCES += uefiextract_main.cpp \
../common/LZMA/LzmaDecompress.c \
../common/LZMA/SDK/C/LzmaDec.c \
../common/Tiano/EfiTianoDecompress.c \
../common/ustring.cpp \
../bstrlib/bstrlib.c \
../bstrlib/bstrwrap.cpp
HEADERS += ffsdumper.h \
HEADERS += \
ffsdumper.h \
../common/basetypes.h \
../common/descriptor.h \
../common/gbe.h \
@ -39,5 +44,10 @@ HEADERS += ffsdumper.h \
../common/treemodel.h \
../common/utility.h \
../common/LZMA/LzmaDecompress.h \
../common/Tiano/EfiTianoDecompress.h
../common/Tiano/EfiTianoDecompress.h \
../common/umodelindex.h \
../common/ubytearray.h \
../common/ustring.h \
../bstrlib/bstrlib.h \
../bstrlib/bstrwrap.cpp

View file

@ -11,11 +11,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
#include <QCoreApplication>
#include <QString>
#include <QFileInfo>
#include <iostream>
#include <../common/ustring.h>
#include "../common/ffsparser.h"
#include "../common/ffsreport.h"
#include "../common/fitparser.h"
@ -35,51 +34,51 @@ int main(int argc, char *argv[])
if (a.arguments().length() > 1) {
// Check that input file exists
QString path = a.arguments().at(1);
UString path = a.arguments().at(1);
QFileInfo fileInfo(path);
if (!fileInfo.exists())
return ERR_FILE_OPEN;
return U_FILE_OPEN;
// Open the input file
QFile inputFile;
inputFile.setFileName(path);
if (!inputFile.open(QFile::ReadOnly))
return ERR_FILE_OPEN;
return U_FILE_OPEN;
// Read and close the file
QByteArray buffer = inputFile.readAll();
UByteArray buffer = inputFile.readAll();
inputFile.close();
// Create model and ffsParser
TreeModel model;
FfsParser ffsParser(&model);
// Parse input buffer
STATUS result = ffsParser.parse(buffer);
USTATUS result = ffsParser.parse(buffer);
if (result)
return result;
// Show ffsParser's messages
std::vector<std::pair<QString, QModelIndex> > messages = ffsParser.getMessages();
std::vector<std::pair<UString, UModelIndex> > messages = ffsParser.getMessages();
for (size_t i = 0; i < messages.size(); i++) {
std::cout << messages[i].first.toLatin1().constData() << std::endl;
}
// Get last VTF
QModelIndex lastVtf = ffsParser.getLastVtf();
UModelIndex lastVtf = ffsParser.getLastVtf();
if (lastVtf.isValid()) {
// Create fitParser
FitParser fitParser(&model);
// Find and parse FIT table
result = fitParser.parse(model.index(0, 0), lastVtf);
if (ERR_SUCCESS == result) {
if (U_SUCCESS == result) {
// Show fitParser's messages
std::vector<std::pair<QString, QModelIndex> > fitMessages = fitParser.getMessages();
std::vector<std::pair<UString, UModelIndex> > fitMessages = fitParser.getMessages();
for (size_t i = 0; i < fitMessages.size(); i++) {
std::cout << fitMessages[i].first.toLatin1().constData() << std::endl;
}
// Show FIT table
std::vector<std::vector<QString> > fitTable = fitParser.getFitTable();
std::vector<std::vector<UString> > fitTable = fitParser.getFitTable();
if (fitTable.size()) {
std::cout << "-------------------------------------------------------------------" << std::endl;
std::cout << " Address | Size | Ver | Type | CS " << std::endl;
@ -97,7 +96,7 @@ int main(int argc, char *argv[])
// Create ffsReport
FfsReport ffsReport(&model);
std::vector<QString> report = ffsReport.generate();
std::vector<UString> report = ffsReport.generate();
if (report.size()) {
QFile file;
file.setFileName(fileInfo.fileName().append(".report.txt"));
@ -114,12 +113,12 @@ int main(int argc, char *argv[])
// Dump all non-leaf elements
if (a.arguments().length() == 2) {
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != ERR_SUCCESS);
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_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 if (a.arguments().length() == 3 && a.arguments().at(2) == UString("all")) { // Dump everything
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), true) != U_SUCCESS);
}
else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("none")) { // Skip dumping
else if (a.arguments().length() == 3 && a.arguments().at(2) == UString("none")) { // Skip dumping
return 0;
}
else { // Dump specific files