Skip to content

Commit

Permalink
dump modules in readable format
Browse files Browse the repository at this point in the history
  • Loading branch information
yeggor committed Oct 5, 2024
1 parent 0573da0 commit 3b5acc5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
29 changes: 14 additions & 15 deletions efiXloader/uefitool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ void efiloader::Uefitool::get_image_guid(qstring &image_guid,
}

std::vector<std::string>
efiloader::Uefitool::parseDepexSectionBody(const UModelIndex &index,
UString &parsed) {
efiloader::Uefitool::parse_depex_section_body(const UModelIndex &index,
UString &parsed) {
// Adopted from FfsParser::parseDepexSectionBody
std::vector<std::string> res;

Expand Down Expand Up @@ -180,7 +180,7 @@ efiloader::Uefitool::parseDepexSectionBody(const UModelIndex &index,
}

std::vector<std::string>
efiloader::Uefitool::parseAprioriRawSection(const UModelIndex &index) {
efiloader::Uefitool::parse_apriori_raw_section(const UModelIndex &index) {
// Adopted from FfsParser::parseDepexSectionBody
std::vector<std::string> res;

Expand Down Expand Up @@ -270,9 +270,8 @@ void efiloader::Uefitool::dump(const UModelIndex &index, uint8_t el_type,
if (images_guids[guid.c_str()]
.is_null()) { // check if GUID already exists
get_unique_name(module_name);
images_guids[guid.c_str()] = {
module_name.c_str(),
fileTypeToUString(model.subtype(index.parent())).toLocal8Bit()};
images_guids[guid.c_str()] = {{"name", module_name.c_str()},
{"kind", get_kind(index)}};
file->qname.swap(module_name);
file->write();
files.push_back(file);
Expand Down Expand Up @@ -307,9 +306,8 @@ void efiloader::Uefitool::dump(const UModelIndex &index, uint8_t el_type,
files.push_back(file);
if (module_name.size()) {
// save image to the images_guids
images_guids[module_name.c_str()] = {
module_name.c_str(),
fileTypeToUString(model.subtype(index.parent())).toLocal8Bit()};
images_guids[module_name.c_str()] = {{"name", module_name.c_str()},
{"kind", get_kind(index)}};
}
}
break;
Expand Down Expand Up @@ -344,7 +342,7 @@ void efiloader::Uefitool::get_deps(UModelIndex index, std::string key) {
qstring image_guid("");

get_image_guid(image_guid, index);
deps = parseDepexSectionBody(index, parsed);
deps = parse_depex_section_body(index, parsed);
if (deps.size()) {
msg("[efiXloader] dependency section for image with GUID %s: %s\n",
image_guid.c_str(), parsed.data);
Expand All @@ -356,22 +354,23 @@ void efiloader::Uefitool::get_apriori(UModelIndex index, std::string key) {
if (all_deps.contains(key)) {
return;
}
std::vector<std::string> deps = parseAprioriRawSection(index);
auto deps = parse_apriori_raw_section(index);
if (deps.empty()) {
return;
}
all_deps[key] = deps;
}

void efiloader::Uefitool::dump_jsons() {
// Dump deps
// dump JSON with DEPEX and GUIDs information for each image

std::filesystem::path out;
out /= get_path(PATH_TYPE_IDB);
out.replace_extension(".deps.json");
std::ofstream out_deps(out);
out_deps << std::setw(4) << all_deps << std::endl;
// Dump images
out_deps << std::setw(2) << all_deps << std::endl;

out.replace_extension("").replace_extension(".images.json");
std::ofstream out_guids(out);
out_guids << std::setw(4) << images_guids << std::endl;
out_guids << std::setw(2) << images_guids << std::endl;
}
21 changes: 14 additions & 7 deletions efiXloader/uefitool.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ class Uefitool {
}
void get_unique_name(qstring &image_name);
void get_image_guid(qstring &image_guid, UModelIndex index);
std::vector<std::string> parseDepexSectionBody(const UModelIndex &index,
UString &parsed);
std::vector<std::string> parseAprioriRawSection(const UModelIndex &index);
std::vector<std::string> parse_depex_section_body(const UModelIndex &index,
UString &parsed);
std::vector<std::string> parse_apriori_raw_section(const UModelIndex &index);
void get_deps(UModelIndex index, std::string key);
void get_apriori(UModelIndex index, std::string key);
void
dump_jsons(); // dump JSON with DEPEX and GUIDs information for each image
json all_deps; // DEPEX information for each image
json images_guids; // matching the modules to the parent's GUIDs
void dump_jsons();

// DEPEX information for each image
json all_deps;

json images_guids;
TreeModel model;
const char *buffer;
uint32_t buffer_size;
Expand All @@ -149,5 +151,10 @@ class Uefitool {
void set_machine_type(UByteArray pe_body);
uint16_t machine_type = 0xffff;
bool machine_type_detected = false;

private:
std::string get_kind(const UModelIndex &index) {
return fileTypeToUString(model.subtype(index.parent())).toLocal8Bit();
}
};
} // namespace efiloader

0 comments on commit 3b5acc5

Please sign in to comment.