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
Factory.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_FACTORY_H
17
#define LIEF_PE_FACTORY_H
18
19
#include "
LIEF/visibility.h
"
20
#include "
LIEF/PE/Binary.hpp
"
21
#include "
LIEF/PE/Section.hpp
"
22
#include "
LIEF/PE/Import.hpp
"
23
#include <memory>
24
25
namespace
LIEF
{
26
namespace
PE
{
27
29
class
LIEF_API
Factory
{
30
public
:
31
Factory
(
const
Factory
&) =
delete
;
32
Factory
&
operator=
(
const
Factory
&) =
delete
;
33
34
Factory
(
Factory
&&);
35
Factory
&
operator=
(
Factory
&&);
36
38
static
std::unique_ptr<Factory>
create
(
PE_TYPE
type);
39
40
Factory
&
add_section
(
const
Section
& section) {
41
sections_.push_back(std::unique_ptr<Section>(
new
Section
(section)));
42
return
*
this
;
43
}
44
45
Factory
&
set_arch
(
Header::MACHINE_TYPES
arch) {
46
pe_->header().machine(arch);
47
return
*
this
;
48
}
49
50
Factory
&
set_entrypoint
(uint64_t ep) {
51
pe_->optional_header().addressof_entrypoint(ep);
52
return
*
this
;
53
}
54
55
std::unique_ptr<Binary>
get
() {
56
return
process();
57
}
58
59
bool
is_32bit
()
const
{
60
return
pe_->type() ==
PE_TYPE::PE32
;
61
}
62
63
bool
is_64bit
()
const
{
64
return
pe_->type() ==
PE_TYPE::PE32_PLUS
;
65
}
66
67
uint32_t
section_align
()
const
{
68
return
pe_->optional_header().section_alignment();
69
}
70
71
uint32_t
file_align
()
const
{
72
return
pe_->optional_header().file_alignment();
73
}
74
75
~Factory
();
76
77
protected
:
78
Factory
() :
79
pe_(std::unique_ptr<
Binary
>(new
Binary
{}))
80
{}
81
std::unique_ptr<Binary> process();
82
83
ok_error_t
check_overlapping()
const
;
84
ok_error_t
assign_locations();
85
ok_error_t
update_headers();
86
ok_error_t
move_sections();
87
uint32_t sizeof_headers()
const
;
88
89
std::vector<std::unique_ptr<Section>> sections_;
90
std::vector<Import> imports_;
91
std::unique_ptr<Binary> pe_;
92
};
93
}
94
}
95
#endif
96
Import.hpp
Binary.hpp
Section.hpp
LIEF::PE::Binary
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition
PE/Binary.hpp:57
LIEF::PE::Factory::set_arch
Factory & set_arch(Header::MACHINE_TYPES arch)
Definition
Factory.hpp:45
LIEF::PE::Factory::set_entrypoint
Factory & set_entrypoint(uint64_t ep)
Definition
Factory.hpp:50
LIEF::PE::Factory::get
std::unique_ptr< Binary > get()
Definition
Factory.hpp:55
LIEF::PE::Factory::is_64bit
bool is_64bit() const
Definition
Factory.hpp:63
LIEF::PE::Factory::file_align
uint32_t file_align() const
Definition
Factory.hpp:71
LIEF::PE::Factory::~Factory
~Factory()
LIEF::PE::Factory::section_align
uint32_t section_align() const
Definition
Factory.hpp:67
LIEF::PE::Factory::is_32bit
bool is_32bit() const
Definition
Factory.hpp:59
LIEF::PE::Factory::add_section
Factory & add_section(const Section §ion)
Definition
Factory.hpp:40
LIEF::PE::Factory::operator=
Factory & operator=(const Factory &)=delete
LIEF::PE::Factory::Factory
Factory(const Factory &)=delete
LIEF::PE::Factory::operator=
Factory & operator=(Factory &&)
LIEF::PE::Factory::create
static std::unique_ptr< Factory > create(PE_TYPE type)
Initiate the factory to construct a PE which the given type.
LIEF::PE::Factory::Factory
Factory(Factory &&)
LIEF::PE::Header::MACHINE_TYPES
MACHINE_TYPES
Definition
PE/Header.hpp:40
LIEF::PE::Section
Class which represents a PE section.
Definition
PE/Section.hpp:46
LIEF::ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition
errors.hpp:112
LIEF::PE
Namespace related to the LIEF's PE module.
Definition
Abstract/Header.hpp:32
LIEF::PE::PE_TYPE
PE_TYPE
Definition
PE/enums.hpp:22
LIEF::PE::PE_TYPE::PE32
@ PE32
32bits
Definition
PE/enums.hpp:23
LIEF::PE::PE_TYPE::PE32_PLUS
@ PE32_PLUS
64 bits
Definition
PE/enums.hpp:24
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:40
visibility.h
LIEF_API
#define LIEF_API
Definition
visibility.h:41
Generated by
1.17.0