Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Enhance PE resources
* Improve Resource Manager * Fix bug when rebuilding resources (aligment issue) * Provide a Python API to access to the resource tree * Pretty print lang/sublang of resources * Parse resource dialog * Parse resource icons * Parse resource version * Add tests on the resource builder * Add tutorial (related to #28)
- Loading branch information
1 parent
a9dcfb5
commit 8473c8e
Showing
135 changed files
with
9,757 additions
and
38,240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* Copyright 2017 R. Thomas | ||
* Copyright 2017 Quarkslab | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "pyPE.hpp" | ||
|
||
#include "LIEF/visitors/Hash.hpp" | ||
#include "LIEF/PE/ResourceData.hpp" | ||
|
||
#include <string> | ||
#include <sstream> | ||
|
||
template<class T> | ||
using getter_t = T (ResourceData::*)(void) const; | ||
|
||
template<class T> | ||
using setter_t = void (ResourceData::*)(T); | ||
|
||
void init_PE_ResourceData_class(py::module& m) { | ||
py::class_<ResourceData, ResourceNode>(m, "ResourceData") | ||
.def(py::init<>(), | ||
"Default constructor") | ||
|
||
.def(py::init<const std::vector<uint8_t>&, uint32_t>(), | ||
"content"_a, "code_page"_a) | ||
|
||
.def_property("code_page", | ||
static_cast<getter_t<uint32_t>>(&ResourceData::code_page), | ||
static_cast<setter_t<uint32_t>>(&ResourceData::code_page), | ||
"The code page that is used to decode code point " | ||
"values within the resource data. Typically, the code " | ||
"page would be the Unicode code page") | ||
|
||
.def_property("content", | ||
static_cast<getter_t<const std::vector<uint8_t>&>>(&ResourceData::content), | ||
static_cast<setter_t<const std::vector<uint8_t>&>>(&ResourceData::content), | ||
"Resource content") | ||
|
||
.def_property("reserved", | ||
static_cast<getter_t<uint32_t>>(&ResourceData::reserved), | ||
static_cast<setter_t<uint32_t>>(&ResourceData::reserved), | ||
"Reserved value. Should be ``0``") | ||
|
||
.def_property_readonly("offset", | ||
&ResourceData::offset, | ||
"Offset of the content within the resource") | ||
|
||
.def("__eq__", &ResourceData::operator==) | ||
.def("__ne__", &ResourceData::operator!=) | ||
|
||
.def("__hash__", | ||
[] (const ResourceData& node) { | ||
return LIEF::Hash::hash(node); | ||
}) | ||
|
||
.def("__str__", | ||
[] (const ResourceData& data) { | ||
std::ostringstream stream; | ||
stream << data; | ||
std::string str = stream.str(); | ||
return str; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* Copyright 2017 R. Thomas | ||
* Copyright 2017 Quarkslab | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "pyPE.hpp" | ||
|
||
#include "LIEF/visitors/Hash.hpp" | ||
#include "LIEF/PE/ResourceDirectory.hpp" | ||
|
||
#include <string> | ||
#include <sstream> | ||
|
||
template<class T> | ||
using getter_t = T (ResourceDirectory::*)(void) const; | ||
|
||
template<class T> | ||
using setter_t = void (ResourceDirectory::*)(T); | ||
|
||
void init_PE_ResourceDirectory_class(py::module& m) { | ||
py::class_<ResourceDirectory, ResourceNode>(m, "ResourceDirectory") | ||
.def(py::init<>(), | ||
"Default constructor") | ||
|
||
.def_property("characteristics", | ||
static_cast<getter_t<uint32_t>>(&ResourceDirectory::characteristics), | ||
static_cast<setter_t<uint32_t>>(&ResourceDirectory::characteristics), | ||
"Resource flags. This field is reserved for future use. " | ||
"It is currently set to zero.") | ||
|
||
.def_property("time_date_stamp", | ||
static_cast<getter_t<uint32_t>>(&ResourceDirectory::time_date_stamp), | ||
static_cast<setter_t<uint32_t>>(&ResourceDirectory::time_date_stamp), | ||
"The time that the resource data was created by the " | ||
"resource compiler.") | ||
|
||
.def_property("major_version", | ||
static_cast<getter_t<uint16_t>>(&ResourceDirectory::major_version), | ||
static_cast<setter_t<uint16_t>>(&ResourceDirectory::major_version), | ||
"The major version number, set by the user.") | ||
|
||
.def_property("minor_version", | ||
static_cast<getter_t<uint16_t>>(&ResourceDirectory::minor_version), | ||
static_cast<setter_t<uint16_t>>(&ResourceDirectory::minor_version), | ||
"The minor version number, set by the user.") | ||
|
||
.def_property("numberof_name_entries", | ||
static_cast<getter_t<uint16_t>>(&ResourceDirectory::numberof_name_entries), | ||
static_cast<setter_t<uint16_t>>(&ResourceDirectory::numberof_name_entries), | ||
"The number of directory entries immediately " | ||
"following the table that use strings to identify Type, " | ||
"Name, or Language entries (depending on the level " | ||
"of the table") | ||
|
||
.def_property("numberof_id_entries", | ||
static_cast<getter_t<uint16_t>>(&ResourceDirectory::numberof_id_entries), | ||
static_cast<setter_t<uint16_t>>(&ResourceDirectory::numberof_id_entries), | ||
"The number of directory entries immediately " | ||
"following the Name entries that use numeric IDs for " | ||
"Type, Name, or Language entries.") | ||
|
||
|
||
.def("__eq__", &ResourceDirectory::operator==) | ||
.def("__ne__", &ResourceDirectory::operator!=) | ||
|
||
.def("__hash__", | ||
[] (const ResourceDirectory& node) { | ||
return LIEF::Hash::hash(node); | ||
}) | ||
|
||
.def("__str__", | ||
[] (const ResourceDirectory& directory) { | ||
std::ostringstream stream; | ||
stream << directory; | ||
std::string str = stream.str(); | ||
return str; | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* Copyright 2017 R. Thomas | ||
* Copyright 2017 Quarkslab | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "pyPE.hpp" | ||
|
||
#include "LIEF/visitors/Hash.hpp" | ||
#include "LIEF/PE/ResourceNode.hpp" | ||
|
||
#include <string> | ||
#include <sstream> | ||
|
||
template<class T> | ||
using getter_t = T (ResourceNode::*)(void) const; | ||
|
||
template<class T> | ||
using setter_t = void (ResourceNode::*)(T); | ||
|
||
void init_PE_ResourceNode_class(py::module& m) { | ||
py::class_<ResourceNode>(m, "ResourceNode") | ||
|
||
.def_property("id", | ||
static_cast<getter_t<uint32_t>>(&ResourceNode::id), | ||
static_cast<setter_t<uint32_t>>(&ResourceNode::id), | ||
"Integer that identifies the Type, Name, or " | ||
"Language ID entry.") | ||
|
||
.def_property_readonly("is_directory", | ||
&ResourceNode::is_directory, | ||
"``True`` if the current resource is a " RST_CLASS_REF(lief.PE.ResourceDirectory) "") | ||
|
||
.def_property_readonly("is_data", | ||
&ResourceNode::is_data, | ||
"``True`` if the current resource is a " RST_CLASS_REF(lief.PE.ResourceData) "") | ||
|
||
.def_property_readonly("has_name", | ||
&ResourceNode::has_name, | ||
"``True`` if the current resource uses a name") | ||
|
||
.def_property("name", | ||
[] (const ResourceNode& node) { | ||
return u16tou8(node.name()); | ||
}, | ||
static_cast<void (ResourceNode::*)(const std::string&)>(&ResourceNode::name), | ||
"Resource name") | ||
|
||
.def_property_readonly("childs", | ||
static_cast<it_childs (ResourceNode::*)(void)>(&ResourceNode::childs), | ||
"Node's childs") | ||
|
||
.def("add_directory_node", | ||
static_cast<ResourceNode& (ResourceNode::*)(const ResourceDirectory&)>(&ResourceNode::add_child), | ||
"Add a " RST_CLASS_REF(lief.PE.ResourceDirectory) " to the current node", | ||
"resource_directory"_a) | ||
|
||
.def("add_data_node", | ||
static_cast<ResourceNode& (ResourceNode::*)(const ResourceData&)>(&ResourceNode::add_child), | ||
"Add a " RST_CLASS_REF(lief.PE.ResourceData) " to the current node", | ||
"resource_data"_a) | ||
|
||
.def("delete_child", | ||
static_cast<void (ResourceNode::*)(const ResourceNode&)>(&ResourceNode::delete_child), | ||
"Delete the given " RST_CLASS_REF(lief.PE.ResourceNode) " from childs", | ||
"node"_a) | ||
|
||
.def("delete_child", | ||
static_cast<void (ResourceNode::*)(uint32_t)>(&ResourceNode::delete_child), | ||
"Delete the " RST_CLASS_REF(lief.PE.ResourceNode) " with the given :attr:`~lief.PE.ResourceNode.id` from childs", | ||
"id"_a) | ||
|
||
.def("sort_by_id", | ||
&ResourceNode::sort_by_id, | ||
"Sort resource childs by ID") | ||
|
||
.def_property_readonly("depth", | ||
&ResourceNode::depth, | ||
"Current depth of the entry in the resource tree") | ||
|
||
.def("__eq__", &ResourceNode::operator==) | ||
.def("__ne__", &ResourceNode::operator!=) | ||
|
||
.def("__hash__", | ||
[] (const ResourceNode& node) { | ||
return LIEF::Hash::hash(node); | ||
}) | ||
|
||
.def("__str__", | ||
[] (const ResourceNode& node) { | ||
std::ostringstream stream; | ||
stream << node; | ||
std::string str = stream.str(); | ||
return str; | ||
}); | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.