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/Parser.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_PARSER_H
17
#define LIEF_COFF_PARSER_H
18
#include <map>
19
#include "
LIEF/compiler_attributes.hpp
"
20
#include "
LIEF/BinaryStream/BinaryStream.hpp
"
21
#include "
LIEF/visibility.h
"
22
#include "
LIEF/errors.hpp
"
23
24
#include "
LIEF/COFF/ParserConfig.hpp
"
25
#include "
LIEF/COFF/Header.hpp
"
26
27
namespace
LIEF
{
28
namespace
COFF
{
29
class
Binary
;
30
class
Section
;
31
class
String
;
32
class
Symbol
;
33
34
class
Parser {
35
public
:
36
static
constexpr
size_t
MAX_NB_SECTIONS
= 1 << 20;
37
40
static
LIEF_API
std::unique_ptr<Binary>
41
parse
(std::unique_ptr<BinaryStream> stream,
42
const
ParserConfig
& config =
ParserConfig::default_conf
());
43
45
static
LIEF_API
std::unique_ptr<Binary>
46
parse
(
const
std::string& file,
47
const
ParserConfig
& config =
ParserConfig::default_conf
());
48
50
struct
SymSec {
51
size_t
sec_idx = 0;
52
Symbol
* symbol =
nullptr
;
53
54
friend
bool
operator<(
const
SymSec& lhs,
const
SymSec& rhs) {
55
return
lhs.sec_idx < rhs.sec_idx;
56
}
57
58
friend
bool
operator==(
const
SymSec& lhs,
const
SymSec& rhs) {
59
return
lhs.sec_idx == rhs.sec_idx && lhs.symbol == rhs.symbol;
60
}
61
62
friend
bool
operator!=(
const
SymSec& lhs,
const
SymSec& rhs) {
63
return
!(lhs == rhs);
64
}
65
};
66
68
using
SymSecMap
= std::vector<SymSec>;
69
71
LIEF_LOCAL
void
memoize(
String
str);
72
74
LIEF_LOCAL
String
* find_coff_string(uint32_t offset)
const
;
75
76
~Parser
();
77
78
private
:
79
Parser(std::unique_ptr<BinaryStream> stream,
const
ParserConfig
& config,
80
Header::KIND
kind);
81
82
ok_error_t
process();
83
ok_error_t
parse_header();
84
ok_error_t
parse_optional_header();
85
ok_error_t
parse_sections();
86
ok_error_t
parse_relocations(
Section
& section);
87
ok_error_t
parse_symbols();
88
ok_error_t
parse_string_table();
89
90
std::unique_ptr<BinaryStream> stream_;
91
std::unique_ptr<Binary> bin_;
92
Header::KIND
kind_ =
Header::KIND::UNKNOWN
;
93
94
std::map<uint32_t, size_t> memoize_coff_str_;
95
std::map<size_t, Symbol*> symbol_idx_;
96
SymSecMap
symsec_;
97
98
LIEF_MAYBE_UNUSED
ParserConfig
config_;
99
};
100
}
101
}
102
#endif
BinaryStream.hpp
Header.hpp
ParserConfig.hpp
LIEF::COFF::Binary
Class that represents a COFF Binary.
Definition
COFF/Binary.hpp:44
LIEF::COFF::Header::KIND
KIND
Definition
COFF/Header.hpp:35
LIEF::COFF::Header::KIND::UNKNOWN
@ UNKNOWN
Definition
COFF/Header.hpp:36
LIEF::COFF::ParserConfig
Class used to configure the COFF parser.
Definition
COFF/ParserConfig.hpp:24
LIEF::COFF::ParserConfig::default_conf
static const ParserConfig & default_conf()
Definition
COFF/ParserConfig.hpp:26
LIEF::COFF::Parser::~Parser
~Parser()
LIEF::COFF::Parser::parse
static std::unique_ptr< Binary > parse(std::unique_ptr< BinaryStream > stream, const ParserConfig &config=ParserConfig::default_conf())
Parse the COFF binary referenced by the stream argument with the given config.
LIEF::COFF::Parser::SymSecMap
std::vector< SymSec > SymSecMap
<=> std::unordered_multimap<section index, Symbol*>
Definition
COFF/Parser.hpp:68
LIEF::COFF::Parser::parse
static std::unique_ptr< Binary > parse(const std::string &file, const ParserConfig &config=ParserConfig::default_conf())
Parse the COFF binary pointed by the file argument with the given config.
LIEF::COFF::Parser::MAX_NB_SECTIONS
static constexpr size_t MAX_NB_SECTIONS
Definition
COFF/Parser.hpp:36
LIEF::COFF::Section
This class represents a COFF section.
Definition
COFF/Section.hpp:40
LIEF::COFF::String
This class represents a string located in the COFF string table.
Definition
String.hpp:34
LIEF::COFF::Symbol
This class represents a COFF symbol.
Definition
COFF/Symbol.hpp:35
LIEF::ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition
errors.hpp:119
compiler_attributes.hpp
LIEF_MAYBE_UNUSED
#define LIEF_MAYBE_UNUSED
Definition
compiler_attributes.hpp:62
errors.hpp
LIEF::COFF
Definition
AuxiliarySymbol.hpp:30
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:41
visibility.h
LIEF_API
#define LIEF_API
Definition
visibility.h:45
LIEF_LOCAL
#define LIEF_LOCAL
Definition
visibility.h:46
Generated by
1.17.0