diff --git a/api/python/PE/objects/pyResourcesManager.cpp b/api/python/PE/objects/pyResourcesManager.cpp index 8da8921..8eb03ee 100644 --- a/api/python/PE/objects/pyResourcesManager.cpp +++ b/api/python/PE/objects/pyResourcesManager.cpp @@ -113,6 +113,14 @@ void create(py::module& m) { &ResourcesManager::string_table, "Return list of " RST_CLASS_REF(lief.PE.ResourceStringTable) " present in the resource") + .def_property_readonly("has_html", + &ResourcesManager::has_html, + "``True`` if resources contain HTML resource") + + .def_property_readonly("html", + &ResourcesManager::html, + "HTML resource as the list of ``string``") + .def("get_node_type", static_cast>(&ResourcesManager::get_node_type), "Return " RST_CLASS_REF(lief.PE.ResourceNode) " with " diff --git a/include/LIEF/PE/ResourcesManager.hpp b/include/LIEF/PE/ResourcesManager.hpp index 1f40351..5f236b1 100644 --- a/include/LIEF/PE/ResourcesManager.hpp +++ b/include/LIEF/PE/ResourcesManager.hpp @@ -127,6 +127,15 @@ class LIEF_API ResourcesManager : public Object { //! @brief Return the list of the string table in the resource std::vector string_table(void) const; + // HTML + // ==== + + //! @brief ``true`` if resources contain html + bool has_html(void) const; + + //! @brief Return the list of the html resource + std::vector html(void) const; + // Print // ===== diff --git a/src/PE/ResourcesManager.cpp b/src/PE/ResourcesManager.cpp index 23ca55c..f6b7d7d 100644 --- a/src/PE/ResourcesManager.cpp +++ b/src/PE/ResourcesManager.cpp @@ -353,7 +353,6 @@ std::string ResourcesManager::manifest(void) const { } it_childs childs_l2 = childs_l1[0].childs(); - if (childs_l2.size() < 1) { throw not_found("Manifest corrupted"); } @@ -1248,6 +1247,46 @@ bool ResourcesManager::has_string_table(void) const { return this->has_type(RESOURCE_TYPES::STRING); } +std::vector ResourcesManager::html(void) const { + it_childs nodes = this->resources_->childs(); + auto&& it_html = std::find_if( + std::begin(nodes), + std::end(nodes), + [] (const ResourceNode& node) { + return static_cast(node.id()) == RESOURCE_TYPES::HTML; + } + ); + + if (it_html == std::end(nodes)) { + throw not_found(std::string("Missing '") + to_string(RESOURCE_TYPES::HTML) + "' entry"); + } + + std::vector html; + for (const ResourceNode& child_l1 : it_html->childs()) { + for (const ResourceNode& child_l2 : child_l1.childs()) { + const ResourceData* html_node = dynamic_cast(&child_l2); + if (!html_node) { + LOG(ERROR) << "html node is null"; + continue; + } + + const std::vector& content = html_node->content(); + if (content.empty()) { + LOG(ERROR) << "html content is empty"; + continue; + } + + html.push_back(std::string{std::begin(content), std::end(content)}); + } + } + + return html; +} + +bool ResourcesManager::has_html(void) const { + return this->has_type(RESOURCE_TYPES::HTML); +} + // Prints // ====== diff --git a/src/PE/json.cpp b/src/PE/json.cpp index 2a04c7f..5047253 100644 --- a/src/PE/json.cpp +++ b/src/PE/json.cpp @@ -507,6 +507,14 @@ void JsonVisitor::visit(const ResourcesManager& resources_manager) { } } + if (resources_manager.has_html()) { + try { + this->node_["html"] = resources_manager.html(); + } catch (const LIEF::exception& e) { + LOG(WARNING) << e.what(); + } + } + if (resources_manager.has_version()) { JsonVisitor version_visitor; try {