mirror of
https://github.com/QuasarApp/LIEF.git
synced 2025-05-19 14:49:33 +00:00
Merge pull request #444 from kohnakagawa/feature/parse_resource_html
Fix to parse html resource
This commit is contained in:
commit
10f0a2857f
@ -113,6 +113,14 @@ void create<ResourcesManager>(py::module& m) {
|
|||||||
&ResourcesManager::string_table,
|
&ResourcesManager::string_table,
|
||||||
"Return list of " RST_CLASS_REF(lief.PE.ResourceStringTable) " present in the resource")
|
"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",
|
.def("get_node_type",
|
||||||
static_cast<no_const_func<ResourceNode&, RESOURCE_TYPES>>(&ResourcesManager::get_node_type),
|
static_cast<no_const_func<ResourceNode&, RESOURCE_TYPES>>(&ResourcesManager::get_node_type),
|
||||||
"Return " RST_CLASS_REF(lief.PE.ResourceNode) " with "
|
"Return " RST_CLASS_REF(lief.PE.ResourceNode) " with "
|
||||||
|
@ -127,6 +127,15 @@ class LIEF_API ResourcesManager : public Object {
|
|||||||
//! @brief Return the list of the string table in the resource
|
//! @brief Return the list of the string table in the resource
|
||||||
std::vector<ResourceStringTable> string_table(void) const;
|
std::vector<ResourceStringTable> 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<std::string> html(void) const;
|
||||||
|
|
||||||
// Print
|
// Print
|
||||||
// =====
|
// =====
|
||||||
|
|
||||||
|
@ -353,7 +353,6 @@ std::string ResourcesManager::manifest(void) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it_childs childs_l2 = childs_l1[0].childs();
|
it_childs childs_l2 = childs_l1[0].childs();
|
||||||
|
|
||||||
if (childs_l2.size() < 1) {
|
if (childs_l2.size() < 1) {
|
||||||
throw not_found("Manifest corrupted");
|
throw not_found("Manifest corrupted");
|
||||||
}
|
}
|
||||||
@ -1248,6 +1247,46 @@ bool ResourcesManager::has_string_table(void) const {
|
|||||||
return this->has_type(RESOURCE_TYPES::STRING);
|
return this->has_type(RESOURCE_TYPES::STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> 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<RESOURCE_TYPES>(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<std::string> html;
|
||||||
|
for (const ResourceNode& child_l1 : it_html->childs()) {
|
||||||
|
for (const ResourceNode& child_l2 : child_l1.childs()) {
|
||||||
|
const ResourceData* html_node = dynamic_cast<const ResourceData*>(&child_l2);
|
||||||
|
if (!html_node) {
|
||||||
|
LOG(ERROR) << "html node is null";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<uint8_t>& 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
|
// Prints
|
||||||
// ======
|
// ======
|
||||||
|
|
||||||
|
@ -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()) {
|
if (resources_manager.has_version()) {
|
||||||
JsonVisitor version_visitor;
|
JsonVisitor version_visitor;
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user