UEFIExtract: add support for extracting uncompressedData for tree items that have it

This commit is contained in:
Nikolaj Schlej 2025-02-14 07:19:09 +01:00
parent c94f78a530
commit ff42cecb07
3 changed files with 33 additions and 8 deletions

View file

@ -59,7 +59,7 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
}
if (currentPath != path) {
counterHeader = counterBody = counterRaw = counterInfo = 0;
counterHeader = counterBody = counterUncData = counterRaw = counterInfo = 0;
currentPath = path;
}
@ -68,7 +68,7 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
&& (sectionType == IgnoreSectionType || model->subtype(index) == sectionType)) {
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_HEADER)
&& !model->header(index).isEmpty()) {
&& !model->hasEmptyHeader(index)) {
fileList.insert(index);
UString filename;
@ -91,7 +91,7 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
}
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_BODY)
&& !model->body(index).isEmpty()) {
&& !model->hasEmptyBody(index)) {
fileList.insert(index);
UString filename;
if (counterBody == 0)
@ -112,6 +112,28 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
dumped = true;
}
if ((dumpMode == DUMP_ALL || dumpMode == DUMP_CURRENT || dumpMode == DUMP_UNC_DATA)
&& !model->hasEmptyUncompressedData(index)) {
fileList.insert(index);
UString filename;
if (counterUncData == 0)
filename = usprintf("%s/unc_data.bin", path.toLocal8Bit());
else
filename = usprintf("%s/unc_data_%d.bin", path.toLocal8Bit(), counterUncData);
counterUncData++;
std::ofstream file(filename.toLocal8Bit(), std::ofstream::binary);
if (!file) {
printf("Cannot open uncompressed data \"%s\".\n", (const char*)filename.toLocal8Bit());
return U_FILE_OPEN;
}
const UByteArray &data = model->uncompressedData(index);
file.write(data.constData(), data.size());
dumped = true;
}
if (dumpMode == DUMP_FILE) {
UModelIndex fileIndex = index;
if (model->type(fileIndex) != Types::File) {

View file

@ -30,6 +30,7 @@ public:
DUMP_CURRENT,
DUMP_ALL,
DUMP_BODY,
DUMP_UNC_DATA,
DUMP_HEADER,
DUMP_INFO,
DUMP_FILE
@ -48,7 +49,7 @@ private:
TreeModel* model;
UString currentPath;
bool dumped;
int counterHeader, counterBody, counterRaw, counterInfo;
int counterHeader, counterBody, counterUncData, counterRaw, counterInfo;
std::set<UModelIndex> fileList;
};
#endif // FFSDUMPER_H

View file

@ -42,7 +42,7 @@ void print_usage()
<< " UEFIExtract imagefile guids - only generate GUID database, no dump or report needed." << std::endl
<< " UEFIExtract imagefile GUID_1 ... [ -o FILE_1 ... ] [ -m MODE_1 ... ] [ -t TYPE_1 ... ] -" << std::endl
<< " Dump only FFS file(s) with specific GUID(s), without report or GUID database." << std::endl
<< " Type is section type or FF to ignore. Mode is one of: all, body, header, info, file." << std::endl
<< " Type is section type or FF to ignore. Mode is one of: all, body, unc_data, header, info, file." << 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;
}
@ -87,7 +87,7 @@ int main(int argc, char *argv[])
// Parse input buffer
result = ffsParser.parse(buffer);
if (result)
return result;
return (int)result;
ffsParser.outputInfo();
@ -102,7 +102,7 @@ int main(int argc, char *argv[])
else if (argc == 3 && !std::strcmp(argv[2], "guids")) {
GuidDatabase db = guidDatabaseFromTreeRecursive(&model, model.index(0, 0));
if (!db.empty()) {
return guidDatabaseExportToFile(path + UString(".guids.csv"), db);
return (int)guidDatabaseExportToFile(path + UString(".guids.csv"), db);
}
}
// Generate report, no dump or GUID database
@ -175,6 +175,8 @@ int main(int argc, char *argv[])
modes.push_back(FfsDumper::DUMP_ALL);
else if (!std::strcmp(arg, "body"))
modes.push_back(FfsDumper::DUMP_BODY);
else if (!std::strcmp(arg, "unc_data"))
modes.push_back(FfsDumper::DUMP_UNC_DATA);
else if (!std::strcmp(arg, "header"))
modes.push_back(FfsDumper::DUMP_HEADER);
else if (!std::strcmp(arg, "info"))
@ -208,7 +210,7 @@ int main(int argc, char *argv[])
}
}
return lastError;
return (int)lastError;
}
// If parameters are different, show version and usage information