LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
TLS.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_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
26#include "LIEF/PE/enums.hpp"
27
28
29namespace LIEF {
30namespace PE {
31
32class Parser;
33class Builder;
34class DataDirectory;
35class Section;
36
37namespace details {
38struct pe32_tls;
39struct pe64_tls;
40}
41
45class LIEF_API TLS : public Object {
46 friend class Parser;
47 friend class Builder;
48
49 public:
50 TLS();
51 TLS(const details::pe32_tls& header);
52 TLS(const details::pe64_tls& header);
53 ~TLS() override;
54
55 TLS(const TLS& copy);
56 TLS& operator=(const TLS& copy);
57
58 TLS(TLS&& other);
59 TLS& operator=(TLS&& other);
60
64 const std::vector<uint64_t>& callbacks() const {
65 return callbacks_;
66 }
67
72
76 const std::pair<uint64_t, uint64_t>& addressof_raw_data() const {
77 return va_rawdata_;
78 }
79
83 uint64_t addressof_index() const {
84 return addressof_index_;
85 }
86
87
92 uint64_t addressof_callbacks() const {
93 return addressof_callbacks_;
94 }
95
100 uint32_t sizeof_zero_fill() const {
101 return sizeof_zero_fill_;
102 }
103
107 uint32_t characteristics() const {
108 return characteristics_;
109 }
110
112 span<const uint8_t> data_template() const {
113 return data_template_;
114 }
115
117 bool has_data_directory() const {
118 return directory_ != nullptr;
119 }
120
124 return directory_;
125 }
126
127 const DataDirectory* directory() const {
128 return directory_;
129 }
130
132 bool has_section() const {
133 return section_ != nullptr;
134 }
135
138 return section_;
139 }
140
141 const Section* section() const {
142 return section_;
143 }
144
145 void callbacks(std::vector<uint64_t> callbacks) {
146 callbacks_ = std::move(callbacks);
147 }
148
149 void addressof_raw_data(std::pair<uint64_t, uint64_t> addresses) {
150 va_rawdata_ = addresses;
151 }
152
153 void addressof_index(uint64_t addr_idx) {
154 addressof_index_ = addr_idx;
155 }
156
157 void addressof_callbacks(uint64_t addr) {
158 addressof_callbacks_ = addr;
159 }
160
161 void sizeof_zero_fill(uint32_t size) {
162 sizeof_zero_fill_ = size;
163 }
164
165 void characteristics(uint32_t characteristics) {
166 characteristics_ = characteristics;
167 }
168
169 void data_template(std::vector<uint8_t> data_template) {
170 data_template_ = std::move(data_template);
171 }
172
173 void accept(Visitor& visitor) const override;
174
175 LIEF_API friend std::ostream& operator<<(std::ostream& os, const TLS& entry);
176
177 private:
178 std::vector<uint64_t> callbacks_;
179 std::pair<uint64_t, uint64_t> va_rawdata_;
180 uint64_t addressof_index_ = 0;
181 uint64_t addressof_callbacks_ = 0;
182 uint32_t sizeof_zero_fill_ = 0;
183 uint32_t characteristics_ = 0;
184 DataDirectory* directory_ = nullptr;
185 Section* section_ = nullptr;
186 std::vector<uint8_t> data_template_;
187};
188}
189}
190#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:41
Class which represents the PE Thread Local Storage.
Definition TLS.hpp:45
DataDirectory * directory()
Return the DataDirectory associated with this object or a nullptr If it exists, its type should be Da...
Definition TLS.hpp:123
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:76
const std::vector< uint64_t > & callbacks() const
List of the callback associated with the current TLS.
Definition TLS.hpp:64
uint32_t sizeof_zero_fill() const
The size in bytes of the template, beyond the initialized data delimited by the addressof_raw_data fi...
Definition TLS.hpp:100
bool has_section() const
Check if there is a section associated with this entry.
Definition TLS.hpp:132
uint32_t characteristics() const
The four bits [23:20] describe alignment info. Possible values are those defined as IMAGE_SCN_ALIGN_*...
Definition TLS.hpp:107
uint64_t addressof_callbacks() const
The pointer to an array of TLS callback functions.
Definition TLS.hpp:92
Section * section()
The section associated with the entry (or a nullptr)
Definition TLS.hpp:137
uint64_t addressof_index() const
The location to receive the TLS index, which the loader assigns. This location is in an ordinary data...
Definition TLS.hpp:83
bool has_data_directory() const
True if there is a data directory associated with this entry.
Definition TLS.hpp:117
span< const uint8_t > data_template() const
The data template content.
Definition TLS.hpp:112
LIEF namespace.
Definition Abstract/Binary.hpp:32