Bugfix for UE 0.12.2

- some testing code leaked to UE, reverted
This commit is contained in:
Nikolaj Schlej 2016-07-09 11:18:11 +02:00
parent 589dbd5719
commit 4381bc6103
6 changed files with 77 additions and 82 deletions

View File

@ -13,16 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "ffsdumper.h" #include "ffsdumper.h"
FfsDumper::FfsDumper(TreeModel* treeModel) USTATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const bool dumpAll, const QString & guid)
: model(treeModel), dumped(false)
{
}
FfsDumper::~FfsDumper()
{
}
USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const bool dumpAll, const UString & guid)
{ {
dumped = false; dumped = false;
UINT8 result = recursiveDump(root, path, dumpAll, guid); UINT8 result = recursiveDump(root, path, dumpAll, guid);
@ -33,7 +24,7 @@ USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const bo
return U_SUCCESS; return U_SUCCESS;
} }
USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path, const bool dumpAll, const UString & guid) USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, const bool dumpAll, const QString & guid)
{ {
if (!index.isValid()) if (!index.isValid())
return U_INVALID_PARAMETER; return U_INVALID_PARAMETER;
@ -43,62 +34,60 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
guidToUString(*(const EFI_GUID*)model->header(index).constData()) == guid || guidToUString(*(const EFI_GUID*)model->header(index).constData()) == guid ||
guidToUString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) { guidToUString(*(const EFI_GUID*)model->header(model->findParentOfType(index, Types::File)).constData()) == guid) {
if (dir.cd(QString(path))) if (dir.cd(path))
return U_DIR_ALREADY_EXIST; return U_DIR_ALREADY_EXIST;
if (!dir.mkpath(QString(path))) if (!dir.mkpath(path))
return U_DIR_CREATE; return U_DIR_CREATE;
QFile file; QFile file;
if (dumpAll || model->rowCount(index) == 0) { // Dump if leaf item or dumpAll is true if (dumpAll || model->rowCount(index) == 0) { // Dump if leaf item or dumpAll is true
if (!model->header(index).isEmpty()) { if (!model->header(index).isEmpty()) {
file.setFileName(QString(path) + UString("/header.bin")); file.setFileName(QObject::tr("%1/header.bin").arg(path));
if (!file.open(QFile::WriteOnly)) if (!file.open(QFile::WriteOnly))
return U_FILE_OPEN; return U_FILE_OPEN;
QByteArray ba(model->header(index).constData(), model->header(index).size()); file.write(model->header(index));
file.write(ba);
file.close(); file.close();
} }
if (!model->body(index).isEmpty()) { if (!model->body(index).isEmpty()) {
file.setFileName(QString(path) + UString("/body.bin")); file.setFileName(QObject::tr("%1/body.bin").arg(path));
if (!file.open(QFile::WriteOnly)) if (!file.open(QFile::WriteOnly))
return U_FILE_OPEN; return U_FILE_OPEN;
QByteArray ba(model->body(index).constData(), model->body(index).size()); file.write(model->body(index));
file.write(ba);
file.close(); file.close();
} }
} }
// Always dump info // Always dump info
UString info = UString("Type: ") + itemTypeToUString(model->type(index)) + UString("\n") QString info = QObject::tr("Type: %1\nSubtype: %2\n%3%4\n")
+ UString("Subtype: ") + itemSubtypeToUString(model->type(index), model->subtype(index)) + UString("\n") .arg(itemTypeToUString(model->type(index)))
+ (model->text(index).isEmpty() ? UString("") : UString("Text: ") + model->text(index) + UString("\n")) .arg(itemSubtypeToUString(model->type(index), model->subtype(index)))
+ model->info(index) + UString("\n"); .arg(model->text(index).isEmpty() ? QObject::tr("") : QObject::tr("Text: %1\n").arg(model->text(index)))
file.setFileName(QString(path) + UString("/info.txt")); .arg(model->info(index));
file.setFileName(QObject::tr("%1/info.txt").arg(path));
if (!file.open(QFile::Text | QFile::WriteOnly)) if (!file.open(QFile::Text | QFile::WriteOnly))
return U_FILE_OPEN; return U_FILE_OPEN;
file.write(info.toLocal8Bit()); file.write(info.toLatin1());
file.close(); file.close();
dumped = true; dumped = true;
} }
UINT8 result; UINT8 result;
for (int i = 0; i < model->rowCount(index); i++) { for (int i = 0; i < model->rowCount(index); i++) {
UModelIndex childIndex = index.child(i, 0); QModelIndex childIndex = index.child(i, 0);
bool useText = FALSE; bool useText = FALSE;
if (model->type(childIndex) != Types::Volume) if (model->type(childIndex) != Types::Volume)
useText = !model->text(childIndex).isEmpty(); useText = !model->text(childIndex).isEmpty();
UString childPath = path + usprintf("/%u ", i) + (useText ? model->text(childIndex) : model->name(childIndex)); QString childPath = QString("%1/%2 %3").arg(path).arg(i).arg(useText ? model->text(childIndex) : model->name(childIndex));
result = recursiveDump(childIndex, childPath, dumpAll, guid); result = recursiveDump(childIndex, childPath, dumpAll, guid);
if (result) if (result)
return result; return result;
} }
return U_SUCCESS; return U_SUCCESS;
} }

View File

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

View File

@ -1,21 +1,18 @@
/* uefiextract_main.cpp /* uefiextract_main.cpp
Copyright (c) 2016, Nikolaj Schlej. All rights reserved. Copyright (c) 2016, Nikolaj Schlej. All rights reserved.
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/ */
#include <QCoreApplication> #include <QCoreApplication>
#include <QString>
#include <QFileInfo> #include <QFileInfo>
#include <iostream>
#include <fstream>
#include <../common/ustring.h> #include <iostream>
#include "../common/ffsparser.h" #include "../common/ffsparser.h"
#include "../common/ffsreport.h" #include "../common/ffsreport.h"
#include "../common/fitparser.h" #include "../common/fitparser.h"
@ -35,23 +32,20 @@ int main(int argc, char *argv[])
if (a.arguments().length() > 1) { if (a.arguments().length() > 1) {
// Check that input file exists // Check that input file exists
UString path(a.arguments().at(1).toLatin1()); QString path = a.arguments().at(1);
QString qpath = QString(path); QFileInfo fileInfo(path);
QFileInfo fileInfo(qpath);
if (!fileInfo.exists()) if (!fileInfo.exists())
return U_FILE_OPEN; return U_FILE_OPEN;
// Open the input file // Open the input file
QFile inputFile; QFile inputFile;
inputFile.setFileName(qpath); inputFile.setFileName(path);
if (!inputFile.open(QFile::ReadOnly)) if (!inputFile.open(QFile::ReadOnly))
return U_FILE_OPEN; return U_FILE_OPEN;
// Read and close the file
QByteArray b = inputFile.readAll();
inputFile.close();
UByteArray buffer(b.constData(), b.size()); // Read and close the file
QByteArray buffer = inputFile.readAll();
inputFile.close();
// Create model and ffsParser // Create model and ffsParser
TreeModel model; TreeModel model;
@ -62,13 +56,13 @@ int main(int argc, char *argv[])
return result; return result;
// Show ffsParser's messages // Show ffsParser's messages
std::vector<std::pair<UString, UModelIndex> > messages = ffsParser.getMessages(); std::vector<std::pair<QString, QModelIndex> > messages = ffsParser.getMessages();
for (size_t i = 0; i < messages.size(); i++) { for (size_t i = 0; i < messages.size(); i++) {
std::cout << (const char*)messages[i].first.toLocal8Bit() << std::endl; std::cout << messages[i].first.toLatin1().constData() << std::endl;
} }
// Get last VTF // Get last VTF
UModelIndex lastVtf = ffsParser.getLastVtf(); QModelIndex lastVtf = ffsParser.getLastVtf();
if (lastVtf.isValid()) { if (lastVtf.isValid()) {
// Create fitParser // Create fitParser
FitParser fitParser(&model); FitParser fitParser(&model);
@ -76,57 +70,59 @@ int main(int argc, char *argv[])
result = fitParser.parse(model.index(0, 0), lastVtf); result = fitParser.parse(model.index(0, 0), lastVtf);
if (U_SUCCESS == result) { if (U_SUCCESS == result) {
// Show fitParser's messages // Show fitParser's messages
std::vector<std::pair<UString, UModelIndex> > fitMessages = fitParser.getMessages(); std::vector<std::pair<QString, QModelIndex> > fitMessages = fitParser.getMessages();
for (size_t i = 0; i < fitMessages.size(); i++) { for (size_t i = 0; i < fitMessages.size(); i++) {
std::cout << (const char*)fitMessages[i].first.toLocal8Bit() << std::endl; std::cout << fitMessages[i].first.toLatin1().constData() << std::endl;
} }
// Show FIT table // Show FIT table
std::vector<std::vector<UString> > fitTable = fitParser.getFitTable(); std::vector<std::vector<QString> > fitTable = fitParser.getFitTable();
if (fitTable.size()) { if (fitTable.size()) {
std::cout << "-------------------------------------------------------------------" << std::endl; std::cout << "-------------------------------------------------------------------" << std::endl;
std::cout << " Address | Size | Ver | Type | CS " << std::endl; std::cout << " Address | Size | Ver | Type | CS " << std::endl;
std::cout << "-------------------------------------------------------------------" << std::endl; std::cout << "-------------------------------------------------------------------" << std::endl;
for (size_t i = 0; i < fitTable.size(); i++) { for (size_t i = 0; i < fitTable.size(); i++) {
std::cout << (const char*)fitTable[i][0].toLocal8Bit() << " | " std::cout << fitTable[i][0].toLatin1().constData() << " | "
<< (const char*)fitTable[i][1].toLocal8Bit() << " | " << fitTable[i][1].toLatin1().constData() << " | "
<< (const char*)fitTable[i][2].toLocal8Bit() << " | " << fitTable[i][2].toLatin1().constData() << " | "
<< (const char*)fitTable[i][3].toLocal8Bit() << " | " << fitTable[i][3].toLatin1().constData() << " | "
<< (const char*)fitTable[i][4].toLocal8Bit() << std::endl; << fitTable[i][4].toLatin1().constData() << std::endl;
} }
} }
} }
} }
// Create ffsReport // Create ffsReport
FfsReport ffsReport(&model); FfsReport ffsReport(&model);
std::vector<UString> report = ffsReport.generate(); std::vector<QString> report = ffsReport.generate();
if (report.size()) { if (report.size()) {
std::ofstream ofs; QFile file;
ofs.open("report.txt", std::ofstream::out); file.setFileName(fileInfo.fileName().append(".report.txt"));
for (size_t i = 0; i < report.size(); i++) { if (file.open(QFile::Text | QFile::WriteOnly)) {
ofs << (const char*)report[i].toLocal8Bit() << std::endl; for (size_t i = 0; i < report.size(); i++) {
file.write(report[i].toLatin1().append('\n'));
}
file.close();
} }
ofs.close();
} }
// Create ffsDumper // Create ffsDumper
FfsDumper ffsDumper(&model); FfsDumper ffsDumper(&model);
// Dump all non-leaf elements // Dump all non-leaf elements
if (a.arguments().length() == 2) { if (a.arguments().length() == 2) {
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump2").toLatin1().constData()) != U_SUCCESS); return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump")) != U_SUCCESS);
} }
else if (a.arguments().length() == 3 && a.arguments().at(2) == UString("all")) { // Dump everything else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("all")) { // Dump everything
return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump2").toLatin1().constData(), true) != U_SUCCESS); return (ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), true) != U_SUCCESS);
} }
else if (a.arguments().length() == 3 && a.arguments().at(2) == UString("none")) { // Skip dumping else if (a.arguments().length() == 3 && a.arguments().at(2) == QString("none")) { // Skip dumping
return 0; return 0;
} }
else { // Dump specific files else { // Dump specific files
UINT32 returned = 0; UINT32 returned = 0;
for (int i = 2; i < a.arguments().length(); i++) { for (int i = 2; i < a.arguments().length(); i++) {
result = ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump2").toLatin1().constData(), true, a.arguments().at(i).toLatin1().constData()); result = ffsDumper.dump(model.index(0, 0), fileInfo.fileName().append(".dump"), true, a.arguments().at(i));
if (result) if (result)
returned |= (1 << (i - 1)); returned |= (1 << (i - 1));
} }
@ -136,14 +132,12 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
else { // Show version and usage information else { // Show version and usage information
std::cout << "UEFIExtract 0.12.1" << std::endl << std::endl std::cout << "UEFIExtract 0.12.2" << std::endl << std::endl
<< "Usage: UEFIExtract imagefile - generate report and dump only leaf tree items into .dump folder" << std::endl << "Usage: UEFIExtract imagefile - generate report and dump only leaf tree items into .dump folder" << std::endl
<< " UEFIExtract imagefile all - generate report and dump all tree items" << std::endl << " UEFIExtract imagefile all - generate report and dump all tree items" << std::endl
<< " UEFIExtract imagefile none - only generate report, no dump needed" << std::endl << " UEFIExtract imagefile none - only generate report, no dump needed" << std::endl
<< " UIFIExtract imagefile GUID_1 GUID_2 ... GUID_31 - dump only FFS file(s) with specific GUID(s)" << std::endl << " UIFIExtract imagefile GUID_1 GUID_2 ... GUID_31 - dump only FFS file(s) with specific GUID(s)" << 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::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;
} }
}
return 0;
}

View File

@ -55,7 +55,7 @@ USTATUS FfsReport::generateRecursive(std::vector<UString> & report, UModelIndex
UString(" ") + itemTypeToUString(model->type(index)).leftJustified(16) UString(" ") + itemTypeToUString(model->type(index)).leftJustified(16)
+ UString("| ") + itemSubtypeToUString(model->type(index), model->subtype(index)).leftJustified(22) + UString("| ") + itemSubtypeToUString(model->type(index), model->subtype(index)).leftJustified(22)
+ usprintf("| %08X | %08X | ", data.size(), crc) + usprintf("| %08X | %08X | ", data.size(), crc)
+ UString('-', level) + UString(" ") + model->name(index) + (text.isEmpty() ? UString("") : UString(" | ") + text) + urepeated('-', level) + UString(" ") + model->name(index) + (text.isEmpty() ? UString("") : UString(" | ") + text)
); );
// Information on child items // Information on child items

View File

@ -23,6 +23,11 @@ UString usprintf(const char* fmt, ...)
va_end(vl); va_end(vl);
return msg; return msg;
}; };
UString urepeated(char c, int len)
{
return UString(len, c);
}
#else #else
/* Give WATCOM C/C++, MSVC some latitude for their non-support of vsnprintf */ /* Give WATCOM C/C++, MSVC some latitude for their non-support of vsnprintf */
#if defined(__WATCOMC__) || defined(_MSC_VER) #if defined(__WATCOMC__) || defined(_MSC_VER)
@ -91,4 +96,9 @@ UString usprintf(const char* fmt, ...)
return msg; return msg;
} }
UString urepeated(char c, int len)
{
return UString(c, len);
}
#endif #endif

View File

@ -26,5 +26,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#endif // QT_CORE_LIB #endif // QT_CORE_LIB
UString usprintf(const char* fmt, ...); UString usprintf(const char* fmt, ...);
UString urepeated(char c, int len);
#endif // USTRING_H #endif // USTRING_H