LIEF: Library to Instrument Executable Formats Version 0.17.0
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}
38class 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 const std::vector<uint64_t>& callbacks() const {
62 return callbacks_;
63 }
64 const std::pair<uint64_t, uint64_t>& addressof_raw_data() const {
74 return va_rawdata_;
75 }
76 uint64_t addressof_index() const {
80 return addressof_index_;
81 }
82 uint64_t addressof_callbacks() const {
88 return addressof_callbacks_;
89 }
90 uint32_t sizeof_zero_fill() const {
94 return sizeof_zero_fill_;
95 }
96 uint32_t characteristics() const {
102 return characteristics_;
103 }
104 span<const uint8_t> data_template() const {
107 return data_template_;
108 }
109 bool has_data_directory() const {
112 return directory_ != nullptr;
113 }
114 DataDirectory* directory() {
118 return directory_;
119 }
120
121 const DataDirectory* directory() const {
122 return directory_;
123 }
124 bool has_section() const {
127 return section_ != nullptr;
128 }
129 Section* section() {
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
Object.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::DataDirectory
Class that represents a PE data directory entry.
Definition DataDirectory.hpp:38
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::Section
Class which represents a PE section.
Definition PE/Section.hpp:43
LIEF::PE::TLS
Class which represents the PE Thread Local Storage.
Definition TLS.hpp:42
LIEF::PE::TLS::directory
DataDirectory * directory()
Return the DataDirectory associated with this object or a nullptr If it exists, its type should be Da...
Definition TLS.hpp:117
LIEF::PE::TLS::operator<<
friend std::ostream & operator<<(std::ostream &os, const TLS &entry)
LIEF::PE::TLS::addressof_raw_data
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
LIEF::PE::TLS::directory
const DataDirectory * directory() const
Definition TLS.hpp:121
LIEF::PE::TLS::callbacks
const std::vector< uint64_t > & callbacks() const
List of the callback associated with the current TLS.
Definition TLS.hpp:61
LIEF::PE::TLS::addressof_callbacks
void addressof_callbacks(uint64_t addr)
Definition TLS.hpp:151
LIEF::PE::TLS::callbacks
void callbacks(std::vector< uint64_t > callbacks)
Definition TLS.hpp:139
LIEF::PE::TLS::sizeof_zero_fill
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
LIEF::PE::TLS::addressof_index
void addressof_index(uint64_t addr_idx)
Definition TLS.hpp:147
LIEF::PE::TLS::addressof_raw_data
void addressof_raw_data(std::pair< uint64_t, uint64_t > addresses)
Definition TLS.hpp:143
LIEF::PE::TLS::has_section
bool has_section() const
Check if there is a section associated with this entry.
Definition TLS.hpp:126
LIEF::PE::TLS::characteristics
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
LIEF::PE::TLS::TLS
TLS(const details::pe32_tls &header)
LIEF::PE::TLS::characteristics
void characteristics(uint32_t characteristics)
Definition TLS.hpp:159
LIEF::PE::TLS::addressof_callbacks
uint64_t addressof_callbacks() const
Pointer to an array of TLS callback functions.
Definition TLS.hpp:87
LIEF::PE::TLS::TLS
TLS()=default
LIEF::PE::TLS::sizeof_zero_fill
void sizeof_zero_fill(uint32_t size)
Definition TLS.hpp:155
LIEF::PE::TLS::TLS
TLS(const details::pe64_tls &header)
LIEF::PE::TLS::section
Section * section()
The section associated with the entry (or a nullptr)
Definition TLS.hpp:131
LIEF::PE::TLS::~TLS
~TLS() override=default
LIEF::PE::TLS::addressof_index
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
LIEF::PE::TLS::TLS
TLS(TLS &&other) noexcept=default
LIEF::PE::TLS::accept
void accept(Visitor &visitor) const override
LIEF::PE::TLS::has_data_directory
bool has_data_directory() const
True if there is a data directory associated with this entry.
Definition TLS.hpp:111
LIEF::PE::TLS::operator=
TLS & operator=(const TLS &copy)=default
LIEF::PE::TLS::operator=
TLS & operator=(TLS &&other) noexcept=default
LIEF::PE::TLS::data_template
void data_template(std::vector< uint8_t > data_template)
Definition TLS.hpp:163
LIEF::PE::TLS::data_template
span< const uint8_t > data_template() const
The initial content used to initialize TLS data.
Definition TLS.hpp:106
LIEF::PE::TLS::TLS
TLS(const TLS &copy)=default
LIEF::PE::TLS::section
const Section * section() const
Definition TLS.hpp:135
LIEF::PE::details
Definition CodeIntegrity.hpp:26
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::PE_SECTION_TYPES::TLS
@ TLS
Definition PE/enums.hpp:668
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
span.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41