LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
ExceptionInfo.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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_EXCEPTION_INFO_H
17#define LIEF_PE_EXCEPTION_INFO_H
18
19#include <memory>
20#include <ostream>
21
22#include "LIEF/PE/Header.hpp"
23#include "LIEF/visibility.h"
24
25namespace LIEF {
26class BinaryStream;
27
28namespace PE {
29class Parser;
30
31
34 public:
35 static std::unique_ptr<ExceptionInfo> parse(Parser& ctx, BinaryStream& strm,
36 uint64_t size, uint64_t nb_scopes);
37 static std::unique_ptr<ExceptionInfo> parse(Parser& ctx, BinaryStream& strm,
38 uint64_t size, uint64_t nb_scopes,
40
41 ExceptionInfo() = delete;
42
43 ExceptionInfo(const ExceptionInfo&) = default;
45
48
49 virtual std::unique_ptr<ExceptionInfo> clone() const = 0;
50
52 enum class ARCH {
53 UNKNOWN = 0,
54 ARM64,
55 X86_64,
56 };
57
58 ExceptionInfo(ARCH arch, uint64_t rva) :
59 arch_(arch),
60 rva_(rva) {}
61
64
66 ARCH arch() const {
67 return arch_;
68 }
69
71 uint32_t rva_start() const {
72 return rva_;
73 }
74
77 uint64_t offset() const {
78 return offset_;
79 }
80
81 virtual std::string to_string() const = 0;
82
83 virtual ~ExceptionInfo() = default;
84
86 template<class T>
87 T* as() {
88 static_assert(std::is_base_of_v<ExceptionInfo, T>,
89 "Require ExceptionInfo inheritance");
90 if (T::classof(this)) {
91 return static_cast<T*>(this);
92 }
93 return nullptr;
94 }
95
96 template<class T>
97 const T* as() const {
98 return const_cast<ExceptionInfo*>(this)->as<T>();
99 }
100
102 void offset(uint64_t value) {
103 offset_ = value;
104 }
105
106 LIEF_API friend std::ostream& operator<<(std::ostream& os,
107 const ExceptionInfo& info) {
108 os << info.to_string();
109 return os;
110 }
111
112 protected:
113 ARCH arch_ = ARCH::UNKNOWN;
114 uint32_t rva_ = 0;
115 uint32_t offset_ = 0;
116};
117
118}
119}
120#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:35
uint32_t rva_start() const
Function start address.
Definition ExceptionInfo.hpp:71
virtual std::string to_string() const =0
ExceptionInfo(const ExceptionInfo &)=default
ExceptionInfo(ARCH arch)
Definition ExceptionInfo.hpp:62
const T * as() const
Definition ExceptionInfo.hpp:97
T * as()
Helper to downcast an ExceptionInfo into a concrete implementation.
Definition ExceptionInfo.hpp:87
ExceptionInfo & operator=(ExceptionInfo &&)=default
ARCH
Arch discriminator for the subclasses.
Definition ExceptionInfo.hpp:52
ARCH arch() const
Target architecture of this exception.
Definition ExceptionInfo.hpp:66
virtual std::unique_ptr< ExceptionInfo > clone() const =0
static std::unique_ptr< ExceptionInfo > parse(Parser &ctx, BinaryStream &strm, uint64_t size, uint64_t nb_scopes, Header::MACHINE_TYPES arch)
ExceptionInfo(ExceptionInfo &&)=default
friend std::ostream & operator<<(std::ostream &os, const ExceptionInfo &info)
Definition ExceptionInfo.hpp:106
virtual ~ExceptionInfo()=default
ExceptionInfo & operator=(const ExceptionInfo &)=default
uint64_t offset() const
Offset in the binary where the raw exception information associated with this entry is defined.
Definition ExceptionInfo.hpp:77
ExceptionInfo(ARCH arch, uint64_t rva)
Definition ExceptionInfo.hpp:58
static std::unique_ptr< ExceptionInfo > parse(Parser &ctx, BinaryStream &strm, uint64_t size, uint64_t nb_scopes)
MACHINE_TYPES
Definition PE/Header.hpp:41
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:54
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
@ T
Definition AcceleratorCodes.hpp:97
LIEF namespace.
Definition Abstract/Binary.hpp:42
#define LIEF_API
Definition visibility.h:45