LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
CorePrStatus.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_ELF_CORE_PRSTATUS_H
17#define LIEF_ELF_CORE_PRSTATUS_H
18
19#include <memory>
20#include <ostream>
21#include <utility>
22#include <vector>
23
24#include "LIEF/ELF/Note.hpp"
25#include "LIEF/ELF/enums.hpp"
26#include "LIEF/visibility.h"
27
28
29namespace LIEF::ELF {
30
31class Parser;
32class Builder;
33class Binary;
34
36class LIEF_API CorePrStatus : public Note {
37 public:
38 struct siginfo_t {
39 int32_t signo = 0;
40 int32_t code = 0;
41 int32_t err = 0;
42 };
43
44 struct timeval_t {
45 uint64_t sec = 0;
46 uint64_t usec = 0;
47 };
48
54 struct pr_status_t {
56
57 uint16_t cursig = 0;
58 uint16_t reserved = 0;
59
60 uint64_t sigpend = 0;
61 uint64_t sighold = 0;
62
63 int32_t pid = 0;
64 int32_t ppid = 0;
65 int32_t pgrp = 0;
66 int32_t sid = 0;
67
72 };
73
74 struct Registers {
76 enum class X86 {
77 EBX = 0,
78 ECX,
79 EDX,
80 ESI,
81 EDI,
82 EBP,
83 EAX,
84 DS,
85 ES,
86 FS,
87 GS,
88 ORIG_EAX,
89 EIP,
90 CS,
91 EFLAGS,
92 ESP,
93 SS,
94 _COUNT,
95 };
96
98 enum class X86_64 {
99 R15 = 0,
100 R14,
101 R13,
102 R12,
103 RBP,
104 RBX,
105 R11,
106 R10,
107 R9,
108 R8,
109 RAX,
110 RCX,
111 RDX,
112 RSI,
113 RDI,
114 ORIG_RAX,
115 RIP,
116 CS,
117 EFLAGS,
118 RSP,
119 SS,
120 FS_BASE,
121 GS_BASE,
122 DS,
123 ES,
124 _COUNT,
125 };
126
128 enum class ARM {
129 R0 = 0,
130 R1,
131 R2,
132 R3,
133 R4,
134 R5,
135 R6,
136 R7,
137 R8,
138 R9,
139 R10,
140 R11,
141 R12,
142 R13,
143 R14,
144 R15,
145 CPSR,
146 _COUNT,
147 };
148
150 enum class AARCH64 {
151 X0 = 0,
152 X1,
153 X2,
154 X3,
155 X4,
156 X5,
157 X6,
158 X7,
159 X8,
160 X9,
161 X10,
162 X11,
163 X12,
164 X13,
165 X14,
166 X15,
167 X16,
168 X17,
169 X18,
170 X19,
171 X20,
172 X21,
173 X22,
174 X23,
175 X24,
176 X25,
177 X26,
178 X27,
179 X28,
180 X29,
181 X30,
182 X31,
183 PC,
184 PSTATE,
185 _COUNT,
186 };
187 };
188
189 public:
190 CorePrStatus(ARCH arch, Header::CLASS cls, std::string name, uint32_t type,
192 Note(std::move(name), TYPE::CORE_PRSTATUS, type, std::move(description), ""),
193 arch_(arch),
194 class_(cls) {}
195
196 std::unique_ptr<Note> clone() const override {
197 return std::make_unique<CorePrStatus>(*this);
198 }
199
203
205 return arch_;
206 }
207
210
213
217
226
227 ok_error_t set(Registers::X86 reg, uint64_t value);
228 ok_error_t set(Registers::X86_64 reg, uint64_t value);
229 ok_error_t set(Registers::ARM reg, uint64_t value);
230 ok_error_t set(Registers::AARCH64 reg, uint64_t value);
231
244 std::vector<uint64_t> register_values() const;
245
247 return get(reg);
248 }
249
251 return get(reg);
252 }
253
255 return get(reg);
256 }
257
259 return get(reg);
260 }
261
262 void dump(std::ostream& os) const override;
263 void accept(Visitor& visitor) const override;
264
265 static bool classof(const Note* note) {
266 return note->type() == Note::TYPE::CORE_PRSTATUS;
267 }
268
269 ~CorePrStatus() override = default;
270
271 LIEF_API friend std::ostream& operator<<(std::ostream& os,
272 const CorePrStatus& note) {
273 note.dump(os);
274 return os;
275 }
276
277 private:
278 ARCH arch_ = ARCH::NONE;
280};
281
286
287}
288
289
290#endif
Class which represents an ELF binary.
Definition ELF/Binary.hpp:61
Class which takes an ELF::Binary object and reconstructs a valid binary.
Definition ELF/Builder.hpp:48
ok_error_t set(Registers::AARCH64 reg, uint64_t value)
result< uint64_t > get(Registers::X86 reg) const
Get the value for the given X86 register or return an error.
result< uint64_t > operator[](Registers::ARM reg) const
Definition CorePrStatus.hpp:254
ok_error_t set(Registers::X86 reg, uint64_t value)
void dump(std::ostream &os) const override
pr_status_t status() const
Return the pr_status_t structure.
void status(const pr_status_t &status)
~CorePrStatus() override=default
friend std::ostream & operator<<(std::ostream &os, const CorePrStatus &note)
Definition CorePrStatus.hpp:271
ok_error_t set(Registers::X86_64 reg, uint64_t value)
ok_error_t set(Registers::ARM reg, uint64_t value)
std::unique_ptr< Note > clone() const override
Clone the current note and keep its polymorphic type.
Definition CorePrStatus.hpp:196
void accept(Visitor &visitor) const override
result< uint64_t > get(Registers::X86_64 reg) const
Get the value for the given X86_64 register or return an error.
result< uint64_t > get(Registers::AARCH64 reg) const
Get the value for the given AARCH64 register or return an error.
static bool classof(const Note *note)
Definition CorePrStatus.hpp:265
CorePrStatus(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, description_t description)
Definition CorePrStatus.hpp:190
result< uint64_t > operator[](Registers::X86 reg) const
Definition CorePrStatus.hpp:246
result< uint64_t > get(Registers::ARM reg) const
Get the value for the given ARM register or return an error.
std::vector< uint64_t > register_values() const
A list of the register values. This list is guarantee to be as long as the Registers::ARM::_COUNT or ...
result< uint64_t > return_value() const
The value of the register that holds the return value according to the calling convention.
result< uint64_t > operator[](Registers::AARCH64 reg) const
Definition CorePrStatus.hpp:258
result< uint64_t > operator[](Registers::X86_64 reg) const
Definition CorePrStatus.hpp:250
result< uint64_t > sp() const
The stack pointer or an error if not found.
result< uint64_t > pc() const
The program counter or an error if not found.
ARCH architecture() const
Definition CorePrStatus.hpp:204
CLASS
Match the result of Elfxx_Ehdr.e_ident[EI_CLASS].
Definition ELF/Header.hpp:74
@ NONE
Invalid class.
Definition ELF/Header.hpp:75
std::vector< uint8_t > description_t
Container used to handle the description data.
Definition Note.hpp:48
TYPE
LIEF representation of the ELF NT_ values.
Definition Note.hpp:51
@ CORE_PRSTATUS
Coredump that wraps the elf_prstatus structure.
Definition Note.hpp:78
TYPE type() const
Return the type of the note. This type does not match the NT_ type value. For accessing the original ...
Definition Note.hpp:206
std::string_view name() const
Return the name of the note (also known as 'owner' ).
Definition Note.hpp:195
Note(const Note &copy)=default
span< const uint8_t > description() const
Return the description associated with the note.
Definition Note.hpp:217
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
Definition Visitor.hpp:212
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:119
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:79
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
const char * to_string(DynamicEntry::TAG e)
ARCH
Definition ELF/enums.hpp:28
@ NONE
Definition ELF/enums.hpp:29
Definition CorePrStatus.hpp:74
ARM
Register for the ARM architecture (ARCH::ARM).
Definition CorePrStatus.hpp:128
X86_64
Register for the x86-64 architecture (ARCH::X86_64).
Definition CorePrStatus.hpp:98
AARCH64
Register for the AARCH64 architecture (ARCH::AARCH64).
Definition CorePrStatus.hpp:150
X86
Register for the x86 architecture (ARCH::I386).
Definition CorePrStatus.hpp:76
Status information from a core dump.
Definition CorePrStatus.hpp:54
uint16_t cursig
Definition CorePrStatus.hpp:57
siginfo_t info
Definition CorePrStatus.hpp:55
timeval_t cstime
Definition CorePrStatus.hpp:71
int32_t ppid
Definition CorePrStatus.hpp:64
uint16_t reserved
Definition CorePrStatus.hpp:58
uint64_t sighold
Definition CorePrStatus.hpp:61
int32_t pid
Definition CorePrStatus.hpp:63
timeval_t stime
Definition CorePrStatus.hpp:69
uint64_t sigpend
Definition CorePrStatus.hpp:60
int32_t sid
Definition CorePrStatus.hpp:66
timeval_t utime
Definition CorePrStatus.hpp:68
timeval_t cutime
Definition CorePrStatus.hpp:70
int32_t pgrp
Definition CorePrStatus.hpp:65
Definition CorePrStatus.hpp:38
int32_t code
Definition CorePrStatus.hpp:40
int32_t signo
Definition CorePrStatus.hpp:39
int32_t err
Definition CorePrStatus.hpp:41
Definition CorePrStatus.hpp:44
uint64_t sec
Definition CorePrStatus.hpp:45
uint64_t usec
Definition CorePrStatus.hpp:46
#define LIEF_API
Definition visibility.h:45