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
COFF
COFF/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_COFF_HEADER_H
17
#define LIEF_COFF_HEADER_H
18
#include <cstdint>
19
#include <memory>
20
#include <ostream>
21
22
#include "
LIEF/visibility.h
"
23
#include "
LIEF/PE/Header.hpp
"
24
25
namespace
LIEF
{
26
class
BinaryStream
;
27
28
namespace
COFF
{
29
33
class
LIEF_API
Header
{
34
public
:
35
enum class
KIND
{
36
UNKNOWN = 0,
37
REGULAR,
38
BIGOBJ,
39
};
40
42
using
MACHINE_TYPES
=
LIEF::PE::Header::MACHINE_TYPES
;
43
45
static
std::unique_ptr<Header>
create
(
BinaryStream
& stream);
46
static
std::unique_ptr<Header>
create
(
BinaryStream
& stream,
KIND
kind
);
47
48
Header
() =
default
;
49
Header
(
KIND
kind
) :
50
kind_(
kind
) {}
51
52
Header
&
operator=
(
const
Header
&) =
default
;
53
Header
(
const
Header
&) =
default
;
54
55
Header
&
operator=
(
Header
&&) =
default
;
56
Header
(
Header
&&) =
default
;
57
58
virtual
std::unique_ptr<Header>
clone
()
const
= 0;
59
62
KIND
kind
()
const
{
63
return
kind_;
64
}
65
67
MACHINE_TYPES
machine
()
const
{
68
return
machine_;
69
}
70
72
uint32_t
nb_sections
()
const
{
73
return
nb_sections_;
74
}
75
77
uint32_t
pointerto_symbol_table
()
const
{
78
return
pointerto_symbol_table_;
79
}
80
82
uint32_t
nb_symbols
()
const
{
83
return
nb_symbols_;
84
}
85
87
uint32_t
timedatestamp
()
const
{
88
return
timedatestamp_;
89
}
90
91
void
machine
(
MACHINE_TYPES
machine
) {
92
machine_ =
machine
;
93
}
94
95
void
nb_sections
(uint32_t value) {
96
nb_sections_ = value;
97
}
98
99
void
pointerto_symbol_table
(uint32_t value) {
100
pointerto_symbol_table_ = value;
101
}
102
103
void
nb_symbols
(uint32_t value) {
104
nb_symbols_ = value;
105
}
106
107
void
timedatestamp
(uint32_t value) {
108
timedatestamp_ = value;
109
}
110
111
virtual
std::string
to_string
()
const
;
112
113
LIEF_API
friend
std::ostream&
operator<<
(std::ostream& os,
const
Header
& hdr) {
114
os << hdr.
to_string
();
115
return
os;
116
}
117
118
template
<
class
T>
119
const
T*
as
()
const
{
120
static_assert
(std::is_base_of<Header, T>::value,
"Require Header inheritance"
);
121
if
(T::classof(
this
)) {
122
return
static_cast<
const
T*
>
(
this
);
123
}
124
return
nullptr
;
125
}
126
127
virtual
~Header
() =
default
;
128
129
protected
:
130
KIND
kind_ =
KIND::UNKNOWN
;
131
MACHINE_TYPES
machine_ = MACHINE_TYPES::UNKNOWN;
132
uint32_t nb_sections_ = 0;
133
uint32_t pointerto_symbol_table_ = 0;
134
uint32_t nb_symbols_ = 0;
135
uint32_t timedatestamp_ = 0;
136
};
137
138
LIEF_API
inline
const
char
*
to_string
(
Header::KIND
kind) {
139
switch
(kind) {
140
case
Header::KIND::UNKNOWN
:
return
"UNKNOWN"
;
141
case
Header::KIND::REGULAR
:
return
"REGULAR"
;
142
case
Header::KIND::BIGOBJ
:
return
"BIGOBJ"
;
143
}
144
return
"UNKNOWN"
;
145
}
146
147
LIEF_API
inline
const
char
*
to_string
(
Header::MACHINE_TYPES
machine) {
148
return
LIEF::PE::to_string
(machine);
149
}
150
}
151
}
152
#endif
Header.hpp
LIEF::BinaryStream
Class that is used to a read stream of data from different sources.
Definition
BinaryStream.hpp:33
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:95
LIEF::COFF::Header::pointerto_symbol_table
uint32_t pointerto_symbol_table() const
Offset of the symbols table.
Definition
COFF/Header.hpp:77
LIEF::COFF::Header::as
const T * as() const
Definition
COFF/Header.hpp:119
LIEF::COFF::Header::operator<<
friend std::ostream & operator<<(std::ostream &os, const Header &hdr)
Definition
COFF/Header.hpp:113
LIEF::COFF::Header::nb_sections
uint32_t nb_sections() const
The number of sections.
Definition
COFF/Header.hpp:72
LIEF::COFF::Header::Header
Header()=default
LIEF::COFF::Header::Header
Header(KIND kind)
Definition
COFF/Header.hpp:49
LIEF::COFF::Header::operator=
Header & operator=(const Header &)=default
LIEF::COFF::Header::machine
void machine(MACHINE_TYPES machine)
Definition
COFF/Header.hpp:91
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:62
LIEF::COFF::Header::timedatestamp
uint32_t timedatestamp() const
Timestamp when the COFF has been generated.
Definition
COFF/Header.hpp:87
LIEF::COFF::Header::timedatestamp
void timedatestamp(uint32_t value)
Definition
COFF/Header.hpp:107
LIEF::COFF::Header::nb_symbols
uint32_t nb_symbols() const
Number of symbols (including auxiliary symbols).
Definition
COFF/Header.hpp:82
LIEF::COFF::Header::nb_symbols
void nb_symbols(uint32_t value)
Definition
COFF/Header.hpp:103
LIEF::COFF::Header::KIND
KIND
Definition
COFF/Header.hpp:35
LIEF::COFF::Header::KIND::UNKNOWN
@ UNKNOWN
Definition
COFF/Header.hpp:36
LIEF::COFF::Header::KIND::REGULAR
@ REGULAR
Definition
COFF/Header.hpp:37
LIEF::COFF::Header::KIND::BIGOBJ
@ BIGOBJ
Definition
COFF/Header.hpp:38
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:42
LIEF::COFF::Header::pointerto_symbol_table
void pointerto_symbol_table(uint32_t value)
Definition
COFF/Header.hpp:99
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:67
LIEF::COFF::Header::clone
virtual std::unique_ptr< Header > clone() const =0
LIEF::PE::Header::MACHINE_TYPES
MACHINE_TYPES
Definition
PE/Header.hpp:40
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:40
visibility.h
LIEF_API
#define LIEF_API
Definition
visibility.h:43
Generated by
1.17.0