Skip to content

Commit 1a1a208

Browse files
author
Nikolaj Schlej
committed
Refactor UEFIExtract a bit
1 parent ddf40c9 commit 1a1a208

File tree

2 files changed

+201
-187
lines changed

2 files changed

+201
-187
lines changed

UEFIExtract/uefidump.cpp

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -85,67 +85,59 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index)
8585
if (!index.isValid())
8686
return U_INVALID_PARAMETER;
8787

88-
//UByteArray itemHeader = model.header(index);
89-
//UByteArray fileHeader = model.header(model.findParentOfType(index, Types::File));
90-
91-
//if (guid.length() == 0 ||
92-
// (itemHeader.size() >= sizeof (EFI_GUID) && guidToUString(*(const EFI_GUID*)itemHeader.constData()) == guid) ||
93-
// (fileHeader.size() >= sizeof(EFI_GUID) && guidToUString(*(const EFI_GUID*)fileHeader.constData()) == guid)) {
94-
95-
// Construct file name
96-
UString orgName = uniqueItemName(index);
97-
UString name = orgName;
98-
bool nameFound = false;
99-
for (int i = 1; i < 1000; ++i) {
100-
if (!isExistOnFs(name + UString("_info.txt"))) {
101-
nameFound = true;
102-
break;
103-
}
104-
name = orgName + UString("_") + usprintf("%03d", i);
88+
// Construct file name
89+
UString orgName = uniqueItemName(index);
90+
UString name = orgName;
91+
bool nameFound = false;
92+
for (int i = 1; i < 1000; ++i) {
93+
if (!isExistOnFs(name + UString("_info.txt"))) {
94+
nameFound = true;
95+
break;
10596
}
106-
107-
if (!nameFound) {
108-
printf("Cannot find unique name for \"%s\".\n", (const char*)orgName.toLocal8Bit());
109-
return U_INVALID_PARAMETER; //TODO: replace with proper errorCode
97+
name = orgName + UString("_") + usprintf("%03d", i);
98+
}
99+
100+
if (!nameFound) {
101+
printf("Cannot find unique name for \"%s\".\n", (const char*)orgName.toLocal8Bit());
102+
return U_INVALID_PARAMETER; //TODO: replace with proper errorCode
103+
}
104+
105+
// Add header and body only for leaf sections
106+
if (model.rowCount(index) == 0) {
107+
// Header
108+
UByteArray data = model.header(index);
109+
if (!data.isEmpty()) {
110+
std::ofstream file;
111+
UString str = name + UString("_header.bin");
112+
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
113+
file.write(data.constData(), data.size());
114+
file.close();
110115
}
111-
112-
// Add header and body only for leaf sections
113-
if (model.rowCount(index) == 0) {
114-
// Header
115-
UByteArray data = model.header(index);
116-
if (!data.isEmpty()) {
117-
std::ofstream file;
118-
UString str = name + UString("_header.bin");
119-
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
120-
file.write(data.constData(), data.size());
121-
file.close();
122-
}
123-
124-
// Body
125-
data = model.body(index);
126-
if (!data.isEmpty()) {
127-
std::ofstream file;
128-
UString str = name + UString("_body.bin");
129-
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
130-
file.write(data.constData(), data.size());
131-
file.close();
132-
}
116+
117+
// Body
118+
data = model.body(index);
119+
if (!data.isEmpty()) {
120+
std::ofstream file;
121+
UString str = name + UString("_body.bin");
122+
file.open(str.toLocal8Bit(), std::ios::out | std::ios::binary);
123+
file.write(data.constData(), data.size());
124+
file.close();
133125
}
134-
// Info
135-
UString info = "Type: " + itemTypeToUString(model.type(index)) + "\n" +
136-
"Subtype: " + itemSubtypeToUString(model.type(index), model.subtype(index)) + "\n";
137-
if (model.text(index).length() > 0)
138-
info += "Text: " + model.text(index) + "\n";
139-
info += model.info(index) + "\n";
140-
141-
std::ofstream file;
142-
UString str = name + UString("_info.txt");
143-
file.open(str.toLocal8Bit(), std::ios::out);
144-
file.write(info.toLocal8Bit(), info.length());
145-
file.close();
146-
147-
dumped = true;
148-
//}
126+
}
127+
// Info
128+
UString info = "Type: " + itemTypeToUString(model.type(index)) + "\n" +
129+
"Subtype: " + itemSubtypeToUString(model.type(index), model.subtype(index)) + "\n";
130+
if (model.text(index).length() > 0)
131+
info += "Text: " + model.text(index) + "\n";
132+
info += model.info(index) + "\n";
133+
134+
std::ofstream file;
135+
UString str = name + UString("_info.txt");
136+
file.open(str.toLocal8Bit(), std::ios::out);
137+
file.write(info.toLocal8Bit(), info.length());
138+
file.close();
139+
140+
dumped = true;
149141

150142
// Process child items
151143
USTATUS result;

0 commit comments

Comments
 (0)