LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
debug/Debug.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_PE_DEBUG_H
16#define LIEF_PE_DEBUG_H
17#include <cstdint>
18#include <memory>
19#include <ostream>
20
21#include "LIEF/Object.hpp"
22#include "LIEF/span.hpp"
23#include "LIEF/visibility.h"
24
25
26namespace LIEF::PE {
27class Parser;
28class Builder;
29class Section;
30
31namespace details {
32struct pe_debug;
33}
34
38class LIEF_API Debug : public Object {
39 friend class Parser;
40 friend class Builder;
41
42 public:
44 enum class TYPES {
45 UNKNOWN = 0,
46
48 COFF = 1,
49
51 CODEVIEW = 2,
52
54 FPO = 3,
55
57 MISC = 4,
58
60 EXCEPTION = 5,
61
63 FIXUP = 6,
64
66 OMAP_TO_SRC = 7,
67
69 OMAP_FROM_SRC = 8,
70
72 BORLAND = 9,
73
75 RESERVED10 = 10,
76
78 CLSID = 11,
79
81 VC_FEATURE = 12,
82
84 POGO = 13,
85
87 ILTCG = 14,
88
89 MPX = 15,
90
92 REPRO = 16,
93
95 PDBCHECKSUM = 19,
96
98 EX_DLLCHARACTERISTICS = 20,
99 };
100 Debug() = default;
102 type_(type) {}
103
104 static span<uint8_t> get_payload(Section& section, uint32_t rva, uint32_t offset,
105 uint32_t size);
106 static span<uint8_t> get_payload(Section& section, const details::pe_debug& hdr);
109 dbg.sizeof_data());
110 }
111
112 Debug(const details::pe_debug& debug_s, Section* section);
113
114 Debug(const Debug& other) = default;
115 Debug& operator=(const Debug& other) = default;
116
117 Debug(Debug&&) = default;
118 Debug& operator=(Debug&&) = default;
119
120 ~Debug() override = default;
121
122 virtual std::unique_ptr<Debug> clone() const {
123 return std::make_unique<Debug>(*this);
124 }
125
127 uint32_t characteristics() const {
128 return characteristics_;
129 }
130
132 uint32_t timestamp() const {
133 return timestamp_;
134 }
135
137 uint16_t major_version() const {
138 return major_version_;
139 }
140
142 uint16_t minor_version() const {
143 return minor_version_;
144 }
145
147 TYPES type() const {
148 return type_;
149 }
150
152 uint32_t sizeof_data() const {
153 return sizeof_data_;
154 }
155
157 uint32_t addressof_rawdata() const {
158 return addressof_rawdata_;
159 }
160
162 uint32_t pointerto_rawdata() const {
163 return pointerto_rawdata_;
164 }
165
168 return section_;
169 }
170
172 return section_;
173 }
174
177
178 span<const uint8_t> payload() const LIEF_LIFETIMEBOUND {
179 return const_cast<Debug*>(this)->payload();
180 }
181
183 characteristics_ = characteristics;
184 }
185
186 void timestamp(uint32_t timestamp) {
187 timestamp_ = timestamp;
188 }
189
191 major_version_ = major_version;
192 }
193
195 minor_version_ = minor_version;
196 }
197
198 void sizeof_data(uint32_t sizeof_data) {
199 sizeof_data_ = sizeof_data;
200 }
201
203 addressof_rawdata_ = addressof_rawdata;
204 }
205
207 pointerto_rawdata_ = pointerto_rawdata;
208 }
209
210 template<class T>
211 const T* as() const {
212 static_assert(std::is_base_of_v<Debug, T>, "Require Debug inheritance");
213 if (T::classof(this)) {
214 return static_cast<const T*>(this);
215 }
216 return nullptr;
217 }
218
219 template<class T>
220 T* as() {
221 return const_cast<T*>(static_cast<const Debug*>(this)->as<T>());
222 }
223
224 void accept(Visitor& visitor) const override;
225
226 virtual std::string to_string() const;
227
228 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Debug& entry) {
229 os << entry.to_string();
230 return os;
231 }
232
233 protected:
234 TYPES type_ = TYPES::UNKNOWN;
235 uint32_t characteristics_ = 0;
236 uint32_t timestamp_ = 0;
237 uint16_t major_version_ = 0;
238 uint16_t minor_version_ = 0;
239 uint32_t sizeof_data_ = 0;
240 uint32_t addressof_rawdata_ = 0;
241 uint32_t pointerto_rawdata_ = 0;
242
243 Section* section_ = nullptr;
244};
245
247
248}
249
250#endif
Definition Object.hpp:24
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:43
void characteristics(uint32_t characteristics)
Definition debug/Debug.hpp:182
void accept(Visitor &visitor) const override
Debug & operator=(Debug &&)=default
Debug(const details::pe_debug &debug_s, Section *section)
uint32_t addressof_rawdata() const
Address of the debug data relative to the image base.
Definition debug/Debug.hpp:157
void pointerto_rawdata(uint32_t pointerto_rawdata)
Definition debug/Debug.hpp:206
virtual std::string to_string() const
uint32_t sizeof_data() const
Size of the debug data.
Definition debug/Debug.hpp:152
uint16_t major_version() const
The major version number of the debug data format.
Definition debug/Debug.hpp:137
Debug(Debug &&)=default
Section * section()
Definition debug/Debug.hpp:171
void addressof_rawdata(uint32_t addressof_rawdata)
Definition debug/Debug.hpp:202
uint16_t minor_version() const
The minor version number of the debug data format.
Definition debug/Debug.hpp:142
span< uint8_t > payload()
Debug data associated with this entry.
uint32_t characteristics() const
Reserved should be 0.
Definition debug/Debug.hpp:127
const T * as() const
Definition debug/Debug.hpp:211
void major_version(uint16_t major_version)
Definition debug/Debug.hpp:190
friend std::ostream & operator<<(std::ostream &os, const Debug &entry)
Definition debug/Debug.hpp:228
friend class Builder
Definition debug/Debug.hpp:40
T * as()
Definition debug/Debug.hpp:220
virtual std::unique_ptr< Debug > clone() const
Definition debug/Debug.hpp:122
void sizeof_data(uint32_t sizeof_data)
Definition debug/Debug.hpp:198
static span< uint8_t > get_payload(Section &section, const details::pe_debug &hdr)
static span< uint8_t > get_payload(Section &section, uint32_t rva, uint32_t offset, uint32_t size)
Debug()=default
friend class Parser
Definition debug/Debug.hpp:39
uint32_t pointerto_rawdata() const
File offset of the debug data.
Definition debug/Debug.hpp:162
Debug(const Debug &other)=default
uint32_t timestamp() const
The time and date when the debug data was created.
Definition debug/Debug.hpp:132
const Section * section() const
The section where debug data is located.
Definition debug/Debug.hpp:167
static span< uint8_t > get_payload(Section &section, const Debug &dbg)
Definition debug/Debug.hpp:107
~Debug() override=default
void minor_version(uint16_t minor_version)
Definition debug/Debug.hpp:194
Debug & operator=(const Debug &other)=default
TYPES type() const
The format DEBUG_TYPES of the debugging information.
Definition debug/Debug.hpp:147
void timestamp(uint32_t timestamp)
Definition debug/Debug.hpp:186
Debug(TYPES type)
Definition debug/Debug.hpp:101
TYPES
The entry types.
Definition debug/Debug.hpp:44
This class represents the IMAGE_DEBUG_TYPE_FPO debug entry.
Definition FPO.hpp:27
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:53
Class which represents a PE section.
Definition PE/Section.hpp:46
Definition Visitor.hpp:211
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition AuxiliarySymbol.hpp:29
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:31
const char * to_string(CODE_PAGES e)
@ T
Definition AcceleratorCodes.hpp:96
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:44