LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
ResourceNode.hpp
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
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24#include "LIEF/iterators.hpp"
25
26#include "LIEF/PE/enums.hpp"
27
28namespace LIEF {
29namespace PE {
30
31class ResourceDirectory;
32class ResourceData;
33
34class Parser;
35class Builder;
36
38class 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>>;
47
49 enum class TYPE {
50 UNKNOWN = 0,
51 DATA,
52 DIRECTORY,
53 };
54
55 ResourceNode(const ResourceNode& other);
56 ResourceNode& operator=(const ResourceNode& other);
57
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
69 uint32_t id() const;
70
72 const std::u16string& name() const;
73
76 it_const_childs childs() const;
77
79 bool has_name() const;
80
82 uint32_t depth() const;
83
91 bool is_directory() const;
92
100 bool is_data() const;
101
102 void id(uint32_t id);
103 void name(const std::string& name);
104
105 void name(std::u16string name) {
106 name_ = std::move(name);
107 }
108
111
114
116 void delete_child(uint32_t id);
117
119 void delete_child(const ResourceNode& node);
120
121 void accept(Visitor& visitor) const override;
122
123
124 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ResourceNode& node);
125
126 protected:
127 ResourceNode();
128 childs_t::iterator insert_child(std::unique_ptr<ResourceNode> child);
129 TYPE type_ = TYPE::UNKNOWN;
130 uint32_t id_ = 0;
131 std::u16string name_;
132 childs_t childs_;
133 uint32_t depth_ = 0;
134};
135}
136}
137#endif /* RESOURCENODE_H */
Definition Object.hpp:25
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:47
Class which represents a Data Node in the PE resources tree.
Definition ResourceData.hpp:32
Definition ResourceDirectory.hpp:37
Class which represents a Node in the resource tree.
Definition ResourceNode.hpp:38
bool is_directory() const
True if the current entry is a ResourceDirectory.
void delete_child(uint32_t id)
Delete the node with the given id
ResourceNode & add_child(const ResourceDirectory &child)
Add a ResourceDirectory to the current node.
const std::u16string & name() const
Name of the entry.
bool is_data() const
True if the current entry is a ResourceData.
uint32_t depth() const
Current depth of the Node in the resource tree.
bool has_name() const
True if the entry uses a name as ID
void delete_child(const ResourceNode &node)
Delete the given node from the node's children.
uint32_t id() const
Integer that identifies the Type, Name, or Language ID of the entry depending on its depth in the tre...
it_childs childs()
Iterator on node's children.
TYPE
Enum that identifies the type of a node in the resource tree.
Definition ResourceNode.hpp:49
ResourceNode & add_child(const ResourceData &child)
Add a ResourceData to the current node.
Definition Visitor.hpp:219
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32