16#ifndef LIEF_PE_RESOURCE_NODE_H
17#define LIEF_PE_RESOURCE_NODE_H
34struct pe_resource_directory_table;
52 using childs_t = std::vector<std::unique_ptr<ResourceNode>>;
83 static std::unique_ptr<ResourceNode>
parse(
const uint8_t* buffer,
size_t size,
87 static std::unique_ptr<ResourceNode>
parse(
const std::vector<uint8_t>& buffer,
90 return parse(buffer.data(), buffer.size(), rva);
97 return parse(buffer.data(), buffer.size(), rva);
100 static std::unique_ptr<ResourceNode>
103 virtual std::unique_ptr<ResourceNode>
clone()
const = 0;
107 uint32_t
id()
const {
112 const std::u16string&
name()
const {
130 return (
bool)(
id() & 0x80000000);
160 void id(uint32_t
id) {
167 name_ = std::move(
name);
189 static_assert(std::is_base_of<ResourceNode, T>::value,
"Require inheritance relationship");
190 if (T::classof(
this)) {
191 return static_cast<const T*
>(
this);
198 return const_cast<T*
>(
static_cast<const ResourceNode*
>(
this)->cast<
T>());
204 std::ostringstream oss;
227 childs_.push_back(std::move(node));
233 return !(LHS == RHS);
242 std::unique_ptr<ResourceNode> parse_resource_node(
243 const details::pe_resource_directory_table& directory_table,
244 uint32_t base_offset, uint32_t current_offset, uint32_t depth = 0);
246 childs_t::iterator insert_child(std::unique_ptr<ResourceNode> child);
248 TYPE type_ = TYPE::UNKNOWN;
250 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:57
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:46
bool is_directory() const
True if the current entry is a ResourceDirectory.
Definition ResourceNode.hpp:145
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:175
static std::unique_ptr< ResourceNode > parse(BinaryStream &stream, const Binary &bin)
std::vector< std::unique_ptr< ResourceNode > > childs_t
Definition ResourceNode.hpp:52
it_const_childs childs() const
Definition ResourceNode.hpp:124
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:112
void push_child(std::unique_ptr< ResourceNode > node)
Definition ResourceNode.hpp:226
bool is_data() const
True if the current entry is a ResourceData.
Definition ResourceNode.hpp:156
static std::unique_ptr< ResourceNode > parse(const std::vector< uint8_t > &buffer, uint64_t rva)
See doc from other parse functions.
Definition ResourceNode.hpp:87
ResourceNode(ResourceNode &&other)=default
std::string to_string() const
Definition ResourceNode.hpp:203
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:188
uint32_t depth() const
Current depth of the Node in the resource tree.
Definition ResourceNode.hpp:134
friend class Builder
Definition ResourceNode.hpp:49
bool has_name() const
True if the entry uses a name as ID
Definition ResourceNode.hpp:129
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:107
friend class Parser
Definition ResourceNode.hpp:48
it_childs childs()
Iterator on node's children.
Definition ResourceNode.hpp:120
ref_iterator< childs_t &, ResourceNode * > it_childs
Definition ResourceNode.hpp:53
void swap(ResourceNode &other)
friend bool operator!=(const ResourceNode &LHS, const ResourceNode &RHS)
Definition ResourceNode.hpp:232
void name(std::u16string name)
Definition ResourceNode.hpp:166
TYPE
Enum that identifies the type of a node in the resource tree.
Definition ResourceNode.hpp:57
@ DIRECTORY
Definition ResourceNode.hpp:60
@ UNKNOWN
Definition ResourceNode.hpp:58
@ DATA
Definition ResourceNode.hpp:59
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:94
void name(const std::string &name)
void id(uint32_t id)
Definition ResourceNode.hpp:160
std::string utf8_name() const
UTF-8 representation of the name().
friend std::ostream & operator<<(std::ostream &os, const ResourceNode &node)
const_ref_iterator< const childs_t &, ResourceNode * > it_const_childs
Definition ResourceNode.hpp:54
T * cast()
Definition ResourceNode.hpp:197
Definition Visitor.hpp:210
Iterator which returns reference on container's values.
Definition iterators.hpp:46
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:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which return const ref on container's values.
Definition iterators.hpp:257
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42