LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
LIEF::COFF::Binary Class Reference

Class that represents a COFF Binary. More...

#include <Binary.hpp>

Public Types

using sections_t = std::vector<std::unique_ptr<Section>>
 Internal container used to store COFF's section.
 
using it_sections = ref_iterator<sections_t&, Section*>
 Iterator that outputs Section& object.
 
using it_const_sections = const_ref_iterator<const sections_t&, const Section*>
 Iterator that outputs const Section& object.
 
using relocations_t = std::vector<std::unique_ptr<Relocation>>
 Internal container used to store COFF's relocations.
 
using it_relocations = ref_iterator<relocations_t&, Relocation*>
 Iterator that outputs Relocation& object.
 
using it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*>
 Iterator that outputs const Relocation& object.
 
using strings_table_t = std::vector<String>
 Internal container used to store COFF's strings.
 
using it_strings_table = ref_iterator<strings_table_t&>
 Iterator that outputs String& object.
 
using it_const_strings_table = const_ref_iterator<const strings_table_t&>
 Iterator that outputs const String& object.
 
using symbols_t = std::vector<std::unique_ptr<Symbol>>
 Internal container used to store COFF's symbols.
 
using it_symbols = ref_iterator<symbols_t&, Symbol*>
 Iterator that outputs Symbol& object.
 
using it_const_symbols = const_ref_iterator<const symbols_t&, const Symbol*>
 Iterator that outputs Symbol& object.
 
using instructions_it = iterator_range<assembly::Instruction::Iterator>
 Instruction iterator.
 
using it_functions = filter_iterator<symbols_t&, Symbol*>
 Iterator which outputs COFF symbols representing functions.
 
using it_const_function = const_filter_iterator<const symbols_t&, const Symbol*>
 Iterator which outputs COFF symbols representing functions.
 

Public Member Functions

const Headerheader () const
 The COFF header.
 
Headerheader ()
 
it_sections sections ()
 Iterator over the different sections located in this COFF binary.
 
it_const_sections sections () const
 
it_relocations relocations ()
 Iterator over all the relocations used by this COFF binary.
 
it_const_relocations relocations () const
 
it_symbols symbols ()
 Iterator over the COFF's symbols.
 
it_const_symbols symbols () const
 
it_const_strings_table string_table () const
 Iterator over the COFF's strings.
 
it_strings_table string_table ()
 
Stringfind_string (uint32_t offset)
 Try to find the COFF string at the given offset in the COFF string table.
 
const Stringfind_string (uint32_t offset) const
 
it_const_function functions () const
 Iterator over the functions implemented in this COFF.
 
it_functions functions ()
 
const Symbolfind_function (const std::string &name) const
 Try to find the function (symbol) with the given name.
 
Symbolfind_function (const std::string &name)
 
const Symbolfind_demangled_function (const std::string &name) const
 Try to find the function (symbol) with the given demangled name.
 
Symbolfind_demangled_function (const std::string &name)
 
instructions_it disassemble (const Symbol &symbol) const
 Disassemble code for the given symbol.
 
instructions_it disassemble (const std::string &symbol) const
 Disassemble code for the given symbol name.
 
instructions_it disassemble (const uint8_t *buffer, size_t size, uint64_t address=0) const
 Disassemble code provided by the given buffer at the specified address parameter.
 
instructions_it disassemble (const std::vector< uint8_t > &buffer, uint64_t address=0) const
 Disassemble code provided by the given vector of bytes at the specified address parameter.
 
instructions_it disassemble (LIEF::span< const uint8_t > buffer, uint64_t address=0) const
 
instructions_it disassemble (LIEF::span< uint8_t > buffer, uint64_t address=0) const
 
std::string to_string () const
 
 ~Binary ()
 

Detailed Description

Class that represents a COFF Binary.

Member Typedef Documentation

◆ instructions_it

◆ it_const_function

Iterator which outputs COFF symbols representing functions.

◆ it_const_relocations

Iterator that outputs const Relocation& object.

◆ it_const_sections

Iterator that outputs const Section& object.

◆ it_const_strings_table

Iterator that outputs const String& object.

◆ it_const_symbols

Iterator that outputs Symbol& object.

◆ it_functions

Iterator which outputs COFF symbols representing functions.

◆ it_relocations

◆ it_sections

Iterator that outputs Section& object.

◆ it_strings_table

Iterator that outputs String& object.

◆ it_symbols

Iterator that outputs Symbol& object.

◆ relocations_t

using LIEF::COFF::Binary::relocations_t = std::vector<std::unique_ptr<Relocation>>

Internal container used to store COFF's relocations.

◆ sections_t

using LIEF::COFF::Binary::sections_t = std::vector<std::unique_ptr<Section>>

Internal container used to store COFF's section.

◆ strings_table_t

Internal container used to store COFF's strings.

◆ symbols_t

using LIEF::COFF::Binary::symbols_t = std::vector<std::unique_ptr<Symbol>>

Internal container used to store COFF's symbols.

Constructor & Destructor Documentation

◆ ~Binary()

LIEF::COFF::Binary::~Binary ( )

Member Function Documentation

◆ disassemble() [1/6]

instructions_it LIEF::COFF::Binary::disassemble ( const std::string & symbol) const

Disassemble code for the given symbol name.

auto insts = binary->disassemble("main");
for (std::unique_ptr<assembly::Instruction> inst : insts) {
std::cout << inst->to_string() << '\n';
}
See also
LIEF::assembly::Instruction

◆ disassemble() [2/6]

instructions_it LIEF::COFF::Binary::disassemble ( const std::vector< uint8_t > & buffer,
uint64_t address = 0 ) const
inline

Disassemble code provided by the given vector of bytes at the specified address parameter.

See also
LIEF::assembly::Instruction

◆ disassemble() [3/6]

instructions_it LIEF::COFF::Binary::disassemble ( const Symbol & symbol) const

Disassemble code for the given symbol.

const Symbol* func = binary->find_demangled_function("int __cdecl my_function(int, int)");
auto insts = binary->disassemble(*func);
for (std::unique_ptr<assembly::Instruction> inst : insts) {
std::cout << inst->to_string() << '\n';
}
See also
LIEF::assembly::Instruction

◆ disassemble() [4/6]

instructions_it LIEF::COFF::Binary::disassemble ( const uint8_t * buffer,
size_t size,
uint64_t address = 0 ) const

Disassemble code provided by the given buffer at the specified address parameter.

See also
LIEF::assembly::Instruction

◆ disassemble() [5/6]

instructions_it LIEF::COFF::Binary::disassemble ( LIEF::span< const uint8_t > buffer,
uint64_t address = 0 ) const
inline

◆ disassemble() [6/6]

instructions_it LIEF::COFF::Binary::disassemble ( LIEF::span< uint8_t > buffer,
uint64_t address = 0 ) const
inline

◆ find_demangled_function() [1/2]

Symbol * LIEF::COFF::Binary::find_demangled_function ( const std::string & name)
inline

◆ find_demangled_function() [2/2]

const Symbol * LIEF::COFF::Binary::find_demangled_function ( const std::string & name) const

Try to find the function (symbol) with the given demangled name.

◆ find_function() [1/2]

Symbol * LIEF::COFF::Binary::find_function ( const std::string & name)
inline

◆ find_function() [2/2]

const Symbol * LIEF::COFF::Binary::find_function ( const std::string & name) const

Try to find the function (symbol) with the given name.

◆ find_string() [1/2]

String * LIEF::COFF::Binary::find_string ( uint32_t offset)
inline

Try to find the COFF string at the given offset in the COFF string table.

Warning
This offset must include the first 4 bytes holding the size of the table. Hence, the first string starts a the offset 4.

◆ find_string() [2/2]

const String * LIEF::COFF::Binary::find_string ( uint32_t offset) const
inline

◆ functions() [1/2]

it_functions LIEF::COFF::Binary::functions ( )

◆ functions() [2/2]

it_const_function LIEF::COFF::Binary::functions ( ) const

Iterator over the functions implemented in this COFF.

◆ header() [1/2]

Header & LIEF::COFF::Binary::header ( )
inline

◆ header() [2/2]

const Header & LIEF::COFF::Binary::header ( ) const
inline

The COFF header.

◆ relocations() [1/2]

it_relocations LIEF::COFF::Binary::relocations ( )
inline

Iterator over all the relocations used by this COFF binary.

◆ relocations() [2/2]

it_const_relocations LIEF::COFF::Binary::relocations ( ) const
inline

◆ sections() [1/2]

it_sections LIEF::COFF::Binary::sections ( )
inline

Iterator over the different sections located in this COFF binary.

◆ sections() [2/2]

it_const_sections LIEF::COFF::Binary::sections ( ) const
inline

◆ string_table() [1/2]

it_strings_table LIEF::COFF::Binary::string_table ( )
inline

◆ string_table() [2/2]

it_const_strings_table LIEF::COFF::Binary::string_table ( ) const
inline

Iterator over the COFF's strings.

◆ symbols() [1/2]

it_symbols LIEF::COFF::Binary::symbols ( )
inline

Iterator over the COFF's symbols.

◆ symbols() [2/2]

it_const_symbols LIEF::COFF::Binary::symbols ( ) const
inline

◆ to_string()

std::string LIEF::COFF::Binary::to_string ( ) const

Referenced by operator<<.


The documentation for this class was generated from the following file: