16#ifndef LIEF_ABSTRACT_BINARY_H
17#define LIEF_ABSTRACT_BINARY_H
136 return original_size_;
154 std::vector<uint64_t>
xref(uint64_t address)
const;
162 virtual void patch_address(uint64_t address,
const std::vector<uint8_t>& patch_value,
163 VA_TYPES addr_type = VA_TYPES::AUTO) = 0;
171 virtual void patch_address(uint64_t address, uint64_t patch_value,
size_t size =
sizeof(uint64_t),
172 VA_TYPES addr_type = VA_TYPES::AUTO) = 0;
177 VA_TYPES addr_type = VA_TYPES::AUTO)
const = 0;
185 original_size_ = size;
206 virtual std::ostream&
print(std::ostream& os)
const;
209 virtual void write(
const std::string& name) = 0;
210 virtual void write(std::ostream& os) = 0;
230 FORMATS format_ = FORMATS::UNKNOWN;
231 mutable std::unique_ptr<DebugInfo> debug_info_;
232 uint64_t original_size_ = 0;
235 virtual Header get_abstract_header()
const = 0;
236 virtual symbols_t get_abstract_symbols() = 0;
237 virtual sections_t get_abstract_sections() = 0;
240 virtual functions_t get_abstract_exported_functions()
const = 0;
241 virtual functions_t get_abstract_imported_functions()
const = 0;
242 virtual std::vector<std::string> get_abstract_imported_libraries()
const = 0;
Abstract binary that exposes an uniform API for the different executable file formats.
Definition Abstract/Binary.hpp:41
Header header() const
Return the abstract header of the binary.
virtual void patch_address(uint64_t address, const std::vector< uint8_t > &patch_value, VA_TYPES addr_type=VA_TYPES::AUTO)=0
Patch the content at virtual address address with patch_value.
std::vector< Function > functions_t
Definition Abstract/Binary.hpp:59
functions_t imported_functions() const
Return functions imported by the binary.
virtual uint64_t entrypoint() const =0
Binary's entrypoint (if any)
FORMATS
Definition Abstract/Binary.hpp:51
@ ELF
Definition Abstract/Binary.hpp:53
@ OAT
Definition Abstract/Binary.hpp:56
@ PE
Definition Abstract/Binary.hpp:54
@ MACHO
Definition Abstract/Binary.hpp:55
virtual result< uint64_t > offset_to_virtual_address(uint64_t offset, uint64_t slide=0) const =0
Convert the given offset into a virtual address.
bool has_symbol(const std::string &name) const
Check if a Symbol with the given name exists.
const Symbol * get_symbol(const std::string &name) const
Return the Symbol with the given name If the symbol does not exist, return a nullptr.
Symbol * get_symbol(const std::string &name)
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:98
friend std::ostream & operator<<(std::ostream &os, const Binary &binary)
it_const_sections sections() const
virtual void remove_section(const std::string &name, bool clear=false)=0
Remove all the sections in the underlying binary.
it_relocations relocations()
Return an iterator over the binary relocation (LIEF::Relocation)
virtual void write(const std::string &name)=0
Build & transform the Binary object representation into a real executable.
it_const_symbols symbols() const
Return an iterator over the abstracted symbols in which the elements can't be modified.
std::vector< Symbol * > symbols_t
Internal container.
Definition Abstract/Binary.hpp:71
void original_size(uint64_t size)
Change binary's original size.
Definition Abstract/Binary.hpp:184
VA_TYPES
Type of a virtual address.
Definition Abstract/Binary.hpp:45
std::vector< uint64_t > xref(uint64_t address) const
std::vector< Section * > sections_t
Internal container.
Definition Abstract/Binary.hpp:62
virtual bool is_pie() const =0
Check if the binary is position independent.
functions_t exported_functions() const
Return the functions exported by the binary.
virtual span< const uint8_t > get_content_from_virtual_address(uint64_t virtual_address, uint64_t size, VA_TYPES addr_type=VA_TYPES::AUTO) const =0
Return the content located at the given virtual address.
virtual std::ostream & print(std::ostream &os) const
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
Patch the address with the given value.
it_symbols symbols()
Return an iterator over the abstracted symbols in which the elements can be modified.
virtual result< uint64_t > get_function_address(const std::string &func_name) const
Return the address of the given function name.
it_sections sections()
Return an iterator over the binary's sections (LIEF::Section)
virtual functions_t ctor_functions() const =0
Constructor functions that are called prior any other functions.
Binary & operator=(const Binary &)=delete
virtual uint64_t imagebase() const =0
Default image base address if the ASLR is not enabled.
std::vector< std::string > imported_libraries() const
Return libraries which are imported by the binary.
DebugInfo * debug_info() const
Return the debug info if present. It can be either a LIEF::dwarf::DebugInfo or a LIEF::pdb::DebugInfo...
uint64_t original_size() const
Binary's original size.
Definition Abstract/Binary.hpp:135
void accept(Visitor &visitor) const override
Method so that a visitor can visit us.
it_const_relocations relocations() const
std::vector< Relocation * > relocations_t
Internal container.
Definition Abstract/Binary.hpp:80
Binary(const Binary &)=delete
virtual void write(std::ostream &os)=0
virtual bool has_nx() const =0
Check if the binary uses NX protection.
Definition Abstract/DebugInfo.hpp:24
Class which represents an abstracted Relocation.
Definition Abstract/Relocation.hpp:27
Class which represents an abstracted section.
Definition Abstract/Section.hpp:29
This class represents a symbol in an executable format.
Definition Abstract/Symbol.hpp:28
Definition Visitor.hpp:224
Iterator which returns reference on container's values.
Definition iterators.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:32
tcb::span< ElementType, Extent > span
Definition span.hpp:22
const char * to_string(Binary::VA_TYPES e)
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:74
#define LIEF_API
Definition visibility.h:41