LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ExceptionInfo.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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 <ostream>
20#include <memory>
21
22#include "LIEF/visibility.h"
23#include "LIEF/PE/Header.hpp"
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 static std::unique_ptr<ExceptionInfo> parse(Parser& ctx, BinaryStream& strm,
38
39 ExceptionInfo() = delete;
40
41 ExceptionInfo(const ExceptionInfo&) = default;
43
46
47 virtual std::unique_ptr<ExceptionInfo> clone() const = 0;
48
50 enum class ARCH {
53 };
54
55 ExceptionInfo(ARCH arch, uint64_t rva) :
56 arch_(arch),
57 rva_(rva)
58 {}
59
61 ExceptionInfo(arch, /*rva=*/0)
62 {}
63
65 ARCH arch() const {
66 return arch_;
67 }
68
70 uint32_t rva_start() const {
71 return rva_;
72 }
73
76 uint64_t offset() const {
77 return offset_;
78 }
79
80 virtual std::string to_string() const = 0;
81
82 virtual ~ExceptionInfo() = default;
83
85 template<class T>
86 T* as() {
87 static_assert(std::is_base_of<ExceptionInfo, T>::value,
88 "Require ExceptionInfo inheritance");
89 if (T::classof(this)) {
90 return static_cast<T*>(this);
91 }
92 return nullptr;
93 }
94
95 template<class T>
96 const T* as() const {
97 return const_cast<ExceptionInfo*>(this)->as<T>();
98 }
99
101 void offset(uint64_t value) {
102 offset_ = value;
103 }
104
105 LIEF_API friend
106 std::ostream& operator<<(std::ostream& os, const ExceptionInfo& info)
107 {
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:33
uint32_t rva_start() const
Function start address.
Definition ExceptionInfo.hpp:70
virtual std::string to_string() const =0
ExceptionInfo(const ExceptionInfo &)=default
ExceptionInfo(ARCH arch)
Definition ExceptionInfo.hpp:60
const T * as() const
Definition ExceptionInfo.hpp:96
T * as()
Helper to downcast an ExceptionInfo into a concrete implementation.
Definition ExceptionInfo.hpp:86
static std::unique_ptr< ExceptionInfo > parse(Parser &ctx, BinaryStream &strm)
ExceptionInfo & operator=(ExceptionInfo &&)=default
ARCH
Arch discriminator for the subclasses.
Definition ExceptionInfo.hpp:50
@ UNKNOWN
Definition ExceptionInfo.hpp:51
@ X86_64
Definition ExceptionInfo.hpp:52
@ ARM64
Definition ExceptionInfo.hpp:52
ARCH arch() const
Target architecture of this exception.
Definition ExceptionInfo.hpp:65
virtual std::unique_ptr< ExceptionInfo > clone() const =0
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:76
static std::unique_ptr< ExceptionInfo > parse(Parser &ctx, BinaryStream &strm, Header::MACHINE_TYPES arch)
ExceptionInfo(ARCH arch, uint64_t rva)
Definition ExceptionInfo.hpp:55
MACHINE_TYPES
Definition PE/Header.hpp:40
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
@ T
Definition AcceleratorCodes.hpp:97
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:41