Arion 1.0.2-alpha
A high-performance C++ framework for emulating executable binaries.
 
Loading...
Searching...
No Matches
arion::CodeTraceReader Class Reference

This class is used to read and parse an execution trace generated by an arion::CodeTracer instance. More...

#include <code_trace_analysis.hpp>

Public Member Functions

 CodeTraceReader (std::string trace_path)
 
std::unique_ptr< CODE_HITcurr_hit ()
 
std::unique_ptr< CODE_HITnext_hit ()
 
std::unique_ptr< CODE_HITnext_mod_hit (uint16_t mod_id)
 
std::unique_ptr< CODE_HITreach_addr (ADDR addr)
 
std::unique_ptr< CODE_HITreach_off (uint16_t mod_id, uint32_t off)
 
off_t get_hit_index ()
 
void set_hit_index (off_t hit_i)
 
void reset_hit_cursor ()
 
TRACE_MODE get_mode ()
 
std::unique_ptr< TRACE_MODULEget_module (uint16_t mod_id)
 
std::unique_ptr< TRACE_MODULEfind_module_from_name (std::string name)
 
std::unique_ptr< TRACE_MODULEfind_module_from_hash (std::string hash)
 
bool has_reg (REG reg)
 

Private Member Functions

void read_header ()
 
void read_sections_table ()
 
void read_modules_section ()
 
void read_regs_section ()
 
void prepare_file ()
 

Private Attributes

std::string trace_path
 Path to the trace file.
 
std::ifstream trace_f
 Stream instance for the trace file.
 
size_t trace_f_sz
 Size in bytes of the trace file.
 
float version
 Version of the trace file.
 
TRACE_MODE mode
 The TRACE_MODE used to generate the trace file.
 
size_t total_hits
 Amount of hits (e.g : instructions, basic blocks...) in the trace file.
 
std::vector< REGctxt_regs
 List of registers making up the context for TRACE_MODE::CTXT traces.
 
off_t secs_table_off
 Offset in bytes to the sections table of the trace file.
 
off_t mod_sec_off
 Offset in bytes to the modules section of the trace file.
 
off_t regs_sec_off
 Offset in bytes to the registers section of the trace file.
 
off_t data_sec_off
 Offset in bytes to the data section of the trace file.
 
off_t hit_i
 Current hit index.
 
std::map< uint16_t, std::unique_ptr< TRACE_MODULE > > modules
 Map of modules in the trace file, given their id.
 

Detailed Description

This class is used to read and parse an execution trace generated by an arion::CodeTracer instance.

Constructor & Destructor Documentation

◆ CodeTraceReader()

arion::CodeTraceReader::CodeTraceReader ( std::string  trace_path)

Builder for CodeTraceReader instances.

Parameters
[in]trace_pathPath to the trace file.

Member Function Documentation

◆ curr_hit()

std::unique_ptr< CODE_HIT > arion::CodeTraceReader::curr_hit ( )

Retrieves the current hit being parsed.

Returns
The current hit being parsed.

◆ find_module_from_hash()

std::unique_ptr< TRACE_MODULE > arion::CodeTraceReader::find_module_from_hash ( std::string  hash)

Retrieves a TRACE_MODULE given its hash.

Parameters
[in]hashHash of the module to be retrieved.
Returns
The TRACE_MODULE instance.

◆ find_module_from_name()

std::unique_ptr< TRACE_MODULE > arion::CodeTraceReader::find_module_from_name ( std::string  name)

Retrieves a TRACE_MODULE given its name.

Parameters
[in]nameName of the module to be retrieved.
Returns
The TRACE_MODULE instance.

◆ get_hit_index()

off_t arion::CodeTraceReader::get_hit_index ( )

Retrieves the current hit index.

Returns
The current hit index.

◆ get_mode()

TRACE_MODE arion::CodeTraceReader::get_mode ( )

Retrieves the TRACE_MODE used to generate the trace file.

Returns
The TRACE_MODE used to generate the trace file.

◆ get_module()

std::unique_ptr< TRACE_MODULE > arion::CodeTraceReader::get_module ( uint16_t  mod_id)

Retrieves a TRACE_MODULE given its ID.

Parameters
[in]mod_idID of the module to be retrieved.
Returns
The TRACE_MODULE instance.

◆ has_reg()

bool arion::CodeTraceReader::has_reg ( REG  reg)

Checks whether the trace file contains the given context register. Only makes sense for files generated with TRACE_MODE::CTXT.

Parameters
[in]regThe register to be checked.
Returns
True if the trace file contains the given context register.

◆ next_hit()

std::unique_ptr< CODE_HIT > arion::CodeTraceReader::next_hit ( )

Retrieves the next hit to be parsed.

Returns
The next hit to be parsed.

◆ next_mod_hit()

std::unique_ptr< CODE_HIT > arion::CodeTraceReader::next_mod_hit ( uint16_t  mod_id)

Retrieves the next hit in the given module to be parsed.

Parameters
[in]mod_idID of the module to find next hit from.
Returns
The next hit in the given module to be parsed.

◆ prepare_file()

void arion::CodeTraceReader::prepare_file ( )
private

Prepares the parser to read the data section containing all the hits.

◆ reach_addr()

std::unique_ptr< CODE_HIT > arion::CodeTraceReader::reach_addr ( ADDR  addr)

Tells the reader to advance until it reaches a given PC address in a hit.

Parameters
[in]addrThe address to reach.
Returns
The hit containing the given PC address.

◆ reach_off()

std::unique_ptr< CODE_HIT > arion::CodeTraceReader::reach_off ( uint16_t  mod_id,
uint32_t  off 
)

Tells the reader to advance until it reaches a given PC offset from a module start in a hit.

Parameters
[in]mod_idID of the module to compute offset from.
[in]offThe offset to reach.
Returns
The hit containing the given PC offset.

◆ read_header()

void arion::CodeTraceReader::read_header ( )
private

Reads and parses the header section of the trace file.

◆ read_modules_section()

void arion::CodeTraceReader::read_modules_section ( )
private

Reads and parses the modules section of the trace file.

◆ read_regs_section()

void arion::CodeTraceReader::read_regs_section ( )
private

Reads and parses the registers section of the trace file.

◆ read_sections_table()

void arion::CodeTraceReader::read_sections_table ( )
private

Reads and parses the sections table of the trace file.

◆ reset_hit_cursor()

void arion::CodeTraceReader::reset_hit_cursor ( )

Resets the reading cursor in the input trace file.

◆ set_hit_index()

void arion::CodeTraceReader::set_hit_index ( off_t  hit_i)

Sets the current hit index to a new value.

Parameters
[in]hit_iThe new hit index.

Member Data Documentation

◆ ctxt_regs

std::vector<REG> arion::CodeTraceReader::ctxt_regs
private

List of registers making up the context for TRACE_MODE::CTXT traces.

◆ data_sec_off

off_t arion::CodeTraceReader::data_sec_off
private

Offset in bytes to the data section of the trace file.

◆ hit_i

off_t arion::CodeTraceReader::hit_i
private

Current hit index.

◆ mod_sec_off

off_t arion::CodeTraceReader::mod_sec_off
private

Offset in bytes to the modules section of the trace file.

◆ mode

TRACE_MODE arion::CodeTraceReader::mode
private

The TRACE_MODE used to generate the trace file.

◆ modules

std::map<uint16_t, std::unique_ptr<TRACE_MODULE> > arion::CodeTraceReader::modules
private

Map of modules in the trace file, given their id.

◆ regs_sec_off

off_t arion::CodeTraceReader::regs_sec_off
private

Offset in bytes to the registers section of the trace file.

◆ secs_table_off

off_t arion::CodeTraceReader::secs_table_off
private

Offset in bytes to the sections table of the trace file.

◆ total_hits

size_t arion::CodeTraceReader::total_hits
private

Amount of hits (e.g : instructions, basic blocks...) in the trace file.

◆ trace_f

std::ifstream arion::CodeTraceReader::trace_f
private

Stream instance for the trace file.

◆ trace_f_sz

size_t arion::CodeTraceReader::trace_f_sz
private

Size in bytes of the trace file.

◆ trace_path

std::string arion::CodeTraceReader::trace_path
private

Path to the trace file.

◆ version

float arion::CodeTraceReader::version
private

Version of the trace file.


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