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,
89 return parse(buffer.data(), buffer.size(), rva);
95 return parse(buffer.data(), buffer.size(), rva);
101 virtual std::unique_ptr<ResourceNode>
clone()
const = 0;
105 uint32_t
id()
const {
110 const std::u16string&
name()
const {
128 return (
bool)(
id() & 0x80000000);
158 void id(uint32_t
id) {
165 name_ = std::move(
name);
187 static_assert(std::is_base_of<ResourceNode, T>::value,
188 "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>());
204 std::ostringstream oss;
219 static_cast<const ResourceNode*
>(
this)->safe_get_at(idx)
229 childs_.push_back(std::move(node));
237 return !(LHS == RHS);
245 std::unique_ptr<ResourceNode> parse_resource_node(
246 const details::pe_resource_directory_table& directory_table,
247 uint32_t base_offset, uint32_t current_offset, uint32_t depth = 0
250 childs_t::iterator insert_child(std::unique_ptr<ResourceNode> child);
252 TYPE type_ = TYPE::UNKNOWN;
254 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 Parser::parse functions 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:143
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:173
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:122
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:110
void push_child(std::unique_ptr< ResourceNode > node)
Definition ResourceNode.hpp:228
bool is_data() const
True if the current entry is a ResourceData.
Definition ResourceNode.hpp:154
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:186
uint32_t depth() const
Current depth of the Node in the resource tree.
Definition ResourceNode.hpp:132
friend class Builder
Definition ResourceNode.hpp:49
bool has_name() const
True if the entry uses a name as ID
Definition ResourceNode.hpp:127
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:105
friend class Parser
Definition ResourceNode.hpp:48
it_childs childs()
Iterator on node's children.
Definition ResourceNode.hpp:118
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:235
void name(std::u16string name)
Definition ResourceNode.hpp:164
TYPE
Enum that identifies the type of a node in the resource tree.
Definition ResourceNode.hpp:57
@ DIRECTORY
Definition ResourceNode.hpp:60
@ 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:93
void name(const std::string &name)
void id(uint32_t id)
Definition ResourceNode.hpp:158
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:196
Definition Visitor.hpp:212
Iterator which returns reference on container's values.
Definition iterators.hpp:45
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:286
#define LIEF_API
Definition visibility.h:43
#define LIEF_LOCAL
Definition visibility.h:44