LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
ResourceData.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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_DATA_H
17#define LIEF_PE_RESOURCE_DATA_H
18
19#include <memory>
20#include <vector>
21
24#include "LIEF/iostream.hpp"
25#include "LIEF/span.hpp"
26#include "LIEF/visibility.h"
27
28
29namespace LIEF::PE {
30
31class Parser;
32class Builder;
33
36 friend class Parser;
37 friend class Builder;
38
39 public:
42 ResourceData(std::vector<uint8_t> content, uint32_t code_page = 0) :
44 content_(std::move(content)),
45 code_page_(code_page) {}
46
47 ResourceData(const std::string& str, uint32_t code_page = 0) :
49 content_{str.begin(), str.end()},
50 code_page_(code_page) {}
51
52 ResourceData(const ResourceData& other) = default;
53 ResourceData& operator=(const ResourceData& other) = default;
54 void swap(ResourceData& other) noexcept;
55
56 ~ResourceData() override = default;
57
58 std::unique_ptr<ResourceNode> clone() const override {
59 return std::make_unique<ResourceData>(*this);
60 }
61
64 uint32_t code_page() const {
65 return code_page_;
66 }
67
70 return content_;
71 }
72
74 return content_;
75 }
76
78 uint32_t reserved() const {
79 return reserved_;
80 }
81
85 uint32_t offset() const {
86 return offset_;
87 }
88
89 void code_page(uint32_t code_page) {
90 code_page_ = code_page;
91 }
92
93 void content(std::vector<uint8_t> content) {
94 content_ = std::move(content);
95 }
96
97 void content(const std::string& string) {
98 content_ = {string.begin(), string.end()};
99 }
100
101 void content(const uint8_t* buffer, size_t size) {
102 content_ = {buffer, buffer + size};
103 }
104
105 void reserved(uint32_t value) {
106 reserved_ = value;
107 }
108
111 return content_;
112 }
113
115 LIEF_LOCAL const std::vector<uint8_t> raw_content() const {
116 return content_;
117 }
118
120 LIEF_LOCAL void set_offset(uint32_t offset) {
121 offset_ = offset;
122 }
123
124 static bool classof(const ResourceNode* node) {
125 return node->is_data();
126 }
127
128 void accept(Visitor& visitor) const override;
129
130 private:
131 std::vector<uint8_t> content_;
132 uint32_t code_page_ = 0;
133 uint32_t reserved_ = 0;
134 uint32_t offset_ = 0;
135};
136
137}
138
139#endif
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:44
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:53
ResourceData(const std::string &str, uint32_t code_page=0)
Definition ResourceData.hpp:47
span< uint8_t > content()
Definition ResourceData.hpp:73
ResourceData()
Definition ResourceData.hpp:40
ResourceData & operator=(const ResourceData &other)=default
void content(const uint8_t *buffer, size_t size)
Definition ResourceData.hpp:101
uint32_t offset() const
Offset of the content within the resource.
Definition ResourceData.hpp:85
std::unique_ptr< ResourceNode > clone() const override
Definition ResourceData.hpp:58
uint32_t reserved() const
Reserved value. Should be 0.
Definition ResourceData.hpp:78
void code_page(uint32_t code_page)
Definition ResourceData.hpp:89
void accept(Visitor &visitor) const override
void reserved(uint32_t value)
Definition ResourceData.hpp:105
friend class Builder
Definition ResourceData.hpp:37
static bool classof(const ResourceNode *node)
Definition ResourceData.hpp:124
span< const uint8_t > content() const
Resource content.
Definition ResourceData.hpp:69
uint32_t code_page() const
Return the code page that is used to decode code point values within the resource data....
Definition ResourceData.hpp:64
ResourceData(const ResourceData &other)=default
void content(const std::string &string)
Definition ResourceData.hpp:97
friend class Parser
Definition ResourceData.hpp:36
~ResourceData() override=default
ResourceData(std::vector< uint8_t > content, uint32_t code_page=0)
Definition ResourceData.hpp:42
void swap(ResourceData &other) noexcept
void content(std::vector< uint8_t > content)
Definition ResourceData.hpp:93
bool is_data() const
True if the current entry is a ResourceData.
Definition ResourceNode.hpp:154
ResourceNode(const ResourceNode &other)
TYPE
Enum that identifies the type of a node in the resource tree.
Definition ResourceNode.hpp:57
Definition Visitor.hpp:212
Definition iostream.hpp:34
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46