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

This class is used to perform tracing operations over an Arion emulation and store the result in a dedicated file. More...

#include <code_tracer.hpp>

Public Member Functions

 CodeTracer (std::weak_ptr< Arion > arion)
 
 ~CodeTracer ()
 
void start (std::string out_f_path, TRACE_MODE mode)
 
void stop ()
 
void process_new_mapping (std::shared_ptr< ARION_MAPPING > mapping)
 
bool is_enabled ()
 
TRACE_MODE get_mode ()
 

Static Public Member Functions

static std::unique_ptr< CodeTracerinitialize (std::weak_ptr< Arion > arion)
 

Private Member Functions

void prepare_file ()
 
void release_file ()
 
void process_hit (ADDR addr, size_t sz)
 
void flush_hits ()
 

Static Private Member Functions

static void instr_hook (std::shared_ptr< Arion > arion, ADDR addr, size_t sz, void *user_data)
 
static void block_hook (std::shared_ptr< Arion > arion, ADDR addr, size_t sz, void *user_data)
 

Private Attributes

std::weak_ptr< Arionarion
 The Arion instance which emulation should be traced.
 
bool enabled = false
 True if the tracing is active.
 
TRACE_MODE mode
 Trace mode, conditions the output file.
 
HOOK_ID curr_hook_id
 
std::string out_f_path
 Path to the output trace file.
 
std::ofstream out_f
 Output stream of the output trace file.
 
size_t total_hits
 Total amount of hits to be stored in the output trace file.
 
off_t total_hits_off
 Offset in the output trace file to the total amount of hits.
 
off_t mod_sec_off
 Offset in the output trace file to the modules section.
 
std::vector< std::unique_ptr< CODE_HIT > > hits
 List of code hits (instructions or basic blocks) which have not yet been flushed in the output trace file.
 
std::vector< std::unique_ptr< TRACER_MAPPING > > mappings
 List of general data concerning memory mappings.
 

Detailed Description

This class is used to perform tracing operations over an Arion emulation and store the result in a dedicated file.

Constructor & Destructor Documentation

◆ CodeTracer()

arion::CodeTracer::CodeTracer ( std::weak_ptr< Arion arion)
inline

Builder for CodeTracer instances.

Parameters
[in]arionThe Arion instance which emulation should be traced.

◆ ~CodeTracer()

arion::CodeTracer::~CodeTracer ( )

Destructor for CodeTracer instances.

Member Function Documentation

◆ block_hook()

static void arion::CodeTracer::block_hook ( std::shared_ptr< Arion arion,
ADDR  addr,
size_t  sz,
void *  user_data 
)
staticprivate

This hook is triggered at every basic block. Of course it is disabled when every instructions are traced.

Parameters
[in]arionThe Arion instance that produced the block hit.
[in]addrThe address at which the block was hit.
[in]szThe size of the block that was hit.
[in]user_dataAdditional user data.

◆ flush_hits()

void arion::CodeTracer::flush_hits ( )
private

Flushes all hits in the "hits" vector into the output trace file.

◆ get_mode()

TRACE_MODE arion::CodeTracer::get_mode ( )

Retrieves the current tracing mode for this instance.

Returns
The tracing mode.

◆ initialize()

static std::unique_ptr< CodeTracer > arion::CodeTracer::initialize ( std::weak_ptr< Arion arion)
static

Instanciates and initializes new CodeTracer objects with some parameters.

Parameters
[in]arionThe Arion instance which emulation should be traced.
Returns
A new CodeTracer instance.

◆ instr_hook()

static void arion::CodeTracer::instr_hook ( std::shared_ptr< Arion arion,
ADDR  addr,
size_t  sz,
void *  user_data 
)
staticprivate

This hook is triggered at every instruction. Of course it is disabled when only basic blocks are traced.

Parameters
[in]arionThe Arion instance that produced the instruction hit.
[in]addrThe address at which the instruction was hit.
[in]szThe size of the instruction that was hit.
[in]user_dataAdditional user data.

◆ is_enabled()

bool arion::CodeTracer::is_enabled ( )

Checks whether the tracing is currently enabled in this instance.

Returns
True if the tracing is currently enabled in this instance.

◆ prepare_file()

void arion::CodeTracer::prepare_file ( )
private

Creates and initializes the output trace file with already known data.

◆ process_hit()

void arion::CodeTracer::process_hit ( ADDR  addr,
size_t  sz 
)
private

Called at every hit (instruction or basic block). Stores the hit in the "hits" vector and flushes the whole in the output trace file if necessary.

Parameters
[in]addrAddress of the hit.
[in]szSize of the hit. It can either be the size of the hit instruction or basic block depending on the used TRACE_MODE.

◆ process_new_mapping()

void arion::CodeTracer::process_new_mapping ( std::shared_ptr< ARION_MAPPING mapping)

Called every time a new memory region is mapped. Identifies if a new module is concerned and if so, stores its general data for later use.

Parameters
[in]mappingThe newly allocated memory mapping.

◆ release_file()

void arion::CodeTracer::release_file ( )
private

Writes remaining data in the output trace file and closes it.

◆ start()

void arion::CodeTracer::start ( std::string  out_f_path,
TRACE_MODE  mode 
)

Starts tracing the emulation of the associated Arion instance.

Parameters
[in]out_f_pathPath to the output trace file.
[in]modeTrace mode, conditions the output file.

◆ stop()

void arion::CodeTracer::stop ( )

Stops tracing the emulation of the associated Arion instance. Releases the output trace file.

Member Data Documentation

◆ arion

std::weak_ptr<Arion> arion::CodeTracer::arion
private

The Arion instance which emulation should be traced.

◆ curr_hook_id

HOOK_ID arion::CodeTracer::curr_hook_id
private

ID of the hook being triggered at every hit. The hits can either occur at every instruction or every basic block depending on the used TRACE_MODE.

◆ enabled

bool arion::CodeTracer::enabled = false
private

True if the tracing is active.

◆ hits

std::vector<std::unique_ptr<CODE_HIT> > arion::CodeTracer::hits
private

List of code hits (instructions or basic blocks) which have not yet been flushed in the output trace file.

◆ mappings

std::vector<std::unique_ptr<TRACER_MAPPING> > arion::CodeTracer::mappings
private

List of general data concerning memory mappings.

◆ mod_sec_off

off_t arion::CodeTracer::mod_sec_off
private

Offset in the output trace file to the modules section.

◆ mode

TRACE_MODE arion::CodeTracer::mode
private

Trace mode, conditions the output file.

◆ out_f

std::ofstream arion::CodeTracer::out_f
private

Output stream of the output trace file.

◆ out_f_path

std::string arion::CodeTracer::out_f_path
private

Path to the output trace file.

◆ total_hits

size_t arion::CodeTracer::total_hits
private

Total amount of hits to be stored in the output trace file.

◆ total_hits_off

off_t arion::CodeTracer::total_hits_off
private

Offset in the output trace file to the total amount of hits.


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