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
34struct pe_resource_directory_table;
52 using childs_t = std::vector<std::unique_ptr<ResourceNode>>;
53 using it_childs = ref_iterator<childs_t&, ResourceNode*>;
54 using it_const_childs = const_ref_iterator<const childs_t&, ResourceNode*>;
67 ResourceNode&
operator=(ResourceNode&& other) =
default;
69 void swap(ResourceNode& other);
72 static std::unique_ptr<ResourceNode>
parse(BinaryStream& stream, uint64_t rva);
79 static std::unique_ptr<ResourceNode>
parse(
const uint8_t* buffer,
size_t size,
85 static std::unique_ptr<ResourceNode>
parse(
const std::vector<uint8_t>& buffer,
90 return parse(buffer.data(), buffer.size(), rva);
92 static std::unique_ptr<ResourceNode>
parse(span<const uint8_t> buffer,
97 return parse(buffer.data(), buffer.size(), rva);
100 static std::unique_ptr<ResourceNode>
101 parse(BinaryStream& stream,
const Binary& bin);
103 virtual std::unique_ptr<ResourceNode>
clone()
const = 0;
104 uint32_t
id()
const {
110 const std::u16string&
name()
const {
130 return (
bool)(id() & 0x80000000);
132 uint32_t
depth()
const {
146 return type_ == TYPE::DIRECTORY;
157 return type_ == TYPE::DATA;
160 void id(uint32_t
id) {
164 void name(
const std::string& name);
166 void name(std::u16string name) {
167 name_ = std::move(name);
169 ResourceNode&
add_child(std::unique_ptr<ResourceNode> child);
173 ResourceNode&
add_child(
const ResourceNode& child) {
176 return add_child(child.
clone());
185 void accept(Visitor& visitor)
const override;
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;
208 LIEF_LOCAL const ResourceNode& safe_get_at(
size_t idx)
const;
215 LIEF_LOCAL ResourceNode& safe_get_at(
size_t idx) {
218 return const_cast<ResourceNode&
>(
static_cast<const ResourceNode*
>(
this)->safe_get_at(idx));
227 childs_.push_back(std::move(node));
233 return !(LHS == RHS);
237 ResourceNode() =
default;
238 ResourceNode(TYPE type) :
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: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: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)
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
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
it_childs childs()
Iterator on node's children.
Definition ResourceNode.hpp:120
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
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)
T * cast()
Definition ResourceNode.hpp:197
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