16#ifndef LIEF_PE_BUILDER_H
17#define LIEF_PE_BUILDER_H
112 bool force_relocating =
false;
118 config_(std::move(config)) {}
131 void write(
const std::string& filename)
const;
149 template<
typename PE_T>
152 template<
typename PE_T>
155 template<
typename PE_T>
164 std::vector<uint8_t> header;
165 std::vector<uint8_t> callbacks;
168 struct rsrc_sizing_info_t {
169 uint32_t header_size = 0;
170 uint32_t data_size = 0;
171 uint32_t name_size = 0;
174 struct rsrc_build_context_t {
175 uint32_t offset_header = 0;
176 uint32_t offset_data = 0;
177 uint32_t offset_name = 0;
179 std::vector<uint64_t> rva_fixups;
182 template<
typename PE_T>
183 ok_error_t build_optional_header(
const OptionalHeader& optional_header);
185 static ok_error_t compute_resources_size(
const ResourceNode& node,
186 rsrc_sizing_info_t& info);
188 static ok_error_t construct_resource(vector_iostream& ios, ResourceNode& node,
189 rsrc_build_context_t& ctx);
191 static ok_error_t construct_resource(vector_iostream& ios,
192 ResourceDirectory& dir,
193 rsrc_build_context_t& ctx);
195 static ok_error_t construct_resource(vector_iostream& ios, ResourceData& dir,
196 rsrc_build_context_t& ctx);
198 mutable vector_iostream ios_;
199 Binary* binary_ =
nullptr;
201 std::vector<uint8_t> reloc_data_;
202 std::vector<uint8_t> rsrc_data_;
203 tls_data_t tls_data_;
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:57
ok_error_t build_load_config()
ok_error_t build_relocations()
ok_error_t build_overlay()
ok_error_t build_exports()
ok_error_t build_resources()
ok_error_t build(const Header &header)
ok_error_t build_debug_info()
ok_error_t build(const DataDirectory &data_directory)
ok_error_t build(const Section §ion)
ok_error_t build(const OptionalHeader &optional_header)
Builder(Binary &binary, config_t config)
Definition PE/Builder.hpp:116
ok_error_t build()
Perform the build process.
void write(std::ostream &os) const
Write the build result into the os stream.
void write(const std::string &filename) const
Write the build result into the output file.
const std::vector< uint8_t > & rsrc_data() const
Definition PE/Builder.hpp:158
ok_error_t build(const DosHeader &dos_header)
ok_error_t build_imports()
const std::vector< uint8_t > & get_build()
Return the build result.
Definition PE/Builder.hpp:126
Class that represents a PE data directory entry.
Definition DataDirectory.hpp:42
Class that represents an entry (i.e. an import) in the import table (Import).
Definition ImportEntry.hpp:36
Class that represents a PE import.
Definition Import.hpp:40
Class which represents a Data Node in the PE resources tree.
Definition ResourceData.hpp:34
Definition ResourceDirectory.hpp:33
Class which represents a Node in the resource tree.
Definition ResourceNode.hpp:46
Class which represents a PE section.
Definition PE/Section.hpp:47
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:119
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF namespace.
Definition Abstract/Binary.hpp:41
This structure is used to configure the build operation.
Definition PE/Builder.hpp:53
resolved_iat_cbk_t resolved_iat_cbk
Definition PE/Builder.hpp:109
std::function< void(Binary *, const Import *, const ImportEntry *, uint32_t)> resolved_iat_cbk_t
Definition PE/Builder.hpp:107
bool debug
Whether the builder should regenerate debug entries.
Definition PE/Builder.hpp:82
bool load_configuration
Whether the builder should regenerate the load config.
Definition PE/Builder.hpp:73
std::string debug_section
Section that holds the debug entries.
Definition PE/Builder.hpp:105
bool overlay
Whether the builder should write back any overlay data.
Definition PE/Builder.hpp:79
std::string rsrc_section
If the resources tree needs to be relocated, this defines the name of the new section that contains t...
Definition PE/Builder.hpp:90
bool relocations
Whether the builder should regenerate relocations.
Definition PE/Builder.hpp:70
bool exports
Whether the builder should reconstruct the export table This option should be turned on if you modify...
Definition PE/Builder.hpp:64
bool dos_stub
Whether the builder should write back dos stub (including the rich header).
Definition PE/Builder.hpp:86
bool tls
Whether the builder should regenerate the TLS info.
Definition PE/Builder.hpp:76
std::string reloc_section
Section that holds the relocated relocations.
Definition PE/Builder.hpp:99
std::string idata_section
Section that holds the relocated import table (IAT/ILT).
Definition PE/Builder.hpp:93
std::string export_section
Section that holds the export table.
Definition PE/Builder.hpp:102
bool resources
Whether the builder should regenerate the resources tree.
Definition PE/Builder.hpp:67
bool imports
Whether the builder should reconstruct the imports table. This option should be turned on if you modi...
Definition PE/Builder.hpp:58
std::string tls_section
Section that holds the relocated TLS info.
Definition PE/Builder.hpp:96
#define LIEF_API
Definition visibility.h:45