LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_PE_RESOURCE_NODE_H
17#define LIEF_PE_RESOURCE_NODE_H
33struct pe_resource_directory_table;
51 using childs_t = std::vector<std::unique_ptr<ResourceNode>>;
52 using it_childs = ref_iterator<childs_t&, ResourceNode*>;
53 using it_const_childs = const_ref_iterator<const childs_t&, ResourceNode*>;
66 ResourceNode&
operator=(ResourceNode&& other) =
default;
68 void swap(ResourceNode& other);
71 static std::unique_ptr<ResourceNode>
parse(BinaryStream& stream, uint64_t rva);
78 static std::unique_ptr<ResourceNode>
parse(
const uint8_t* buffer,
size_t size,
84 static std::unique_ptr<ResourceNode>
parse(
const std::vector<uint8_t>& buffer,
89 return parse(buffer.data(), buffer.size(), rva);
91 static std::unique_ptr<ResourceNode>
parse(span<const uint8_t> buffer,
96 return parse(buffer.data(), buffer.size(), rva);
99 static std::unique_ptr<ResourceNode>
100 parse(BinaryStream& stream,
const Binary& bin);
102 virtual std::unique_ptr<ResourceNode>
clone()
const = 0;
103 uint32_t
id()
const {
109 const std::u16string&
name()
const {
129 return (
bool)(id() & 0x80000000);
131 uint32_t
depth()
const {
145 return type_ == TYPE::DIRECTORY;
156 return type_ == TYPE::DATA;
159 void id(uint32_t
id) {
163 void name(
const std::string& name);
165 void name(std::u16string name) {
166 name_ = std::move(name);
168 ResourceNode&
add_child(std::unique_ptr<ResourceNode> child);
172 ResourceNode&
add_child(
const ResourceNode& child) {
175 return add_child(child.
clone());
184 void accept(Visitor& visitor)
const override;
188 static_assert(std::is_base_of<ResourceNode, T>::value,
"Require inheritance relationship");
189 if (T::classof(
this)) {
190 return static_cast<const T*
>(
this);
197 return const_cast<T*
>(
static_cast<const ResourceNode*
>(
this)->cast<
T>());
203 std::ostringstream oss;
207 LIEF_LOCAL const ResourceNode& safe_get_at(
size_t idx)
const;
214 LIEF_LOCAL ResourceNode& safe_get_at(
size_t idx) {
217 return const_cast<ResourceNode&
>(
static_cast<const ResourceNode*
>(
this)->safe_get_at(idx));
226 childs_.push_back(std::move(node));
232 return !(LHS == RHS);
236 ResourceNode() =
default;
237 ResourceNode(TYPE type) :
241 std::unique_ptr<ResourceNode> parse_resource_node(
242 const details::pe_resource_directory_table& directory_table,
243 uint32_t base_offset, uint32_t current_offset, uint32_t depth = 0);
245 childs_t::iterator insert_child(std::unique_ptr<ResourceNode> child);
247 TYPE type_ = TYPE::UNKNOWN;
249 std::u16string name_;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:56
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
Class which represents a Data Node in the PE resources tree.
Definition ResourceData.hpp:33
Definition ResourceDirectory.hpp:33
Class which represents a Node in the resource tree.
Definition ResourceNode.hpp:45
bool is_directory() const
True if the current entry is a ResourceDirectory.
Definition ResourceNode.hpp:144
void delete_child(uint32_t id)
Delete the node with the given id
ResourceNode & add_child(const ResourceNode &child)
Add a new child to the current node.
Definition ResourceNode.hpp:174
static std::unique_ptr< ResourceNode > parse(BinaryStream &stream, const Binary &bin)
it_const_childs childs() const
Definition ResourceNode.hpp:123
ResourceNode & add_child(std::unique_ptr< ResourceNode > child)
Add a new child to the current node, taking the ownership of the provided unique_ptr
ResourceNode & operator=(const ResourceNode &other)
const std::u16string & name() const
Name of the entry (if any)
Definition ResourceNode.hpp:111
void push_child(std::unique_ptr< ResourceNode > node)
Definition ResourceNode.hpp:225
bool is_data() const
True if the current entry is a ResourceData.
Definition ResourceNode.hpp:155
static std::unique_ptr< ResourceNode > parse(const std::vector< uint8_t > &buffer, uint64_t rva)
See doc from other parse functions.
Definition ResourceNode.hpp:86
ResourceNode(ResourceNode &&other)=default
std::string to_string() const
Definition ResourceNode.hpp:202
ResourceNode & operator=(ResourceNode &&other)=default
static std::unique_ptr< ResourceNode > parse(BinaryStream &stream, uint64_t rva)
Parse the resource tree from the provided BinaryStream stream and with the original RVA provided in t...
friend bool operator==(const ResourceNode &LHS, const ResourceNode &RHS)
const T * cast() const
Definition ResourceNode.hpp:187
uint32_t depth() const
Current depth of the Node in the resource tree.
Definition ResourceNode.hpp:133
bool has_name() const
True if the entry uses a name as ID
Definition ResourceNode.hpp:128
static std::unique_ptr< ResourceNode > parse(const uint8_t *buffer, size_t size, uint64_t rva)
Parse the resource tree from the provided buffer referenced by a pointer and the size....
void delete_child(const ResourceNode &node)
Delete the given node from the node's children.
ResourceNode(const ResourceNode &other)
virtual std::unique_ptr< ResourceNode > clone() const =0
uint32_t id() const
Integer that identifies the Type, Name, or Language ID of the entry depending on its depth in the tre...
Definition ResourceNode.hpp:106
it_childs childs()
Iterator on node's children.
Definition ResourceNode.hpp:119
void swap(ResourceNode &other)
friend bool operator!=(const ResourceNode &LHS, const ResourceNode &RHS)
Definition ResourceNode.hpp:231
void name(std::u16string name)
Definition ResourceNode.hpp:165
void accept(Visitor &visitor) const override
static std::unique_ptr< ResourceNode > parse(span< const uint8_t > buffer, uint64_t rva)
See doc from other parse functions.
Definition ResourceNode.hpp:93
void name(const std::string &name)
void id(uint32_t id)
Definition ResourceNode.hpp:159
std::string utf8_name() const
UTF-8 representation of the name()
friend std::ostream & operator<<(std::ostream &os, const ResourceNode &node)
T * cast()
Definition ResourceNode.hpp:196
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
@ T
Definition AcceleratorCodes.hpp:97
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42