LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
debug/Debug.hpp
Go to the documentation of this file.
1
2/* Copyright 2017 - 2026 R. Thomas
3 * Copyright 2017 - 2026 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 {
47 UNKNOWN = 0,
48
50 COFF = 1,
51
53 CODEVIEW = 2,
54
56 FPO = 3,
57
59 MISC = 4,
60
62 EXCEPTION = 5,
63
65 FIXUP = 6,
66
68 OMAP_TO_SRC = 7,
69
71 OMAP_FROM_SRC = 8,
72
74 BORLAND = 9,
75
77 RESERVED10 = 10,
78
80 CLSID = 11,
81
83 VC_FEATURE = 12,
84
86 POGO = 13,
87
89 ILTCG = 14,
90
91 MPX = 15,
92
94 REPRO = 16,
95
97 PDBCHECKSUM = 19,
98
100 EX_DLLCHARACTERISTICS = 20,
101 };
102 Debug() = default;
104 type_(type) {}
105
106 static span<uint8_t> get_payload(Section& section, uint32_t rva, uint32_t offset,
107 uint32_t size);
108 static span<uint8_t> get_payload(Section& section, const details::pe_debug& hdr);
111 dbg.sizeof_data());
112 }
113
114 Debug(const details::pe_debug& debug_s, Section* section);
115
116 Debug(const Debug& other) = default;
117 Debug& operator=(const Debug& other) = default;
118
119 Debug(Debug&&) = default;
120 Debug& operator=(Debug&&) = default;
121
122 ~Debug() override = default;
123
124 virtual std::unique_ptr<Debug> clone() const {
125 return std::unique_ptr<Debug>(new Debug(*this));
126 }
127
129 uint32_t characteristics() const {
130 return characteristics_;
131 }
132
134 uint32_t timestamp() const {
135 return timestamp_;
136 }
137
139 uint16_t major_version() const {
140 return major_version_;
141 }
142
144 uint16_t minor_version() const {
145 return minor_version_;
146 }
147
149 TYPES type() const {
150 return type_;
151 }
152
154 uint32_t sizeof_data() const {
155 return sizeof_data_;
156 }
157
159 uint32_t addressof_rawdata() const {
160 return addressof_rawdata_;
161 }
162
164 uint32_t pointerto_rawdata() const {
165 return pointerto_rawdata_;
166 }
167
170 return section_;
171 }
172
174 return section_;
175 }
176
179
180 span<const uint8_t> payload() const LIEF_LIFETIMEBOUND {
181 return const_cast<Debug*>(this)->payload();
182 }
183
185 characteristics_ = characteristics;
186 }
187
188 void timestamp(uint32_t timestamp) {
189 timestamp_ = timestamp;
190 }
191
193 major_version_ = major_version;
194 }
195
197 minor_version_ = minor_version;
198 }
199
200 void sizeof_data(uint32_t sizeof_data) {
201 sizeof_data_ = sizeof_data;
202 }
203
205 addressof_rawdata_ = addressof_rawdata;
206 }
207
209 pointerto_rawdata_ = pointerto_rawdata;
210 }
211
212 template<class T>
213 const T* as() const {
214 static_assert(std::is_base_of<Debug, T>::value, "Require Debug inheritance");
215 if (T::classof(this)) {
216 return static_cast<const T*>(this);
217 }
218 return nullptr;
219 }
220
221 template<class T>
222 T* as() {
223 return const_cast<T*>(static_cast<const Debug*>(this)->as<T>());
224 }
225
226 void accept(Visitor& visitor) const override;
227
228 virtual std::string to_string() const;
229
230 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Debug& entry) {
231 os << entry.to_string();
232 return os;
233 }
234
235 protected:
236 TYPES type_ = TYPES::UNKNOWN;
237 uint32_t characteristics_ = 0;
238 uint32_t timestamp_ = 0;
239 uint16_t major_version_ = 0;
240 uint16_t minor_version_ = 0;
241 uint32_t sizeof_data_ = 0;
242 uint32_t addressof_rawdata_ = 0;
243 uint32_t pointerto_rawdata_ = 0;
244
245 Section* section_ = nullptr;
246};
247
249
250}
251}
252#endif
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:44
void characteristics(uint32_t characteristics)
Definition debug/Debug.hpp:184
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:159
void pointerto_rawdata(uint32_t pointerto_rawdata)
Definition debug/Debug.hpp:208
virtual std::string to_string() const
uint32_t sizeof_data() const
Size of the debug data.
Definition debug/Debug.hpp:154
uint16_t major_version() const
The major version number of the debug data format.
Definition debug/Debug.hpp:139
Debug(Debug &&)=default
Section * section()
Definition debug/Debug.hpp:173
void addressof_rawdata(uint32_t addressof_rawdata)
Definition debug/Debug.hpp:204
uint16_t minor_version() const
The minor version number of the debug data format.
Definition debug/Debug.hpp:144
span< uint8_t > payload()
Debug data associated with this entry.
uint32_t characteristics() const
Reserved should be 0.
Definition debug/Debug.hpp:129
const T * as() const
Definition debug/Debug.hpp:213
void major_version(uint16_t major_version)
Definition debug/Debug.hpp:192
friend std::ostream & operator<<(std::ostream &os, const Debug &entry)
Definition debug/Debug.hpp:230
friend class Builder
Definition debug/Debug.hpp:42
T * as()
Definition debug/Debug.hpp:222
virtual std::unique_ptr< Debug > clone() const
Definition debug/Debug.hpp:124
void sizeof_data(uint32_t sizeof_data)
Definition debug/Debug.hpp:200
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:164
Debug(const Debug &other)=default
uint32_t timestamp() const
The time and date when the debug data was created.
Definition debug/Debug.hpp:134
const Section * section() const
The section where debug data is located.
Definition debug/Debug.hpp:169
static span< uint8_t > get_payload(Section &section, const Debug &dbg)
Definition debug/Debug.hpp:109
~Debug() override=default
void minor_version(uint16_t minor_version)
Definition debug/Debug.hpp:196
Debug & operator=(const Debug &other)=default
TYPES type() const
The format DEBUG_TYPES of the debugging information.
Definition debug/Debug.hpp:149
void timestamp(uint32_t timestamp)
Definition debug/Debug.hpp:188
Debug(TYPES type)
Definition debug/Debug.hpp:103
TYPES
The entry types.
Definition debug/Debug.hpp:46
This class represents the IMAGE_DEBUG_TYPE_FPO debug entry.
Definition FPO.hpp:28
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:47
Definition Visitor.hpp:212
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition AuxiliarySymbol.hpp:30
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:41
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45