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
34 public:
35 static std::unique_ptr<ExceptionInfo> parse(Parser& ctx, BinaryStream& strm);
36 static std::unique_ptr<ExceptionInfo> parse(Parser& ctx, BinaryStream& strm,
37 Header::MACHINE_TYPES arch);
38
39 ExceptionInfo() = delete;
40
41 ExceptionInfo(const ExceptionInfo&) = default;
42 ExceptionInfo& operator=(const ExceptionInfo&) = default;
43
44 ExceptionInfo(ExceptionInfo&&) = default;
45 ExceptionInfo& operator=(ExceptionInfo&&) = default;
46
47 virtual std::unique_ptr<ExceptionInfo> clone() const = 0;
48 enum class ARCH {
51 UNKNOWN = 0,
52 ARM64, X86_64
53 };
54
55 ExceptionInfo(ARCH arch, uint64_t rva) :
56 arch_(arch),
57 rva_(rva)
58 {}
59
60 ExceptionInfo(ARCH arch) :
61 ExceptionInfo(arch, /*rva=*/0)
62 {}
63 ARCH arch() const {
66 return arch_;
67 }
68 uint32_t rva_start() const {
71 return rva_;
72 }
73
74 virtual std::string to_string() const = 0;
75
76 virtual ~ExceptionInfo() = default;
77 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
Header.hpp
LIEF::BinaryStream
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
LIEF::PE::ExceptionInfo
This class is the base class for any exception or runtime function entry.
Definition ExceptionInfo.hpp:33
LIEF::PE::ExceptionInfo::rva_start
uint32_t rva_start() const
Function start address.
Definition ExceptionInfo.hpp:70
LIEF::PE::ExceptionInfo::to_string
virtual std::string to_string() const =0
LIEF::PE::ExceptionInfo::ExceptionInfo
ExceptionInfo(const ExceptionInfo &)=default
LIEF::PE::ExceptionInfo::ExceptionInfo
ExceptionInfo(ARCH arch)
Definition ExceptionInfo.hpp:60
LIEF::PE::ExceptionInfo::as
const T * as() const
Definition ExceptionInfo.hpp:90
LIEF::PE::ExceptionInfo::as
T * as()
Helper to downcast an ExceptionInfo into a concrete implementation.
Definition ExceptionInfo.hpp:80
LIEF::PE::ExceptionInfo::parse
static std::unique_ptr< ExceptionInfo > parse(Parser &ctx, BinaryStream &strm)
LIEF::PE::ExceptionInfo::operator=
ExceptionInfo & operator=(ExceptionInfo &&)=default
LIEF::PE::ExceptionInfo::arch
ARCH arch() const
Target architecture of this exception.
Definition ExceptionInfo.hpp:65
LIEF::PE::ExceptionInfo::clone
virtual std::unique_ptr< ExceptionInfo > clone() const =0
LIEF::PE::ExceptionInfo::ExceptionInfo
ExceptionInfo(ExceptionInfo &&)=default
LIEF::PE::ExceptionInfo::operator<<
friend std::ostream & operator<<(std::ostream &os, const ExceptionInfo &info)
Definition ExceptionInfo.hpp:95
LIEF::PE::ExceptionInfo::~ExceptionInfo
virtual ~ExceptionInfo()=default
LIEF::PE::ExceptionInfo::ExceptionInfo
ExceptionInfo()=delete
LIEF::PE::ExceptionInfo::operator=
ExceptionInfo & operator=(const ExceptionInfo &)=default
LIEF::PE::ExceptionInfo::parse
static std::unique_ptr< ExceptionInfo > parse(Parser &ctx, BinaryStream &strm, Header::MACHINE_TYPES arch)
LIEF::PE::ExceptionInfo::ExceptionInfo
ExceptionInfo(ARCH arch, uint64_t rva)
Definition ExceptionInfo.hpp:55
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
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::ACCELERATOR_CODES::T
@ T
Definition AcceleratorCodes.hpp:97
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41