LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
PE/Binary.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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"
25#include "LIEF/PE/Builder.hpp"
29
30#include "LIEF/COFF/Symbol.hpp"
31#include "LIEF/COFF/String.hpp"
32
34
35#include "LIEF/visibility.h"
36
37namespace LIEF {
38namespace PE {
41class ExceptionInfo;
42class CodeViewPDB;
43class Debug;
44class Export;
46class Parser;
47class Relocation;
48class ResourceData;
50class ResourceNode;
51class RichHeader;
52class TLS;
53class Factory;
54class LIEF_API Binary : public LIEF::Binary {
58 friend class Parser;
59 friend class Builder;
60 friend class Factory;
61
62 public: using sections_t = std::vector<std::unique_ptr<Section>>;
65 using it_sections = ref_iterator<sections_t&, Section*>;
68 using it_const_sections = const_ref_iterator<const sections_t&, const Section*>;
71 using data_directories_t = std::vector<std::unique_ptr<DataDirectory>>;
74 using it_data_directories = ref_iterator<data_directories_t&, DataDirectory*>;
77 using it_const_data_directories = const_ref_iterator<const data_directories_t&, const DataDirectory*>;
80 using relocations_t = std::vector<std::unique_ptr<Relocation>>;
83 using it_relocations = ref_iterator<relocations_t&, Relocation*>;
86 using it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*>;
89 using imports_t = std::vector<std::unique_ptr<Import>>;
92 using it_imports = ref_iterator<imports_t&, Import*>;
95 using it_const_imports = const_ref_iterator<const imports_t&, const Import*>;
98 using delay_imports_t = std::vector<std::unique_ptr<DelayImport>>;
101 using it_delay_imports = ref_iterator<delay_imports_t&, DelayImport*>;
104 using it_const_delay_imports = const_ref_iterator<const delay_imports_t&, const DelayImport*>;
107 using debug_entries_t = std::vector<std::unique_ptr<Debug>>;
110 using it_debug_entries = ref_iterator<debug_entries_t&, Debug*>;
113 using it_const_debug_entries = const_ref_iterator<const debug_entries_t&, const Debug*>;
116 using symbols_t = std::vector<std::unique_ptr<COFF::Symbol>>;
119 using it_symbols = ref_iterator<symbols_t&, COFF::Symbol*>;
122 using it_const_symbols = const_ref_iterator<const symbols_t&, const COFF::Symbol*>;
125 using strings_table_t = std::vector<COFF::String>;
128 using it_strings_table = ref_iterator<strings_table_t&>;
131 using it_const_strings_table = const_ref_iterator<const strings_table_t&>;
134 using signatures_t = std::vector<Signature>;
137 using it_signatures = ref_iterator<signatures_t&>;
140 using it_const_signatures = const_ref_iterator<const signatures_t&>;
143 using exceptions_t = std::vector<std::unique_ptr<ExceptionInfo>>;
146 using it_exceptions = ref_iterator<exceptions_t&, ExceptionInfo*>;
149 using it_const_exceptions = const_ref_iterator<const exceptions_t&, const ExceptionInfo*>;
152
154 ~Binary() override;
155 PE_TYPE type() const {
158 return type_;
159 }
160 uint64_t rva_to_offset(uint64_t RVA) const;
166 uint64_t va_to_offset(uint64_t VA) const {
170 uint64_t rva = VA - optional_header().imagebase();
171 return rva_to_offset(rva);
172 }
173 result<uint64_t> offset_to_virtual_address(uint64_t offset, uint64_t slide = 0) const override;
179 uint64_t imagebase() const override {
184 return optional_header().imagebase();
185 }
186 Section* section_from_offset(uint64_t offset) {
191 return const_cast<Section*>(static_cast<const Binary*>(this)->section_from_offset(offset));
192 }
193 const Section* section_from_offset(uint64_t offset) const;
194 Section* section_from_rva(uint64_t virtual_address) {
199 return const_cast<Section*>(static_cast<const Binary*>(this)->section_from_rva(virtual_address));
200 }
201 const Section* section_from_rva(uint64_t virtual_address) const;
202 it_sections sections() {
205 return sections_;
206 }
207
208 it_const_sections sections() const {
209 return sections_;
210 }
211 DosHeader& dos_header() {
214 return dos_header_;
215 }
216
217 const DosHeader& dos_header() const {
218 return dos_header_;
219 }
220 Header& header() {
223 return header_;
224 }
225
226 const Header& header() const {
227 return header_;
228 }
229 OptionalHeader& optional_header() {
233 return optional_header_;
234 }
235
236 const OptionalHeader& optional_header() const {
237 return optional_header_;
238 }
239 uint32_t compute_checksum() const;
246 uint64_t virtual_size() const;
250 uint32_t sizeof_headers() const;
253 TLS* tls() {
256 return tls_.get();
257 }
258
259 const TLS* tls() const {
260 return tls_.get();
261 }
262 TLS& tls(const TLS& tls);
265 bool has_tls() const {
268 return tls_ != nullptr;
269 }
270 void remove_tls();
273 bool has_imports() const {
278 return !imports_.empty();
279 }
280 bool has_signatures() const {
285 return !signatures_.empty();
286 }
287 bool has_exports() const {
292 return export_ != nullptr;
293 }
294 bool has_resources() const {
297 return resources_ != nullptr;
298 }
299 bool has_exceptions() const {
302 return exceptions_dir()->size() != 0;
303 }
304 bool has_relocations() const {
309 return !relocations_.empty();
310 }
311 bool has_debug() const {
314 return !debug_.empty();
315 }
316 bool has_configuration() const {
319 return loadconfig_ != nullptr;
320 }
321 bool is_reproducible_build() const;
327 it_const_signatures signatures() const {
330 return signatures_;
331 }
332
333 it_signatures signatures() {
334 return signatures_;
335 }
336 Signature::VERIFICATION_FLAGS verify_signature(
345 Signature::VERIFICATION_CHECKS checks = Signature::VERIFICATION_CHECKS::DEFAULT) const;
346 Signature::VERIFICATION_FLAGS verify_signature(const Signature& sig,
357 Signature::VERIFICATION_CHECKS checks = Signature::VERIFICATION_CHECKS::DEFAULT) const;
358 std::vector<uint8_t> authentihash(ALGORITHMS algo) const;
362 Export* get_export() {
365 return export_.get();
366 }
367
368 const Export* get_export() const {
369 return export_.get();
370 }
371
372 Export& set_export(const Export& export_table);
373 it_symbols symbols() {
376 return symbols_;
377 }
378
379 it_const_symbols symbols() const {
380 return symbols_;
381 }
382 it_const_strings_table coff_string_table() const {
385 return strings_table_;
386 }
387
388 it_strings_table coff_string_table() {
389 return strings_table_;
390 }
391 COFF::String* find_coff_string(uint32_t offset) {
397 auto it = std::find_if(strings_table_.begin(), strings_table_.end(),
398 [offset] (const COFF::String& item) {
399 return offset == item.offset();
400 }
401 );
402 return it == strings_table_.end() ? nullptr : &*it;
403 }
404
405 const COFF::String* find_coff_string(uint32_t offset) const {
406 return const_cast<Binary*>(this)->find_coff_string(offset);
407 }
408 ResourceNode* resources() {
411 return resources_.get();
412 }
413
414 const ResourceNode* resources() const {
415 return resources_.get();
416 }
417 ResourceNode* set_resources(const ResourceNode& root);
421
422 ResourceNode* set_resources(std::unique_ptr<ResourceNode> root);
423 result<ResourcesManager> resources_manager() const;
426 Section* get_section(const std::string& name) {
432 return const_cast<Section*>(static_cast<const Binary*>(this)->get_section(name));
433 }
434 const Section* get_section(const std::string& name) const;
435 const Section* import_section() const;
439 Section* import_section() {
440 return const_cast<Section*>(static_cast<const Binary*>(this)->import_section());
441 }
442 void remove_section(const std::string& name, bool clear = false) override;
449 void remove(const Section& section, bool clear = false);
454 Section* add_section(const Section& section);
457 it_relocations relocations() {
460 return relocations_;
461 }
462
463 it_const_relocations relocations() const {
464 return relocations_;
465 }
466 Relocation& add_relocation(const Relocation& relocation);
469 void remove_all_relocations();
472 it_data_directories data_directories() {
475 return data_directories_;
476 }
477
478 it_const_data_directories data_directories() const {
479 return data_directories_;
480 }
481 DataDirectory* data_directory(DataDirectory::TYPES type) {
484 return const_cast<DataDirectory*>(static_cast<const Binary*>(this)->data_directory(type));
485 }
486 const DataDirectory* data_directory(DataDirectory::TYPES type) const;
487 bool has(DataDirectory::TYPES type) const {
490 return data_directory(type) != nullptr;
491 }
492 it_debug_entries debug() {
495 return debug_;
496 }
497
498 it_const_debug_entries debug() const {
499 return debug_;
500 }
501 Debug* add_debug_info(const Debug& entry);
504 bool remove_debug(const Debug& entry);
507 bool clear_debug();
510 const CodeViewPDB* codeview_pdb() const;
513 const LoadConfiguration* load_configuration() const {
517 return loadconfig_.get();
518 }
519
520 LoadConfiguration* load_configuration() {
521 return loadconfig_.get();
522 }
523 span<const uint8_t> overlay() const {
526 return overlay_;
527 }
528
529 span<uint8_t> overlay() {
530 return overlay_;
531 }
532 uint64_t overlay_offset() const {
535 return overlay_offset_;
536 }
537 span<const uint8_t> dos_stub() const {
540 return dos_stub_;
541 }
542
543 span<uint8_t> dos_stub() {
544 return dos_stub_;
545 }
546 void dos_stub(std::vector<uint8_t> content) {
549 dos_stub_ = std::move(content);
550 }
551 RichHeader* rich_header() {
554 return rich_header_.get();
555 }
556
557 const RichHeader* rich_header() const {
558 return rich_header_.get();
559 }
560 void rich_header(const RichHeader& rich_header);
563 bool has_rich_header() const {
566 return rich_header_ != nullptr;
567 }
568 it_imports imports() {
571 return imports_;
572 }
573
574 it_const_imports imports() const {
575 return imports_;
576 }
577 Import* get_import(const std::string& import_name) {
582 return const_cast<Import*>(static_cast<const Binary*>(this)->get_import(import_name));
583 }
584
585 const Import* get_import(const std::string& import_name) const;
586 bool has_import(const std::string& import_name) const {
589 return get_import(import_name) != nullptr;
590 }
591 bool has_delay_imports() const {
594 return !delay_imports_.empty();
595 }
596 it_delay_imports delay_imports() {
599 return delay_imports_;
600 }
601
602 it_const_delay_imports delay_imports() const {
603 return delay_imports_;
604 }
605 DelayImport* get_delay_import(const std::string& import_name) {
609 return const_cast<DelayImport*>(static_cast<const Binary*>(this)->get_delay_import(import_name));
610 }
611 const DelayImport* get_delay_import(const std::string& import_name) const;
612
613 bool has_delay_import(const std::string& import_name) const {
616 return get_delay_import(import_name) != nullptr;
617 }
618 Import& add_import(const std::string& name) {
621 imports_.push_back(std::unique_ptr<Import>(new Import(name)));
622 return *imports_.back();
623 }
624 bool remove_import(const std::string& name);
629 void remove_all_imports() {
632 imports_.clear();
633 }
634 std::unique_ptr<Builder> write(const std::string& filename) {
637 return write(filename, Builder::config_t());
638 }
639 std::unique_ptr<Builder> write(const std::string& filename,
643 const Builder::config_t& config);
644 std::unique_ptr<Builder> write(std::ostream& os) {
650 return write(os, Builder::config_t());
651 }
652
653 std::unique_ptr<Builder> write(std::ostream& os,
654 const Builder::config_t& config);
655
656 void accept(Visitor& visitor) const override;
657 void patch_address(uint64_t address, const std::vector<uint8_t>& patch_value,
664 VA_TYPES addr_type = VA_TYPES::AUTO) override;
665
666 void patch_address(uint64_t address, uint64_t patch_value, size_t size = sizeof(uint64_t),
674 VA_TYPES addr_type = VA_TYPES::AUTO) override;
675
676 void fill_address(uint64_t address, size_t size, uint8_t value = 0,
679 VA_TYPES addr_type = VA_TYPES::AUTO);
680 span<const uint8_t> get_content_from_virtual_address(
687 uint64_t virtual_address, uint64_t size,
688 Binary::VA_TYPES addr_type = Binary::VA_TYPES::AUTO) const override;
689 uint64_t entrypoint() const override {
692 return optional_header_.imagebase() + optional_header_.addressof_entrypoint();
693 }
694 bool is_pie() const override {
697 return optional_header_.has(OptionalHeader::DLL_CHARACTERISTICS::DYNAMIC_BASE);
698 }
699 bool has_nx() const override {
702 return optional_header_.has(OptionalHeader::DLL_CHARACTERISTICS::NX_COMPAT);
703 }
704
705 uint64_t last_section_offset() const;
706 DataDirectory* export_dir() {
709 return data_directory(DataDirectory::TYPES::EXPORT_TABLE);
710 }
711
712 const DataDirectory* export_dir() const {
713 return data_directory(DataDirectory::TYPES::EXPORT_TABLE);
714 }
715 DataDirectory* import_dir() {
718 return data_directory(DataDirectory::TYPES::IMPORT_TABLE);
719 }
720
721 const DataDirectory* import_dir() const {
722 return data_directory(DataDirectory::TYPES::IMPORT_TABLE);
723 }
724 DataDirectory* rsrc_dir() {
727 return data_directory(DataDirectory::TYPES::RESOURCE_TABLE);
728 }
729
730 const DataDirectory* rsrc_dir() const {
731 return data_directory(DataDirectory::TYPES::RESOURCE_TABLE);
732 }
733 DataDirectory* exceptions_dir() {
736 return data_directory(DataDirectory::TYPES::EXCEPTION_TABLE);
737 }
738
739 const DataDirectory* exceptions_dir() const {
740 return data_directory(DataDirectory::TYPES::EXCEPTION_TABLE);
741 }
742 DataDirectory* cert_dir() {
746 return data_directory(DataDirectory::TYPES::CERTIFICATE_TABLE);
747 }
748
749 const DataDirectory* cert_dir() const {
750 return data_directory(DataDirectory::TYPES::CERTIFICATE_TABLE);
751 }
752 DataDirectory* relocation_dir() {
755 return data_directory(DataDirectory::TYPES::BASE_RELOCATION_TABLE);
756 }
757
758 const DataDirectory* relocation_dir() const {
759 return data_directory(DataDirectory::TYPES::BASE_RELOCATION_TABLE);
760 }
761 DataDirectory* debug_dir() {
764 return data_directory(DataDirectory::TYPES::DEBUG_DIR);
765 }
766
767 const DataDirectory* debug_dir() const {
768 return data_directory(DataDirectory::TYPES::DEBUG_DIR);
769 }
770 DataDirectory* tls_dir() {
773 return data_directory(DataDirectory::TYPES::TLS_TABLE);
774 }
775
776 const DataDirectory* tls_dir() const {
777 return data_directory(DataDirectory::TYPES::TLS_TABLE);
778 }
779 DataDirectory* load_config_dir() {
782 return data_directory(DataDirectory::TYPES::LOAD_CONFIG_TABLE);
783 }
784
785 const DataDirectory* load_config_dir() const {
786 return data_directory(DataDirectory::TYPES::LOAD_CONFIG_TABLE);
787 }
788 DataDirectory* iat_dir() {
791 return data_directory(DataDirectory::TYPES::IAT);
792 }
793
794 const DataDirectory* iat_dir() const {
795 return data_directory(DataDirectory::TYPES::IAT);
796 }
797 DataDirectory* delay_dir() {
800 return data_directory(DataDirectory::TYPES::DELAY_IMPORT_DESCRIPTOR);
801 }
802
803 const DataDirectory* delay_dir() const {
804 return data_directory(DataDirectory::TYPES::DELAY_IMPORT_DESCRIPTOR);
805 }
806 LIEF::Binary::functions_t ctor_functions() const override;
811 LIEF::Binary::functions_t functions() const;
814 LIEF::Binary::functions_t exception_functions() const;
817 it_exceptions exceptions() {
824 return exceptions_;
825 }
826
827 it_const_exceptions exceptions() const {
828 return exceptions_;
829 }
830 ExceptionInfo* find_exception_at(uint32_t rva);
837
838 const ExceptionInfo* find_exception_at(uint32_t rva) const {
839 return const_cast<Binary*>(this)->find_exception_at(rva);
840 }
841 bool is_arm64ec() const;
844 bool is_arm64x() const;
848 const Binary* nested_pe_binary() const {
860 return nested_.get();
861 }
862
863 Binary* nested_pe_binary() {
864 return nested_.get();
865 }
866
867 static bool classof(const LIEF::Binary* bin) {
868 return bin->format() == Binary::FORMATS::PE;
869 }
870
871 std::ostream& print(std::ostream& os) const override;
872
873 LIEF_LOCAL std::unique_ptr<Binary> move_nested_pe_binary() {
878 auto ret = std::move(nested_);
879 nested_ = nullptr;
880 return ret;
881 }
882
883 private:
884 struct sizing_info_t {
885 uint32_t nb_tls_callbacks = 0;
886 uint32_t load_config_size = 0;
887 };
888 result<uint64_t> make_space_for_new_section();
892 LIEF::Binary::symbols_t get_abstract_symbols() override;
895
896 LIEF::Header get_abstract_header() const override {
897 return LIEF::Header::from(*this);
898 }
899 LIEF::Binary::sections_t get_abstract_sections() override;
902
903 LIEF::Binary::relocations_t get_abstract_relocations() override;
904
905 LIEF::Binary::functions_t get_abstract_exported_functions() const override;
906 LIEF::Binary::functions_t get_abstract_imported_functions() const override;
907 std::vector<std::string> get_abstract_imported_libraries() const override;
908
909 void update_lookup_address_table_offset();
910 void update_iat();
911 void shift(uint64_t from, uint64_t by);
912
913 PE_TYPE type_ = PE_TYPE::PE32_PLUS;
914 DosHeader dos_header_;
915 Header header_;
916 OptionalHeader optional_header_;
917
918 int32_t available_sections_space_ = 0;
919
920 signatures_t signatures_;
921 sections_t sections_;
922 data_directories_t data_directories_;
923 symbols_t symbols_;
924 strings_table_t strings_table_;
925 relocations_t relocations_;
926 imports_t imports_;
927 delay_imports_t delay_imports_;
928 debug_entries_t debug_;
929 exceptions_t exceptions_;
930 uint64_t overlay_offset_ = 0;
931 std::vector<uint8_t> overlay_;
932 std::vector<uint8_t> dos_stub_;
933 std::vector<uint8_t> section_offset_padding_;
934
935 std::unique_ptr<RichHeader> rich_header_;
936 std::unique_ptr<Export> export_;
937 std::unique_ptr<ResourceNode> resources_;
938 std::unique_ptr<TLS> tls_;
939 std::unique_ptr<LoadConfiguration> loadconfig_;
940 std::unique_ptr<Binary> nested_;
941
942 sizing_info_t sizing_info_;
943};
944
945}
946}
947#endif
Binary.hpp
Symbol.hpp
DataDirectory.hpp
DelayImport.hpp
DosHeader.hpp
ExceptionInfo.hpp
Import.hpp
OptionalHeader.hpp
Builder.hpp
Header.hpp
ResourcesManager.hpp
Signature.hpp
String.hpp
LIEF::Binary::functions_t
std::vector< Function > functions_t
Definition Abstract/Binary.hpp:70
LIEF::Binary::format
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:112
LIEF::Binary::symbols_t
std::vector< Symbol * > symbols_t
Internal container.
Definition Abstract/Binary.hpp:82
LIEF::Binary::sections_t
std::vector< Section * > sections_t
Internal container.
Definition Abstract/Binary.hpp:73
LIEF::Binary::relocations_t
std::vector< Relocation * > relocations_t
Internal container.
Definition Abstract/Binary.hpp:91
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:57
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:232
LIEF::PE::Binary::export_dir
const DataDirectory * export_dir() const
Definition PE/Binary.hpp:712
LIEF::PE::Binary::remove_all_relocations
void remove_all_relocations()
Remove all the relocations.
LIEF::PE::Binary::export_dir
DataDirectory * export_dir()
Return the data directory associated with the export table.
Definition PE/Binary.hpp:708
LIEF::PE::Binary::exceptions
it_exceptions exceptions()
Iterator over the exception (_RUNTIME_FUNCTION) functions.
Definition PE/Binary.hpp:823
LIEF::PE::Binary::write
std::unique_ptr< Builder > write(std::ostream &os)
Reconstruct the binary object and write the raw PE in os stream.
Definition PE/Binary.hpp:649
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::remove_tls
void remove_tls()
Remove the TLS from the binary.
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:516
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:602
LIEF::PE::Binary::debug
it_const_debug_entries debug() const
Definition PE/Binary.hpp:498
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::patch_address
void patch_address(uint64_t address, uint64_t patch_value, size_t size=sizeof(uint64_t), VA_TYPES addr_type=VA_TYPES::AUTO) override
Patch the address with the given value.
LIEF::PE::Binary::is_pie
bool is_pie() const override
Check if the binary is position independent.
Definition PE/Binary.hpp:696
LIEF::PE::Binary::ctor_functions
LIEF::Binary::functions_t ctor_functions() const override
Return the list of the binary constructors.
LIEF::PE::Binary::exceptions_dir
DataDirectory * exceptions_dir()
Return the data directory associated with the exceptions.
Definition PE/Binary.hpp:735
LIEF::PE::Binary::dos_stub
void dos_stub(std::vector< uint8_t > content)
Update the DOS stub content.
Definition PE/Binary.hpp:548
LIEF::PE::Binary::delay_dir
DataDirectory * delay_dir()
Return the data directory associated with delayed imports.
Definition PE/Binary.hpp:799
LIEF::PE::Binary::imports
it_imports imports()
Return an iterator over the binary imports.
Definition PE/Binary.hpp:570
LIEF::PE::Binary::has_resources
bool has_resources() const
Check if the current binary has resources.
Definition PE/Binary.hpp:296
LIEF::PE::Binary::import_dir
const DataDirectory * import_dir() const
Definition PE/Binary.hpp:721
LIEF::PE::Binary::tls
TLS & tls(const TLS &tls)
Set a TLS object in the current Binary.
LIEF::PE::Binary::resources
const ResourceNode * resources() const
Definition PE/Binary.hpp:414
LIEF::PE::Binary::has_debug
bool has_debug() const
Check if the current binary contains debug information.
Definition PE/Binary.hpp:313
LIEF::PE::Binary::iat_dir
const DataDirectory * iat_dir() const
Definition PE/Binary.hpp:794
LIEF::PE::Binary::get_delay_import
DelayImport * get_delay_import(const std::string &import_name)
Returns the DelayImport matching the given name. If it can't be found, it returns a nullptr.
Definition PE/Binary.hpp:608
LIEF::PE::Binary::exceptions
it_const_exceptions exceptions() const
Definition PE/Binary.hpp:827
LIEF::PE::Binary::tls_dir
const DataDirectory * tls_dir() const
Definition PE/Binary.hpp:776
LIEF::PE::Binary::debug_dir
const DataDirectory * debug_dir() const
Definition PE/Binary.hpp:767
LIEF::PE::Binary::has_relocations
bool has_relocations() const
Check if the current binary has relocations.
Definition PE/Binary.hpp:308
LIEF::PE::Binary::has_exports
bool has_exports() const
Check if the current binary has exports.
Definition PE/Binary.hpp:291
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::remove_import
bool remove_import(const std::string &name)
Remove the imported library with the given name
LIEF::PE::Binary::clear_debug
bool clear_debug()
Remove all debug info from the binary.
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:574
LIEF::PE::Binary::optional_header
const OptionalHeader & optional_header() const
Definition PE/Binary.hpp:236
LIEF::PE::Binary::signatures
it_signatures signatures()
Definition PE/Binary.hpp:333
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::add_debug_info
Debug * add_debug_info(const Debug &entry)
Add a new debug entry.
LIEF::PE::Binary::overlay
span< const uint8_t > overlay() const
Return the overlay content.
Definition PE/Binary.hpp:525
LIEF::PE::Binary::is_arm64x
bool is_arm64x() const
True if this binary is compiled in ARM64X mode (contains both ARM64 and ARM64EC code)
LIEF::PE::Binary::is_arm64ec
bool is_arm64ec() const
True if this binary is compiled in ARM64EC mode (emulation compatible)
LIEF::PE::Binary::rsrc_dir
DataDirectory * rsrc_dir()
Return the data directory associated with the resources tree.
Definition PE/Binary.hpp:726
LIEF::PE::Binary::Binary
Binary()
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::tls_dir
DataDirectory * tls_dir()
Return the data directory associated with TLS.
Definition PE/Binary.hpp:772
LIEF::PE::Binary::rsrc_dir
const DataDirectory * rsrc_dir() const
Definition PE/Binary.hpp:730
LIEF::PE::Binary::fill_address
void fill_address(uint64_t address, size_t size, uint8_t value=0, VA_TYPES addr_type=VA_TYPES::AUTO)
Fill the content at the provided with a fixed value.
LIEF::PE::Binary::has_rich_header
bool has_rich_header() const
Check if the current binary has a RichHeader object.
Definition PE/Binary.hpp:565
LIEF::PE::Binary::has_signatures
bool has_signatures() const
Check if the current binary contains signatures.
Definition PE/Binary.hpp:284
LIEF::PE::Binary::has_delay_imports
bool has_delay_imports() const
Check if the current binary contains delay imports.
Definition PE/Binary.hpp:593
LIEF::PE::Binary::load_config_dir
const DataDirectory * load_config_dir() const
Definition PE/Binary.hpp:785
LIEF::PE::Binary::rich_header
void rich_header(const RichHeader &rich_header)
Set a RichHeader object in the current Binary.
LIEF::PE::Binary::relocation_dir
DataDirectory * relocation_dir()
Return the data directory associated with the relocation table.
Definition PE/Binary.hpp:754
LIEF::PE::Binary::exceptions_dir
const DataDirectory * exceptions_dir() const
Definition PE/Binary.hpp:739
LIEF::PE::Binary::tls
TLS * tls()
Return a reference to the TLS object.
Definition PE/Binary.hpp:255
LIEF::PE::Binary::data_directories
it_const_data_directories data_directories() const
Definition PE/Binary.hpp:478
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:691
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::find_exception_at
const ExceptionInfo * find_exception_at(uint32_t rva) const
Definition PE/Binary.hpp:838
LIEF::PE::Binary::get_import
const Import * get_import(const std::string &import_name) const
LIEF::PE::Binary::last_section_offset
uint64_t last_section_offset() const
LIEF::PE::Binary::delay_dir
const DataDirectory * delay_dir() const
Definition PE/Binary.hpp:803
LIEF::PE::Binary::classof
static bool classof(const LIEF::Binary *bin)
Definition PE/Binary.hpp:867
LIEF::PE::Binary::get_section
const Section * get_section(const std::string &name) const
LIEF::PE::Binary::symbols
it_symbols symbols()
Return binary Symbols.
Definition PE/Binary.hpp:375
LIEF::PE::Binary::import_section
Section * import_section()
Definition PE/Binary.hpp:439
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::patch_address
void patch_address(uint64_t address, const std::vector< uint8_t > &patch_value, VA_TYPES addr_type=VA_TYPES::AUTO) override
Patch the content at virtual address address with patch_value.
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::write
std::unique_ptr< Builder > write(std::ostream &os, const Builder::config_t &config)
LIEF::PE::Binary::add_import
Import & add_import(const std::string &name)
Add an imported library (i.e. DLL) to the binary.
Definition PE/Binary.hpp:620
LIEF::PE::Binary::find_coff_string
COFF::String * find_coff_string(uint32_t offset)
Try to find the COFF string at the given offset in the COFF string table.
Definition PE/Binary.hpp:396
LIEF::PE::Binary::set_resources
ResourceNode * set_resources(std::unique_ptr< ResourceNode > root)
LIEF::PE::Binary::~Binary
~Binary() override
LIEF::PE::Binary::overlay
span< uint8_t > overlay()
Definition PE/Binary.hpp:529
LIEF::PE::Binary::overlay_offset
uint64_t overlay_offset() const
Return the original overlay offset.
Definition PE/Binary.hpp:534
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:198
LIEF::PE::Binary::add_section
Section * add_section(const Section &section)
Add a section to the binary and return the section added.
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:368
LIEF::PE::Binary::type
PE_TYPE type() const
Return PE32 or PE32+
Definition PE/Binary.hpp:157
LIEF::PE::Binary::has_tls
bool has_tls() const
Check if the current binary has a TLS object.
Definition PE/Binary.hpp:267
LIEF::PE::Binary::set_export
Export & set_export(const Export &export_table)
LIEF::PE::Binary::data_directory
DataDirectory * data_directory(DataDirectory::TYPES type)
Return the DataDirectory with the given type (or index)
Definition PE/Binary.hpp:483
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:190
LIEF::PE::Binary::has_exceptions
bool has_exceptions() const
Check if the current binary has exceptions.
Definition PE/Binary.hpp:301
LIEF::PE::Binary::delay_imports
it_delay_imports delay_imports()
Return an iterator over the binary's delay imports.
Definition PE/Binary.hpp:598
LIEF::PE::Binary::symbols
it_const_symbols symbols() const
Definition PE/Binary.hpp:379
LIEF::PE::Binary::rich_header
const RichHeader * rich_header() const
Definition PE/Binary.hpp:557
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::write
std::unique_ptr< Builder > write(const std::string &filename, const Builder::config_t &config)
Reconstruct the binary object with the given configuration and write it in filename
LIEF::PE::Binary::debug_dir
DataDirectory * debug_dir()
Return the data directory associated with the debug table.
Definition PE/Binary.hpp:763
LIEF::PE::Binary::va_to_offset
uint64_t va_to_offset(uint64_t VA) const
Convert the absolute virtual address into an offset.
Definition PE/Binary.hpp:169
LIEF::PE::Binary::relocation_dir
const DataDirectory * relocation_dir() const
Definition PE/Binary.hpp:758
LIEF::PE::Binary::nested_pe_binary
Binary * nested_pe_binary()
Definition PE/Binary.hpp:863
LIEF::PE::Binary::dos_header
DosHeader & dos_header()
Return a reference to the PE::DosHeader object.
Definition PE/Binary.hpp:213
LIEF::PE::Binary::relocations
it_const_relocations relocations() const
Definition PE/Binary.hpp:463
LIEF::PE::Binary::section_from_rva
const Section * section_from_rva(uint64_t virtual_address) const
LIEF::PE::Binary::iat_dir
DataDirectory * iat_dir()
Return the data directory associated with the IAT.
Definition PE/Binary.hpp:790
LIEF::PE::Binary::cert_dir
DataDirectory * cert_dir()
Return the data directory associated with the certificate table (authenticode)
Definition PE/Binary.hpp:745
LIEF::PE::Binary::has_nx
bool has_nx() const override
Check if the binary uses NX protection.
Definition PE/Binary.hpp:701
LIEF::PE::Binary::dos_stub
span< const uint8_t > dos_stub() const
Return the DOS stub content.
Definition PE/Binary.hpp:539
LIEF::PE::Binary::find_coff_string
const COFF::String * find_coff_string(uint32_t offset) const
Definition PE/Binary.hpp:405
LIEF::PE::Binary::header
Header & header()
Return a reference to the PE::Header object.
Definition PE/Binary.hpp:222
LIEF::PE::Binary::relocations
it_relocations relocations()
Return an iterator over the PE's Relocation.
Definition PE/Binary.hpp:459
LIEF::PE::Binary::imagebase
uint64_t imagebase() const override
Return binary's imagebase. 0 if not relevant.
Definition PE/Binary.hpp:183
LIEF::PE::Binary::has_configuration
bool has_configuration() const
Check if the current binary has a load configuration.
Definition PE/Binary.hpp:318
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:259
LIEF::PE::Binary::resources
ResourceNode * resources()
Return resources as a tree or a nullptr if there is no resources.
Definition PE/Binary.hpp:410
LIEF::PE::Binary::set_resources
ResourceNode * set_resources(const ResourceNode &root)
Change or set the current resource tree with the new one provided in parameter.
LIEF::PE::Binary::has
bool has(DataDirectory::TYPES type) const
Check if the current binary has the given DataDirectory::TYPES.
Definition PE/Binary.hpp:489
LIEF::PE::Binary::load_configuration
LoadConfiguration * load_configuration()
Definition PE/Binary.hpp:520
LIEF::PE::Binary::sizeof_headers
uint32_t sizeof_headers() const
Compute the size of all the headers.
LIEF::PE::Binary::remove_debug
bool remove_debug(const Debug &entry)
Remove a specific debug entry.
LIEF::PE::Binary::load_config_dir
DataDirectory * load_config_dir()
Return the data directory associated with the load config.
Definition PE/Binary.hpp:781
LIEF::PE::Binary::nested_pe_binary
const Binary * nested_pe_binary() const
If the current binary contains dynamic relocations (e.g. LIEF::PE::DynamicFixupARM64X),...
Definition PE/Binary.hpp:859
LIEF::PE::Binary::get_import
Import * get_import(const std::string &import_name)
Return the Import matching the provided name (case sensitive)
Definition PE/Binary.hpp:581
LIEF::PE::Binary::write
std::unique_ptr< Builder > write(const std::string &filename)
Reconstruct the binary object and write the raw PE in filename
Definition PE/Binary.hpp:636
LIEF::PE::Binary::coff_string_table
it_strings_table coff_string_table()
Definition PE/Binary.hpp:388
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:329
LIEF::PE::Binary::debug
it_debug_entries debug()
Return an iterator over the Debug entries.
Definition PE/Binary.hpp:494
LIEF::PE::Binary::sections
it_const_sections sections() const
Definition PE/Binary.hpp:208
LIEF::PE::Binary::coff_string_table
it_const_strings_table coff_string_table() const
Iterator over the strings located in the COFF string table.
Definition PE/Binary.hpp:384
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:615
LIEF::PE::Binary::has_imports
bool has_imports() const
Check if the current binary contains imports.
Definition PE/Binary.hpp:277
LIEF::PE::Binary::find_exception_at
ExceptionInfo * find_exception_at(uint32_t rva)
Try to find the exception info at the given RVA.
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:226
LIEF::PE::Binary::cert_dir
const DataDirectory * cert_dir() const
Definition PE/Binary.hpp:749
LIEF::PE::Binary::data_directories
it_data_directories data_directories()
Return an iterator over the DataDirectory present in the Binary.
Definition PE/Binary.hpp:474
LIEF::PE::Binary::sections
it_sections sections()
Return an iterator over the PE's Section.
Definition PE/Binary.hpp:204
LIEF::PE::Binary::remove_all_imports
void remove_all_imports()
Remove all libraries in the binary.
Definition PE/Binary.hpp:631
LIEF::PE::Binary::get_export
Export * get_export()
Return the Export object.
Definition PE/Binary.hpp:364
LIEF::PE::Binary::dos_stub
span< uint8_t > dos_stub()
Definition PE/Binary.hpp:543
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:588
LIEF::PE::Binary::import_dir
DataDirectory * import_dir()
Return the data directory associated with the import table.
Definition PE/Binary.hpp:717
LIEF::PE::Binary::add_relocation
Relocation & add_relocation(const Relocation &relocation)
Add a new 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:431
LIEF::PE::Binary::rich_header
RichHeader * rich_header()
Return a reference to the RichHeader object.
Definition PE/Binary.hpp:553
LIEF::PE::Binary::dos_header
const DosHeader & dos_header() const
Definition PE/Binary.hpp:217
LIEF::PE::CodeViewPDB
CodeView PDB specialization.
Definition CodeViewPDB.hpp:35
LIEF::PE::Debug
This class represents a generic entry in the debug data directory. For known types,...
Definition debug/Debug.hpp:40
LIEF::PE::ExceptionInfo
This class is the base class for any exception or runtime function entry.
Definition ExceptionInfo.hpp:33
LIEF::PE::Export
Class which represents a PE Export.
Definition Export.hpp:39
LIEF::PE::Factory
This factory is used to create PE from scratch.
Definition Factory.hpp:29
LIEF::PE::LoadConfiguration
This class represents the load configuration data associated with the IMAGE_LOAD_CONFIG_DIRECTORY.
Definition LoadConfiguration.hpp:46
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
LIEF::PE::Relocation
Class which represents the Base Relocation Block We usually find this structure in the ....
Definition PE/Relocation.hpp:43
LIEF::PE::ResourceData
Class which represents a Data Node in the PE resources tree.
Definition ResourceData.hpp:33
LIEF::PE::ResourceDirectory
Definition ResourceDirectory.hpp:33
LIEF::PE::ResourceNode
Class which represents a Node in the resource tree.
Definition ResourceNode.hpp:46
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:43
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
LIEF namespace.
Definition Abstract/Binary.hpp:39
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41
LIEF_LOCAL
#define LIEF_LOCAL
Definition visibility.h:42