LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
TLS.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_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"
24#include "LIEF/visibility.h"
25
26namespace LIEF {
27namespace PE {
28
29class Parser;
30class Builder;
31class DataDirectory;
32class Section;
33
34namespace details {
35struct pe32_tls;
36struct pe64_tls;
37}
38
42class LIEF_API TLS : public Object {
43 friend class Parser;
44 friend class Builder;
45
46 public:
47 TLS() = default;
48 TLS(const details::pe32_tls& header);
49 TLS(const details::pe64_tls& header);
50 ~TLS() override = default;
51
52 TLS(const TLS& copy) = default;
53 TLS& operator=(const TLS& copy) = default;
54
55 TLS(TLS&& other) noexcept = default;
56 TLS& operator=(TLS&& other) noexcept = default;
57
61 const std::vector<uint64_t>& callbacks() const {
62 return callbacks_;
63 }
64
69
73 const std::pair<uint64_t, uint64_t>& addressof_raw_data() const {
74 return va_rawdata_;
75 }
76
79 uint64_t addressof_index() const {
80 return addressof_index_;
81 }
82
87 uint64_t addressof_callbacks() const {
88 return addressof_callbacks_;
89 }
90
93 uint32_t sizeof_zero_fill() const {
94 return sizeof_zero_fill_;
95 }
96
101 uint32_t characteristics() const {
102 return characteristics_;
103 }
104
107 return data_template_;
108 }
109
111 bool has_data_directory() const {
112 return directory_ != nullptr;
113 }
114
118 return directory_;
119 }
120
121 const DataDirectory* directory() const {
122 return directory_;
123 }
124
126 bool has_section() const {
127 return section_ != nullptr;
128 }
129
132 return section_;
133 }
134
135 const Section* section() const {
136 return section_;
137 }
138
139 void callbacks(std::vector<uint64_t> callbacks) {
140 callbacks_ = std::move(callbacks);
141 }
142
143 void addressof_raw_data(std::pair<uint64_t, uint64_t> addresses) {
144 va_rawdata_ = addresses;
145 }
146
147 void addressof_index(uint64_t addr_idx) {
148 addressof_index_ = addr_idx;
149 }
150
151 void addressof_callbacks(uint64_t addr) {
152 addressof_callbacks_ = addr;
153 }
154
155 void sizeof_zero_fill(uint32_t size) {
156 sizeof_zero_fill_ = size;
157 }
158
159 void characteristics(uint32_t characteristics) {
160 characteristics_ = characteristics;
161 }
162
163 void data_template(std::vector<uint8_t> data_template) {
164 data_template_ = std::move(data_template);
165 }
166
167 void accept(Visitor& visitor) const override;
168
169 LIEF_API friend std::ostream& operator<<(std::ostream& os, const TLS& entry);
170
171 private:
172 std::vector<uint64_t> callbacks_;
173 std::pair<uint64_t, uint64_t> va_rawdata_;
174 uint64_t addressof_index_ = 0;
175 uint64_t addressof_callbacks_ = 0;
176 uint32_t sizeof_zero_fill_ = 0;
177 uint32_t characteristics_ = 0;
178 DataDirectory* directory_ = nullptr;
179 Section* section_ = nullptr;
180 std::vector<uint8_t> data_template_;
181};
182}
183}
184#endif
Definition Object.hpp:25
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:38
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 PE section.
Definition PE/Section.hpp:40
Class which represents the PE Thread Local Storage.
Definition TLS.hpp:42
DataDirectory * directory()
Return the DataDirectory associated with this object or a nullptr If it exists, its type should be Da...
Definition TLS.hpp:117
friend std::ostream & operator<<(std::ostream &os, const TLS &entry)
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:73
const DataDirectory * directory() const
Definition TLS.hpp:121
const std::vector< uint64_t > & callbacks() const
List of the callback associated with the current TLS.
Definition TLS.hpp:61
void addressof_callbacks(uint64_t addr)
Definition TLS.hpp:151
void callbacks(std::vector< uint64_t > callbacks)
Definition TLS.hpp:139
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:93
void addressof_index(uint64_t addr_idx)
Definition TLS.hpp:147
void addressof_raw_data(std::pair< uint64_t, uint64_t > addresses)
Definition TLS.hpp:143
bool has_section() const
Check if there is a section associated with this entry.
Definition TLS.hpp:126
uint32_t characteristics() const
The four bits [23:20] describe alignment info. Possible values are those defined as IMAGE_SCN_ALIGN_*...
Definition TLS.hpp:101
TLS(const details::pe32_tls &header)
void characteristics(uint32_t characteristics)
Definition TLS.hpp:159
uint64_t addressof_callbacks() const
Pointer to an array of TLS callback functions.
Definition TLS.hpp:87
TLS()=default
void sizeof_zero_fill(uint32_t size)
Definition TLS.hpp:155
TLS(const details::pe64_tls &header)
Section * section()
The section associated with the entry (or a nullptr)
Definition TLS.hpp:131
~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:79
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:111
TLS & operator=(const TLS &copy)=default
TLS & operator=(TLS &&other) noexcept=default
void data_template(std::vector< uint8_t > data_template)
Definition TLS.hpp:163
span< const uint8_t > data_template() const
The initial content used to initialize TLS data.
Definition TLS.hpp:106
TLS(const TLS &copy)=default
const Section * section() const
Definition TLS.hpp:135
Definition Visitor.hpp:224
LIEF namespace.
Definition Abstract/Binary.hpp:32
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:41