LIEF: Library to Instrument Executable Formats Version 0.16.6
Loading...
Searching...
No Matches
ResourceNode.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_PE_RESOURCE_NODE_H
17#define LIEF_PE_RESOURCE_NODE_H
18#include <string>
19#include <vector>
20#include <memory>
21#include <sstream>
22#include <cstdint>
23
24#include "LIEF/Object.hpp"
25#include "LIEF/visibility.h"
26#include "LIEF/iterators.hpp"
27
28namespace LIEF {
29namespace PE {
30
32class ResourceData;
33
34class Parser;
35class Builder;
36class LIEF_API ResourceNode : public Object {
39
40 friend class Parser;
41 friend class Builder;
42
43 public:
44 using childs_t = std::vector<std::unique_ptr<ResourceNode>>;
45 using it_childs = ref_iterator<childs_t&, ResourceNode*>;
46 using it_const_childs = const_ref_iterator<const childs_t&, ResourceNode*>;
47 enum class TYPE {
50 UNKNOWN = 0,
52 DIRECTORY,
53 };
54
55 ResourceNode(const ResourceNode& other);
56 ResourceNode& operator=(const ResourceNode& other);
57
58 ResourceNode(ResourceNode&& other);
59 ResourceNode& operator=(ResourceNode&& other);
60
61 void swap(ResourceNode& other);
62
63 ~ResourceNode() override;
64
65 virtual std::unique_ptr<ResourceNode> clone() const = 0;
66 uint32_t id() const {
70 return id_;
71 }
72 const std::u16string& name() const {
75 return name_;
76 }
77 it_childs childs() {
80 return childs_;
81 }
82 it_const_childs childs() const {
83 return childs_;
84 }
85 bool has_name() const {
88 return static_cast<bool>(id() & 0x80000000);
89 }
90 uint32_t depth() const {
93 return depth_;
94 }
95 bool is_directory() const {
104 return type_ == TYPE::DIRECTORY;
105 }
106 bool is_data() const {
115 return type_ == TYPE::DATA;
116 }
117
118 void id(uint32_t id) {
119 id_ = id;
120 }
121 void name(const std::string& name);
122
123 void name(std::u16string name) {
124 name_ = std::move(name);
125 }
126 ResourceNode& add_child(const ResourceDirectory& child);
129 ResourceNode& add_child(const ResourceData& child);
132 void delete_child(uint32_t id);
135 void delete_child(const ResourceNode& node);
138
139 void accept(Visitor& visitor) const override;
140
141 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ResourceNode& node);
142
143 protected:
144 ResourceNode();
145 ResourceNode(TYPE type);
146 childs_t::iterator insert_child(std::unique_ptr<ResourceNode> child);
147 TYPE type_ = TYPE::UNKNOWN;
148 uint32_t id_ = 0;
149 std::u16string name_;
150 childs_t childs_;
151 uint32_t depth_ = 0;
152};
153}
154}
155#endif /* RESOURCENODE_H */
Object.hpp
LIEF::PE::Builder
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:47
LIEF::PE::ResourceData
Class which represents a Data Node in the PE resources tree.
Definition ResourceData.hpp:32
LIEF::PE::ResourceDirectory
Definition ResourceDirectory.hpp:33
LIEF::PE::ResourceNode
Class which represents a Node in the resource tree.
Definition ResourceNode.hpp:38
LIEF::PE::ResourceNode::is_directory
bool is_directory() const
True if the current entry is a ResourceDirectory.
Definition ResourceNode.hpp:103
LIEF::PE::ResourceNode::delete_child
void delete_child(uint32_t id)
Delete the node with the given id
LIEF::PE::ResourceNode::add_child
ResourceNode & add_child(const ResourceDirectory &child)
Add a ResourceDirectory to the current node.
LIEF::PE::ResourceNode::childs
it_const_childs childs() const
Definition ResourceNode.hpp:82
LIEF::PE::ResourceNode::operator=
ResourceNode & operator=(const ResourceNode &other)
LIEF::PE::ResourceNode::name
const std::u16string & name() const
Name of the entry.
Definition ResourceNode.hpp:74
LIEF::PE::ResourceNode::is_data
bool is_data() const
True if the current entry is a ResourceData.
Definition ResourceNode.hpp:114
LIEF::PE::ResourceNode::depth
uint32_t depth() const
Current depth of the Node in the resource tree.
Definition ResourceNode.hpp:92
LIEF::PE::ResourceNode::ResourceNode
ResourceNode(ResourceNode &&other)
LIEF::PE::ResourceNode::has_name
bool has_name() const
True if the entry uses a name as ID
Definition ResourceNode.hpp:87
LIEF::PE::ResourceNode::delete_child
void delete_child(const ResourceNode &node)
Delete the given node from the node's children.
LIEF::PE::ResourceNode::ResourceNode
ResourceNode(const ResourceNode &other)
LIEF::PE::ResourceNode::clone
virtual std::unique_ptr< ResourceNode > clone() const =0
LIEF::PE::ResourceNode::id
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:69
LIEF::PE::ResourceNode::childs
it_childs childs()
Iterator on node's children.
Definition ResourceNode.hpp:79
LIEF::PE::ResourceNode::swap
void swap(ResourceNode &other)
LIEF::PE::ResourceNode::name
void name(std::u16string name)
Definition ResourceNode.hpp:123
LIEF::PE::ResourceNode::accept
void accept(Visitor &visitor) const override
LIEF::PE::ResourceNode::add_child
ResourceNode & add_child(const ResourceData &child)
Add a ResourceData to the current node.
LIEF::PE::ResourceNode::name
void name(const std::string &name)
LIEF::PE::ResourceNode::id
void id(uint32_t id)
Definition ResourceNode.hpp:118
LIEF::PE::ResourceNode::operator<<
friend std::ostream & operator<<(std::ostream &os, const ResourceNode &node)
LIEF::PE::ResourceNode::operator=
ResourceNode & operator=(ResourceNode &&other)
LIEF::PE::ResourceNode::~ResourceNode
~ResourceNode() override
iterators.hpp
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::PE_SECTION_TYPES::DATA
@ DATA
Definition PE/enums.hpp:670
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41