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
74 virtual std::string to_string() const = 0;
75
76 virtual ~ExceptionInfo() = default;
77
79 template<class T>
80 T* as() {
81 static_assert(std::is_base_of<ExceptionInfo, T>::value,
82 "Require ExceptionInfo inheritance");
83 if (T::classof(this)) {
84 return static_cast<T*>(this);
85 }
86 return nullptr;
87 }
88
89 template<class T>
90 const T* as() const {
91 return const_cast<ExceptionInfo*>(this)->as<T>();
92 }
93
94 LIEF_API friend
95 std::ostream& operator<<(std::ostream& os, const ExceptionInfo& info)
96 {
97 os << info.to_string();
98 return os;
99 }
100
101 protected:
102 ARCH arch_ = ARCH::UNKNOWN;
103 uint32_t rva_ = 0;
104};
105
106}
107}
108#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:90
T * as()
Helper to downcast an ExceptionInfo into a concrete implementation.
Definition ExceptionInfo.hpp:80
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:95
virtual ~ExceptionInfo()=default
ExceptionInfo & operator=(const ExceptionInfo &)=default
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