LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
TLS.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_TLS_H
17#define LIEF_PE_TLS_H
18
19#include <vector>
20#include <ostream>
21
22#include "LIEF/span.hpp"
23#include "LIEF/Object.hpp"
25#include "LIEF/visibility.h"
26
27namespace LIEF {
28namespace PE {
29
30class Parser;
31class Builder;
32class DataDirectory;
33class Section;
34class Binary;
35
36namespace details {
37struct pe32_tls;
38struct pe64_tls;
39}
40
44class LIEF_API TLS : public Object {
45 friend class Parser;
46 friend class Builder;
47 friend class Binary;
48
49 public:
50 TLS() = default;
51
52 LIEF_LOCAL TLS(const details::pe32_tls& header);
53 LIEF_LOCAL TLS(const details::pe64_tls& header);
54
55 ~TLS() override = default;
56
57 TLS(const TLS& copy) = default;
58 TLS& operator=(const TLS& copy) = default;
59
60 TLS(TLS&& other) noexcept = default;
61 TLS& operator=(TLS&& other) noexcept = default;
62
66 const std::vector<uint64_t>& callbacks() const {
67 return callbacks_;
68 }
69
72 callbacks_.push_back(addr);
73 return *this;
74 }
75
83 const std::pair<uint64_t, uint64_t>& addressof_raw_data() const {
84 return va_rawdata_;
85 }
86
89 uint64_t addressof_index() const {
90 return addressof_index_;
91 }
92
97 uint64_t addressof_callbacks() const {
98 return addressof_callbacks_;
99 }
100
103 uint32_t sizeof_zero_fill() const {
104 return sizeof_zero_fill_;
105 }
106
111 uint32_t characteristics() const {
112 return characteristics_;
113 }
114
117 return data_template_;
118 }
119
121 bool has_data_directory() const {
122 return directory_ != nullptr;
123 }
124
128 return directory_;
129 }
130
132 return directory_;
133 }
134
136 bool has_section() const {
137 return section_ != nullptr;
138 }
139
142 return section_;
143 }
144
146 return section_;
147 }
148
149 void callbacks(std::vector<uint64_t> callbacks) {
150 callbacks_ = std::move(callbacks);
151 }
152
153 void addressof_raw_data(std::pair<uint64_t, uint64_t> addresses) {
154 va_rawdata_ = addresses;
155 }
156
157 void addressof_index(uint64_t addr_idx) {
158 addressof_index_ = addr_idx;
159 }
160
161 void addressof_callbacks(uint64_t addr) {
162 addressof_callbacks_ = addr;
163 }
164
165 void sizeof_zero_fill(uint32_t size) {
166 sizeof_zero_fill_ = size;
167 }
168
170 characteristics_ = characteristics;
171 }
172
173 void data_template(std::vector<uint8_t> data_template) {
174 data_template_ = std::move(data_template);
175 }
176
177 void accept(Visitor& visitor) const override;
178
179 LIEF_API friend std::ostream& operator<<(std::ostream& os, const TLS& entry);
180
181 private:
182 std::vector<uint64_t> callbacks_;
183 std::pair<uint64_t, uint64_t> va_rawdata_;
184 uint64_t addressof_index_ = 0;
185 uint64_t addressof_callbacks_ = 0;
186 uint32_t sizeof_zero_fill_ = 0;
187 uint32_t characteristics_ = 0;
188 DataDirectory* directory_ = nullptr;
189 Section* section_ = nullptr;
190 std::vector<uint8_t> data_template_;
191};
192}
193}
194#endif
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:57
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
Class that represents a PE data directory entry.
Definition DataDirectory.hpp:42
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:52
Class which represents a PE section.
Definition PE/Section.hpp:47
DataDirectory * directory()
Return the DataDirectory associated with this object or a nullptr If it exists, its type should be Da...
Definition TLS.hpp:127
friend std::ostream & operator<<(std::ostream &os, const TLS &entry)
TLS & add_callback(uint64_t addr)
Add a new TLS callback.
Definition TLS.hpp:71
const std::pair< uint64_t, uint64_t > & addressof_raw_data() const
Pair (start address, end address) of the TLS template. The template is a block of data that is used t...
Definition TLS.hpp:83
const DataDirectory * directory() const
Definition TLS.hpp:131
const std::vector< uint64_t > & callbacks() const
List of the callbacks associated with the current TLS.
Definition TLS.hpp:66
void addressof_callbacks(uint64_t addr)
Definition TLS.hpp:161
void callbacks(std::vector< uint64_t > callbacks)
Definition TLS.hpp:149
uint32_t sizeof_zero_fill() const
Size in bytes of the zero to be padded after the data specified by data_template.
Definition TLS.hpp:103
void addressof_index(uint64_t addr_idx)
Definition TLS.hpp:157
void addressof_raw_data(std::pair< uint64_t, uint64_t > addresses)
Definition TLS.hpp:153
bool has_section() const
Check if there is a section associated with this entry.
Definition TLS.hpp:136
uint32_t characteristics() const
The four bits [23:20] describe alignment info. Possible values are those defined as IMAGE_SCN_ALIGN_*...
Definition TLS.hpp:111
TLS(const details::pe32_tls &header)
void characteristics(uint32_t characteristics)
Definition TLS.hpp:169
uint64_t addressof_callbacks() const
Pointer to an array of TLS callback functions.
Definition TLS.hpp:97
TLS()=default
void sizeof_zero_fill(uint32_t size)
Definition TLS.hpp:165
friend class Builder
Definition TLS.hpp:46
TLS(const details::pe64_tls &header)
friend class Binary
Definition TLS.hpp:47
Section * section()
The section associated with the entry (or a nullptr).
Definition TLS.hpp:141
~TLS() override=default
uint64_t addressof_index() const
The location to receive the TLS index assigned by the loader. This location should be located in a wr...
Definition TLS.hpp:89
friend class Parser
Definition TLS.hpp:45
TLS(TLS &&other) noexcept=default
void accept(Visitor &visitor) const override
bool has_data_directory() const
True if there is a data directory associated with this entry.
Definition TLS.hpp:121
TLS & operator=(const TLS &copy)=default
TLS & operator=(TLS &&other) noexcept=default
void data_template(std::vector< uint8_t > data_template)
Definition TLS.hpp:173
span< const uint8_t > data_template() const
The initial content used to initialize TLS data.
Definition TLS.hpp:116
TLS(const TLS &copy)=default
const Section * section() const
Definition TLS.hpp:145
Definition Visitor.hpp:212
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF namespace.
Definition Abstract/Binary.hpp:41
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46