LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
debug/Debug.hpp
Go to the documentation of this file.
1
2/* Copyright 2017 - 2025 R. Thomas
3 * Copyright 2017 - 2025 Quarkslab
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifndef LIEF_PE_DEBUG_H
18#define LIEF_PE_DEBUG_H
19#include <cstdint>
20#include <ostream>
21#include <memory>
22
23#include "LIEF/Object.hpp"
24#include "LIEF/visibility.h"
25#include "LIEF/span.hpp"
26
27namespace LIEF {
28namespace PE {
29class Parser;
30class Builder;
31class Section;
32
33namespace details {
34struct pe_debug;
35}
36
40class LIEF_API Debug : public Object {
41 friend class Parser;
42 friend class Builder;
43
44 public:
46 enum class TYPES {
48
50 COFF = 1,
51
54
56 FPO = 3,
57
59 MISC = 4,
60
63
65 FIXUP = 6,
66
69
72
75
78
80 CLSID = 11,
81
84
86 POGO = 13,
87
89 ILTCG = 14,
90
91 MPX = 15,
92
94 REPRO = 16,
95
98
101 };
102 Debug() = default;
104 type_ = type;
105 }
106
108 uint32_t offset, uint32_t size);
109 static span<uint8_t> get_payload(Section& section, const details::pe_debug& hdr);
112 dbg.sizeof_data());
113 }
114
115 Debug(const details::pe_debug& debug_s, Section* section);
116
117 Debug(const Debug& other) = default;
118 Debug& operator=(const Debug& other) = default;
119
120 Debug(Debug&&) = default;
121 Debug& operator=(Debug&&) = default;
122
123 ~Debug() override = default;
124
125 virtual std::unique_ptr<Debug> clone() const {
126 return std::unique_ptr<Debug>(new Debug(*this));
127 }
128
130 uint32_t characteristics() const {
131 return characteristics_;
132 }
133
135 uint32_t timestamp() const {
136 return timestamp_;
137 }
138
140 uint16_t major_version() const {
141 return major_version_;
142 }
143
145 uint16_t minor_version() const {
146 return minor_version_;
147 }
148
150 TYPES type() const {
151 return type_;
152 }
153
155 uint32_t sizeof_data() const {
156 return sizeof_data_;
157 }
158
160 uint32_t addressof_rawdata() const {
161 return addressof_rawdata_;
162 }
163
165 uint32_t pointerto_rawdata() const {
166 return pointerto_rawdata_;
167 }
168
170 const Section* section() const {
171 return section_;
172 }
173
175 return section_;
176 }
177
180
182 return const_cast<Debug*>(this)->payload();
183 }
184
186 characteristics_ = characteristics;
187 }
188
189 void timestamp(uint32_t timestamp) {
190 timestamp_ = timestamp;
191 }
192
194 major_version_ = major_version;
195 }
196
198 minor_version_ = minor_version;
199 }
200
201 void sizeof_data(uint32_t sizeof_data) {
202 sizeof_data_ = sizeof_data;
203 }
204
206 addressof_rawdata_ = addressof_rawdata;
207 }
208
210 pointerto_rawdata_ = pointerto_rawdata;
211 }
212
213 template<class T>
214 const T* as() const {
215 static_assert(std::is_base_of<Debug, T>::value, "Require Debug inheritance");
216 if (T::classof(this)) {
217 return static_cast<const T*>(this);
218 }
219 return nullptr;
220 }
221
222 template<class T>
223 T* as() {
224 return const_cast<T*>(static_cast<const Debug*>(this)->as<T>());
225 }
226
227 void accept(Visitor& visitor) const override;
228
229 virtual std::string to_string() const;
230
231 LIEF_API friend
232 std::ostream& operator<<(std::ostream& os, const Debug& entry)
233 {
234 os << entry.to_string();
235 return os;
236 }
237
238 protected:
239 TYPES type_ = TYPES::UNKNOWN;
240 uint32_t characteristics_ = 0;
241 uint32_t timestamp_ = 0;
242 uint16_t major_version_ = 0;
243 uint16_t minor_version_ = 0;
244 uint32_t sizeof_data_ = 0;
245 uint32_t addressof_rawdata_ = 0;
246 uint32_t pointerto_rawdata_ = 0;
247
248 Section* section_ = nullptr;
249};
250
252
253}
254}
255#endif
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
void characteristics(uint32_t characteristics)
Definition debug/Debug.hpp:185
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:160
void pointerto_rawdata(uint32_t pointerto_rawdata)
Definition debug/Debug.hpp:209
virtual std::string to_string() const
uint32_t sizeof_data() const
Size of the debug data.
Definition debug/Debug.hpp:155
uint16_t major_version() const
The major version number of the debug data format.
Definition debug/Debug.hpp:140
Debug(Debug &&)=default
Section * section()
Definition debug/Debug.hpp:174
void addressof_rawdata(uint32_t addressof_rawdata)
Definition debug/Debug.hpp:205
uint16_t minor_version() const
The minor version number of the debug data format.
Definition debug/Debug.hpp:145
span< uint8_t > payload()
Debug data associated with this entry.
uint32_t characteristics() const
Reserved should be 0.
Definition debug/Debug.hpp:130
const T * as() const
Definition debug/Debug.hpp:214
void major_version(uint16_t major_version)
Definition debug/Debug.hpp:193
friend std::ostream & operator<<(std::ostream &os, const Debug &entry)
Definition debug/Debug.hpp:232
friend class Builder
Definition debug/Debug.hpp:42
T * as()
Definition debug/Debug.hpp:223
virtual std::unique_ptr< Debug > clone() const
Definition debug/Debug.hpp:125
void sizeof_data(uint32_t sizeof_data)
Definition debug/Debug.hpp:201
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:41
uint32_t pointerto_rawdata() const
File offset of the debug data.
Definition debug/Debug.hpp:165
Debug(const Debug &other)=default
uint32_t timestamp() const
The time and date when the debug data was created.
Definition debug/Debug.hpp:135
span< const uint8_t > payload() const
Definition debug/Debug.hpp:181
const Section * section() const
The section where debug data is located.
Definition debug/Debug.hpp:170
static span< uint8_t > get_payload(Section &section, const Debug &dbg)
Definition debug/Debug.hpp:110
~Debug() override=default
void minor_version(uint16_t minor_version)
Definition debug/Debug.hpp:197
Debug & operator=(const Debug &other)=default
TYPES type() const
The format DEBUG_TYPES of the debugging information.
Definition debug/Debug.hpp:150
void timestamp(uint32_t timestamp)
Definition debug/Debug.hpp:189
Debug(TYPES type)
Definition debug/Debug.hpp:103
TYPES
The entry types.
Definition debug/Debug.hpp:46
@ FPO
Frame pointer omission information.
Definition debug/Debug.hpp:56
@ MPX
Definition debug/Debug.hpp:91
@ COFF
COFF Debug information.
Definition debug/Debug.hpp:50
@ POGO
Profile Guided Optimization metadata.
Definition debug/Debug.hpp:86
@ UNKNOWN
Definition debug/Debug.hpp:47
@ FIXUP
(Reserved) Debug information used for fixup relocations
Definition debug/Debug.hpp:65
@ CODEVIEW
CodeView debug information that is used to store PDB info.
Definition debug/Debug.hpp:53
@ OMAP_TO_SRC
The mapping from an RVA in image to an RVA in source image.
Definition debug/Debug.hpp:68
@ RESERVED10
Reserved.
Definition debug/Debug.hpp:77
@ EX_DLLCHARACTERISTICS
Extended DLL characteristics.
Definition debug/Debug.hpp:100
@ VC_FEATURE
Visual C++ feature information.
Definition debug/Debug.hpp:83
@ BORLAND
Reserved for Borland.
Definition debug/Debug.hpp:74
@ MISC
Miscellaneous debug information.
Definition debug/Debug.hpp:59
@ EXCEPTION
Debug information that is a copy of the .pdata section.
Definition debug/Debug.hpp:62
@ CLSID
Reserved.
Definition debug/Debug.hpp:80
@ OMAP_FROM_SRC
The mapping from an RVA in source image to an RVA in image.
Definition debug/Debug.hpp:71
@ REPRO
PE determinism or reproducibility information.
Definition debug/Debug.hpp:94
@ PDBCHECKSUM
Checksum of the PDB file.
Definition debug/Debug.hpp:97
@ ILTCG
Incremental Link Time Code Generation metadata.
Definition debug/Debug.hpp:89
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
Class which represents a PE section.
Definition PE/Section.hpp:46
Definition Visitor.hpp:210
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
const char * to_string(CODE_PAGES e)
@ T
Definition AcceleratorCodes.hpp:97
LIEF namespace.
Definition Abstract/Binary.hpp:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:41