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}
36class LIEF_API Debug : public Object {
41 friend class Parser;
42 friend class Builder;
43
44 public: enum class TYPES {
47 UNKNOWN = 0,
48 COFF = 1,
51 CODEVIEW = 2,
54 FPO = 3,
57 MISC = 4,
60 EXCEPTION = 5,
63 FIXUP = 6,
66 OMAP_TO_SRC = 7,
69 OMAP_FROM_SRC = 8,
72 BORLAND = 9,
75 RESERVED10 = 10,
78 CLSID = 11,
81 VC_FEATURE = 12,
84 POGO = 13,
87 ILTCG = 14,
90
91 MPX = 15,
92 REPRO = 16,
95 PDBCHECKSUM = 19,
98 EX_DLLCHARACTERISTICS = 20,
101 };
102 Debug() = default;
103 Debug(TYPES type) {
104 type_ = type;
105 }
106
107 static span<uint8_t> get_payload(Section& section, uint32_t rva,
108 uint32_t offset, uint32_t size);
109 static span<uint8_t> get_payload(Section& section, const details::pe_debug& hdr);
110 static span<uint8_t> get_payload(Section& section, const Debug& dbg) {
111 return get_payload(section, dbg.addressof_rawdata(), dbg.pointerto_rawdata(),
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 uint32_t characteristics() const {
131 return characteristics_;
132 }
133 uint32_t timestamp() const {
136 return timestamp_;
137 }
138 uint16_t major_version() const {
141 return major_version_;
142 }
143 uint16_t minor_version() const {
146 return minor_version_;
147 }
148 TYPES type() const {
151 return type_;
152 }
153 uint32_t sizeof_data() const {
156 return sizeof_data_;
157 }
158 uint32_t addressof_rawdata() const {
161 return addressof_rawdata_;
162 }
163 uint32_t pointerto_rawdata() const {
166 return pointerto_rawdata_;
167 }
168 const Section* section() const {
171 return section_;
172 }
173
174 Section* section() {
175 return section_;
176 }
177 span<uint8_t> payload();
180
181 span<const uint8_t> payload() const {
182 return const_cast<Debug*>(this)->payload();
183 }
184
185 void characteristics(uint32_t characteristics) {
186 characteristics_ = characteristics;
187 }
188
189 void timestamp(uint32_t timestamp) {
190 timestamp_ = timestamp;
191 }
192
193 void major_version(uint16_t major_version) {
194 major_version_ = major_version;
195 }
196
197 void minor_version(uint16_t minor_version) {
198 minor_version_ = minor_version;
199 }
200
201 void sizeof_data(uint32_t sizeof_data) {
202 sizeof_data_ = sizeof_data;
203 }
204
205 void addressof_rawdata(uint32_t addressof_rawdata) {
206 addressof_rawdata_ = addressof_rawdata;
207 }
208
209 void pointerto_rawdata(uint32_t pointerto_rawdata) {
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
251LIEF_API const char* to_string(Debug::TYPES e);
252
253}
254}
255#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::Debug
This class represents a generic entry in the debug data directory. For known types,...
Definition debug/Debug.hpp:40
LIEF::PE::Debug::characteristics
void characteristics(uint32_t characteristics)
Definition debug/Debug.hpp:185
LIEF::PE::Debug::accept
void accept(Visitor &visitor) const override
LIEF::PE::Debug::operator=
Debug & operator=(Debug &&)=default
LIEF::PE::Debug::Debug
Debug(const details::pe_debug &debug_s, Section *section)
LIEF::PE::Debug::addressof_rawdata
uint32_t addressof_rawdata() const
Address of the debug data relative to the image base.
Definition debug/Debug.hpp:160
LIEF::PE::Debug::pointerto_rawdata
void pointerto_rawdata(uint32_t pointerto_rawdata)
Definition debug/Debug.hpp:209
LIEF::PE::Debug::to_string
virtual std::string to_string() const
LIEF::PE::Debug::sizeof_data
uint32_t sizeof_data() const
Size of the debug data.
Definition debug/Debug.hpp:155
LIEF::PE::Debug::major_version
uint16_t major_version() const
The major version number of the debug data format.
Definition debug/Debug.hpp:140
LIEF::PE::Debug::Debug
Debug(Debug &&)=default
LIEF::PE::Debug::section
Section * section()
Definition debug/Debug.hpp:174
LIEF::PE::Debug::addressof_rawdata
void addressof_rawdata(uint32_t addressof_rawdata)
Definition debug/Debug.hpp:205
LIEF::PE::Debug::minor_version
uint16_t minor_version() const
The minor version number of the debug data format.
Definition debug/Debug.hpp:145
LIEF::PE::Debug::payload
span< uint8_t > payload()
Debug data associated with this entry.
LIEF::PE::Debug::characteristics
uint32_t characteristics() const
Reserved should be 0.
Definition debug/Debug.hpp:130
LIEF::PE::Debug::as
const T * as() const
Definition debug/Debug.hpp:214
LIEF::PE::Debug::major_version
void major_version(uint16_t major_version)
Definition debug/Debug.hpp:193
LIEF::PE::Debug::operator<<
friend std::ostream & operator<<(std::ostream &os, const Debug &entry)
Definition debug/Debug.hpp:232
LIEF::PE::Debug::as
T * as()
Definition debug/Debug.hpp:223
LIEF::PE::Debug::clone
virtual std::unique_ptr< Debug > clone() const
Definition debug/Debug.hpp:125
LIEF::PE::Debug::sizeof_data
void sizeof_data(uint32_t sizeof_data)
Definition debug/Debug.hpp:201
LIEF::PE::Debug::get_payload
static span< uint8_t > get_payload(Section &section, const details::pe_debug &hdr)
LIEF::PE::Debug::get_payload
static span< uint8_t > get_payload(Section &section, uint32_t rva, uint32_t offset, uint32_t size)
LIEF::PE::Debug::Debug
Debug()=default
LIEF::PE::Debug::pointerto_rawdata
uint32_t pointerto_rawdata() const
File offset of the debug data.
Definition debug/Debug.hpp:165
LIEF::PE::Debug::Debug
Debug(const Debug &other)=default
LIEF::PE::Debug::timestamp
uint32_t timestamp() const
The time and date when the debug data was created.
Definition debug/Debug.hpp:135
LIEF::PE::Debug::payload
span< const uint8_t > payload() const
Definition debug/Debug.hpp:181
LIEF::PE::Debug::section
const Section * section() const
The section where debug data is located.
Definition debug/Debug.hpp:170
LIEF::PE::Debug::get_payload
static span< uint8_t > get_payload(Section &section, const Debug &dbg)
Definition debug/Debug.hpp:110
LIEF::PE::Debug::~Debug
~Debug() override=default
LIEF::PE::Debug::minor_version
void minor_version(uint16_t minor_version)
Definition debug/Debug.hpp:197
LIEF::PE::Debug::operator=
Debug & operator=(const Debug &other)=default
LIEF::PE::Debug::type
TYPES type() const
The format DEBUG_TYPES of the debugging information.
Definition debug/Debug.hpp:150
LIEF::PE::Debug::timestamp
void timestamp(uint32_t timestamp)
Definition debug/Debug.hpp:189
LIEF::PE::Debug::Debug
Debug(TYPES type)
Definition debug/Debug.hpp:103
LIEF::PE::Debug::TYPES
TYPES
The entry types.
Definition debug/Debug.hpp:46
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
LIEF::PE::Section
Class which represents a PE section.
Definition PE/Section.hpp:43
LIEF::PE::details
Definition DataDirectory.hpp:37
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::ACCELERATOR_CODES::T
@ T
Definition AcceleratorCodes.hpp:97
LIEF::PE::to_string
const char * to_string(AuxiliaryWeakExternal::CHARACTERISTICS e)
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
span.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41