LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
PE/Binary.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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_BINARY_H
17#define LIEF_PE_BINARY_H
18
19#include "LIEF/PE/Header.hpp"
21#include "LIEF/PE/DosHeader.hpp"
22#include "LIEF/PE/Import.hpp"
24#include "LIEF/PE/Symbol.hpp"
28
30
31#include "LIEF/visibility.h"
32
33namespace LIEF {
34namespace PE {
37class Builder;
38class CodeViewPDB;
39class Debug;
40class Export;
42class Parser;
43class Relocation;
44class ResourceData;
46class ResourceNode;
47class RichHeader;
48class TLS;
49class LIEF_API Binary : public LIEF::Binary {
53 friend class Parser;
54 friend class Builder;
55
56 public: using sections_t = std::vector<std::unique_ptr<Section>>;
59 using it_sections = ref_iterator<sections_t&, Section*>;
62 using it_const_sections = const_ref_iterator<const sections_t&, const Section*>;
65 using data_directories_t = std::vector<std::unique_ptr<DataDirectory>>;
68 using it_data_directories = ref_iterator<data_directories_t&, DataDirectory*>;
71 using it_const_data_directories = const_ref_iterator<const data_directories_t&, const DataDirectory*>;
74 using relocations_t = std::vector<std::unique_ptr<Relocation>>;
77 using it_relocations = ref_iterator<relocations_t&, Relocation*>;
80 using it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*>;
83 using imports_t = std::vector<Import>;
86 using it_imports = ref_iterator<imports_t&>;
89 using it_const_imports = const_ref_iterator<const imports_t&>;
92 using delay_imports_t = std::vector<DelayImport>;
95 using it_delay_imports = ref_iterator<delay_imports_t&>;
98 using it_const_delay_imports = const_ref_iterator<const delay_imports_t&>;
101 using debug_entries_t = std::vector<std::unique_ptr<Debug>>;
104 using it_debug_entries = ref_iterator<debug_entries_t&, Debug*>;
107 using it_const_debug_entries = const_ref_iterator<const debug_entries_t&, const Debug*>;
110 using symbols_t = std::vector<Symbol>;
113 using it_symbols = ref_iterator<symbols_t&>;
116 using it_const_symbols = const_ref_iterator<const symbols_t&>;
119 using strings_table_t = std::vector<std::string>;
122 using it_strings_table = ref_iterator<strings_table_t&>;
125 using it_const_strings_table = const_ref_iterator<const strings_table_t&>;
128 using signatures_t = std::vector<Signature>;
131 using it_signatures = ref_iterator<signatures_t&>;
134 using it_const_signatures = const_ref_iterator<const signatures_t&>;
137
138 Binary(PE_TYPE type);
139
140 ~Binary() override;
141 PE_TYPE type() const {
144 return type_;
145 }
146 uint64_t rva_to_offset(uint64_t RVA) const;
152 uint64_t va_to_offset(uint64_t VA) const;
156 result<uint64_t> offset_to_virtual_address(uint64_t offset, uint64_t slide = 0) const override;
162 uint64_t imagebase() const override {
167 return optional_header().imagebase();
168 }
169 Section* section_from_offset(uint64_t offset) {
174 return const_cast<Section*>(static_cast<const Binary*>(this)->section_from_offset(offset));
175 }
176 const Section* section_from_offset(uint64_t offset) const;
177 Section* section_from_rva(uint64_t virtual_address) {
182 return const_cast<Section*>(static_cast<const Binary*>(this)->section_from_rva(virtual_address));
183 }
184 const Section* section_from_rva(uint64_t virtual_address) const;
185 it_sections sections() {
188 return sections_;
189 }
190
191 it_const_sections sections() const {
192 return sections_;
193 }
194 DosHeader& dos_header() {
197 return dos_header_;
198 }
199
200 const DosHeader& dos_header() const {
201 return dos_header_;
202 }
203 Header& header() {
206 return header_;
207 }
208
209 const Header& header() const {
210 return header_;
211 }
212 OptionalHeader& optional_header() {
216 return optional_header_;
217 }
218
219 const OptionalHeader& optional_header() const {
220 return optional_header_;
221 }
222 uint32_t compute_checksum() const;
229 uint64_t virtual_size() const;
233 uint32_t sizeof_headers() const;
236 TLS* tls() {
239 return tls_.get();
240 }
241
242 const TLS* tls() const {
243 return tls_.get();
244 }
245 void tls(const TLS& tls);
248 bool has_tls() const {
251 return tls_ != nullptr;
252 }
253 bool has_imports() const {
258 return !imports_.empty();
259 }
260 bool has_signatures() const {
265 return !signatures_.empty();
266 }
267 bool has_exports() const {
272 return export_ != nullptr;
273 }
274 bool has_resources() const {
277 return resources_ != nullptr;
278 }
279 bool has_exceptions() const {
282 return has(DataDirectory::TYPES::EXCEPTION_TABLE);
283 }
284 bool has_relocations() const {
289 return !relocations_.empty();
290 }
291 bool has_debug() const {
294 return !debug_.empty();
295 }
296 bool has_configuration() const {
299 return load_configuration_ != nullptr;
300 }
301 bool is_reproducible_build() const;
306 it_const_signatures signatures() const {
309 return signatures_;
310 }
311
312 it_signatures signatures() {
313 return signatures_;
314 }
315 Signature::VERIFICATION_FLAGS verify_signature(
324 Signature::VERIFICATION_CHECKS checks = Signature::VERIFICATION_CHECKS::DEFAULT) const;
325 Signature::VERIFICATION_FLAGS verify_signature(const Signature& sig,
336 Signature::VERIFICATION_CHECKS checks = Signature::VERIFICATION_CHECKS::DEFAULT) const;
337 std::vector<uint8_t> authentihash(ALGORITHMS algo) const;
341 uint32_t predict_function_rva(const std::string& library, const std::string& function);
355 Export* get_export() {
358 return export_.get();
359 }
360
361 const Export* get_export() const {
362 return export_.get();
363 }
364 std::vector<Symbol>& symbols() {
367 return symbols_;
368 }
369
370 const std::vector<Symbol>& symbols() const {
371 return symbols_;
372 }
373 ResourceNode* resources() {
376 return resources_.get();
377 }
378
379 const ResourceNode* resources() const {
380 return resources_.get();
381 }
382 void set_resources(const ResourceDirectory& resource);
385 void set_resources(const ResourceData& resource);
388 result<ResourcesManager> resources_manager() const;
391 Section* get_section(const std::string& name) {
397 return const_cast<Section*>(static_cast<const Binary*>(this)->get_section(name));
398 }
399 const Section* get_section(const std::string& name) const;
400 const Section* import_section() const;
404 Section* import_section() {
405 return const_cast<Section*>(static_cast<const Binary*>(this)->import_section());
406 }
407 void remove_section(const std::string& name, bool clear = false) override;
414 void remove(const Section& section, bool clear = false);
419 Section* add_section(const Section& section,
422 PE_SECTION_TYPES type = PE_SECTION_TYPES::UNKNOWN);
423 it_relocations relocations() {
426 return relocations_;
427 }
428
429 it_const_relocations relocations() const {
430 return relocations_;
431 }
432 Relocation& add_relocation(const Relocation& relocation);
435 void remove_all_relocations();
438 it_data_directories data_directories() {
441 return data_directories_;
442 }
443
444 it_const_data_directories data_directories() const {
445 return data_directories_;
446 }
447 DataDirectory* data_directory(DataDirectory::TYPES type) {
450 return const_cast<DataDirectory*>(static_cast<const Binary*>(this)->data_directory(type));
451 }
452 const DataDirectory* data_directory(DataDirectory::TYPES type) const;
453 bool has(DataDirectory::TYPES type) const {
456 return data_directory(type) != nullptr;
457 }
458 it_debug_entries debug() {
461 return debug_;
462 }
463
464 it_const_debug_entries debug() const {
465 return debug_;
466 }
467 const CodeViewPDB* codeview_pdb() const;
470 const LoadConfiguration* load_configuration() const {
474 return load_configuration_.get();
475 }
476
477 LoadConfiguration* load_configuration() {
478 return load_configuration_.get();
479 }
480 span<const uint8_t> overlay() const {
483 return overlay_;
484 }
485
486 span<uint8_t> overlay() {
487 return overlay_;
488 }
489 uint64_t overlay_offset() const {
492 return overlay_offset_;
493 }
494 span<const uint8_t> dos_stub() const {
497 return dos_stub_;
498 }
499
500 span<uint8_t> dos_stub() {
501 return dos_stub_;
502 }
503 void dos_stub(std::vector<uint8_t> content) {
506 dos_stub_ = std::move(content);
507 }
508
509 // Rich Header
510 // -----------
511 RichHeader* rich_header() {
514 return rich_header_.get();
515 }
516
517 const RichHeader* rich_header() const {
518 return rich_header_.get();
519 }
520 void rich_header(const RichHeader& rich_header);
523 bool has_rich_header() const {
526 return rich_header_ != nullptr;
527 }
528 it_imports imports() {
531 return imports_;
532 }
533
534 it_const_imports imports() const {
535 return imports_;
536 }
537 Import* get_import(const std::string& import_name) {
543 return const_cast<Import*>(static_cast<const Binary*>(this)->get_import(import_name));
544 }
545 const Import* get_import(const std::string& import_name) const;
546 bool has_import(const std::string& import_name) const {
551 return get_import(import_name) != nullptr;
552 }
553 bool has_delay_imports() const {
559 return !delay_imports_.empty();
560 }
561 it_delay_imports delay_imports() {
564 return delay_imports_;
565 }
566
567 it_const_delay_imports delay_imports() const {
568 return delay_imports_;
569 }
570 DelayImport* get_delay_import(const std::string& import_name) {
576 return const_cast<DelayImport*>(static_cast<const Binary*>(this)->get_delay_import(import_name));
577 }
578 const DelayImport* get_delay_import(const std::string& import_name) const;
579
580 bool has_delay_import(const std::string& import_name) const {
585 return get_delay_import(import_name) != nullptr;
586 }
587
588 ImportEntry* add_import_function(const std::string& library, const std::string& function);
595 Import& add_library(const std::string& name) {
598 imports_.emplace_back(name);
599 return imports_.back();
600 }
601 void remove_library(const std::string& name);
604 void remove_all_libraries() {
607 imports_.clear();
608 }
609 void write(const std::string& filename) override;
615 void write(std::ostream& os) override;
621
622 void accept(Visitor& visitor) const override;
623 void patch_address(uint64_t address, const std::vector<uint8_t>& patch_value,
630 LIEF::Binary::VA_TYPES addr_type = LIEF::Binary::VA_TYPES::AUTO) override;
631
632 void patch_address(uint64_t address, uint64_t patch_value, size_t size = sizeof(uint64_t),
640 LIEF::Binary::VA_TYPES addr_type = LIEF::Binary::VA_TYPES::AUTO) override;
641 span<const uint8_t> get_content_from_virtual_address(
648 uint64_t virtual_address, uint64_t size,
649 Binary::VA_TYPES addr_type = Binary::VA_TYPES::AUTO) const override;
650 uint64_t entrypoint() const override {
653 return optional_header_.imagebase() + optional_header_.addressof_entrypoint();
654 }
655 bool is_pie() const override {
658 return optional_header_.has(OptionalHeader::DLL_CHARACTERISTICS::DYNAMIC_BASE);
659 }
660 bool has_nx() const override {
663 return optional_header_.has(OptionalHeader::DLL_CHARACTERISTICS::NX_COMPAT);
664 }
665 LIEF::Binary::functions_t ctor_functions() const override;
670 LIEF::Binary::functions_t functions() const;
673 LIEF::Binary::functions_t exception_functions() const;
676
677 static bool classof(const LIEF::Binary* bin) {
678 return bin->format() == Binary::FORMATS::PE;
679 }
680
681 std::ostream& print(std::ostream& os) const override;
682
683 private:
684 Binary();
685 void make_space_for_new_section();
689 LIEF::Binary::symbols_t get_abstract_symbols() override;
692
693 LIEF::Header get_abstract_header() const override {
694 return LIEF::Header::from(*this);
695 }
696 LIEF::Binary::sections_t get_abstract_sections() override;
699
700 LIEF::Binary::relocations_t get_abstract_relocations() override;
701
702 LIEF::Binary::functions_t get_abstract_exported_functions() const override;
703 LIEF::Binary::functions_t get_abstract_imported_functions() const override;
704 std::vector<std::string> get_abstract_imported_libraries() const override;
705
706 void update_lookup_address_table_offset();
707 void update_iat();
708
709 PE_TYPE type_ = PE_TYPE::PE32_PLUS;
710 DosHeader dos_header_;
711 Header header_;
712 OptionalHeader optional_header_;
713
714 int32_t available_sections_space_ = 0;
715
716 signatures_t signatures_;
717 sections_t sections_;
718 data_directories_t data_directories_;
719 symbols_t symbols_;
720 strings_table_t strings_table_;
721 relocations_t relocations_;
722 imports_t imports_;
723 delay_imports_t delay_imports_;
724 debug_entries_t debug_;
725 uint64_t overlay_offset_ = 0;
726 std::vector<uint8_t> overlay_;
727 std::vector<uint8_t> dos_stub_;
728 std::vector<uint8_t> section_offset_padding_;
729
730 std::unique_ptr<RichHeader> rich_header_;
731 std::unique_ptr<Export> export_;
732 std::unique_ptr<ResourceNode> resources_;
733 std::unique_ptr<TLS> tls_;
734 std::unique_ptr<LoadConfiguration> load_configuration_;
735};
736
737}
738}
739#endif
Binary.hpp
DataDirectory.hpp
DelayImport.hpp
DosHeader.hpp
Import.hpp
OptionalHeader.hpp
Header.hpp
Symbol.hpp
ResourcesManager.hpp
Signature.hpp
LIEF::Binary::functions_t
std::vector< Function > functions_t
Definition Abstract/Binary.hpp:67
LIEF::Binary::format
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:109
LIEF::Binary::symbols_t
std::vector< Symbol * > symbols_t
Internal container.
Definition Abstract/Binary.hpp:79
LIEF::Binary::VA_TYPES
VA_TYPES
Type of a virtual address.
Definition Abstract/Binary.hpp:53
LIEF::Binary::VA_TYPES::AUTO
@ AUTO
Try to guess if it's relative or not.
Definition Abstract/Binary.hpp:54
LIEF::Binary::sections_t
std::vector< Section * > sections_t
Internal container.
Definition Abstract/Binary.hpp:70
LIEF::Binary::relocations_t
std::vector< Relocation * > relocations_t
Internal container.
Definition Abstract/Binary.hpp:88
LIEF::Header::from
static Header from(const LIEF::ELF::Binary &elf)
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:52
LIEF::PE::Binary::optional_header
OptionalHeader & optional_header()
Header that follows the header(). It is named optional from the COFF specfication but it is mandatory...
Definition PE/Binary.hpp:215
LIEF::PE::Binary::remove_all_relocations
void remove_all_relocations()
Remove all the relocations.
LIEF::PE::Binary::authentihash
std::vector< uint8_t > authentihash(ALGORITHMS algo) const
Compute the authentihash according to the algorithm provided in the first parameter.
LIEF::PE::Binary::load_configuration
const LoadConfiguration * load_configuration() const
Retrun the LoadConfiguration object or a nullptr if the binary does not use the LoadConfiguration.
Definition PE/Binary.hpp:473
LIEF::PE::Binary::print
std::ostream & print(std::ostream &os) const override
LIEF::PE::Binary::delay_imports
it_const_delay_imports delay_imports() const
Definition PE/Binary.hpp:567
LIEF::PE::Binary::debug
it_const_debug_entries debug() const
Definition PE/Binary.hpp:464
LIEF::PE::Binary::remove_section
void remove_section(const std::string &name, bool clear=false) override
Delete the section with the given name.
LIEF::PE::Binary::is_pie
bool is_pie() const override
Check if the binary is position independent.
Definition PE/Binary.hpp:657
LIEF::PE::Binary::ctor_functions
LIEF::Binary::functions_t ctor_functions() const override
Return the list of the binary constructors.
LIEF::PE::Binary::set_resources
void set_resources(const ResourceDirectory &resource)
Set a new resource tree.
LIEF::PE::Binary::dos_stub
void dos_stub(std::vector< uint8_t > content)
Update the DOS stub content.
Definition PE/Binary.hpp:505
LIEF::PE::Binary::imports
it_imports imports()
Return an iterator over the binary imports.
Definition PE/Binary.hpp:530
LIEF::PE::Binary::has_resources
bool has_resources() const
Check if the current binary has resources.
Definition PE/Binary.hpp:276
LIEF::PE::Binary::predict_function_rva
uint32_t predict_function_rva(const std::string &library, const std::string &function)
Try to predict the RVA of the function function in the import library library
LIEF::PE::Binary::symbols
std::vector< Symbol > & symbols()
Return binary Symbols.
Definition PE/Binary.hpp:366
LIEF::PE::Binary::resources
const ResourceNode * resources() const
Definition PE/Binary.hpp:379
LIEF::PE::Binary::has_debug
bool has_debug() const
Check if the current binary contains debug information.
Definition PE/Binary.hpp:293
LIEF::PE::Binary::get_delay_import
DelayImport * get_delay_import(const std::string &import_name)
Returns the PE::DelayImport from the given name. If it can't be found, return a nullptr.
Definition PE/Binary.hpp:575
LIEF::PE::Binary::has_relocations
bool has_relocations() const
Check if the current binary has relocations.
Definition PE/Binary.hpp:288
LIEF::PE::Binary::add_import_function
ImportEntry * add_import_function(const std::string &library, const std::string &function)
Add the function function of the library library. If the function fails, it returns a nullptr.
LIEF::PE::Binary::has_exports
bool has_exports() const
Check if the current binary has exports.
Definition PE/Binary.hpp:271
LIEF::PE::Binary::virtual_size
uint64_t virtual_size() const
Compute the binary's virtual size. It should match OptionalHeader::sizeof_image.
LIEF::PE::Binary::rva_to_offset
uint64_t rva_to_offset(uint64_t RVA) const
Convert a Relative Virtual Address into an offset.
LIEF::PE::Binary::resources_manager
result< ResourcesManager > resources_manager() const
Return the ResourcesManager (class to manage resources more easily than the tree one)
LIEF::PE::Binary::offset_to_virtual_address
result< uint64_t > offset_to_virtual_address(uint64_t offset, uint64_t slide=0) const override
Convert the given offset into a virtual address.
LIEF::PE::Binary::imports
it_const_imports imports() const
Definition PE/Binary.hpp:534
LIEF::PE::Binary::optional_header
const OptionalHeader & optional_header() const
Definition PE/Binary.hpp:219
LIEF::PE::Binary::signatures
it_signatures signatures()
Definition PE/Binary.hpp:312
LIEF::PE::Binary::patch_address
void patch_address(uint64_t address, uint64_t patch_value, size_t size=sizeof(uint64_t), LIEF::Binary::VA_TYPES addr_type=LIEF::Binary::VA_TYPES::AUTO) override
Patch the address with the given value.
LIEF::PE::Binary::verify_signature
Signature::VERIFICATION_FLAGS verify_signature(const Signature &sig, Signature::VERIFICATION_CHECKS checks=Signature::VERIFICATION_CHECKS::DEFAULT) const
Verify the binary with the Signature object provided in the first parameter. It can be used to verify...
LIEF::PE::Binary::overlay
span< const uint8_t > overlay() const
Return the overlay content.
Definition PE/Binary.hpp:482
LIEF::PE::Binary::get_content_from_virtual_address
span< const uint8_t > get_content_from_virtual_address(uint64_t virtual_address, uint64_t size, Binary::VA_TYPES addr_type=Binary::VA_TYPES::AUTO) const override
Return the content located at the provided virtual address.
LIEF::PE::Binary::data_directory
const DataDirectory * data_directory(DataDirectory::TYPES type) const
LIEF::PE::Binary::add_section
Section * add_section(const Section &section, PE_SECTION_TYPES type=PE_SECTION_TYPES::UNKNOWN)
Add a section to the binary and return the section added.
LIEF::PE::Binary::has_rich_header
bool has_rich_header() const
Check if the current binary has a RichHeader object.
Definition PE/Binary.hpp:525
LIEF::PE::Binary::has_signatures
bool has_signatures() const
Check if the current binary contains signatures.
Definition PE/Binary.hpp:264
LIEF::PE::Binary::has_delay_imports
bool has_delay_imports() const
Check if the current binary contains delay imports.
Definition PE/Binary.hpp:558
LIEF::PE::Binary::set_resources
void set_resources(const ResourceData &resource)
Set a new resource tree.
LIEF::PE::Binary::write
void write(std::ostream &os) override
Reconstruct the binary object and write the raw PE in os stream.
LIEF::PE::Binary::rich_header
void rich_header(const RichHeader &rich_header)
Set a RichHeader object in the current Binary.
LIEF::PE::Binary::tls
TLS * tls()
Return a reference to the TLS object.
Definition PE/Binary.hpp:238
LIEF::PE::Binary::data_directories
it_const_data_directories data_directories() const
Definition PE/Binary.hpp:444
LIEF::PE::Binary::entrypoint
uint64_t entrypoint() const override
Return the binary's entrypoint (It is the same value as OptionalHeader::addressof_entrypoint.
Definition PE/Binary.hpp:652
LIEF::PE::Binary::verify_signature
Signature::VERIFICATION_FLAGS verify_signature(Signature::VERIFICATION_CHECKS checks=Signature::VERIFICATION_CHECKS::DEFAULT) const
Verify the binary against the embedded signature(s) (if any) First, it checks that the embedded signa...
LIEF::PE::Binary::get_import
const Import * get_import(const std::string &import_name) const
LIEF::PE::Binary::remove_all_libraries
void remove_all_libraries()
Remove all libraries in the binary.
Definition PE/Binary.hpp:606
LIEF::PE::Binary::classof
static bool classof(const LIEF::Binary *bin)
Definition PE/Binary.hpp:677
LIEF::PE::Binary::get_section
const Section * get_section(const std::string &name) const
LIEF::PE::Binary::import_section
Section * import_section()
Definition PE/Binary.hpp:404
LIEF::PE::Binary::accept
void accept(Visitor &visitor) const override
Method so that a visitor can visit us.
LIEF::PE::Binary::functions
LIEF::Binary::functions_t functions() const
All functions found in the binary
LIEF::PE::Binary::exception_functions
LIEF::Binary::functions_t exception_functions() const
Functions found in the Exception table directory.
LIEF::PE::Binary::section_from_offset
const Section * section_from_offset(uint64_t offset) const
LIEF::PE::Binary::compute_checksum
uint32_t compute_checksum() const
Re-compute the value of OptionalHeader::checksum. If both values do not match, it could mean that the...
LIEF::PE::Binary::symbols
const std::vector< Symbol > & symbols() const
Definition PE/Binary.hpp:370
LIEF::PE::Binary::~Binary
~Binary() override
LIEF::PE::Binary::overlay
span< uint8_t > overlay()
Definition PE/Binary.hpp:486
LIEF::PE::Binary::add_library
Import & add_library(const std::string &name)
Add an imported library (i.e. DLL) to the binary.
Definition PE/Binary.hpp:597
LIEF::PE::Binary::overlay_offset
uint64_t overlay_offset() const
Return the original overlay offset.
Definition PE/Binary.hpp:491
LIEF::PE::Binary::get_delay_import
const DelayImport * get_delay_import(const std::string &import_name) const
LIEF::PE::Binary::section_from_rva
Section * section_from_rva(uint64_t virtual_address)
Find the section associated that encompasses the given RVA.
Definition PE/Binary.hpp:181
LIEF::PE::Binary::import_section
const Section * import_section() const
Return the section associated with import table or a nullptr if the binary does not have an import ta...
LIEF::PE::Binary::get_export
const Export * get_export() const
Definition PE/Binary.hpp:361
LIEF::PE::Binary::type
PE_TYPE type() const
Return PE32 or PE32+
Definition PE/Binary.hpp:143
LIEF::PE::Binary::has_tls
bool has_tls() const
Check if the current binary has a TLS object.
Definition PE/Binary.hpp:250
LIEF::PE::Binary::data_directory
DataDirectory * data_directory(DataDirectory::TYPES type)
Return the DataDirectory with the given type (or index)
Definition PE/Binary.hpp:449
LIEF::PE::Binary::remove_library
void remove_library(const std::string &name)
Remove the library with the given name
LIEF::PE::Binary::section_from_offset
Section * section_from_offset(uint64_t offset)
Find the section associated that encompasses the given offset.
Definition PE/Binary.hpp:173
LIEF::PE::Binary::has_exceptions
bool has_exceptions() const
Check if the current binary has exceptions.
Definition PE/Binary.hpp:281
LIEF::PE::Binary::delay_imports
it_delay_imports delay_imports()
Return an iterator over the binary's delay imports.
Definition PE/Binary.hpp:563
LIEF::PE::Binary::rich_header
const RichHeader * rich_header() const
Definition PE/Binary.hpp:517
LIEF::PE::Binary::is_reproducible_build
bool is_reproducible_build() const
Check if the current binary is reproducible build, replacing timestamps by a compile hash.
LIEF::PE::Binary::va_to_offset
uint64_t va_to_offset(uint64_t VA) const
Convert the absolute virtual address into an offset.
LIEF::PE::Binary::dos_header
DosHeader & dos_header()
Return a reference to the PE::DosHeader object.
Definition PE/Binary.hpp:196
LIEF::PE::Binary::relocations
it_const_relocations relocations() const
Definition PE/Binary.hpp:429
LIEF::PE::Binary::section_from_rva
const Section * section_from_rva(uint64_t virtual_address) const
LIEF::PE::Binary::has_nx
bool has_nx() const override
Check if the binary uses NX protection.
Definition PE/Binary.hpp:662
LIEF::PE::Binary::dos_stub
span< const uint8_t > dos_stub() const
Return the DOS stub content.
Definition PE/Binary.hpp:496
LIEF::PE::Binary::header
Header & header()
Return a reference to the PE::Header object.
Definition PE/Binary.hpp:205
LIEF::PE::Binary::Binary
Binary(PE_TYPE type)
LIEF::PE::Binary::relocations
it_relocations relocations()
Return an iterator over the PE's Relocation.
Definition PE/Binary.hpp:425
LIEF::PE::Binary::imagebase
uint64_t imagebase() const override
Return binary's imagebase. 0 if not relevant.
Definition PE/Binary.hpp:166
LIEF::PE::Binary::has_configuration
bool has_configuration() const
Check if the current binary has a load configuration.
Definition PE/Binary.hpp:298
LIEF::PE::Binary::codeview_pdb
const CodeViewPDB * codeview_pdb() const
Return the CodeViewPDB object if present.
LIEF::PE::Binary::tls
const TLS * tls() const
Definition PE/Binary.hpp:242
LIEF::PE::Binary::resources
ResourceNode * resources()
Return resources as a tree or a nullptr if there is no resources.
Definition PE/Binary.hpp:375
LIEF::PE::Binary::has
bool has(DataDirectory::TYPES type) const
Check if the current binary has the given DataDirectory::TYPES.
Definition PE/Binary.hpp:455
LIEF::PE::Binary::load_configuration
LoadConfiguration * load_configuration()
Definition PE/Binary.hpp:477
LIEF::PE::Binary::sizeof_headers
uint32_t sizeof_headers() const
Compute the size of all the headers.
LIEF::PE::Binary::tls
void tls(const TLS &tls)
Set a TLS object in the current Binary.
LIEF::PE::Binary::get_import
Import * get_import(const std::string &import_name)
Returns the PE::Import from the given name. If it can't be found, return a nullptr.
Definition PE/Binary.hpp:542
LIEF::PE::Binary::signatures
it_const_signatures signatures() const
Return an iterator over the Signature object(s) if the binary is signed.
Definition PE/Binary.hpp:308
LIEF::PE::Binary::debug
it_debug_entries debug()
Return an iterator over the Debug entries.
Definition PE/Binary.hpp:460
LIEF::PE::Binary::sections
it_const_sections sections() const
Definition PE/Binary.hpp:191
LIEF::PE::Binary::patch_address
void patch_address(uint64_t address, const std::vector< uint8_t > &patch_value, LIEF::Binary::VA_TYPES addr_type=LIEF::Binary::VA_TYPES::AUTO) override
Patch the content at virtual address address with patch_value.
LIEF::PE::Binary::has_delay_import
bool has_delay_import(const std::string &import_name) const
True if the binary delay-imports the given library name
Definition PE/Binary.hpp:584
LIEF::PE::Binary::has_imports
bool has_imports() const
Check if the current binary contains imports.
Definition PE/Binary.hpp:257
LIEF::PE::Binary::remove
void remove(const Section &section, bool clear=false)
Remove the given section.
LIEF::PE::Binary::header
const Header & header() const
Definition PE/Binary.hpp:209
LIEF::PE::Binary::data_directories
it_data_directories data_directories()
Return an iterator over the DataDirectory present in the Binary.
Definition PE/Binary.hpp:440
LIEF::PE::Binary::sections
it_sections sections()
Return an iterator over the PE's Section.
Definition PE/Binary.hpp:187
LIEF::PE::Binary::get_export
Export * get_export()
Return the Export object.
Definition PE/Binary.hpp:357
LIEF::PE::Binary::dos_stub
span< uint8_t > dos_stub()
Definition PE/Binary.hpp:500
LIEF::PE::Binary::write
void write(const std::string &filename) override
Reconstruct the binary object and write the raw PE in filename
LIEF::PE::Binary::has_import
bool has_import(const std::string &import_name) const
True if the binary imports the given library name
Definition PE/Binary.hpp:550
LIEF::PE::Binary::add_relocation
Relocation & add_relocation(const Relocation &relocation)
Add a PE::Relocation.
LIEF::PE::Binary::get_section
Section * get_section(const std::string &name)
Return binary's section from its name. If the secion can't be found, return a nullptr.
Definition PE/Binary.hpp:396
LIEF::PE::Binary::rich_header
RichHeader * rich_header()
Return a reference to the RichHeader object.
Definition PE/Binary.hpp:513
LIEF::PE::Binary::dos_header
const DosHeader & dos_header() const
Definition PE/Binary.hpp:200
LIEF::PE::Builder
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
LIEF::PE::CodeViewPDB
CodeView PDB specialization.
Definition CodeViewPDB.hpp:34
LIEF::PE::Debug
This class represents a generic entry in the debug data directory. For known types,...
Definition debug/Debug.hpp:38
LIEF::PE::Export
Class which represents a PE Export.
Definition Export.hpp:38
LIEF::PE::LoadConfiguration
Class that represents the default PE's LoadConfiguration
Definition LoadConfiguration.hpp:35
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:47
LIEF::PE::Relocation
Class which represents the Base Relocation Block We usually find this structure in the ....
Definition PE/Relocation.hpp:37
LIEF::PE::ResourceData
Class which represents a Data Node in the PE resources tree.
Definition ResourceData.hpp:32
LIEF::PE::ResourceDirectory
Definition ResourceDirectory.hpp:33
LIEF::PE::ResourceNode
Class which represents a Node in the resource tree.
Definition ResourceNode.hpp:36
LIEF::PE::RichHeader
Class which represents the not-so-documented rich header.
Definition RichHeader.hpp:37
LIEF::PE::TLS
Class which represents the PE Thread Local Storage.
Definition TLS.hpp:42
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::PE_SECTION_TYPES::TLS
@ TLS
Definition PE/enums.hpp:668
LIEF::PE::PE_TYPE
PE_TYPE
Definition PE/enums.hpp:680
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41