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

This class purpose is to manage user-defined Arion hooks including hook creation, deletion, trigger handling... More...

#include <hooks_manager.hpp>

Public Member Functions

 HooksManager (std::weak_ptr< Arion > arion)
 
 ~HooksManager ()
 
HOOK_ID hook_intr (U32_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_insn (NO_PARAM_HOOK_CALLBACK callback, uint64_t insn, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_code (ADDR_SZ_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_addr (ADDR_SZ_HOOK_CALLBACK callback, ADDR addr, void *user_data=nullptr)
 
HOOK_ID hook_block (ADDR_SZ_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_read_unmapped (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_write_unmapped (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_fetch_unmapped (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_read_prot (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_write_prot (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_fetch_prot (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_read (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_write (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_fetch (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_mem_read_after (MEM_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_insn_invalid (NO_PARAM_BOOL_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_edge_generated (EDGE_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_tcg_opcode (TCG_HOOK_CALLBACK callback, uint64_t aux1, uint64_t aux2, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_tlb_fill (TLB_HOOK_CALLBACK callback, ADDR start=0, ADDR end=ARION_MAX_U64, void *user_data=nullptr)
 
HOOK_ID hook_fork (PROCESS_HOOK_CALLBACK callback, void *user_data=nullptr)
 
HOOK_ID hook_execve (PROCESS_HOOK_CALLBACK callback, void *user_data=nullptr)
 
HOOK_ID hook_syscall (SYSCALL_HOOK_CALLBACK callback, void *user_data=nullptr)
 
void unhook (HOOK_ID hook_id)
 
void clear_hooks ()
 
template<typename... HookParams>
void trigger_arion_hook (ARION_HOOK_TYPE type, HookParams... params)
 

Static Public Member Functions

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

Private Member Functions

HOOK_ID gen_next_id ()
 
template<typename... UcParams>
HOOK_ID hook_uc (ARION_HOOK_TYPE type, HOOK_CALLBACK callback, void *user_data, ADDR start=0, ADDR end=ARION_MAX_U64, UcParams... uc_params)
 
HOOK_ID hook_arion (ARION_HOOK_TYPE type, HOOK_CALLBACK callback, void *user_data)
 

Private Attributes

std::weak_ptr< Arionarion
 The Arion instance associated with this instance.
 
uc_engine * uc
 The Unicorn engine associated with this instance.
 
HOOK_ID curr_id = 1
 ID of the next hook to be created.
 
std::map< HOOK_ID, std::shared_ptr< ARION_HOOK > > hooks
 A map identifying an Arion hook given its ID.
 
std::stack< HOOK_IDfree_hook_ids
 A stack of hook IDs that got deleted and that can be reused.
 

Detailed Description

This class purpose is to manage user-defined Arion hooks including hook creation, deletion, trigger handling...

Constructor & Destructor Documentation

◆ HooksManager()

arion::HooksManager::HooksManager ( std::weak_ptr< Arion arion)

Builder for HooksManager instances.

Parameters
[in]arionThe Arion instance associated with this instance.

◆ ~HooksManager()

arion::HooksManager::~HooksManager ( )

Destructor for HooksManager instances.

Member Function Documentation

◆ clear_hooks()

void arion::HooksManager::clear_hooks ( )

Deletes all Arion hooks, preventing them from being triggered.

◆ gen_next_id()

HOOK_ID arion::HooksManager::gen_next_id ( )
private

Generates a new hook ID.

Returns
The new ID.

◆ hook_addr()

HOOK_ID arion::HooksManager::hook_addr ( ADDR_SZ_HOOK_CALLBACK  callback,
ADDR  addr,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when execution reaches a specific address.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]addrExact memory address where the hook should trigger.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_arion()

HOOK_ID arion::HooksManager::hook_arion ( ARION_HOOK_TYPE  type,
HOOK_CALLBACK  callback,
void *  user_data 
)
private

Creates a new hook which is not related to the Unicorn engine.

Parameters
[in]typeArion type for the hook.
[in]callbackArion callback which gets called when the Unicorn hook is triggered.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_block()

HOOK_ID arion::HooksManager::hook_block ( ADDR_SZ_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered at the start of a new basic block or translation block (TB).

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address where the hook should trigger.
[in]endEnd memory address where the hook should trigger.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_code()

HOOK_ID arion::HooksManager::hook_code ( ADDR_SZ_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when code execution reaches a specified address or range.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address where the hook should trigger.
[in]endEnd memory address where the hook should trigger.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_edge_generated()

HOOK_ID arion::HooksManager::hook_edge_generated ( EDGE_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when a new control-flow edge (translation block to translation block) is generated.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_execve()

HOOK_ID arion::HooksManager::hook_execve ( PROCESS_HOOK_CALLBACK  callback,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when a process executes a new program (via execve()).

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_fork()

HOOK_ID arion::HooksManager::hook_fork ( PROCESS_HOOK_CALLBACK  callback,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when a process forks (via fork(), vfork(), or clone()).

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_insn()

HOOK_ID arion::HooksManager::hook_insn ( NO_PARAM_HOOK_CALLBACK  callback,
uint64_t  insn,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered before or after executing a specific instruction.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]insnInstruction identifier (architecture-specific).
[in]startStart memory address where the hook should trigger.
[in]endEnd memory address where the hook should trigger.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_insn_invalid()

HOOK_ID arion::HooksManager::hook_insn_invalid ( NO_PARAM_BOOL_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when an invalid or unimplemented instruction is encountered.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_intr()

HOOK_ID arion::HooksManager::hook_intr ( U32_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when an interrupt occurs (e.g., software or hardware interrupt).

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address where the hook should trigger.
[in]endEnd memory address where the hook should trigger.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_fetch()

HOOK_ID arion::HooksManager::hook_mem_fetch ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when fetching instructions from valid mapped memory.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_fetch_prot()

HOOK_ID arion::HooksManager::hook_mem_fetch_prot ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when fetching instructions from a protected region.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_fetch_unmapped()

HOOK_ID arion::HooksManager::hook_mem_fetch_unmapped ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when fetching instructions from an unmapped region.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_read()

HOOK_ID arion::HooksManager::hook_mem_read ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered on every valid memory read access.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_read_after()

HOOK_ID arion::HooksManager::hook_mem_read_after ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered after a memory read operation completes.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_read_prot()

HOOK_ID arion::HooksManager::hook_mem_read_prot ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered on a memory read violating protection flags.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_read_unmapped()

HOOK_ID arion::HooksManager::hook_mem_read_unmapped ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered on a memory read from an unmapped region.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_write()

HOOK_ID arion::HooksManager::hook_mem_write ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered on every valid memory write access.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_write_prot()

HOOK_ID arion::HooksManager::hook_mem_write_prot ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered on a memory write violating protection flags.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_mem_write_unmapped()

HOOK_ID arion::HooksManager::hook_mem_write_unmapped ( MEM_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered on a memory write to an unmapped region.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_syscall()

HOOK_ID arion::HooksManager::hook_syscall ( SYSCALL_HOOK_CALLBACK  callback,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when a system call is invoked.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_tcg_opcode()

HOOK_ID arion::HooksManager::hook_tcg_opcode ( TCG_HOOK_CALLBACK  callback,
uint64_t  aux1,
uint64_t  aux2,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered for each TCG opcode during translation or emulation.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]aux1Auxiliary value (architecture-specific argument 1).
[in]aux2Auxiliary value (architecture-specific argument 2).
[in]startStart memory address where the hook should trigger.
[in]endEnd memory address where the hook should trigger.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_tlb_fill()

HOOK_ID arion::HooksManager::hook_tlb_fill ( TLB_HOOK_CALLBACK  callback,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
void *  user_data = nullptr 
)

Creates a new hook that gets triggered when a TLB entry is filled or a translation lookup occurs.

Parameters
[in]callbackCallback being called when this hook gets triggered.
[in]startStart memory address range monitored by this hook.
[in]endEnd memory address range monitored by this hook.
[in]user_dataOptional user-defined data passed to the hook.
Returns
The new hook ID.

◆ hook_uc()

template<typename... UcParams>
HOOK_ID arion::HooksManager::hook_uc ( ARION_HOOK_TYPE  type,
HOOK_CALLBACK  callback,
void *  user_data,
ADDR  start = 0,
ADDR  end = ARION_MAX_U64,
UcParams...  uc_params 
)
private

Creates a new hook related to the Unicorn engine, which means every hooks that are defined in Unicorn.

Template Parameters
UcParamsAdditional parameters for genericity purpose.
Parameters
[in]typeArion type for the hook.
[in]callbackArion callback which gets called when the Unicorn hook is triggered.
[in]user_dataOptional user-defined data passed to the hook.
[in]startStart memory address where the hook should trigger.
[in]endEnd memory address where the hook should trigger.
[in]uc_paramsAdditional parameters for the hook.
Returns
The new hook ID.

◆ initialize()

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

Instanciates and initializes new HooksManager objects with some parameters.

Parameters
[in]arionThe Arion instance associated with this instance.
Returns
A new HooksManager instance.

◆ trigger_arion_hook()

template<typename... HookParams>
void arion::HooksManager::trigger_arion_hook ( ARION_HOOK_TYPE  type,
HookParams...  params 
)
inline

Triggers all hooks with a given type, which are not related to the Unicorn engine.

Template Parameters
HookParamsAdditional parameters for genericity purpose.
Parameters
[in]typeArion type for the hooks to be triggered.
[in]paramsAdditional parameters for the hooks.

◆ unhook()

void arion::HooksManager::unhook ( HOOK_ID  hook_id)

Deletes an Arion hook, preventing it from being triggered.

Parameters
[in]hook_idID of the hook which must get deleted.

Member Data Documentation

◆ arion

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

The Arion instance associated with this instance.

◆ curr_id

HOOK_ID arion::HooksManager::curr_id = 1
private

ID of the next hook to be created.

◆ free_hook_ids

std::stack<HOOK_ID> arion::HooksManager::free_hook_ids
private

A stack of hook IDs that got deleted and that can be reused.

◆ hooks

std::map<HOOK_ID, std::shared_ptr<ARION_HOOK> > arion::HooksManager::hooks
private

A map identifying an Arion hook given its ID.

◆ uc

uc_engine* arion::HooksManager::uc
private

The Unicorn engine associated with this instance.


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