mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-23 00:18:23 +08:00
Fix header&body extraction
This commit is contained in:
parent
2201a9b10c
commit
7ab6dd4285
@ -56,30 +56,33 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
currentPath = path;
|
currentPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dumpMode == DUMP_ALL || model->rowCount(index) == 0) { // Dump if leaf item or dumpAll is true
|
if (fileList.count(index) == 0
|
||||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER) {
|
&& (dumpMode == DUMP_ALL || model->rowCount(index) == 0)
|
||||||
if (!model->header(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType) &&
|
&& (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
||||||
fileList.count(index) == 0) {
|
|
||||||
|
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER)
|
||||||
|
&& !model->header(index).isEmpty()) {
|
||||||
fileList.insert(index);
|
fileList.insert(index);
|
||||||
|
|
||||||
UString filename;
|
UString filename;
|
||||||
if (counterHeader == 0)
|
if (counterHeader == 0)
|
||||||
filename = usprintf("%s/header.bin", path.toLocal8Bit());
|
filename = usprintf("%s/header.bin", path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
filename = usprintf("%s/header_%d.bin", path.toLocal8Bit(), counterHeader);
|
filename = usprintf("%s/header_%d.bin", path.toLocal8Bit(), counterHeader);
|
||||||
counterHeader++;
|
counterHeader++;
|
||||||
|
|
||||||
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
if (!file)
|
if (!file)
|
||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
|
||||||
const UByteArray &data = model->header(index);
|
const UByteArray &data = model->header(index);
|
||||||
file.write(data.constData(), data.size());
|
file.write(data.constData(), data.size());
|
||||||
|
|
||||||
dumped = true;
|
dumped = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY) {
|
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY)
|
||||||
if (!model->body(index).isEmpty() && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType) &&
|
&& !model->body(index).isEmpty()) {
|
||||||
fileList.count(index) == 0) {
|
|
||||||
fileList.insert(index);
|
fileList.insert(index);
|
||||||
UString filename;
|
UString filename;
|
||||||
if (counterBody == 0)
|
if (counterBody == 0)
|
||||||
@ -87,37 +90,42 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
else
|
else
|
||||||
filename = usprintf("%s/body_%d.bin", path.toLocal8Bit(), counterBody);
|
filename = usprintf("%s/body_%d.bin", path.toLocal8Bit(), counterBody);
|
||||||
counterBody++;
|
counterBody++;
|
||||||
|
|
||||||
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
if (!file)
|
if (!file)
|
||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
|
||||||
const UByteArray &data = model->body(index);
|
const UByteArray &data = model->body(index);
|
||||||
file.write(data.constData(), data.size());
|
file.write(data.constData(), data.size());
|
||||||
|
|
||||||
dumped = true;
|
dumped = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (dumpMode == DUMP_FILE && (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
|
if (dumpMode == DUMP_FILE) {
|
||||||
UModelIndex fileIndex = index;
|
UModelIndex fileIndex = index;
|
||||||
if (model->type(fileIndex) != Types::File) {
|
if (model->type(fileIndex) != Types::File) {
|
||||||
fileIndex = model->findParentOfType(index, Types::File);
|
fileIndex = model->findParentOfType(index, Types::File);
|
||||||
if (!fileIndex.isValid())
|
if (!fileIndex.isValid())
|
||||||
fileIndex = index;
|
fileIndex = index;
|
||||||
}
|
}
|
||||||
if (fileList.count(fileIndex) == 0) {
|
|
||||||
fileList.insert(fileIndex);
|
fileList.insert(fileIndex);
|
||||||
|
|
||||||
UString filename;
|
UString filename;
|
||||||
if (counterRaw == 0)
|
if (counterRaw == 0)
|
||||||
filename = usprintf("%s/file.ffs", path.toLocal8Bit());
|
filename = usprintf("%s/file.ffs", path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
filename = usprintf("%s/file_%d.ffs", path.toLocal8Bit(), counterRaw);
|
filename = usprintf("%s/file_%d.ffs", path.toLocal8Bit(), counterRaw);
|
||||||
counterRaw++;
|
counterRaw++;
|
||||||
|
|
||||||
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
|
||||||
if (!file)
|
if (!file)
|
||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
|
||||||
const UByteArray &headerData = model->header(fileIndex);
|
const UByteArray &headerData = model->header(fileIndex);
|
||||||
const UByteArray &bodyData = model->body(fileIndex);
|
const UByteArray &bodyData = model->body(fileIndex);
|
||||||
const UByteArray &tailData = model->tail(fileIndex);
|
const UByteArray &tailData = model->tail(fileIndex);
|
||||||
|
|
||||||
file.write(headerData.constData(), headerData.size());
|
file.write(headerData.constData(), headerData.size());
|
||||||
file.write(bodyData.constData(), bodyData.size());
|
file.write(bodyData.constData(), bodyData.size());
|
||||||
file.write(tailData.constData(), tailData.size());
|
file.write(tailData.constData(), tailData.size());
|
||||||
@ -125,7 +133,6 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
dumped = true;
|
dumped = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Always dump info unless explicitly prohibited
|
// Always dump info unless explicitly prohibited
|
||||||
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_INFO)
|
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_INFO)
|
||||||
@ -136,15 +143,18 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
|
|||||||
(model->text(index).isEmpty() ? UString("") :
|
(model->text(index).isEmpty() ? UString("") :
|
||||||
usprintf("Text: %s\n", model->text(index).toLocal8Bit())).toLocal8Bit(),
|
usprintf("Text: %s\n", model->text(index).toLocal8Bit())).toLocal8Bit(),
|
||||||
model->info(index).toLocal8Bit());
|
model->info(index).toLocal8Bit());
|
||||||
|
|
||||||
UString filename;
|
UString filename;
|
||||||
if (counterInfo == 0)
|
if (counterInfo == 0)
|
||||||
filename = usprintf("%s/info.txt", path.toLocal8Bit());
|
filename = usprintf("%s/info.txt", path.toLocal8Bit());
|
||||||
else
|
else
|
||||||
filename = usprintf("%s/info_%d.txt", path.toLocal8Bit(), counterInfo);
|
filename = usprintf("%s/info_%d.txt", path.toLocal8Bit(), counterInfo);
|
||||||
counterInfo++;
|
counterInfo++;
|
||||||
|
|
||||||
std::ofstream file(filename.toLocal8Bit());
|
std::ofstream file(filename.toLocal8Bit());
|
||||||
if (!file)
|
if (!file)
|
||||||
return U_FILE_OPEN;
|
return U_FILE_OPEN;
|
||||||
|
|
||||||
file << info.toLocal8Bit();
|
file << info.toLocal8Bit();
|
||||||
|
|
||||||
dumped = true;
|
dumped = true;
|
||||||
|
@ -168,7 +168,7 @@ int main(int argc, char *argv[])
|
|||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS);
|
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump")) != U_SUCCESS);
|
||||||
}
|
}
|
||||||
else if (argc == 3 && !std::strcmp(argv[2], "all")) { // Dump every elementm with report
|
else if (argc == 3 && !std::strcmp(argv[2], "all")) { // Dump every element with report
|
||||||
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump"), FfsDumper::DUMP_ALL) != U_SUCCESS);
|
return (ffsDumper.dump(model.index(0, 0), path + UString(".dump"), FfsDumper::DUMP_ALL) != U_SUCCESS);
|
||||||
}
|
}
|
||||||
else if (argc == 3 && !std::strcmp(argv[2], "report")) { // Skip dumping
|
else if (argc == 3 && !std::strcmp(argv[2], "report")) { // Skip dumping
|
||||||
|
Loading…
Reference in New Issue
Block a user