mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-06-01 07:48:22 -04:00
Rough attempt to deglue UEFIExtract from Qt
This commit is contained in:
parent
0a2f115056
commit
c9db871c12
9 changed files with 227 additions and 209 deletions
UEFIExtract
|
@ -13,13 +13,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
|
||||
#include "ffsdumper.h"
|
||||
|
||||
USTATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const DumpMode dumpMode, const UINT8 sectionType, const QString & guid)
|
||||
#include <fstream>
|
||||
|
||||
USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid)
|
||||
{
|
||||
dumped = false;
|
||||
counter = 0;
|
||||
counterHeader = counterBody = counterRaw = counterInfo = 0;
|
||||
|
||||
QDir dir;
|
||||
if (dir.cd(path))
|
||||
if (changeDirectory(path))
|
||||
return U_DIR_ALREADY_EXIST;
|
||||
|
||||
UINT8 result = recursiveDump(root, path, dumpMode, sectionType, guid);
|
||||
|
@ -30,49 +31,50 @@ USTATUS FfsDumper::dump(const QModelIndex & root, const QString & path, const Du
|
|||
return U_SUCCESS;
|
||||
}
|
||||
|
||||
USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path, const DumpMode dumpMode, const UINT8 sectionType, const QString & guid)
|
||||
USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path, const DumpMode dumpMode, const UINT8 sectionType, const UString & guid)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return U_INVALID_PARAMETER;
|
||||
|
||||
QDir dir;
|
||||
if (guid.isEmpty() ||
|
||||
(model->subtype(index) == EFI_SECTION_FREEFORM_SUBTYPE_GUID &&
|
||||
guidToUString(*(const EFI_GUID*)(model->header(index).constData() + sizeof(EFI_COMMON_SECTION_HEADER))) == 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) && !dir.mkpath(path))
|
||||
if (!changeDirectory(path) && !makeDirectory(path))
|
||||
return U_DIR_CREATE;
|
||||
|
||||
QFile file;
|
||||
counterHeader = counterBody = counterRaw = counterInfo = 0;
|
||||
|
||||
std::ofstream file;
|
||||
if (dumpMode == DUMP_ALL || model->rowCount(index) == 0) { // Dump if leaf item or dumpAll is true
|
||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER) {
|
||||
if (!model->header(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||
if (counter == 0)
|
||||
file.setFileName(QObject::tr("%1/header.bin").arg(path));
|
||||
UString filename;
|
||||
if (counterHeader == 0)
|
||||
filename = usprintf("%s/header.bin", (const char *)path.toLocal8Bit());
|
||||
else
|
||||
file.setFileName(QObject::tr("%1/header_%2.bin").arg(path).arg(counter));
|
||||
counter++;
|
||||
if (!file.open(QFile::WriteOnly))
|
||||
return U_FILE_OPEN;
|
||||
|
||||
file.write(model->header(index));
|
||||
filename = usprintf("%s/header_%d.bin", (const char *)path.toLocal8Bit(), counterHeader);
|
||||
counterHeader++;
|
||||
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
|
||||
const UByteArray &data = model->header(index);
|
||||
file.write(data.constData(), data.size());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY) {
|
||||
if (!model->body(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||
if (counter == 0)
|
||||
file.setFileName(QObject::tr("%1/body.bin").arg(path));
|
||||
UString filename;
|
||||
if (counterBody == 0)
|
||||
filename = usprintf("%s/body.bin", (const char *)path.toLocal8Bit());
|
||||
else
|
||||
file.setFileName(QObject::tr("%1/body_%2.bin").arg(path).arg(counter));
|
||||
counter++;
|
||||
if (!file.open(QFile::WriteOnly))
|
||||
return U_FILE_OPEN;
|
||||
|
||||
file.write(model->body(index));
|
||||
filename = usprintf("%s/body_%d.bin", (const char *)path.toLocal8Bit(), counterBody);
|
||||
counterBody++;
|
||||
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
|
||||
const UByteArray &data = model->body(index);
|
||||
file.write(data.constData(), data.size());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
@ -81,16 +83,19 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path
|
|||
UModelIndex fileIndex = model->findParentOfType(index, Types::File);
|
||||
if (!fileIndex.isValid())
|
||||
fileIndex = index;
|
||||
if (counter == 0)
|
||||
file.setFileName(QObject::tr("%1/file.ffs").arg(path));
|
||||
UString filename;
|
||||
if (counterRaw == 0)
|
||||
filename = usprintf("%s/file.ffs", (const char *)path.toLocal8Bit());
|
||||
else
|
||||
file.setFileName(QObject::tr("%1/file_%2.ffs").arg(path).arg(counter));
|
||||
counter++;
|
||||
if (!file.open(QFile::WriteOnly))
|
||||
return U_FILE_OPEN;
|
||||
file.write(model->header(fileIndex));
|
||||
file.write(model->body(fileIndex));
|
||||
file.write(model->tail(fileIndex));
|
||||
filename = usprintf("%s/file_%d.bin", (const char *)path.toLocal8Bit(), counterRaw);
|
||||
counterRaw++;
|
||||
file.open((const char *)filename.toLocal8Bit(), std::ofstream::binary);
|
||||
const UByteArray &headerData = model->header(index);
|
||||
const UByteArray &bodyData = model->body(index);
|
||||
const UByteArray &tailData = model->tail(index);
|
||||
file.write(headerData.constData(), headerData.size());
|
||||
file.write(bodyData.constData(), bodyData.size());
|
||||
file.write(tailData.constData(), tailData.size());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
@ -98,20 +103,20 @@ USTATUS FfsDumper::recursiveDump(const QModelIndex & index, const QString & path
|
|||
// Always dump info unless explicitly prohibited
|
||||
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_INFO)
|
||||
&& (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||
QString info = QObject::tr("Type: %1\nSubtype: %2\n%3%4\n")
|
||||
.arg(itemTypeToUString(model->type(index)))
|
||||
.arg(itemSubtypeToUString(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));
|
||||
if (counter == 0)
|
||||
file.setFileName(QObject::tr("%1/info.txt").arg(path));
|
||||
UString info = usprintf("Type: %s\nSubtype: %s\n%s%s\n",
|
||||
(const char *)itemTypeToUString(model->type(index)).toLocal8Bit(),
|
||||
(const char *)itemSubtypeToUString(model->type(index), model->subtype(index)).toLocal8Bit(),
|
||||
(const char *)(model->text(index).isEmpty() ? UString("") :
|
||||
usprintf("Text: %s\n", (const char *)model->text(index).toLocal8Bit())).toLocal8Bit(),
|
||||
(const char *)model->info(index).toLocal8Bit());
|
||||
UString filename;
|
||||
if (counterInfo == 0)
|
||||
filename = usprintf("%s/info.txt", (const char *)path.toLocal8Bit());
|
||||
else
|
||||
file.setFileName(QObject::tr("%1/info_%2.txt").arg(path).arg(counter));
|
||||
counter++;
|
||||
if (!file.open(QFile::Text | QFile::WriteOnly))
|
||||
return U_FILE_OPEN;
|
||||
|
||||
file.write(info.toLatin1());
|
||||
filename = usprintf("%s/info_%d.txt", (const char *)path.toLocal8Bit(), counterInfo);
|
||||
counterInfo++;
|
||||
file.open((const char *)filename.toLocal8Bit());
|
||||
file << (const char *)info.toLocal8Bit();
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
@ -120,14 +125,15 @@ USTATUS 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 = path;
|
||||
UString childPath = path;
|
||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT)
|
||||
childPath = QString("%1/%2 %3").arg(path).arg(i).arg(useText ? model->text(childIndex) : model->name(childIndex));
|
||||
childPath = usprintf("%s/%d %s", (const char *)path.toLocal8Bit(), i,
|
||||
(const char *)(useText ? model->text(childIndex) : model->name(childIndex)).toLocal8Bit());
|
||||
result = recursiveDump(childIndex, childPath, dumpMode, sectionType, guid);
|
||||
if (result)
|
||||
return result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue