LIEF: Library to Instrument Executable Formats
Version 1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
LIEF
PE
PE/Header.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_PE_HEADER_H
17
#define LIEF_PE_HEADER_H
18
#include <array>
19
#include <vector>
20
#include <ostream>
21
#include <cstdint>
22
23
#include "
LIEF/Object.hpp
"
24
#include "
LIEF/visibility.h
"
25
#include "
LIEF/enums.hpp
"
26
#include "
LIEF/PE/enums.hpp
"
27
28
namespace
LIEF
{
29
namespace
PE
{
30
31
namespace
details
{
32
struct
pe_header;
33
}
34
36
class
LIEF_API
Header
:
public
Object
{
37
public
:
38
using
signature_t
= std::array<uint8_t,
/* PE Magic */
4>;
39
40
enum class
MACHINE_TYPES
{
41
UNKNOWN = 0x0,
42
ALPHA = 0x184,
43
ALPHA64 = 0x284,
44
AM33 = 0x1D3,
45
AMD64 = 0x8664,
46
ARM = 0x1C0,
47
ARMNT = 0x1C4,
48
ARM64 = 0xAA64,
49
EBC = 0xEBC,
50
I386 = 0x14C,
51
IA64 = 0x200,
52
LOONGARCH32 = 0x6232,
53
LOONGARCH64 = 0x6264,
54
M32R = 0x9041,
55
MIPS16 = 0x266,
56
MIPSFPU = 0x366,
57
MIPSFPU16 = 0x466,
58
POWERPC = 0x1F0,
59
POWERPCFP = 0x1F1,
60
POWERPCBE = 0x1F2,
61
R4000 = 0x166,
62
RISCV32 = 0x5032,
63
RISCV64 = 0x5064,
64
RISCV128 = 0x5128,
65
SH3 = 0x1A2,
66
SH3DSP = 0x1A3,
67
SH4 = 0x1A6,
68
SH5 = 0x1A8,
69
THUMB = 0x1C2,
70
WCEMIPSV2 = 0x169,
71
ARM64EC = 0xa641,
72
ARM64X = 0xa64e,
73
CHPE_X86 = 0x3a64,
74
};
75
76
static
bool
is_known_machine
(uint16_t
machine
);
77
78
static
bool
is_arm
(
MACHINE_TYPES
ty) {
79
switch
(ty) {
80
default
:
return
false
;
81
case
MACHINE_TYPES::ARM
:
82
case
MACHINE_TYPES::THUMB
:
83
case
MACHINE_TYPES::ARMNT
:
return
true
;
84
}
85
return
false
;
86
}
87
88
static
bool
is_riscv
(
MACHINE_TYPES
ty) {
89
switch
(ty) {
90
default
:
return
false
;
91
case
MACHINE_TYPES::RISCV32
:
92
case
MACHINE_TYPES::RISCV64
:
93
case
MACHINE_TYPES::RISCV128
:
return
true
;
94
}
95
return
false
;
96
}
97
98
static
bool
is_loonarch
(
MACHINE_TYPES
ty) {
99
switch
(ty) {
100
default
:
return
false
;
101
case
MACHINE_TYPES::LOONGARCH32
:
102
case
MACHINE_TYPES::LOONGARCH64
:
return
true
;
103
}
104
return
false
;
105
}
106
107
108
static
bool
is_arm64
(
MACHINE_TYPES
ty) {
109
return
ty ==
MACHINE_TYPES::ARM64
;
110
}
111
112
static
bool
is_thumb
(
MACHINE_TYPES
ty) {
113
return
ty ==
MACHINE_TYPES::THUMB
;
114
}
115
116
static
bool
x86
(
MACHINE_TYPES
ty) {
117
return
ty ==
MACHINE_TYPES::I386
;
118
}
119
120
static
bool
x86_64
(
MACHINE_TYPES
ty) {
121
return
ty ==
MACHINE_TYPES::AMD64
;
122
}
123
124
static
bool
is_mips
(
MACHINE_TYPES
ty) {
125
switch
(ty) {
126
default
:
return
false
;
127
case
MACHINE_TYPES::MIPS16
:
128
case
MACHINE_TYPES::MIPSFPU
:
129
case
MACHINE_TYPES::MIPSFPU16
:
130
case
MACHINE_TYPES::R4000
:
131
case
MACHINE_TYPES::WCEMIPSV2
:
return
true
;
132
}
133
return
false
;
134
}
135
136
static
bool
is_ppc
(
MACHINE_TYPES
ty) {
137
switch
(ty) {
138
default
:
return
false
;
139
case
MACHINE_TYPES::POWERPC
:
140
case
MACHINE_TYPES::POWERPCFP
:
141
case
MACHINE_TYPES::POWERPCBE
:
return
true
;
142
}
143
return
false
;
144
}
145
146
enum class
CHARACTERISTICS
{
147
NONE = 0x0000,
148
RELOCS_STRIPPED = 0x0001,
151
EXECUTABLE_IMAGE = 0x0002,
153
LINE_NUMS_STRIPPED = 0x0004,
155
LOCAL_SYMS_STRIPPED =
156
0x0008,
158
AGGRESSIVE_WS_TRIM = 0x0010,
160
LARGE_ADDRESS_AWARE = 0x0020,
161
BYTES_REVERSED_LO = 0x0080,
163
NEED_32BIT_MACHINE =
164
0x0100,
165
DEBUG_STRIPPED = 0x0200,
166
REMOVABLE_RUN_FROM_SWAP = 0x0400,
168
NET_RUN_FROM_SWAP = 0x0800,
170
SYSTEM = 0x1000,
171
DLL = 0x2000,
172
UP_SYSTEM_ONLY =
173
0x4000,
174
BYTES_REVERSED_HI = 0x8000,
176
};
177
static
Header
create
(
PE_TYPE
type);
178
179
Header
(
const
details::pe_header& header);
180
~Header
()
override
=
default
;
181
182
Header
&
operator=
(
const
Header
&) =
default
;
183
Header
(
const
Header
&) =
default
;
184
186
const
signature_t
&
signature
()
const
{
187
return
signature_;
188
}
189
191
MACHINE_TYPES
machine
()
const
{
192
return
machine_;
193
}
194
196
uint16_t
numberof_sections
()
const
{
197
return
nb_sections_;
198
}
199
202
uint32_t
time_date_stamp
()
const
{
203
return
timedatestamp_;
204
}
205
210
uint32_t
pointerto_symbol_table
()
const
{
211
return
pointerto_symtab_;
212
}
213
219
uint32_t
numberof_symbols
()
const
{
220
return
nb_symbols_;
221
}
222
232
uint16_t
sizeof_optional_header
()
const
{
233
return
sizeof_opt_header_;
234
}
235
237
uint32_t
characteristics
()
const
{
238
return
characteristics_;
239
}
240
242
bool
has_characteristic
(
CHARACTERISTICS
c)
const
{
243
return
(
characteristics
() &
static_cast<
uint32_t
>
(c)) > 0;
244
}
245
247
std::vector<CHARACTERISTICS>
characteristics_list
()
const
;
248
249
void
machine
(
MACHINE_TYPES
type) {
250
machine_ = type;
251
}
252
253
void
numberof_sections
(uint16_t nb) {
254
nb_sections_ = nb;
255
}
256
257
void
time_date_stamp
(uint32_t timestamp) {
258
timedatestamp_ = timestamp;
259
}
260
261
void
pointerto_symbol_table
(uint32_t ptr) {
262
pointerto_symtab_ = ptr;
263
}
264
265
void
numberof_symbols
(uint32_t nb) {
266
nb_symbols_ = nb;
267
}
268
269
void
sizeof_optional_header
(uint16_t size) {
270
sizeof_opt_header_ = size;
271
}
272
273
void
characteristics
(uint32_t
characteristics
) {
274
characteristics_ =
characteristics
;
275
}
276
277
void
signature
(
const
signature_t
& sig) {
278
signature_ = sig;
279
}
280
281
void
add_characteristic
(
CHARACTERISTICS
c) {
282
characteristics_ |=
static_cast<
uint32_t
>
(c);
283
}
284
285
void
remove_characteristic
(
CHARACTERISTICS
c) {
286
characteristics_ &= ~static_cast<uint32_t>(c);
287
}
288
289
void
accept
(
Visitor
& visitor)
const override
;
290
291
LIEF_API
friend
std::ostream&
operator<<
(std::ostream& os,
const
Header
& entry);
292
294
LIEF_LOCAL
Header
() =
default
;
295
296
private
:
297
signature_t
signature_;
298
MACHINE_TYPES
machine_ =
MACHINE_TYPES::UNKNOWN
;
299
uint16_t nb_sections_ = 0;
300
uint32_t timedatestamp_ = 0;
301
uint32_t pointerto_symtab_ = 0;
302
uint32_t nb_symbols_ = 0;
303
uint16_t sizeof_opt_header_ = 0;
304
uint32_t characteristics_ = 0;
305
};
306
307
LIEF_API
const
char
*
to_string
(
Header::CHARACTERISTICS
c);
308
LIEF_API
const
char
*
to_string
(
Header::MACHINE_TYPES
c);
309
}
310
}
311
312
ENABLE_BITMASK_OPERATORS
(
LIEF::PE::Header::CHARACTERISTICS
);
313
#endif
Object.hpp
enums.hpp
LIEF::Object::Object
Object()
LIEF::PE::Header::CHARACTERISTICS
CHARACTERISTICS
Definition
PE/Header.hpp:146
LIEF::PE::Header::accept
void accept(Visitor &visitor) const override
LIEF::PE::Header::is_ppc
static bool is_ppc(MACHINE_TYPES ty)
Definition
PE/Header.hpp:136
LIEF::PE::Header::x86_64
static bool x86_64(MACHINE_TYPES ty)
Definition
PE/Header.hpp:120
LIEF::PE::Header::characteristics
uint32_t characteristics() const
Characteristics of the binary like whether it is a DLL or an executable.
Definition
PE/Header.hpp:237
LIEF::PE::Header::machine
MACHINE_TYPES machine() const
The targeted machine architecture like ARM, x86, AMD64, ...
Definition
PE/Header.hpp:191
LIEF::PE::Header::operator=
Header & operator=(const Header &)=default
LIEF::PE::Header::numberof_sections
uint16_t numberof_sections() const
The number of sections in the binary.
Definition
PE/Header.hpp:196
LIEF::PE::Header::remove_characteristic
void remove_characteristic(CHARACTERISTICS c)
Definition
PE/Header.hpp:285
LIEF::PE::Header::is_riscv
static bool is_riscv(MACHINE_TYPES ty)
Definition
PE/Header.hpp:88
LIEF::PE::Header::signature
const signature_t & signature() const
Signature (or magic byte) of the header. It must be: PE\0\0.
Definition
PE/Header.hpp:186
LIEF::PE::Header::signature
void signature(const signature_t &sig)
Definition
PE/Header.hpp:277
LIEF::PE::Header::sizeof_optional_header
uint16_t sizeof_optional_header() const
Size of the OptionalHeader AND the data directories which follows this header.
Definition
PE/Header.hpp:232
LIEF::PE::Header::has_characteristic
bool has_characteristic(CHARACTERISTICS c) const
Check if the given CHARACTERISTICS is present.
Definition
PE/Header.hpp:242
LIEF::PE::Header::~Header
~Header() override=default
LIEF::PE::Header::characteristics_list
std::vector< CHARACTERISTICS > characteristics_list() const
The list of the CHARACTERISTICS.
LIEF::PE::Header::numberof_symbols
void numberof_symbols(uint32_t nb)
Definition
PE/Header.hpp:265
LIEF::PE::Header::is_thumb
static bool is_thumb(MACHINE_TYPES ty)
Definition
PE/Header.hpp:112
LIEF::PE::Header::numberof_symbols
uint32_t numberof_symbols() const
The number of entries in the symbol table. This data can be used to locate the string table which imm...
Definition
PE/Header.hpp:219
LIEF::PE::Header::pointerto_symbol_table
void pointerto_symbol_table(uint32_t ptr)
Definition
PE/Header.hpp:261
LIEF::PE::Header::is_arm
static bool is_arm(MACHINE_TYPES ty)
Definition
PE/Header.hpp:78
LIEF::PE::Header::machine
void machine(MACHINE_TYPES type)
Definition
PE/Header.hpp:249
LIEF::PE::Header::is_known_machine
static bool is_known_machine(uint16_t machine)
LIEF::PE::Header::add_characteristic
void add_characteristic(CHARACTERISTICS c)
Definition
PE/Header.hpp:281
LIEF::PE::Header::operator<<
friend std::ostream & operator<<(std::ostream &os, const Header &entry)
LIEF::PE::Header::signature_t
std::array< uint8_t, 4 > signature_t
Definition
PE/Header.hpp:38
LIEF::PE::Header::x86
static bool x86(MACHINE_TYPES ty)
Definition
PE/Header.hpp:116
LIEF::PE::Header::characteristics
void characteristics(uint32_t characteristics)
Definition
PE/Header.hpp:273
LIEF::PE::Header::is_arm64
static bool is_arm64(MACHINE_TYPES ty)
Definition
PE/Header.hpp:108
LIEF::PE::Header::pointerto_symbol_table
uint32_t pointerto_symbol_table() const
The offset of the COFF symbol table.
Definition
PE/Header.hpp:210
LIEF::PE::Header::numberof_sections
void numberof_sections(uint16_t nb)
Definition
PE/Header.hpp:253
LIEF::PE::Header::create
static Header create(PE_TYPE type)
LIEF::PE::Header::Header
Header(const details::pe_header &header)
LIEF::PE::Header::time_date_stamp
uint32_t time_date_stamp() const
The low 32 bits of the number of seconds since January 1, 1970. It indicates when the file was create...
Definition
PE/Header.hpp:202
LIEF::PE::Header::is_loonarch
static bool is_loonarch(MACHINE_TYPES ty)
Definition
PE/Header.hpp:98
LIEF::PE::Header::is_mips
static bool is_mips(MACHINE_TYPES ty)
Definition
PE/Header.hpp:124
LIEF::PE::Header::sizeof_optional_header
void sizeof_optional_header(uint16_t size)
Definition
PE/Header.hpp:269
LIEF::PE::Header::Header
Header(const Header &)=default
LIEF::PE::Header::time_date_stamp
void time_date_stamp(uint32_t timestamp)
Definition
PE/Header.hpp:257
LIEF::PE::Header::MACHINE_TYPES
MACHINE_TYPES
Definition
PE/Header.hpp:40
LIEF::PE::Header::MACHINE_TYPES::RISCV128
@ RISCV128
Definition
PE/Header.hpp:64
LIEF::PE::Header::MACHINE_TYPES::ARMNT
@ ARMNT
Definition
PE/Header.hpp:47
LIEF::PE::Header::MACHINE_TYPES::LOONGARCH32
@ LOONGARCH32
Definition
PE/Header.hpp:52
LIEF::PE::Header::MACHINE_TYPES::POWERPCFP
@ POWERPCFP
Definition
PE/Header.hpp:59
LIEF::PE::Header::MACHINE_TYPES::LOONGARCH64
@ LOONGARCH64
Definition
PE/Header.hpp:53
LIEF::PE::Header::MACHINE_TYPES::ARM
@ ARM
Definition
PE/Header.hpp:46
LIEF::PE::Header::MACHINE_TYPES::MIPSFPU
@ MIPSFPU
Definition
PE/Header.hpp:56
LIEF::PE::Header::MACHINE_TYPES::R4000
@ R4000
Definition
PE/Header.hpp:61
LIEF::PE::Header::MACHINE_TYPES::UNKNOWN
@ UNKNOWN
Definition
PE/Header.hpp:41
LIEF::PE::Header::MACHINE_TYPES::WCEMIPSV2
@ WCEMIPSV2
Definition
PE/Header.hpp:70
LIEF::PE::Header::MACHINE_TYPES::AMD64
@ AMD64
Definition
PE/Header.hpp:45
LIEF::PE::Header::MACHINE_TYPES::MIPS16
@ MIPS16
Definition
PE/Header.hpp:55
LIEF::PE::Header::MACHINE_TYPES::MIPSFPU16
@ MIPSFPU16
Definition
PE/Header.hpp:57
LIEF::PE::Header::MACHINE_TYPES::RISCV32
@ RISCV32
Definition
PE/Header.hpp:62
LIEF::PE::Header::MACHINE_TYPES::RISCV64
@ RISCV64
Definition
PE/Header.hpp:63
LIEF::PE::Header::MACHINE_TYPES::POWERPCBE
@ POWERPCBE
Definition
PE/Header.hpp:60
LIEF::PE::Header::MACHINE_TYPES::ARM64
@ ARM64
Definition
PE/Header.hpp:48
LIEF::PE::Header::MACHINE_TYPES::I386
@ I386
Definition
PE/Header.hpp:50
LIEF::PE::Header::MACHINE_TYPES::POWERPC
@ POWERPC
Definition
PE/Header.hpp:58
LIEF::PE::Header::MACHINE_TYPES::THUMB
@ THUMB
Definition
PE/Header.hpp:69
LIEF::Visitor
Definition
Visitor.hpp:212
enums.hpp
ENABLE_BITMASK_OPERATORS
#define ENABLE_BITMASK_OPERATORS(X)
Definition
enums.hpp:24
LIEF::PE::details
Definition
DataDirectory.hpp:37
LIEF::PE
Namespace related to the LIEF's PE module.
Definition
Abstract/Header.hpp:32
LIEF::PE::to_string
const char * to_string(CODE_PAGES e)
LIEF::PE::PE_TYPE
PE_TYPE
Definition
PE/enums.hpp:22
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:40
visibility.h
LIEF_API
#define LIEF_API
Definition
visibility.h:43
LIEF_LOCAL
#define LIEF_LOCAL
Definition
visibility.h:44
Generated by
1.17.0