LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
ResourceData.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_DATA_H
17#define LIEF_PE_RESOURCE_DATA_H
18
19#include <vector>
20
21#include "LIEF/visibility.h"
23#include "LIEF/span.hpp"
24
25namespace LIEF {
26namespace PE {
27
28class Parser;
29class Builder;
30class LIEF_API ResourceData : public ResourceNode {
33
34 friend class Parser;
35 friend class Builder;
36
37 public:
39 ResourceNode(ResourceNode::TYPE::DATA)
40 {}
41 ResourceData(std::vector<uint8_t> content, uint32_t code_page) :
42 ResourceNode(ResourceNode::TYPE::DATA),
43 content_(std::move(content)),
44 code_page_(code_page)
45 {}
46
47 ResourceData(const ResourceData& other) = default;
48 ResourceData& operator=(const ResourceData& other) = default;
49 void swap(ResourceData& other) noexcept;
50
51 ~ResourceData() override = default;
52
53 std::unique_ptr<ResourceNode> clone() const override {
54 return std::unique_ptr<ResourceNode>{new ResourceData{*this}};
55 }
56 uint32_t code_page() const {
60 return code_page_;
61 }
62 span<const uint8_t> content() const {
65 return content_;
66 }
67 span<uint8_t> content() {
68 return content_;
69 }
70 uint32_t reserved() const {
73 return reserved_;
74 }
75 uint32_t offset() const {
80 return offset_;
81 }
82
83 void code_page(uint32_t code_page) {
84 code_page_ = code_page;
85 }
86
87 void content(std::vector<uint8_t> content) {
88 content_ = std::move(content);
89 }
90
91 void reserved(uint32_t value) {
92 reserved_ = value;
93 }
94
95 static bool classof(const ResourceNode* node) {
96 return node->is_data();
97 }
98
99 void accept(Visitor& visitor) const override;
100
101 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ResourceData& data);
102
103 private:
104 std::vector<uint8_t> content_;
105 uint32_t code_page_ = 0;
106 uint32_t reserved_ = 0;
107 uint32_t offset_ = 0;
108
109};
110
111} // namespace PE
112} // namepsace LIEF
113#endif /* RESOURCEDATA_H */
ResourceNode.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::ResourceData::ResourceData
ResourceData(std::vector< uint8_t > content, uint32_t code_page)
Definition ResourceData.hpp:41
LIEF::PE::ResourceData::content
span< uint8_t > content()
Definition ResourceData.hpp:67
LIEF::PE::ResourceData::ResourceData
ResourceData()
Definition ResourceData.hpp:38
LIEF::PE::ResourceData::operator=
ResourceData & operator=(const ResourceData &other)=default
LIEF::PE::ResourceData::operator<<
friend std::ostream & operator<<(std::ostream &os, const ResourceData &data)
LIEF::PE::ResourceData::offset
uint32_t offset() const
Offset of the content within the resource.
Definition ResourceData.hpp:79
LIEF::PE::ResourceData::clone
std::unique_ptr< ResourceNode > clone() const override
Definition ResourceData.hpp:53
LIEF::PE::ResourceData::reserved
uint32_t reserved() const
Reserved value. Should be 0
Definition ResourceData.hpp:72
LIEF::PE::ResourceData::code_page
void code_page(uint32_t code_page)
Definition ResourceData.hpp:83
LIEF::PE::ResourceData::accept
void accept(Visitor &visitor) const override
LIEF::PE::ResourceData::reserved
void reserved(uint32_t value)
Definition ResourceData.hpp:91
LIEF::PE::ResourceData::classof
static bool classof(const ResourceNode *node)
Definition ResourceData.hpp:95
LIEF::PE::ResourceData::content
span< const uint8_t > content() const
Resource content.
Definition ResourceData.hpp:64
LIEF::PE::ResourceData::code_page
uint32_t code_page() const
Return the code page that is used to decode code point values within the resource data....
Definition ResourceData.hpp:59
LIEF::PE::ResourceData::ResourceData
ResourceData(const ResourceData &other)=default
LIEF::PE::ResourceData::~ResourceData
~ResourceData() override=default
LIEF::PE::ResourceData::swap
void swap(ResourceData &other) noexcept
LIEF::PE::ResourceData::content
void content(std::vector< uint8_t > content)
Definition ResourceData.hpp:87
LIEF::PE::ResourceNode
Class which represents a Node in the resource tree.
Definition ResourceNode.hpp:36
LIEF::PE::ResourceNode::is_data
bool is_data() const
True if the current entry is a ResourceData.
Definition ResourceNode.hpp:112
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
span.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41