Skip to content

Commit

Permalink
Inline functions that are suitable for inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Jul 26, 2023
1 parent 96193a0 commit c225890
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 313 deletions.
176 changes: 130 additions & 46 deletions include/LIEF/PE/Binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ class LIEF_API Binary : public LIEF::Binary {
~Binary() override;

//! Return `PE32` or `PE32+`
PE_TYPE type() const;
PE_TYPE type() const {
return type_;
}

//! Convert a Relative Virtual Address into an offset
//!
Expand All @@ -161,7 +163,9 @@ class LIEF_API Binary : public LIEF::Binary {
//! Return binary's imagebase. ``0`` if not relevant
//!
//! The value is the same as those returned by OptionalHeader::imagebase
uint64_t imagebase() const override;
uint64_t imagebase() const override {
return optional_header().imagebase();
}

//! Find the section associated that encompasses the given offset.
//!
Expand All @@ -176,20 +180,40 @@ class LIEF_API Binary : public LIEF::Binary {
const Section* section_from_rva(uint64_t virtual_address) const;

//! Return an iterator over the PE's Section
it_sections sections();
it_const_sections sections() const;
it_sections sections() {
return sections_;
}

it_const_sections sections() const {
return sections_;
}

//! Return a reference to the PE::DosHeader object
DosHeader& dos_header();
const DosHeader& dos_header() const;
DosHeader& dos_header() {
return dos_header_;
}

const DosHeader& dos_header() const {
return dos_header_;
}

//! Return a reference to the PE::Header object
Header& header();
const Header& header() const;
Header& header() {
return header_;
}

const Header& header() const {
return header_;
}

//! Return a reference to the OptionalHeader object
OptionalHeader& optional_header();
const OptionalHeader& optional_header() const;
OptionalHeader& optional_header() {
return optional_header_;
}

const OptionalHeader& optional_header() const {
return optional_header_;
}

//! Compute the binary's virtual size.
//! It should match OptionalHeader::sizeof_image
Expand Down Expand Up @@ -218,44 +242,58 @@ class LIEF_API Binary : public LIEF::Binary {
//! Check if the current binary contains imports
//!
//! @see Import
bool has_imports() const;
bool has_imports() const {
return !imports_.empty();
}

//! Check if the current binary contains signatures
//!
//! @see signatures
bool has_signatures() const;
bool has_signatures() const {
return !signatures_.empty();
}

//! Check if the current binary has exports.
//!
//! @see Export
bool has_exports() const;
bool has_exports() const {
return export_ != nullptr;
}

//! Check if the current binary has resources
bool has_resources() const;
bool has_resources() const {
return resources_ != nullptr;
}

//! Check if the current binary has exceptions
bool has_exceptions() const;

//! Check if the current binary has relocations
//!
//! @see Relocation
bool has_relocations() const;
bool has_relocations() const {
return relocations_.empty();
}

//! Check if the current binary contains debug information
bool has_debug() const {
return !debug_.empty();
}

//! Check if the current binary has a load configuration
bool has_configuration() const;
bool has_configuration() const {
return load_configuration_ != nullptr;
}

//! Check if the current binary is *reproducible build*, replacing timestamps by a compile hash.
//!
//! @see Repro
bool is_reproducible_build() const;

//! Return an iterator over the Signature object(s) if the binary is signed
it_const_signatures signatures() const;
it_const_signatures signatures() const {
return signatures_;
}

//! Verify the binary against the embedded signature(s) (if any)
//! First, it checks that the embedded signatures are correct (c.f. Signature::check)
Expand Down Expand Up @@ -311,8 +349,13 @@ class LIEF_API Binary : public LIEF::Binary {
const std::vector<Symbol>& symbols() const;

//! Return resources as a tree or a nullptr if there is no resources
ResourceNode* resources();
const ResourceNode* resources() const;
ResourceNode* resources() {
return resources_.get();
}

const ResourceNode* resources() const {
return resources_.get();
}

//! Set a new resource tree
void set_resources(const ResourceDirectory& resource);
Expand Down Expand Up @@ -352,8 +395,13 @@ class LIEF_API Binary : public LIEF::Binary {
PE_SECTION_TYPES type = PE_SECTION_TYPES::UNKNOWN);

//! Return an iterator over the PE's Relocation
it_relocations relocations();
it_const_relocations relocations() const;
it_relocations relocations() {
return relocations_;
}

it_const_relocations relocations() const {
return relocations_;
}

//! Add a PE::Relocation
Relocation& add_relocation(const Relocation& relocation);
Expand All @@ -362,32 +410,59 @@ class LIEF_API Binary : public LIEF::Binary {
void remove_all_relocations();

//! Return an iterator over the DataDirectory present in the Binary
it_data_directories data_directories();
it_const_data_directories data_directories() const;
it_data_directories data_directories() {
return data_directories_;
}

it_const_data_directories data_directories() const {
return data_directories_;
}

//! Return the DataDirectory with the given type (or index)
DataDirectory* data_directory(DATA_DIRECTORY index);
const DataDirectory* data_directory(DATA_DIRECTORY index) const;

//! Check if the current binary has the given DATA_DIRECTORY
bool has(DATA_DIRECTORY index) const;
bool has(DATA_DIRECTORY index) const {
return data_directory(index) != nullptr;
}

//! Return an iterator over the Debug entries
it_debug_entries debug();
const it_const_debug_entries debug() const;
it_debug_entries debug() {
return debug_;
}

it_const_debug_entries debug() const {
return debug_;
}

//! Retrun the LoadConfiguration object or a nullptr
//! if the binary does not use the LoadConfiguration
const LoadConfiguration* load_configuration() const;
LoadConfiguration* load_configuration();
const LoadConfiguration* load_configuration() const {
return load_configuration_.get();
}

LoadConfiguration* load_configuration() {
return load_configuration_.get();
}

//! Return the overlay content
span<const uint8_t> overlay() const;
span<uint8_t> overlay();
span<const uint8_t> overlay() const {
return overlay_;
}

span<uint8_t> overlay() {
return overlay_;
}

//! Return the DOS stub content
span<const uint8_t> dos_stub() const;
span<uint8_t> dos_stub();
span<const uint8_t> dos_stub() const {
return dos_stub_;
}

span<uint8_t> dos_stub() {
return dos_stub_;
}

//! Update the DOS stub content
void dos_stub(const std::vector<uint8_t>& content);
Expand All @@ -413,8 +488,13 @@ class LIEF_API Binary : public LIEF::Binary {
}

//! Return an iterator over the binary imports
it_imports imports();
it_const_imports imports() const;
it_imports imports() {
return imports_;
}

it_const_imports imports() const {
return imports_;
}

//! Returns the PE::Import from the given name. If it can't be
//! found, return a nullptr
Expand All @@ -426,17 +506,26 @@ class LIEF_API Binary : public LIEF::Binary {
//! ``True`` if the binary imports the given library name
//!
//! @param[in] import_name Name of the import
bool has_import(const std::string& import_name) const;
bool has_import(const std::string& import_name) const {
return get_import(import_name) != nullptr;
}

//! Check if the current binary contains delay imports
//!
//! @see DelayImport
//! @see has_import
bool has_delay_imports() const;
bool has_delay_imports() const {
return !delay_imports_.empty();
}

//! Return an iterator over the binary's delay imports
it_delay_imports delay_imports();
it_const_delay_imports delay_imports() const;
it_delay_imports delay_imports() {
return delay_imports_;
}

it_const_delay_imports delay_imports() const {
return delay_imports_;
}

//! Returns the PE::DelayImport from the given name. If it can't be
//! found, return a nullptr
Expand All @@ -449,7 +538,9 @@ class LIEF_API Binary : public LIEF::Binary {
//! ``True`` if the binary delay-imports the given library name
//!
//! @param[in] import_name Name of the delay import
bool has_delay_import(const std::string& import_name) const;
bool has_delay_import(const std::string& import_name) const {
return get_delay_import(import_name) != nullptr;
}


//! Add the function @p function of the library @p library.
Expand Down Expand Up @@ -563,14 +654,7 @@ class LIEF_API Binary : public LIEF::Binary {

int32_t available_sections_space_ = 0;

bool has_rich_header_ = false;
bool has_tls_ = false;
bool has_imports_ = false;
bool has_exports_ = false;
bool has_resources_ = false;
bool has_exceptions_ = false;
bool has_relocations_ = false;
bool has_configuration_ = false;

signatures_t signatures_;
sections_t sections_;
Expand Down
Loading

0 comments on commit c225890

Please sign in to comment.