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

#include <arch_manager.hpp>

Inheritance diagram for arion::ArchManager:
arion_arm64::ArchManagerARM64 arion_arm::ArchManagerARM arion_x86::ArchManagerX86 arion_x86_64::ArchManagerX8664 arion_lnx_arm64::ArchManagerLinuxARM64 arion_lnx_arm::ArchManagerLinuxARM arion_lnx_x86::ArchManagerLinuxX86 arion_lnx_x86_64::ArchManagerLinuxX8664

Public Member Functions

virtual ~ArchManager ()=default
 
std::shared_ptr< ARCH_ATTRIBUTESget_attrs ()
 
bool does_hook_intr ()
 
std::string get_name_by_syscall_no (uint64_t syscall_no)
 
bool has_syscall_with_name (std::string name)
 
uint64_t get_syscall_no_by_name (std::string name)
 
std::vector< REGget_context_regs ()
 
std::unique_ptr< std::map< REG, RVAL > > dump_regs ()
 
void load_regs (std::unique_ptr< std::map< REG, RVAL > > regs)
 
bool has_idt_entry (uint64_t intno)
 
CPU_INTR get_idt_entry (uint64_t intno)
 
std::unique_ptr< std::map< REG, RVAL > > init_thread_regs (ADDR pc, ADDR sp)
 
virtual ks_engine * curr_ks ()=0
 
virtual csh * curr_cs ()=0
 
virtual void setup ()=0
 
virtual ADDR dump_tls ()=0
 
virtual void load_tls (ADDR new_tls)=0
 
virtual void prerun_hook (ADDR &start)
 
template<typename T >
read_reg (REG reg)
 
template<typename T >
read_reg (std::string reg_name)
 
uint64_t read_arch_reg (REG reg)
 
template<typename T >
void write_reg (REG reg, T val)
 
template<typename T >
void write_reg (std::string reg_name, T val)
 
void write_arch_reg (REG reg, uint64_t val)
 

Static Public Member Functions

static std::unique_ptr< ArchManagerinitialize (std::weak_ptr< Arion > arion, CPU_ARCH arch, PLATFORM platform=PLATFORM::UNKNOWN_PLATFORM)
 
static int get_signal_from_intr (CPU_INTR intr)
 

Protected Member Functions

 ArchManager (std::shared_ptr< ARCH_ATTRIBUTES > attrs, std::map< std::string, REG > arch_regs, std::map< REG, uint8_t > arch_regs_sz, std::vector< REG > ctxt_regs, std::map< uint64_t, CPU_INTR > cpu_idt, bool hooks_intr)
 

Protected Attributes

std::weak_ptr< Arionarion
 The Arion instanced associated to this instance.
 
uc_engine * uc
 The Unicorn engine associated with this instance.
 
std::vector< ks_engine * > ks
 The Keystone engine associated with this instance.
 
std::vector< csh * > cs
 The Capstone engine associated with this instance.
 
std::shared_ptr< ARCH_ATTRIBUTESattrs
 Multiple architecture specific attributes, grouped in a structure for genericity purpose.
 
std::map< std::string, REGarch_regs
 Unicorn registers by their name.
 
std::map< REG, uint8_t > arch_regs_sz
 Unicorn registers sizes.
 
std::vector< REGctxt_regs
 Unicorn registers making up the context to save and restore.
 
std::map< uint64_t, CPU_INTRcpu_idt
 Interrupt Descriptor Table for the CPU.
 
bool hooks_intr
 True if the ArchManager subclass uses hook_intr to intercept syscalls.
 

Static Private Attributes

static std::map< CPU_INTR, int > signo_by_intr
 A map identifying a signal number given a cpu interruption.
 

Detailed Description

A class responsible for performing architecture specific operations. This class is abstract and its subclasses must implement a specific architecture.

Constructor & Destructor Documentation

◆ ArchManager()

arion::ArchManager::ArchManager ( std::shared_ptr< ARCH_ATTRIBUTES attrs,
std::map< std::string, REG arch_regs,
std::map< REG, uint8_t >  arch_regs_sz,
std::vector< REG ctxt_regs,
std::map< uint64_t, CPU_INTR cpu_idt,
bool  hooks_intr 
)
inlineprotected

Builder for ArchManager instances.

Parameters
[in]attrsMultiple architecture specific attributes, grouped in a structure for genericity purpose.
[in]arch_regsUnicorn registers by their name.
[in]arch_regs_szUnicorn registers sizes.
[in]ctxt_regsUnicorn registers making up the context to save and restore.
[in]InterruptDescriptor Table for the CPU.
[in]hooks_intrTrue if the ArchManager subclass uses hook_intr to detect syscalls.

◆ ~ArchManager()

virtual arion::ArchManager::~ArchManager ( )
virtualdefault

Member Function Documentation

◆ curr_cs()

virtual csh * arion::ArchManager::curr_cs ( )
pure virtual

Retrieves a Capstone engine associated with this instance, based on the current mode of the CPU.

Returns
The Capstone engine.

Implemented in arion_arm::ArchManagerARM, arion_arm64::ArchManagerARM64, arion_x86_64::ArchManagerX8664, and arion_x86::ArchManagerX86.

◆ curr_ks()

virtual ks_engine * arion::ArchManager::curr_ks ( )
pure virtual

Retrieves a Keystone engine associated with this instance, based on the current mode of the CPU.

Returns
The Keystone engine.

Implemented in arion_arm::ArchManagerARM, arion_arm64::ArchManagerARM64, arion_x86_64::ArchManagerX8664, and arion_x86::ArchManagerX86.

◆ does_hook_intr()

bool arion::ArchManager::does_hook_intr ( )

Checks whether the ArchManager subclass uses hook_intr to intercept syscalls.

Returns
True if the ArchManager subclass uses hook_intr to intercept syscalls.

◆ dump_regs()

std::unique_ptr< std::map< REG, RVAL > > arion::ArchManager::dump_regs ( )

During emulation, dumps values of registers making up the context inside a map.

Returns
A map identifying a value by its associated register.

◆ dump_tls()

virtual ADDR arion::ArchManager::dump_tls ( )
pure virtual

Retrieves the current Thread Local Storage (TLS) address from the emulation context.

Returns
The TLS address.

Implemented in arion_arm::ArchManagerARM, arion_arm64::ArchManagerARM64, arion_x86_64::ArchManagerX8664, and arion_x86::ArchManagerX86.

◆ get_attrs()

std::shared_ptr< ARCH_ATTRIBUTES > arion::ArchManager::get_attrs ( )

Retrieves the list of architecture specific attributes.

Returns
The list of architecture specific attributes.

◆ get_context_regs()

std::vector< REG > arion::ArchManager::get_context_regs ( )

Retrieves the list of registers making up the context to save and restore.

Returns
The list of registers.

◆ get_idt_entry()

CPU_INTR arion::ArchManager::get_idt_entry ( uint64_t  intno)

Retrieves a Arion Interrupt Descriptor Table value from an interrupt number.

Parameters
[in]intnoThe interrupt number.
Returns
The Arion IDT value.

◆ get_name_by_syscall_no()

std::string arion::ArchManager::get_name_by_syscall_no ( uint64_t  syscall_no)

Retrieves a syscall name by its number.

Parameters
[in]syscall_noThe syscall number.
Returns
The syscall name.

◆ get_signal_from_intr()

static int arion::ArchManager::get_signal_from_intr ( CPU_INTR  intr)
static

Retrieves a signal number from a CPU interrupt based on the Interrupt Descriptor Table for the architecture.

Parameters
[in]intrThe CPU interrupt.
Returns
The signal number.

◆ get_syscall_no_by_name()

uint64_t arion::ArchManager::get_syscall_no_by_name ( std::string  name)

Retrieves a syscall number by its name.

Parameters
[in]nameThe syscall name.
Returns
The syscall number.

◆ has_idt_entry()

bool arion::ArchManager::has_idt_entry ( uint64_t  intno)

Checks whether this CPU architecture has a given Interrupt Descriptor Table entry.

Parameters
[in]intnoThe interrupt number.
Returns
True if this CPU architecture has a given Interrupt Descriptor Table entry.

◆ has_syscall_with_name()

bool arion::ArchManager::has_syscall_with_name ( std::string  name)

Checks whether this architecture has a syscall with a given name.

Parameters
[in]nameThe syscall name.
Returns
True if this architecture has a syscall with a given name.

◆ init_thread_regs()

std::unique_ptr< std::map< REG, RVAL > > arion::ArchManager::init_thread_regs ( ADDR  pc,
ADDR  sp 
)

Initializes a map of values associated to registers, with a PC and SP value. This method is used when instanciating a new thread, where only these two registers are initialized.

Parameters
[in]pcThe Unicorn PC register.
[in]spThe Unicorn SP register.
Returns
The map of values associated to registers.

◆ initialize()

static std::unique_ptr< ArchManager > arion::ArchManager::initialize ( std::weak_ptr< Arion arion,
CPU_ARCH  arch,
PLATFORM  platform = PLATFORM::UNKNOWN_PLATFORM 
)
static

Instanciates and initializes new ArchManager objects with some parameters.

Parameters
[in]arionThe Arion instance associated with this instance.
[in]archArion CPU architecture.
[in]platformArion platform on which the emulation occurs.
Returns
A new ArchManager instance.

◆ load_regs()

void arion::ArchManager::load_regs ( std::unique_ptr< std::map< REG, RVAL > >  regs)

During emulation, loads values of registers making up the context from a map.

Parameters
[in]regsA map identifying a value by its associated register.

◆ load_tls()

virtual void arion::ArchManager::load_tls ( ADDR  new_tls)
pure virtual

Defines a Thread Local Storage (TLS) address to apply to the emulation.

Parameters
[in]new_tlsThe new TLS address.

Implemented in arion_arm::ArchManagerARM, arion_arm64::ArchManagerARM64, arion_x86_64::ArchManagerX8664, and arion_x86::ArchManagerX86.

◆ prerun_hook()

virtual void arion::ArchManager::prerun_hook ( ADDR start)
inlinevirtual

Performs architecture specific operations each time emulation starts.

Parameters
[in,out]startThe emulation start address.

Reimplemented in arion_arm::ArchManagerARM.

◆ read_arch_reg()

uint64_t arion::ArchManager::read_arch_reg ( REG  reg)

Reads a general-purpose register value from the CPU context during emulation. The result is casted on a 64-bit integer for convenience.

Parameters
[in]regThe Unicorn register.
Returns
The register value.

◆ read_reg() [1/2]

template<typename T >
T arion::ArchManager::read_reg ( REG  reg)
inline

Reads a register value from the CPU context during emulation.

Template Parameters
TA RVAL type large enough to store the register value.
Parameters
[in]regThe Unicorn register.
Returns
The register value.

◆ read_reg() [2/2]

template<typename T >
T arion::ArchManager::read_reg ( std::string  reg_name)
inline

Reads a register value from the CPU context during emulation.

Template Parameters
TA RVAL type large enough to store the register value.
Parameters
[in]regThe register name.
Returns
The register value.

◆ setup()

virtual void arion::ArchManager::setup ( )
pure virtual

◆ write_arch_reg()

void arion::ArchManager::write_arch_reg ( REG  reg,
uint64_t  val 
)

Writes a general-purpose register value to the CPU context during emulation. The new value is casted on a 64-bit integer for convenience.

Parameters
[in]regThe Unicorn register.
[in]valThe new register value.

◆ write_reg() [1/2]

template<typename T >
void arion::ArchManager::write_reg ( REG  reg,
val 
)
inline

Writes a register value to the CPU context during emulation.

Template Parameters
TA RVAL type large enough to store the register value.
Parameters
[in]regThe Unicorn register.
[in]valThe new register value.

◆ write_reg() [2/2]

template<typename T >
void arion::ArchManager::write_reg ( std::string  reg_name,
val 
)
inline

Writes a register value to the CPU context during emulation.

Template Parameters
TA RVAL type large enough to store the register value.
Parameters
[in]regThe register name.
[in]valThe new register value.

Member Data Documentation

◆ arch_regs

std::map<std::string, REG> arion::ArchManager::arch_regs
protected

Unicorn registers by their name.

◆ arch_regs_sz

std::map<REG, uint8_t> arion::ArchManager::arch_regs_sz
protected

Unicorn registers sizes.

◆ arion

std::weak_ptr<Arion> arion::ArchManager::arion
protected

The Arion instanced associated to this instance.

◆ attrs

std::shared_ptr<ARCH_ATTRIBUTES> arion::ArchManager::attrs
protected

Multiple architecture specific attributes, grouped in a structure for genericity purpose.

◆ cpu_idt

std::map<uint64_t, CPU_INTR> arion::ArchManager::cpu_idt
protected

Interrupt Descriptor Table for the CPU.

◆ cs

std::vector<csh *> arion::ArchManager::cs
protected

The Capstone engine associated with this instance.

◆ ctxt_regs

std::vector<REG> arion::ArchManager::ctxt_regs
protected

Unicorn registers making up the context to save and restore.

◆ hooks_intr

bool arion::ArchManager::hooks_intr
protected

True if the ArchManager subclass uses hook_intr to intercept syscalls.

◆ ks

std::vector<ks_engine *> arion::ArchManager::ks
protected

The Keystone engine associated with this instance.

◆ signo_by_intr

std::map<CPU_INTR, int> arion::ArchManager::signo_by_intr
staticprivate

A map identifying a signal number given a cpu interruption.

◆ uc

uc_engine* arion::ArchManager::uc
protected

The Unicorn engine associated with this instance.


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