LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
FPO.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_FPO_H
17#define LIEF_PE_FPO_H
18
19#include <vector>
20#include "LIEF/iterators.hpp"
21#include "LIEF/visibility.h"
23
24namespace LIEF {
25namespace PE {
26
28class LIEF_API FPO : public Debug {
29 public:
30
31 enum class FRAME_TYPE {
32 FPO = 0,
33 TRAP = 1,
34 TSS = 2,
36 };
37
42 uint32_t rva = 0;
43
45 uint32_t proc_size = 0;
46
48 uint32_t nb_locals = 0;
49
51 uint32_t parameters_size = 0;
52
54 uint16_t prolog_size = 0;
55
57 uint16_t nb_saved_regs = 0;
58
60 bool use_seh = false;
61
63 bool use_bp = false;
64
66 uint16_t reserved = 0;
67
70
71 std::string to_string() const;
72
73 friend LIEF_API
74 std::ostream& operator<<(std::ostream& os, const entry_t& entry)
75 {
76 os << entry.to_string();
77 return os;
78 }
79 };
80
81 using entries_t = std::vector<entry_t>;
84
85 static std::unique_ptr<FPO>
86 parse(const details::pe_debug& hdr, Section* section, span<uint8_t> payload);
87
88 FPO(const details::pe_debug& hdr, Section* section) :
89 Debug(hdr, section)
90 {}
91
92 FPO(const FPO& other) = default;
93 FPO& operator=(const FPO& other) = default;
94
95 FPO(FPO&&) = default;
96 FPO& operator=(FPO&& other) = default;
97
98 std::unique_ptr<Debug> clone() const override {
99 return std::unique_ptr<Debug>(new FPO(*this));
100 }
101
104 return entries_;
105 }
106
108 return entries_;
109 }
110
111 static bool classof(const Debug* debug) {
112 return debug->type() == Debug::TYPES::FPO;
113 }
114
115 ~FPO() override = default;
116
117 std::string to_string() const override;
118
119 private:
120 entries_t entries_;
121};
122
124
125}
126}
127
128#endif
span< uint8_t > payload()
Debug data associated with this entry.
Debug()=default
const Section * section() const
The section where debug data is located.
Definition debug/Debug.hpp:170
@ FPO
Frame pointer omission information.
Definition debug/Debug.hpp:56
FPO(const FPO &other)=default
it_entries entries()
Definition FPO.hpp:107
FPO & operator=(FPO &&other)=default
it_const_entries entries() const
Iterator over the FPO entries.
Definition FPO.hpp:103
static bool classof(const Debug *debug)
Definition FPO.hpp:111
FPO(const details::pe_debug &hdr, Section *section)
Definition FPO.hpp:88
~FPO() override=default
std::string to_string() const override
const_ref_iterator< const entries_t & > it_const_entries
Definition FPO.hpp:83
FPO(FPO &&)=default
std::vector< entry_t > entries_t
Definition FPO.hpp:81
static std::unique_ptr< FPO > parse(const details::pe_debug &hdr, Section *section, span< uint8_t > payload)
FRAME_TYPE
Definition FPO.hpp:31
@ TRAP
Definition FPO.hpp:33
@ NON_FPO
Definition FPO.hpp:35
@ FPO
Definition FPO.hpp:32
@ TSS
Definition FPO.hpp:34
ref_iterator< entries_t & > it_entries
Definition FPO.hpp:82
std::unique_ptr< Debug > clone() const override
Definition FPO.hpp:98
FPO & operator=(const FPO &other)=default
Class which represents a PE section.
Definition PE/Section.hpp:46
Iterator which returns reference on container's values.
Definition iterators.hpp:46
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
const char * to_string(CODE_PAGES e)
LIEF namespace.
Definition Abstract/Binary.hpp:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which return const ref on container's values.
Definition iterators.hpp:257
Represents the stack frame layout for a x86 function when frame pointer omission (FPO) optimization i...
Definition FPO.hpp:40
uint32_t proc_size
The number of bytes in the function.
Definition FPO.hpp:45
uint16_t nb_saved_regs
Number of registers saved.
Definition FPO.hpp:57
std::string to_string() const
uint16_t prolog_size
The number of bytes in the function prolog code.
Definition FPO.hpp:54
uint16_t reserved
Reserved for future use.
Definition FPO.hpp:66
friend std::ostream & operator<<(std::ostream &os, const entry_t &entry)
Definition FPO.hpp:74
uint32_t nb_locals
The number of local variables.
Definition FPO.hpp:48
uint32_t parameters_size
The size of the parameters.
Definition FPO.hpp:51
FRAME_TYPE type
Variable that indicates the frame type.
Definition FPO.hpp:69
bool use_seh
Whether the function uses structured exception handling.
Definition FPO.hpp:60
uint32_t rva
The function RVA.
Definition FPO.hpp:42
bool use_bp
Whether the EBP register has been allocated.
Definition FPO.hpp:63
#define LIEF_API
Definition visibility.h:41