4
0
mirror of https://github.com/QuasarApp/LIEF.git synced 2025-05-12 03:19:34 +00:00

Update doc

This commit is contained in:
Romain Thomas 2020-12-18 18:55:09 +01:00
parent 01c33053ab
commit 576d791f80
28 changed files with 270 additions and 287 deletions

@ -20,7 +20,7 @@
#include "LIEF/ELF/enums.h"
#include "LIEF/types.h"
/* @defgroup elf_symbol_c_api Symbol
/** @defgroup elf_symbol_c_api Symbol
* @ingroup elf_c_api
* @addtogroup elf_symbol_c_api
* @brief Symbol C API

@ -186,7 +186,7 @@ Core File
Core File Entry
***************
.. doxygenclass:: LIEF::ELF::CoreFileEntry
.. doxygenstruct:: LIEF::ELF::CoreFileEntry
:project: lief
----------

@ -77,13 +77,13 @@ Iterators
.. doxygenclass:: LIEF::ref_iterator
:project: lief
.. doxygenclass:: LIEF::const_ref_iterator
.. doxygentypedef:: LIEF::const_ref_iterator
:project: lief
.. doxygenclass:: LIEF::filter_iterator
:project: lief
.. doxygenclass:: LIEF::const_filter_iterator
.. doxygentypedef:: LIEF::const_filter_iterator
:project: lief
Logging

@ -248,9 +248,6 @@ Data Code Entry
.. doxygenclass:: LIEF::MachO::DataCodeEntry
:project: lief
.. doxygenenum:: LIEF::MachO::DataCodeEntry::TYPES
:project: lief
----------
Segment Split Info

@ -4,22 +4,22 @@ OAT
Utilities
*********
.. doxygenfunction:: LIEF::OAT::is_oat(const ELF::Binary&)
.. doxygenfunction:: LIEF::OAT::is_oat(const LIEF::ELF::Binary &elf_binary)
:project: lief
.. doxygenfunction:: LIEF::OAT::is_oat(const std::string&)
.. doxygenfunction:: LIEF::OAT::is_oat(const std::string &file)
:project: lief
.. doxygenfunction:: LIEF::OAT::is_oat(const std::vector<uint8_t>&)
.. doxygenfunction:: LIEF::OAT::is_oat(const std::vector<uint8_t> &raw))
:project: lief
.. doxygenfunction:: LIEF::OAT::version(const std::string&)
.. doxygenfunction:: LIEF::OAT::version(const LIEF::ELF::Binary &elf_binary)
:project: lief
.. doxygenfunction:: LIEF::OAT::version(const std::vector<uint8_t>&)
.. doxygenfunction:: LIEF::OAT::version(const std::string &file)
:project: lief
.. doxygenfunction:: LIEF::OAT::version(const LIEF::ELF::Binary&)
.. doxygenfunction:: LIEF::OAT::version(const std::vector<uint8_t> &raw)
:project: lief
.. doxygenfunction:: LIEF::OAT::android_version

@ -8,8 +8,6 @@ Parser
----------
.. _python-elf-binary-api-ref:
Binary
******
@ -652,12 +650,3 @@ Hexagon Processor flags
:members:
:inherited-members:
:undoc-members:

@ -1,15 +1,10 @@
.. lief documentation master file, created by
sphinx-quickstart on Thu Jun 11 14:32:14 2015.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to LIEF's documentation!
================================
.. toctree::
:maxdepth: 2
Intro
intro
installation
getting_started
compilation

@ -236,7 +236,6 @@ For the compilation:
.. literalinclude:: _static/ReadmeExternalProject.rst
:language: rst
:lines: 1-42
A *full* example is available in the ``examples/cmake/external_project`` directory.

@ -210,8 +210,9 @@ The transformation of the execution flow can be represented as follow:
:align: center
.. _glic229:
Warning for glic >= 2.29 users
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you are using glibc >= 2.29 (or a close version depending on your Linux
distribution), you might have encountered this error while using the `dlopen`
@ -219,7 +220,7 @@ function:
.. code::
dlopen error: cannot dynamically load position-independent executable
dlopen error: cannot dynamically load position-independent executable
Loading PIE binaries as shared libraries wasn't indeed really an intended use
case for ``dlopen``, and it used to work without really being properly

@ -165,16 +165,16 @@ When installing an application, the Android package manager will copy files from
Frida is aware of these requirements as illustrated in listing below. Hence we can simply add the suffix ``.so`` to ``libgadget.conf``
.. code-block:: vapi
.. code-block:: cpp
#if ANDROID
if (!FileUtils.test (config_path, FileTest.EXISTS)) {
var ext_index = config_path.last_index_of_char ('.');
if (ext_index != -1) {
config_path = config_path[0:ext_index] + ".config.so";
} else {
config_path = config_path + ".config.so";
}
if (ext_index != -1) {
config_path = config_path[0:ext_index] + ".config.so";
} else {
config_path = config_path + ".config.so";
}
}
#endif

@ -39,7 +39,7 @@ The main limitation of these techniques is that the size and the number of comma
If the padding size is tiny, we can't add a ``LOAD_DYLIB`` command with a *very long* library path. Moreover ``codesign`` may complain that there are not enough spaces to add the ``LC_CODE_SIGNATURE`` since we are using the space that was reserved for it.
Next parts are about format modifications and how we managed to address this limitation
Next parts are about format modifications and how we managed to address this limitation.
When PIE makes thing easier
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -385,12 +385,12 @@ Finally, we remove the signature and reconstruct the binary:
The execution of ``id.modified`` should give a similar output:
.. code-block:: console
Mac-mini:tmp romain$ ./id.modified
tmp @ [romain] $
You can also check other tools such as optool [2]_ or insert_dylib [3]_
.. rubric:: References
@ -400,8 +400,6 @@ The execution of ``id.modified`` should give a similar output:
.. [3] https://github.com/Tyilo/insert_dylib
.. rubric:: API
* :meth:`lief.MachO.Binary.add_section`

@ -10,7 +10,7 @@ Files and scripts used in this tutorial are available on the `tutorials reposito
Introduction
~~~~~~~~~~~~
ELF core files provide information about the CPU state and the memory state of a program when the coredump
ELF core [1]_ files provide information about the CPU state and the memory state of a program when the coredump
has been generated. The memory state embeds
a *snapshot* of all segments mapped in the memory space of the program. The CPU state contains register values
when the core dump has been generated.

@ -114,6 +114,7 @@ class LIEF_API Binary : public Object {
//!
//! @param[in] address Address to patch
//! @param[in] patch_value Patch to apply
//! @param[in] addr_type Specify if the address should be used as an absolute virtual address or an RVA
virtual void patch_address(uint64_t address, const std::vector<uint8_t>& patch_value, VA_TYPES addr_type = VA_TYPES::AUTO) = 0;
//! @brief Patch the address with the given value
@ -121,6 +122,7 @@ class LIEF_API Binary : public Object {
//! @param[in] address Address to patch
//! @param[in] patch_value Patch to apply
//! @param[in] size Size of the value in **bytes** (1, 2, ... 8)
//! @param[in] addr_type Specify if the address should be used as an absolute virtual address or an RVA
virtual void patch_address(uint64_t address, uint64_t patch_value, size_t size = sizeof(uint64_t), VA_TYPES addr_type = VA_TYPES::AUTO) = 0;
//! @brief Return the content located at virtual address

@ -49,7 +49,7 @@ class Relocation;
class Parser;
class Builder;
//! @brief Class which represent an ELF binary
//! Class which represent an ELF binary
class LIEF_API Binary : public LIEF::Binary {
friend class Parser;
friend class Builder;
@ -64,25 +64,25 @@ class LIEF_API Binary : public LIEF::Binary {
Binary& operator=(const Binary& ) = delete;
Binary(const Binary& copy) = delete;
//! @brief Return binary's class (ELF32 or ELF64)
//! Return binary's class (ELF32 or ELF64)
ELF_CLASS type(void) const;
//! @brief Return @link ELF::Header Elf header @endlink
//! Return @link ELF::Header Elf header @endlink
Header& header(void);
const Header& header(void) const;
//! @brief Return the last offset used in binary
//! Return the last offset used in binary
//! according to section headers
uint64_t last_offset_section(void) const;
//! @brief Return the last offset used in binary
//! Return the last offset used in binary
//! according to segment headers
uint64_t last_offset_segment(void) const;
//! @brief Return the next virtual address available
//! Return the next virtual address available
uint64_t next_virtual_address(void) const;
//! @brief Return binary's sections
//! Return binary's sections
//!
//! @warning
//! This method return a vector of references thus you can
@ -90,82 +90,82 @@ class LIEF_API Binary : public LIEF::Binary {
it_sections sections(void);
it_const_sections sections(void) const;
//! @brief Return binary entrypoint
//! Return binary entrypoint
virtual uint64_t entrypoint(void) const override;
//! @brief Return binary's segments
//! Return binary's segments
it_segments segments(void);
it_const_segments segments(void) const;
//! @brief Return binary's dynamic entries
//! Return binary's dynamic entries
it_dynamic_entries dynamic_entries(void);
it_const_dynamic_entries dynamic_entries(void) const;
//! @brief Add the given dynamic entry and return the entry added
//! Add the given dynamic entry and return the entry added
DynamicEntry& add(const DynamicEntry& entry);
//! @brief Add the given note and return the entry added
//! Add the given note and return the entry added
Note& add(const Note& note);
//! @brief Remove the given dynamic entry
//! Remove the given dynamic entry
void remove(const DynamicEntry& entry);
//! @brief Remove **all** dynamic entries with the given tag
//! Remove **all** dynamic entries with the given tag
void remove(DYNAMIC_TAGS tag);
//! @brief Remove the given section
//! Remove the given section
void remove(const Section& section, bool clear = false);
//! @brief Remove the given note
//! Remove the given note
void remove(const Note& note);
//! @brief Remove **all** notes with the given type
//! Remove **all** notes with the given type
void remove(NOTE_TYPES tag);
//! @brief Return binary's dynamic symbols
//! Return binary's dynamic symbols
it_symbols dynamic_symbols(void);
it_const_symbols dynamic_symbols(void) const;
//! @brief Return symbols which are exported by the binary
//! Return symbols which are exported by the binary
it_exported_symbols exported_symbols(void);
it_const_exported_symbols exported_symbols(void) const;
//! @brief Return symbols which are imported by the binary
//! Return symbols which are imported by the binary
it_imported_symbols imported_symbols(void);
it_const_imported_symbols imported_symbols(void) const;
//! @brief Return statics symbols
//! Return statics symbols
it_symbols static_symbols(void);
it_const_symbols static_symbols(void) const;
//! @brief Return symbol versions
//! Return symbol versions
it_symbols_version symbols_version(void);
it_const_symbols_version symbols_version(void) const;
//! @brief Return symbols version definition
//! Return symbols version definition
it_symbols_version_definition symbols_version_definition(void);
it_const_symbols_version_definition symbols_version_definition(void) const;
//! @brief Return Symbol version requirement
//! Return Symbol version requirement
it_symbols_version_requirement symbols_version_requirement(void);
it_const_symbols_version_requirement symbols_version_requirement(void) const;
//! @brief Return dynamic relocations
//! Return dynamic relocations
it_dynamic_relocations dynamic_relocations(void);
it_const_dynamic_relocations dynamic_relocations(void) const;
Relocation& add_dynamic_relocation(const Relocation& relocation);
Relocation& add_pltgot_relocation(const Relocation& relocation);
//! @brief Return `plt.got` relocations
//! Return `plt.got` relocations
it_pltgot_relocations pltgot_relocations(void);
it_const_pltgot_relocations pltgot_relocations(void) const;
//! @brief Return relocations used in an object file (``*.o``)
//! Return relocations used in an object file (``*.o``)
it_object_relocations object_relocations(void);
it_const_object_relocations object_relocations(void) const;
//! @brief Return **all** relocations present in the binary
//! Return **all** relocations present in the binary
it_relocations relocations(void);
it_const_relocations relocations(void) const;
@ -182,23 +182,23 @@ class LIEF_API Binary : public LIEF::Binary {
const Relocation* get_relocation(const std::string& symbol_name) const;
Relocation* get_relocation(const std::string& symbol_name);
//! @brief ``true`` if GNU hash is used
//! ``true`` if GNU hash is used
//!
//! @see gnu_hash and use_sysv_hash
bool use_gnu_hash(void) const;
//! @brief Return the GnuHash object in **readonly**
//! Return the GnuHash object in **readonly**
const GnuHash& gnu_hash(void) const;
//! @brief ``true`` if SYSV hash is used
//! ``true`` if SYSV hash is used
//!
//! @see sysv_hash and use_gnu_hash
bool use_sysv_hash(void) const;
//! @brief Return the SysvHash object in **readonly**
//! Return the SysvHash object in **readonly**
const SysvHash& sysv_hash(void) const;
//! @brief Check if a section with the given name exists in the binary
//! Check if a section with the given name exists in the binary
bool has_section(const std::string& name) const;
//! Check if a section that handle the given offset exists
@ -207,42 +207,42 @@ class LIEF_API Binary : public LIEF::Binary {
//! Check if a section that handle the given virtual address exists
bool has_section_with_va(uint64_t va) const;
//! @brief Return Section with the given `name`
//! Return Section with the given `name`
Section& get_section(const std::string& name);
const Section& get_section(const std::string& name) const;
//! @brief Return `.text` section
//! Return `.text` section
Section& text_section(void);
//! @brief Return `.dynamic` section
//! Return `.dynamic` section
Section& dynamic_section(void);
//! @brief Return hash section
//! Return hash section
Section& hash_section(void);
//! @brief Return section which holds static symbols
//! Return section which holds static symbols
Section& static_symbols_section(void);
//! @brief Return program image base. For instance 0x40000
//! Return program image base. For instance 0x40000
//!
//! To compute the image base, we look for the PT_PHDR segment header (phdr),
//! and we return phdr->p_vaddr - phdr->p_offset
uint64_t imagebase(void) const;
//! @brief Return the size of the mapped binary
//! Return the size of the mapped binary
uint64_t virtual_size(void) const;
//! @brief Check if the binary uses a loader
//! Check if the binary uses a loader
//! @see interpreter
bool has_interpreter(void) const;
//! @brief Return ELF interprer if any. (e.g. `/lib64/ld-linux-x86-64.so.2`)
//! Return ELF interprer if any. (e.g. `/lib64/ld-linux-x86-64.so.2`)
const std::string& interpreter(void) const;
//! @brief Change the interpreter
//! Change the interpreter
void interpreter(const std::string& interpreter);
//! @brief Return both static and dynamic symbols
//! Return both static and dynamic symbols
it_symbols symbols(void);
it_const_symbols symbols(void) const;
@ -273,31 +273,31 @@ class LIEF_API Binary : public LIEF::Binary {
//! Basically we look for string in the ``.roadata``
string_list_t strings(const size_t min_size = 5) const;
//! @brief Remove symbols with the given name in boths
//! Remove symbols with the given name in boths
//! * dynamic symbols
//! * static symbols
//! @see remove_static_symbol, remove_dynamic_symbol
void remove_symbol(const std::string& name);
//void remove_symbol(Symbol* symbol);
//!@brief Remove static symbols with the given name
//!Remove static symbols with the given name
void remove_static_symbol(const std::string& name);
void remove_static_symbol(Symbol* symbol);
//!@brief Remove dynamic symbols with the given name
//!Remove dynamic symbols with the given name
void remove_dynamic_symbol(const std::string& name);
//! @brief Remove the given symbol from the dynamic symbol table.
//! Remove the given symbol from the dynamic symbol table.
//!
//! As a side effect, it will remove any ELF::Relocation
//! that refer to this symbol and the SymbolVersion (if any)
//! associated with this symbol
void remove_dynamic_symbol(Symbol* symbol);
//! @brief Return the address of the given function name
//! Return the address of the given function name
virtual uint64_t get_function_address(const std::string& func_name) const override;
//! @brief Return the address of the given function name
//! Return the address of the given function name
//! @param func_name The function's name target
//! @param demangled Use the demangled name
uint64_t get_function_address(const std::string& func_name, bool demangled) const;
@ -312,31 +312,31 @@ class LIEF_API Binary : public LIEF::Binary {
Section& extend(const Section& section, uint64_t size);
//! @brief Add a static symbol
//! Add a static symbol
Symbol& add_static_symbol(const Symbol& symbol);
//! @brief Add a dynamic symbol with the associated SymbolVersion
//! Add a dynamic symbol with the associated SymbolVersion
Symbol& add_dynamic_symbol(const Symbol& symbol, const SymbolVersion* version = nullptr);
//! Create a symbol for the function at the given address and export it
Symbol& add_exported_function(uint64_t address, const std::string& name = "");
//! @brief Add a library as dependency
//! Add a library as dependency
DynamicEntryLibrary& add_library(const std::string& library_name);
//! @brief Remove the given library
//! Remove the given library
void remove_library(const std::string& library_name);
//! @brief Get the library object (DynamicEntryLibrary) from the given name
//! Get the library object (DynamicEntryLibrary) from the given name
DynamicEntryLibrary& get_library(const std::string& library_name);
//! @brief Get the library object (DynamicEntryLibrary) from the given name
//! Get the library object (DynamicEntryLibrary) from the given name
const DynamicEntryLibrary& get_library(const std::string& library_name) const;
//! @brief Check if the given library name exists in the current binary
//! Check if the given library name exists in the current binary
bool has_library(const std::string& name) const;
//! @brief Add a new segment in the binary
//! Add a new segment in the binary
//!
//! The segment is inserted at the end
//! @warning We assume that the binary is not position independent
@ -352,122 +352,124 @@ class LIEF_API Binary : public LIEF::Binary {
Segment& extend(const Segment& segment, uint64_t size);
//! @brief Patch the content at virtual address @p address with @p patch_value
//! Patch the content at virtual address @p address with @p patch_value
//!
//! @param[in] address Address to patch
//! @param[in] patch_value Patch to apply
//! @param[in] addr_type Specify if the address should be used as an absolute virtual address or an RVA
virtual 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;
//! @brief Patch the address with the given value
//! Patch the address with the given value
//!
//! @param[in] address Address to patch
//! @param[in] patch_value Patch to apply
//! @param[in] size Size of the value in **bytes** (1, 2, ... 8)
//! @param[in] addr_type Specify if the address should be used as an absolute virtual address or an RVA
virtual 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;
//! @brief Patch the imported symbol with the ``address``
//! Patch the imported symbol with the ``address``
//!
//! @param[in] symbol Imported symbol to patch
//! @param[in] address New address
void patch_pltgot(const Symbol& symbol, uint64_t address);
//! @brief Patch the imported symbol's name with the ``address``
//! Patch the imported symbol's name with the ``address``
//!
//! @param[in] symbol_name Imported symbol's name to patch
//! @param[in] address New address
void patch_pltgot(const std::string& symbol_name, uint64_t address);
//! @brief Strip the binary by removing static symbols
//! Strip the binary by removing static symbols
void strip(void);
//! @brief Remove a binary's section.
//! Remove a binary's section.
//!
//! We clear data used by this section and it's removed from
//! section table
virtual void remove_section(const std::string& name, bool clear = false) override;
//! @brief Reconstruct the binary object and write it in `filename`
//! Reconstruct the binary object and write it in `filename`
//! @param filename Path to write the reconstructed binary
virtual void write(const std::string& filename) override;
//! @brief Reconstruct the binary object and return his content as bytes
//! Reconstruct the binary object and return his content as bytes
std::vector<uint8_t> raw(void);
//! @brief Convert a virtual address to an offset in the file
//! Convert a virtual address to an offset in the file
uint64_t virtual_address_to_offset(uint64_t virtual_address) const;
//! @brief Check if the binary has been compiled with `-fpie -pie` flags
//! Check if the binary has been compiled with `-fpie -pie` flags
//!
//! To do so we check if there is a `PT_INTERP` segment and if
//! the binary type is `ET_DYN` (Shared object)
virtual bool is_pie(void) const override;
//! @brief Check if the binary uses ``NX`` protection
//! Check if the binary uses ``NX`` protection
virtual bool has_nx(void) const override;
//! @brief Return the @link ELF::Section Section @endlink
//! Return the @link ELF::Section Section @endlink
//! from the @p offset
const Section& section_from_offset(uint64_t offset) const;
Section& section_from_offset(uint64_t offset);
//! @brief Return the @link ELF::Section Section @endlink
//! Return the @link ELF::Section Section @endlink
//! from the @p address
const Section& section_from_virtual_address(uint64_t address) const;
Section& section_from_virtual_address(uint64_t address);
//! @brief Return the @link ELF::Segment Segment @endlink
//! Return the @link ELF::Segment Segment @endlink
//! from the @p address
const Segment& segment_from_virtual_address(uint64_t address) const;
Segment& segment_from_virtual_address(uint64_t address);
//! @brief Return the @link ELF::Segment Segment @endlink
//! Return the @link ELF::Segment Segment @endlink
//! from the @p offset
const Segment& segment_from_offset(uint64_t offset) const;
Segment& segment_from_offset(uint64_t offset);
//! @brief Return the **first** ELF::DynamicEntry associated with the given tag
//! Return the **first** ELF::DynamicEntry associated with the given tag
const DynamicEntry& get(DYNAMIC_TAGS tag) const;
DynamicEntry& get(DYNAMIC_TAGS tag);
//! @brief Return the **first** ELF::Segment associated with the given type
//! Return the **first** ELF::Segment associated with the given type
const Segment& get(SEGMENT_TYPES type) const;
Segment& get(SEGMENT_TYPES type);
//! @brief Return the **first** ELF::Note associated with the given type
//! Return the **first** ELF::Note associated with the given type
const Note& get(NOTE_TYPES type) const;
Note& get(NOTE_TYPES type);
//! @brief Return the **first** ELF::Section associated with the given type
//! Return the **first** ELF::Section associated with the given type
const Section& get(ELF_SECTION_TYPES type) const;
Section& get(ELF_SECTION_TYPES type);
//! @brief Check if an ELF::DynamicEntry associated with the given tag
//! Check if an ELF::DynamicEntry associated with the given tag
//! exists.
bool has(DYNAMIC_TAGS tag) const;
//! @brief Check if ELF::Segment associated with the given type
//! Check if ELF::Segment associated with the given type
//! exists.
bool has(SEGMENT_TYPES type) const;
//! @brief Check if a ELF::Note associated with the given type
//! Check if a ELF::Note associated with the given type
//! exists.
bool has(NOTE_TYPES type) const;
//! @brief Check if a ELF::Section associated with the given type
//! Check if a ELF::Section associated with the given type
//! exists.
bool has(ELF_SECTION_TYPES type) const;
//! @brief Return the content located at virtual address
//! Return the content located at virtual address
virtual std::vector<uint8_t> get_content_from_virtual_address(uint64_t virtual_address, uint64_t size,
LIEF::Binary::VA_TYPES addr_type = LIEF::Binary::VA_TYPES::AUTO) const override;
//! @brief Method so that the ``visitor`` can visit us
//! Method so that the ``visitor`` can visit us
virtual void accept(LIEF::Visitor& visitor) const override;
//! @brief Apply the given permutation on the dynamic symbols table
//! Apply the given permutation on the dynamic symbols table
//!
//! To avoid override by the ELF::Builder, one should set ELF::Builder::empties_gnuhash
//! to ``true``
@ -478,10 +480,10 @@ class LIEF_API Binary : public LIEF::Binary {
LIEF::Binary::functions_t functions(void) const;
//! @brief ``true`` if the binary embed notes
//! ``true`` if the binary embed notes
bool has_notes(void) const;
//! @brief Return the Note object if any
//! Return the Note object if any
//! @see has_note
it_const_notes notes(void) const;
@ -533,7 +535,7 @@ class LIEF_API Binary : public LIEF::Binary {
protected:
Binary(void);
//! @brief Return an abstraction of binary's section: LIEF::Section
//! Return an abstraction of binary's section: LIEF::Section
virtual LIEF::sections_t get_abstract_sections(void) override;
virtual LIEF::Header get_abstract_header(void) const override;

@ -33,7 +33,7 @@ class Note;
//! Class representing the ".note.android.ident" section
//!
//! @See: https://android.googlesource.com/platform/ndk/+/ndk-release-r16/sources/crt/crtbrand.S#39
//! @see: https://android.googlesource.com/platform/ndk/+/ndk-release-r16/sources/crt/crtbrand.S#39
class LIEF_API AndroidNote : public NoteDetails {
friend class Parser;

@ -33,7 +33,7 @@ class Binary;
//! Class representing the ".note.android.ident" section
//!
//! @See: https://android.googlesource.com/platform/ndk/+/ndk-release-r16/sources/crt/crtbrand.S#39
//! @see: https://android.googlesource.com/platform/ndk/+/ndk-release-r16/sources/crt/crtbrand.S#39
class LIEF_API NoteAbi : public NoteDetails {
friend class Parser;
@ -41,6 +41,7 @@ class LIEF_API NoteAbi : public NoteDetails {
friend class Binary;
public:
//! Version type: (Major, Minor, Patch)
using version_t = std::array<uint32_t, 3>;

@ -32,6 +32,7 @@ class Builder;
class Binary;
class Note;
//! Core file entry
struct CoreFileEntry {
uint64_t start; ///< Start address of mapped file
uint64_t end; ///< End address of mapped file

@ -36,7 +36,7 @@ class Section;
class Binary;
//! @brief Class which parse an ELF file and transform into a ELF::Binary
//! Class which parse an ELF file and transform into a ELF::Binary
class LIEF_API Parser : public LIEF::Parser {
friend class OAT::Parser;
public:
@ -55,23 +55,25 @@ class LIEF_API Parser : public LIEF::Parser {
static constexpr uint32_t MAX_SEGMENT_SIZE = MAX_SECTION_SIZE;
//! @brief Parse an ELF file an return a LIEF::ELF::Binary object
//! Parse an ELF file an return a LIEF::ELF::Binary object
//!
//! For weird binaries (e.g. sectionless) you can choose which method use to count dynamic symbols
//!
//! @param[in] file Path to the ELF binary
//! @param[in] count_mtd Method used to count dynamic symbols. Default: LIEF::ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO
//! @Return LIEF::ELF::Binary
//!
//! @return LIEF::ELF::Binary
LIEF_API static std::unique_ptr<Binary> parse(const std::string& file, DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
//! @brief Parse the given raw data as an ELF binary and return a LIEF::ELF::Binary object
//! Parse the given raw data as an ELF binary and return a LIEF::ELF::Binary object
//!
//! For weird binaries (e.g. sectionless) you can choose which method use to count dynamic symbols
//!
//! @param[in] data Raw ELF
//! @param[in] name Binary name (optional)
//! @param[in] count_mtd Method used to count dynamic symbols. Default: LIEF::ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO
//! @Return LIEF::ELF::Binary
//!
//! @return LIEF::ELF::Binary
LIEF_API static std::unique_ptr<Binary> parse(const std::vector<uint8_t>& data, const std::string& name = "", DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
Parser& operator=(const Parser&) = delete;
@ -97,46 +99,46 @@ class LIEF_API Parser : public LIEF::Parser {
template<typename ELF_T>
bool parse_header(void);
//! @brief Parse binary's Section
//! Parse binary's Section
//!
//! Parse sections by using the ``e_shoff`` field as offset
template<typename ELF_T>
void parse_sections(void);
//! @brief Parse binary's segments
//! Parse binary's segments
//!
//! Parse segment by using the ``e_phoff`` field as offset
template<typename ELF_T>
void parse_segments(void);
//! @brief Return offset of the dynamic string table
//! Return offset of the dynamic string table
uint64_t get_dynamic_string_table(void) const;
uint64_t get_dynamic_string_table_from_segments(void) const;
uint64_t get_dynamic_string_table_from_sections(void) const;
//! @brief Return the number of dynamic symbols using the given method
//! Return the number of dynamic symbols using the given method
template<typename ELF_T>
uint32_t get_numberof_dynamic_symbols(DYNSYM_COUNT_METHODS mtd) const;
//! @brief Count based on hash table (reliable)
//! Count based on hash table (reliable)
template<typename ELF_T>
uint32_t nb_dynsym_hash(void) const;
//! @brief Count based on SYSV hash table
//! Count based on SYSV hash table
template<typename ELF_T>
uint32_t nb_dynsym_sysv_hash(void) const;
//! @brief Count based on GNU hash table
//! Count based on GNU hash table
template<typename ELF_T>
uint32_t nb_dynsym_gnu_hash(void) const;
//! @brief Count based on sections (not very reliable)
//! Count based on sections (not very reliable)
template<typename ELF_T>
uint32_t nb_dynsym_section(void) const;
//! @brief Count based on PLT/GOT relocations (very reliable but not accurate)
//! Count based on PLT/GOT relocations (very reliable but not accurate)
template<typename ELF_T>
uint32_t nb_dynsym_relocations(void) const;
@ -146,7 +148,7 @@ class LIEF_API Parser : public LIEF::Parser {
template<typename ELF_T>
void parse_dynamic_symbols(uint64_t offset);
//! @brief Parse static Symbol
//! Parse static Symbol
//!
//! Parser find Symbols offset by using the file offset attribute of the
//! ELF_SECTION_TYPES::SHT_SYMTAB Section.
@ -157,13 +159,13 @@ class LIEF_API Parser : public LIEF::Parser {
template<typename ELF_T>
void parse_static_symbols(uint64_t offset, uint32_t nbSymbols, const Section* string_section);
//! @brief Parse Dynamic relocations
//! Parse Dynamic relocations
//!
//! It use DT_REL/DT_RELA dynamic entries to parse it
template<typename ELF_T, typename REL_T>
void parse_dynamic_relocations(uint64_t relocations_offset, uint64_t size);
//! @brief Parse `.plt.got`/`got` relocations
//! Parse `.plt.got`/`got` relocations
//!
//! For:
//! * ELF32 it uses **DT_JMPREL** and **DT_PLTRELSZ**
@ -172,7 +174,7 @@ class LIEF_API Parser : public LIEF::Parser {
void parse_pltgot_relocations(uint64_t offset, uint64_t size);
//! @brief Parse relocations using LIEF::ELF::Section.
//! Parse relocations using LIEF::ELF::Section.
//!
//! Parser::parse_dynamic_relocations and Parser::parse_pltgot_relocations
//! use parse relocations by using LIEF::ELF::Segment. This method parse relocations
@ -180,7 +182,7 @@ class LIEF_API Parser : public LIEF::Parser {
template<typename ELF_T, typename REL_T>
void parse_section_relocations(const Section& section);
//! @brief Parse SymbolVersionRequirement
//! Parse SymbolVersionRequirement
//!
//! We use the virtual address stored in the
//! DYNAMIC_TAGS::DT_VERNEED entry to get the offset.
@ -189,7 +191,7 @@ class LIEF_API Parser : public LIEF::Parser {
void parse_symbol_version_requirement(uint64_t offset, uint32_t nb_entries);
//! @brief Parse SymbolVersionDefinition.
//! Parse SymbolVersionDefinition.
//!
//! We use the virtual address stored in
//! the DYNAMIC_TAGS::DT_VERDEF DT_VERDEF entry to get the offset.
@ -198,7 +200,7 @@ class LIEF_API Parser : public LIEF::Parser {
void parse_symbol_version_definition(uint64_t offset, uint32_t nb_entries);
//! @brief Parse @link SymbolVersion Symbol version @endlink.
//! Parse @link SymbolVersion Symbol version @endlink.
//!
//! We use the virtual address stored in the
//! DYNAMIC_TAGS::DT_VERSYM entry to parse it.
@ -206,16 +208,16 @@ class LIEF_API Parser : public LIEF::Parser {
//! @see http://dev.gentoo.org/~solar/elf/symbol-versioning
void parse_symbol_version(uint64_t symbol_version_offset);
//! @brief Parse Symbols's GNU hash
//! Parse Symbols's GNU hash
//!
//! @see https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
template<typename ELF_T>
void parse_symbol_gnu_hash(uint64_t offset);
//! @brief Parse Note (.gnu.note)
//! Parse Note (.gnu.note)
void parse_notes(uint64_t offset, uint64_t size);
//! @brief Parse Symbols's SYSV hash
//! Parse Symbols's SYSV hash
void parse_symbol_sysv_hash(uint64_t offset);
void parse_overlay(void);

@ -276,6 +276,7 @@ class LIEF_API Binary : public LIEF::Binary {
//!
//! @param[in] address Address to patch
//! @param[in] patch_value Patch to apply
//! @param[in] addr_type Specify if the address should be used as an absolute virtual address or an RVA
virtual 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 address with the given value
@ -283,6 +284,7 @@ class LIEF_API Binary : public LIEF::Binary {
//! @param[in] address Address to patch
//! @param[in] patch_value Patch to apply
//! @param[in] size Size of the value in **bytes** (1, 2, ... 8)
//! @param[in] addr_type Specify if the address should be used as an absolute virtual address or an RVA
virtual 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;
//! Return the content located at virtual address

@ -1,4 +1,3 @@
/* Copyright 2017 R. Thomas
* Copyright 2017 Quarkslab
*

@ -33,7 +33,7 @@ namespace MachO {
class BinaryParser;
//! @brief Object modeling relocation
//! Object modeling relocation
//!
//! @see:
//! * MachO::RelocationObject
@ -57,19 +57,19 @@ class LIEF_API Relocation : public LIEF::Relocation {
virtual Relocation* clone(void) const = 0;
//! @brief For @link MachO::FILE_TYPES::MH_OBJECT object @endlink this is an
//! offset from the start of the @link MachO::Section section @endlink
//! to the item containing the address requiring relocation.
// For @link MachO::FILE_TYPES::MH_OBJECT object @endlink this is an
// offset from the start of the @link MachO::Section section @endlink
// to the item containing the address requiring relocation.
//virtual uint64_t address(void) const override;
//! @brief Indicates whether the item containing the address to be
//! Indicates whether the item containing the address to be
//! relocated is part of a CPU instruction that uses PC-relative addressing.
//!
//! For addresses contained in PC-relative instructions, the CPU adds the address of
//! the instruction to the address contained in the instruction.
virtual bool is_pc_relative(void) const = 0;
//! @brief Type of the relocation according to the
//! Type of the relocation according to the
//! @link Relocation::architecture architecture@endlink and/or
//! @link Relocation::origin origin@endlink
//!
@ -82,30 +82,30 @@ class LIEF_API Relocation : public LIEF::Relocation {
//! * MachO::REBASE_TYPES
virtual uint8_t type(void) const;
//! @brief @link Relocation::architecture architecture @endlink of the relocation
//! @link Relocation::architecture architecture @endlink of the relocation
CPU_TYPES architecture(void) const;
//! @brief Origin of the relocation
//! Origin of the relocation
virtual RELOCATION_ORIGINS origin(void) const = 0;
//! @brief ``true`` if the relocation has a symbol associated with
//! ``true`` if the relocation has a symbol associated with
bool has_symbol(void) const;
//! @brief Symbol associated with the relocation (if any)
//! Symbol associated with the relocation (if any)
Symbol& symbol(void);
const Symbol& symbol(void) const;
//! @brief ``true`` if the relocation has a section associated with
//! ``true`` if the relocation has a section associated with
bool has_section(void) const;
//! @brief Section associated with the relocation (if any)
//! Section associated with the relocation (if any)
Section& section(void);
const Section& section(void) const;
//! @brief ``true`` if the relocation has a SegmentCommand associated with
//! ``true`` if the relocation has a SegmentCommand associated with
bool has_segment(void) const;
//! @brief SegmentCommand associated with the relocation (if any)
//! SegmentCommand associated with the relocation (if any)
SegmentCommand& segment(void);
const SegmentCommand& segment(void) const;

@ -402,7 +402,7 @@ enum _LIEF_EN(X86_RELOCATION) {
_LIEF_EI(GENERIC_RELOC_SECTDIFF) = 2, /**< A relocation entry for an item that contains the difference of two section addresses. This is generally used for position-independent code generation. */
_LIEF_EI(GENERIC_RELOC_PB_LA_PTR) = 3, /**< contains the address from which to subtract; it must be followed by a X86_RELOCATION::GENERIC_RELOC_PAIR containing the address to subtract.*/
_LIEF_EI(GENERIC_RELOC_LOCAL_SECTDIFF) = 4, /**< Similar to X86_RELOCATION::GENERIC_RELOC_SECTDIFF except that this entry refers specifically to the address in this item. If the address is that of a globally visible coalesced symbol, this relocation entry does not change if the symbol is overridden. This is used to associate stack unwinding information with the object code this relocation entry describes.*/
_LIEF_EI(GENERIC_RELOC_TLV) = 5, /**< A relocation entry for a prebound lazy pointer. This is always a scattered relocation entry. The @link MachO::Relocation::value value @endlink field contains the non-prebound value of the lazy pointer.*/
_LIEF_EI(GENERIC_RELOC_TLV) = 5, /**< A relocation entry for a prebound lazy pointer. This is always a scattered relocation entry. The MachO::Relocation::value field contains the non-prebound value of the lazy pointer.*/
};
@ -459,12 +459,12 @@ enum _LIEF_EN(ARM64_RELOCATION) {
_LIEF_EI(ARM64_RELOC_SUBTRACTOR) = 1, /**< Must be followed by an ARM64_RELOCATION::ARM64_RELOC_UNSIGNED */
_LIEF_EI(ARM64_RELOC_BRANCH26) = 2, /**< A B/BL instruction with 26-bit displacement. */
_LIEF_EI(ARM64_RELOC_PAGE21) = 3, /**< PC-rel distance to page of target. */
_LIEF_EI(ARM64_RELOC_PAGEOFF12) = 4, /**< Offset within page, scaled by @link MachO::Relocation::size size @endlink. */
_LIEF_EI(ARM64_RELOC_PAGEOFF12) = 4, /**< Offset within page, scaled by MachO::Relocation::size. */
_LIEF_EI(ARM64_RELOC_GOT_LOAD_PAGE21) = 5, /**< PC-rel distance to page of GOT slot */
_LIEF_EI(ARM64_RELOC_GOT_LOAD_PAGEOFF12) = 6, /**< Offset within page of GOT slot, scaled by @link MachO::Relocation::size size @endlink. */
_LIEF_EI(ARM64_RELOC_GOT_LOAD_PAGEOFF12) = 6, /**< Offset within page of GOT slot, scaled by MachO::Relocation::size. */
_LIEF_EI(ARM64_RELOC_POINTER_TO_GOT) = 7, /**< For pointers to GOT slots. */
_LIEF_EI(ARM64_RELOC_TLVP_LOAD_PAGE21) = 8, /**< PC-rel distance to page of TLVP slot. */
_LIEF_EI(ARM64_RELOC_TLVP_LOAD_PAGEOFF12) = 9, /**< Offset within page of TLVP slot, scaled by @link MachO::Relocation::size size @endlink.*/
_LIEF_EI(ARM64_RELOC_TLVP_LOAD_PAGEOFF12) = 9, /**< Offset within page of TLVP slot, scaled by MachO::Relocation::size.*/
_LIEF_EI(ARM64_RELOC_ADDEND) = 10, /**< Must be followed by ARM64_RELOCATION::ARM64_RELOC_PAGE21 or ARM64_RELOCATION::ARM64_RELOC_PAGEOFF12. */
};

@ -37,7 +37,7 @@ namespace PE {
class Parser;
class Builder;
//! @brief Class which represent a PE binary object
//! Class which represent a PE binary object
class LIEF_API Binary : public LIEF::Binary {
friend class Parser;
friend class Builder;
@ -47,28 +47,28 @@ class LIEF_API Binary : public LIEF::Binary {
virtual ~Binary(void);
//! @brief Return `PE32` or `PE32+`
//! Return `PE32` or `PE32+`
PE_TYPE type(void) const;
//! @brief Convert Relative Virtual Address to offset
//! Convert Relative Virtual Address to offset
//!
//! We try to get the get section wich hold the given
//! `RVA` and convert it to offset. If the section
//! does not exist, we assume that `RVA` = `offset`
uint64_t rva_to_offset(uint64_t RVA);
//! @brief Convert Virtual address to offset
//! Convert Virtual address to offset
uint64_t va_to_offset(uint64_t VA);
//! @brief Find the section associated with the `offset`
//! Find the section associated with the `offset`
Section& section_from_offset(uint64_t offset);
const Section& section_from_offset(uint64_t offset) const;
//! @brief Find the section associated with the `virtual address`
//! Find the section associated with the `virtual address`
Section& section_from_rva(uint64_t virtual_address);
const Section& section_from_rva(uint64_t virtual_address) const;
//! @brief Return binary's sections
//! Return binary's sections
it_sections sections(void);
it_const_sections sections(void) const;
@ -76,74 +76,74 @@ class LIEF_API Binary : public LIEF::Binary {
// Headers
// =======
//! @brief Return a reference to the PE::DosHeader object
//! Return a reference to the PE::DosHeader object
DosHeader& dos_header(void);
const DosHeader& dos_header(void) const;
//! @brief Return a reference to the PE::Header object
//! Return a reference to the PE::Header object
Header& header(void);
const Header& header(void) const;
//! @brief Return a reference to the OptionalHeader object
//! Return a reference to the OptionalHeader object
OptionalHeader& optional_header(void);
const OptionalHeader& optional_header(void) const;
//! @brief Compute the binary's virtual size.
//! Compute the binary's virtual size.
//! It should match with OptionalHeader::sizeof_image
uint64_t virtual_size(void) const;
//! @brief Compute the size of all headers
//! Compute the size of all headers
uint32_t sizeof_headers(void) const;
//! @brief Return a reference to the TLS object
//! Return a reference to the TLS object
TLS& tls(void);
const TLS& tls(void) const;
//! @brief Set a TLS object in the current Binary
//! Set a TLS object in the current Binary
void tls(const TLS& tls);
//! @brief Check if the current binary has a TLS object
//! Check if the current binary has a TLS object
bool has_tls(void) const;
//! @brief Check if the current binary has imports
//! Check if the current binary has imports
//!
//! @see Import
bool has_imports(void) const;
//! @brief Check if the current binary is signed
//! Check if the current binary is signed
bool has_signature(void) const;
//! @brief Check if the current binary has exports.
//! Check if the current binary has exports.
//!
//! @see Export
bool has_exports(void) const;
//! @brief Check if the current binary has resources
//! Check if the current binary has resources
bool has_resources(void) const;
//! @brief Check if the current binary has exceptions
//! Check if the current binary has exceptions
bool has_exceptions(void) const;
//! @brief Check if the current binary has relocations
//! Check if the current binary has relocations
//!
//! @see Relocation
bool has_relocations(void) const;
//! @brief Check if the current binary has debugs
//! Check if the current binary has debugs
bool has_debug(void) const;
//! @brief Check if the current binary has a load configuration
//! Check if the current binary has a load configuration
bool has_configuration(void) const;
//! @brief Check if the current binary has been built has reproducible, replacing timestamps by a compile hash.
//! Check if the current binary has been built has reproducible, replacing timestamps by a compile hash.
//!
//! @see Debug
bool is_reproducible_build(void) const;
//! @brief Return the Signature object if the bianry is signed
//! Return the Signature object if the bianry is signed
const Signature& signature(void) const;
//! @brief Try to predict the RVA of the function `function` in the import library `library`
//! Try to predict the RVA of the function `function` in the import library `library`
//!
//! @warning
//! The value could be chang if imports change
@ -157,25 +157,25 @@ class LIEF_API Binary : public LIEF::Binary {
//! @return The address of the function (``IAT``) in the new import table
uint32_t predict_function_rva(const std::string& library, const std::string& function);
//! @brief Return the Export object
//! Return the Export object
Export& get_export(void);
const Export& get_export(void) const;
//! @brief Return binary Symbols
//! Return binary Symbols
std::vector<Symbol>& symbols(void);
const std::vector<Symbol>& symbols(void) const;
//! @brief Return resources as a tree
//! Return resources as a tree
ResourceNode& resources(void);
const ResourceNode& resources(void) const;
//! @brief Set a new resource tree
//! Set a new resource tree
void set_resources(const ResourceDirectory& resource);
//! @brief Set a new resource tree
//! Set a new resource tree
void set_resources(const ResourceData& resource);
//! @brief Return the ResourcesManager (class to manage resources more easily than the tree one)
//! Return the ResourcesManager (class to manage resources more easily than the tree one)
ResourcesManager resources_manager(void);
const ResourcesManager resources_manager(void) const;
@ -183,25 +183,26 @@ class LIEF_API Binary : public LIEF::Binary {
// Methods to manage sections
// ==========================
//! @brief Return binary's section from its name
//! Return binary's section from its name
//!
//! @param[in] name Name of the Section
Section& get_section(const std::string& name);
const Section& get_section(const std::string& name) const;
//! @brief Return the section associated with import table
//! Return the section associated with import table
const Section& import_section(void) const;
Section& import_section(void);
//! @brief Delete the section with the given name
//! Delete the section with the given name
//!
//! @param[in] name Name of section to delete
//! @param[in] clear if ``true`` clear the section's content with 0 before removing (default: ``false``)
virtual void remove_section(const std::string& name, bool clear = false) override;
//! Remove the given section
void remove(const Section& section, bool clear = false);
//! @brief Add a section to the binary and return the section added.
//! Add a section to the binary and return the section added.
Section& add_section(
const Section& section,
PE_SECTION_TYPES type = PE_SECTION_TYPES::UNKNOWN);
@ -213,31 +214,31 @@ class LIEF_API Binary : public LIEF::Binary {
it_relocations relocations(void);
it_const_relocations relocations(void) const;
//! @brief Add a @link PE::Relocation relocation @endlink
//! Add a @link PE::Relocation relocation @endlink
Relocation& add_relocation(const Relocation& relocation);
//! @brief Remove all relocations
//! Remove all relocations
void remove_all_relocations(void);
// ===============================
// Methods to manage DataDirectory
// ===============================
//! @brief Return data directories in the binary
//! Return data directories in the binary
it_data_directories data_directories(void);
it_const_data_directories data_directories(void) const;
//! @brief Return the DataDirectory with the given type (or index)
//! Return the DataDirectory with the given type (or index)
DataDirectory& data_directory(DATA_DIRECTORY index);
const DataDirectory& data_directory(DATA_DIRECTORY index) const;
bool has(DATA_DIRECTORY index) const;
//! @brief Return the debug_entries_t object
//! Return the debug_entries_t object
debug_entries_t& debug(void);
const debug_entries_t& debug(void) const;
//! @brief Retrun the LoadConfiguration object
//! Retrun the LoadConfiguration object
const LoadConfiguration& load_configuration(void) const;
LoadConfiguration& load_configuration(void);
@ -245,7 +246,7 @@ class LIEF_API Binary : public LIEF::Binary {
// Overlay
// =======
//! @brief Return the overlay content
//! Return the overlay content
const std::vector<uint8_t>& overlay(void) const;
std::vector<uint8_t>& overlay(void);
@ -253,61 +254,61 @@ class LIEF_API Binary : public LIEF::Binary {
// DOS Stub
// ========
//! @brief Return the DOS stub content
//! Return the DOS stub content
const std::vector<uint8_t>& dos_stub(void) const;
std::vector<uint8_t>& dos_stub(void);
//! @brief Update the DOS stub content
//! Update the DOS stub content
void dos_stub(const std::vector<uint8_t>& content);
// Rich Header
// -----------
//! @brief Return a reference to the RichHeader object
//! Return a reference to the RichHeader object
RichHeader& rich_header(void);
const RichHeader& rich_header(void) const;
//! @brief Set a RichHeader object in the current Binary
//! Set a RichHeader object in the current Binary
void rich_header(const RichHeader& rich_header);
//! @brief Check if the current binary has a RichHeader object
//! Check if the current binary has a RichHeader object
bool has_rich_header(void) const;
// =========================
// Methods to manage Imports
// =========================
//! @brief return binary's @link PE::Import imports @endlink
//! return binary's @link PE::Import imports @endlink
it_imports imports(void);
it_const_imports imports(void) const;
//! @brief Returns the PE::Import from the given name
//! Returns the PE::Import from the given name
//!
//! @param[in] import_name Name of the import
Import& get_import(const std::string& import_name);
const Import& get_import(const std::string& import_name) const;
//! @brief ``True`` if the binary import the given library name
//! ``True`` if the binary import the given library name
//!
//! @param[in] import_name Name of the import
bool has_import(const std::string& import_name) const;
//! @brief Add the function @p function of the library @p library
//! Add the function @p function of the library @p library
//!
//! @param[in] library library name of the function
//! @param[in] function function's name from the library to import
ImportEntry& add_import_function(const std::string& library, const std::string& function);
//! @brief add an imported library (i.e. `DLL`) to the binary
//! add an imported library (i.e. `DLL`) to the binary
Import& add_library(const std::string& name);
//! @brief Remove the library with the given `name`
//! Remove the library with the given `name`
void remove_library(const std::string& name);
//! @brief Remove all libraries in the binary
//! Remove all libraries in the binary
void remove_all_libraries(void);
//! @brief Hook an imported function
//! Hook an imported function
//!
//! When using this function, LIEF::PE::Builder::build_imports and LIEF::PE::Builder::patch_imports
//! should be set to ``true``
@ -317,7 +318,7 @@ class LIEF_API Binary : public LIEF::Binary {
void hook_function(const std::string& function, uint64_t address);
//! @brief Hook an imported function
//! Hook an imported function
//!
//! When using this function, LIEF::PE::Builder::build_imports(true) and LIEF::PE::Builder::patch_imports
//! should be set to ``true``
@ -327,7 +328,7 @@ class LIEF_API Binary : public LIEF::Binary {
//! @param[in] address Address of the hook
void hook_function(const std::string& library, const std::string& function, uint64_t address);
//! @brief Reconstruct the binary object and write it in `filename`
//! Reconstruct the binary object and write it in `filename`
//!
//! Rebuild a PE binary from the current Binary object.
//! When rebuilding, import table and relocations are not rebuilt.
@ -339,7 +340,7 @@ class LIEF_API Binary : public LIEF::Binary {
// LIEF Interface
// ==============
//! @brief Patch the content at virtual address @p address with @p patch_value
//! Patch the content at virtual address @p address with @p patch_value
//!
//! @param[in] address Address to patch
//! @param[in] patch_value Patch to apply
@ -347,7 +348,7 @@ class LIEF_API Binary : public LIEF::Binary {
virtual 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;
//! @brief Patch the address with the given value
//! Patch the address with the given value
//!
//! @param[in] address Address to patch
//! @param[in] patch_value Patch to apply
@ -355,7 +356,7 @@ class LIEF_API Binary : public LIEF::Binary {
//! @param[in] addr_type Type of the Virtual address: VA or RVA. Default: Auto
virtual 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;
//! @brief Return the content located at virtual address
//! Return the content located at virtual address
//
//! @param[in] virtual_address Virtual address of the data to retrieve
//! @param[in] size Size in bytes of the data to retrieve
@ -363,13 +364,13 @@ class LIEF_API Binary : public LIEF::Binary {
virtual std::vector<uint8_t> get_content_from_virtual_address(uint64_t virtual_address, uint64_t size,
LIEF::Binary::VA_TYPES addr_type = LIEF::Binary::VA_TYPES::AUTO) const override;
//! @brief Return the binary's entrypoint
//! Return the binary's entrypoint
virtual uint64_t entrypoint(void) const override;
//! @brief Check if the binary is position independent
//! Check if the binary is position independent
virtual bool is_pie(void) const override;
//! @brief Check if the binary uses ``NX`` protection
//! Check if the binary uses ``NX`` protection
virtual bool has_nx(void) const override;
virtual LIEF::Binary::functions_t ctor_functions(void) const override;
@ -388,16 +389,16 @@ class LIEF_API Binary : public LIEF::Binary {
private:
Binary(void);
//! @brief Make space between the last section header and the beginning of the
//! Make space between the last section header and the beginning of the
//! content of first section
void make_space_for_new_section(void);
//! @brief Return binary's symbols as LIEF::Symbol
//! Return binary's symbols as LIEF::Symbol
virtual LIEF::symbols_t get_abstract_symbols(void) override;
virtual LIEF::Header get_abstract_header(void) const override;
//! @brief Return binary's section as LIEF::Section
//! Return binary's section as LIEF::Section
virtual LIEF::sections_t get_abstract_sections(void) override;
virtual LIEF::relocations_t get_abstract_relocations(void) override;

@ -31,7 +31,7 @@ namespace PE {
class ResourcesManager;
//! @brief It's basically a map of key/value
//! It's basically a map of key/value
//!
//! @see LIEF::PE::ResourceStringFileInfo
//!
@ -48,26 +48,26 @@ class LIEF_API LangCodeItem : public Object {
LangCodeItem& operator=(const LangCodeItem&);
virtual ~LangCodeItem(void);
//! @brief The type of data in the version resource
//! The type of data in the version resource
//! * ``1`` if it contains text data
//! * ``0`` if it contains binary data
uint16_t type(void) const;
//! @brief A 8-digit hexadecimal number stored as an Unicode string.
//! A 8-digit hexadecimal number stored as an Unicode string.
//! * The four most significant digits represent the language identifier.
//! * The four least significant digits represent the code page for which the data is formatted.
//!
//! @see LangCodeItem::code_page, LangCodeItem::lang, LangCodeItem::sublang
const std::u16string& key(void) const;
//! @brief @link https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx Code page @endlink
//! for which @link LangCodeItem::items items @endlink are defined
//! [Code page](https://msdn.microsoft.com/en-us/library/windows/desktop/dd317756.aspx)
//! for which LangCodeItem::items are defined
CODE_PAGES code_page(void) const;
//! @brief Lang for which @link LangCodeItem::items items @endlink are defined
//! Lang for which LangCodeItem::items are defined
RESOURCE_LANGS lang(void) const;
//! @brief Sublang for which @link LangCodeItem::items items @endlink are defined
//! Sublang for which LangCodeItem::items are defined
RESOURCE_SUBLANGS sublang(void) const;
const items_t& items(void) const;

@ -27,7 +27,7 @@
namespace LIEF {
namespace PE {
//! @brief Modelization of the @link VS_FIXEDFILEINFO https://msdn.microsoft.com/en-us/library/windows/desktop/ms646997(v=vs.85).aspx @endlink
//! Modelization of [VS_FIXEDFILEINFO](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646997.aspx)
//! Structure
class LIEF_API ResourceFixedFileInfo : public Object {
@ -39,57 +39,57 @@ class LIEF_API ResourceFixedFileInfo : public Object {
ResourceFixedFileInfo& operator=(const ResourceFixedFileInfo&);
virtual ~ResourceFixedFileInfo(void);
//! @brief Contains the value ``0xFEEF04BD``
//! Contains the value ``0xFEEF04BD``
uint32_t signature(void) const;
//! @brief The binary version number of this structure.
//! The binary version number of this structure.
//!
//! The high-order word of this member contains the major version number,
//! and the low-order word contains the minor version number.
uint32_t struct_version(void) const;
//! @brief The **most** significant 32 bits of the file's binary version number.
//! The **most** significant 32 bits of the file's binary version number.
//!
//! This member is used with ResourceFixedFileInfo::file_version_LS to form a 64-bits value used for numeric comparisons.
uint32_t file_version_MS(void) const;
//! @brief The **least** significant 32 bits of the file's binary version number.
//! The **least** significant 32 bits of the file's binary version number.
//!
//! This member is used with ResourceFixedFileInfo::file_version_MS to form a 64-bits value used for numeric comparisons.
uint32_t file_version_LS(void) const;
//! @brief The **most** significant 32 bits of the product with which this file was distributed
//! The **most** significant 32 bits of the product with which this file was distributed
//!
//! This member is used with ResourceFixedFileInfo::product_version_LS to form a 64-bits value used for numeric comparisons.
uint32_t product_version_MS(void) const;
//! @brief The **least** significant 32 bits of the product with which this file was distributed
//! The **least** significant 32 bits of the product with which this file was distributed
//!
//! This member is used with ResourceFixedFileInfo::product_version_MS to form a 64-bits value used for numeric comparisons.
uint32_t product_version_LS(void) const;
//! @brief Contains a bitmask that specifies the valid bits in ResourceFixedFileInfo::file_flags.
//! Contains a bitmask that specifies the valid bits in ResourceFixedFileInfo::file_flags.
//!
//! A bit is valid only if it was defined when the file was created.
uint32_t file_flags_mask(void) const;
//! @brief Contains a bitmask that specifies the Boolean attributes of the file
//! Contains a bitmask that specifies the Boolean attributes of the file
//! (PE::FIXED_VERSION_FILE_FLAGS)
uint32_t file_flags(void) const;
//! @brief The operating system for which this file was designed (PE::FIXED_VERSION_OS).
//! The operating system for which this file was designed (PE::FIXED_VERSION_OS).
FIXED_VERSION_OS file_os(void) const;
//! @brief The general type of file (PE::FIXED_VERSION_FILE_TYPES)
//! The general type of file (PE::FIXED_VERSION_FILE_TYPES)
FIXED_VERSION_FILE_TYPES file_type(void) const;
//! @brief The function of the file (PE::FIXED_VERSION_FILE_SUB_TYPES)
//! The function of the file (PE::FIXED_VERSION_FILE_SUB_TYPES)
FIXED_VERSION_FILE_SUB_TYPES file_subtype(void) const;
//! @brief The **most** significant 32 bits of the file's 64-bit binary creation date and time stamp.
//! The **most** significant 32 bits of the file's 64-bit binary creation date and time stamp.
uint32_t file_date_MS(void) const;
//! @brief The **least** significant 32 bits of the file's 64-bit binary creation date and time stamp.
//! The **least** significant 32 bits of the file's 64-bit binary creation date and time stamp.
uint32_t file_date_LS(void) const;
void signature(uint32_t signature);

@ -27,19 +27,19 @@ namespace PE {
class Binary;
class Import;
//! @brief check if the `file` is a PE file
//! check if the `file` is a PE file
LIEF_API bool is_pe(const std::string& file);
//! @brief check if the raw data is a PE file
//! check if the raw data is a PE file
LIEF_API bool is_pe(const std::vector<uint8_t>& raw);
//! @brief if the input `file` is a PE one, return `PE32` or `PE32+`
//! if the input `file` is a PE one, return `PE32` or `PE32+`
LIEF_API PE_TYPE get_type(const std::string& file);
//! @brief Return `PE32` or `PE32+`
//! Return `PE32` or `PE32+`
LIEF_API PE_TYPE get_type(const std::vector<uint8_t>& raw);
//! @brief Compute the hash of imported functions
//! Compute the hash of imported functions
//!
//! Properties of the hash generated:
//! * Order agnostic
@ -51,7 +51,7 @@ LIEF_API PE_TYPE get_type(const std::vector<uint8_t>& raw);
//! @see https://www.fireeye.com/blog/threat-research/2014/01/tracking-malware-import-hashing.html
LIEF_API std::string get_imphash(const Binary& binary);
//! @brief Take a PE::Import as entry and try to resolve imports
//! Take a PE::Import as entry and try to resolve imports
//! by ordinal.
//!
//! The ``strict`` boolean parameter enables to throw an LIEF::not_found exception
@ -59,7 +59,8 @@ LIEF_API std::string get_imphash(const Binary& binary);
//!
//! @param[in] import Import to resolve
//! @param[in] strict If set to ``true``, throw an exception if the import can't be resolved
//! @param[out] Import The import resolved: PE::ImportEntry::name is set
//!
//! @return The PE::import resolved with PE::ImportEntry::name set
LIEF_API Import resolve_ordinals(const Import& import, bool strict=false);
}
}

@ -24,6 +24,7 @@
#include <functional>
#include <algorithm>
#include <type_traits>
#include <vector>
#include "LIEF/exception.hpp"
@ -42,9 +43,7 @@ template< class T >
using add_lvalue_reference_t = typename std::add_lvalue_reference<T>::type;
// Iterator which return ref on container's values
// ===============================================
//! Iterator which returns reference on container's values
template<class T, class ITERATOR_T = typename decay_t<T>::iterator>
class ref_iterator : public std::iterator<
std::bidirectional_iterator_tag,
@ -136,14 +135,14 @@ class ref_iterator : public std::iterator<
ref_iterator* no_const_this = const_cast<ref_iterator*>(this);
typename ref_iterator::difference_type saved_dist = std::distance(std::begin(no_const_this->container_), no_const_this->it_);
typename ref_iterator::difference_type saved_dist = std::distance(std::begin(no_const_this->container_), no_const_this->it_);
no_const_this->it_ = std::begin(no_const_this->container_);
std::advance(no_const_this->it_, n);
std::advance(no_const_this->it_, n);
auto&& v = const_cast<add_const_t<ref_t>>(no_const_this->operator*());
no_const_this->it_ = std::begin(no_const_this->container_);
std::advance(no_const_this->it_, saved_dist);
no_const_this->it_ = std::begin(no_const_this->container_);
std::advance(no_const_this->it_, saved_dist);
return v;
}
@ -250,15 +249,12 @@ class ref_iterator : public std::iterator<
};
// Iterator which return const ref on container's values
// =====================================================
//! Iterator which return const ref on container's values
template<class T, class CT = typename std::add_const<T>::type>
using const_ref_iterator = ref_iterator<CT, typename decay_t<CT>::const_iterator>;
// Iterator which return a ref on container's values given predicates
// ==================================================================
//! Iterator which return a ref on container's values given predicates
template<class T, class ITERATOR_T = typename decay_t<T>::iterator>
class filter_iterator : public std::iterator<
std::forward_iterator_tag,
@ -480,13 +476,10 @@ class filter_iterator : public std::iterator<
typename filter_iterator::difference_type distance_;
};
// Iterator which return a const ref on container's values given predicates
// ========================================================================
//! Iterator which return a const ref on container's values given predicates
template<class T, class CT = typename std::add_const<T>::type>
using const_filter_iterator = filter_iterator<CT, typename decay_t<CT>::const_iterator>;
}
#endif