LIEF: Library to Instrument Executable Formats
Version 2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
LIEF
COFF
COFF/Header.hpp
Go to the documentation of this file.
1
/* Copyright 2017 - 2026 R. Thomas
2
*
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
6
*
7
* http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*/
15
#ifndef LIEF_COFF_HEADER_H
16
#define LIEF_COFF_HEADER_H
17
#include <cstdint>
18
#include <memory>
19
#include <ostream>
20
21
#include "
LIEF/PE/Header.hpp
"
22
#include "
LIEF/visibility.h
"
23
24
namespace
LIEF
{
25
class
BinaryStream
;
26
27
namespace
COFF
{
28
32
class
LIEF_API
Header
{
33
public
:
34
enum class
KIND
{
35
UNKNOWN = 0,
36
REGULAR,
37
BIGOBJ,
38
};
39
41
using
MACHINE_TYPES
=
LIEF::PE::Header::MACHINE_TYPES
;
42
44
static
std::unique_ptr<Header>
create
(
BinaryStream
& stream);
45
static
std::unique_ptr<Header>
create
(
BinaryStream
& stream,
KIND
kind
);
46
47
Header
() =
default
;
48
Header
(
KIND
kind
) :
49
kind_(
kind
) {}
50
51
Header
&
operator=
(
const
Header
&) =
default
;
52
Header
(
const
Header
&) =
default
;
53
54
Header
&
operator=
(
Header
&&) =
default
;
55
Header
(
Header
&&) =
default
;
56
57
virtual
std::unique_ptr<Header>
clone
()
const
= 0;
58
61
KIND
kind
()
const
{
62
return
kind_;
63
}
64
66
MACHINE_TYPES
machine
()
const
{
67
return
machine_;
68
}
69
71
uint32_t
nb_sections
()
const
{
72
return
nb_sections_;
73
}
74
76
uint32_t
pointerto_symbol_table
()
const
{
77
return
pointerto_symbol_table_;
78
}
79
81
uint32_t
nb_symbols
()
const
{
82
return
nb_symbols_;
83
}
84
86
uint32_t
timedatestamp
()
const
{
87
return
timedatestamp_;
88
}
89
90
void
machine
(
MACHINE_TYPES
machine
) {
91
machine_ =
machine
;
92
}
93
94
void
nb_sections
(uint32_t value) {
95
nb_sections_ = value;
96
}
97
98
void
pointerto_symbol_table
(uint32_t value) {
99
pointerto_symbol_table_ = value;
100
}
101
102
void
nb_symbols
(uint32_t value) {
103
nb_symbols_ = value;
104
}
105
106
void
timedatestamp
(uint32_t value) {
107
timedatestamp_ = value;
108
}
109
110
virtual
std::string
to_string
()
const
;
111
112
LIEF_API
friend
std::ostream&
operator<<
(std::ostream& os,
const
Header
& hdr) {
113
os << hdr.
to_string
();
114
return
os;
115
}
116
117
template
<
class
T>
118
const
T*
as
()
const
{
119
static_assert
(std::is_base_of_v<Header, T>,
"Require Header inheritance"
);
120
if
(T::classof(
this
)) {
121
return
static_cast<
const
T*
>
(
this
);
122
}
123
return
nullptr
;
124
}
125
126
virtual
~Header
() =
default
;
127
128
protected
:
129
KIND
kind_ =
KIND::UNKNOWN
;
130
MACHINE_TYPES
machine_ = MACHINE_TYPES::UNKNOWN;
131
uint32_t nb_sections_ = 0;
132
uint32_t pointerto_symbol_table_ = 0;
133
uint32_t nb_symbols_ = 0;
134
uint32_t timedatestamp_ = 0;
135
};
136
137
LIEF_API
inline
const
char
*
to_string
(
Header::KIND
kind) {
138
switch
(kind) {
139
case
Header::KIND::UNKNOWN
:
return
"UNKNOWN"
;
140
case
Header::KIND::REGULAR
:
return
"REGULAR"
;
141
case
Header::KIND::BIGOBJ
:
return
"BIGOBJ"
;
142
}
143
return
"UNKNOWN"
;
144
}
145
146
LIEF_API
inline
const
char
*
to_string
(
Header::MACHINE_TYPES
machine) {
147
return
LIEF::PE::to_string
(machine);
148
}
149
}
150
}
151
#endif
Header.hpp
LIEF::BinaryStream
Class that is used to a read stream of data from different sources.
Definition
BinaryStream.hpp:34
LIEF::COFF::Header::create
static std::unique_ptr< Header > create(BinaryStream &stream, KIND kind)
LIEF::COFF::Header::nb_sections
void nb_sections(uint32_t value)
Definition
COFF/Header.hpp:94
LIEF::COFF::Header::pointerto_symbol_table
uint32_t pointerto_symbol_table() const
Offset of the symbols table.
Definition
COFF/Header.hpp:76
LIEF::COFF::Header::as
const T * as() const
Definition
COFF/Header.hpp:118
LIEF::COFF::Header::operator<<
friend std::ostream & operator<<(std::ostream &os, const Header &hdr)
Definition
COFF/Header.hpp:112
LIEF::COFF::Header::nb_sections
uint32_t nb_sections() const
The number of sections.
Definition
COFF/Header.hpp:71
LIEF::COFF::Header::Header
Header()=default
LIEF::COFF::Header::Header
Header(KIND kind)
Definition
COFF/Header.hpp:48
LIEF::COFF::Header::operator=
Header & operator=(const Header &)=default
LIEF::COFF::Header::machine
void machine(MACHINE_TYPES machine)
Definition
COFF/Header.hpp:90
LIEF::COFF::Header::Header
Header(const Header &)=default
LIEF::COFF::Header::Header
Header(Header &&)=default
LIEF::COFF::Header::to_string
virtual std::string to_string() const
LIEF::COFF::Header::kind
KIND kind() const
The type of this header: whether it is regular or using the /bigobj format.
Definition
COFF/Header.hpp:61
LIEF::COFF::Header::timedatestamp
uint32_t timedatestamp() const
Timestamp when the COFF has been generated.
Definition
COFF/Header.hpp:86
LIEF::COFF::Header::timedatestamp
void timedatestamp(uint32_t value)
Definition
COFF/Header.hpp:106
LIEF::COFF::Header::nb_symbols
uint32_t nb_symbols() const
Number of symbols (including auxiliary symbols).
Definition
COFF/Header.hpp:81
LIEF::COFF::Header::nb_symbols
void nb_symbols(uint32_t value)
Definition
COFF/Header.hpp:102
LIEF::COFF::Header::KIND
KIND
Definition
COFF/Header.hpp:34
LIEF::COFF::Header::KIND::UNKNOWN
@ UNKNOWN
Definition
COFF/Header.hpp:35
LIEF::COFF::Header::KIND::REGULAR
@ REGULAR
Definition
COFF/Header.hpp:36
LIEF::COFF::Header::KIND::BIGOBJ
@ BIGOBJ
Definition
COFF/Header.hpp:37
LIEF::COFF::Header::~Header
virtual ~Header()=default
LIEF::COFF::Header::MACHINE_TYPES
LIEF::PE::Header::MACHINE_TYPES MACHINE_TYPES
The different architectures (mirrored from PE).
Definition
COFF/Header.hpp:41
LIEF::COFF::Header::pointerto_symbol_table
void pointerto_symbol_table(uint32_t value)
Definition
COFF/Header.hpp:98
LIEF::COFF::Header::operator=
Header & operator=(Header &&)=default
LIEF::COFF::Header::create
static std::unique_ptr< Header > create(BinaryStream &stream)
Create a header from the given stream.
LIEF::COFF::Header::machine
MACHINE_TYPES machine() const
The machine type targeted by this COFF.
Definition
COFF/Header.hpp:66
LIEF::COFF::Header::clone
virtual std::unique_ptr< Header > clone() const =0
LIEF::PE::Header::MACHINE_TYPES
MACHINE_TYPES
Definition
PE/Header.hpp:44
LIEF::COFF
Definition
AuxiliarySymbol.hpp:29
LIEF::COFF::to_string
const char * to_string(AuxiliarySectionDefinition::COMDAT_SELECTION e)
LIEF::PE::to_string
const char * to_string(CODE_PAGES e)
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:41
visibility.h
LIEF_API
#define LIEF_API
Definition
visibility.h:44
Generated by
1.19.0