Skip to content

Commit

Permalink
Refactor UEFIExtract a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajSchlej committed Apr 23, 2023
1 parent ddf40c9 commit 1a1a208
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 187 deletions.
108 changes: 50 additions & 58 deletions UEFIExtract/uefidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,67 +85,59 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
if (!index.isValid())
return U_INVALID_PARAMETER;

//UByteArray itemHeader = model.header(index);
//UByteArray fileHeader = model.header(model.findParentOfType(index, Types::File));

//if (guid.length() == 0 ||
// (itemHeader.size() >= sizeof (EFI_GUID) && guidToUString(*(const EFI_GUID*)itemHeader.constData()) == guid) ||
// (fileHeader.size() >= sizeof(EFI_GUID) && guidToUString(*(const EFI_GUID*)fileHeader.constData()) == guid)) {

// Construct file name
UString orgName = uniqueItemName(index);
UString name = orgName;
bool nameFound = false;
for (int i = 1; i < 1000; ++i) {
if (!isExistOnFs(name + UString("_info.txt"))) {
nameFound = true;
break;
}
name = orgName + UString("_") + usprintf("%03d", i);
// Construct file name
UString orgName = uniqueItemName(index);
UString name = orgName;
bool nameFound = false;
for (int i = 1; i < 1000; ++i) {
if (!isExistOnFs(name + UString("_info.txt"))) {
nameFound = true;
break;
}

if (!nameFound) {
printf("Cannot find unique name for \"%s\".\n", (const char*)orgName.toLocal8Bit());
return U_INVALID_PARAMETER; //TODO: replace with proper errorCode
name = orgName + UString("_") + usprintf("%03d", i);
}

if (!nameFound) {
printf("Cannot find unique name for \"%s\".\n", (const char*)orgName.toLocal8Bit());
return U_INVALID_PARAMETER; //TODO: replace with proper errorCode
}

// Add header and body only for leaf sections
if (model.rowCount(index) == 0) {
// Header
UByteArray data = model.header(index);
if (!data.isEmpty()) {
std::ofstream file;
UString str = name + UString("_header.bin");
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
file.write(data.constData(), data.size());
file.close();
}

// Add header and body only for leaf sections
if (model.rowCount(index) == 0) {
// Header
UByteArray data = model.header(index);
if (!data.isEmpty()) {
std::ofstream file;
UString str = name + UString("_header.bin");
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
file.write(data.constData(), data.size());
file.close();
}

// Body
data = model.body(index);
if (!data.isEmpty()) {
std::ofstream file;
UString str = name + UString("_body.bin");
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
file.write(data.constData(), data.size());
file.close();
}

// Body
data = model.body(index);
if (!data.isEmpty()) {
std::ofstream file;
UString str = name + UString("_body.bin");
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
file.write(data.constData(), data.size());
file.close();
}
// Info
UString info = "Type: " + itemTypeToUString(model.type(index)) + "\n" +
"Subtype: " + itemSubtypeToUString(model.type(index), model.subtype(index)) + "\n";
if (model.text(index).length() > 0)
info += "Text: " + model.text(index) + "\n";
info += model.info(index) + "\n";

std::ofstream file;
UString str = name + UString("_info.txt");
file.open(str.toLocal8Bit(), std::ios::out);
file.write(info.toLocal8Bit(), info.length());
file.close();

dumped = true;
//}
}
// Info
UString info = "Type: " + itemTypeToUString(model.type(index)) + "\n" +
"Subtype: " + itemSubtypeToUString(model.type(index), model.subtype(index)) + "\n";
if (model.text(index).length() > 0)
info += "Text: " + model.text(index) + "\n";
info += model.info(index) + "\n";

std::ofstream file;
UString str = name + UString("_info.txt");
file.open(str.toLocal8Bit(), std::ios::out);
file.write(info.toLocal8Bit(), info.length());
file.close();

dumped = true;

// Process child items
USTATUS result;
Expand Down
Loading

0 comments on commit 1a1a208

Please sign in to comment.