Skip to content

Commit

Permalink
Rename instruction hooks (#75)
Browse files Browse the repository at this point in the history
* rename instruction hooks
  • Loading branch information
rmalmain authored Jun 3, 2024
1 parent 9d2197b commit 712661c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion accel/tcg/translator.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,

//// --- Begin LibAFL code ---

struct libafl_hook* hk = libafl_search_hook(db->pc_next);
struct libafl_hook* hk = libafl_search_instruction_hook(db->pc_next);
if (hk) {
TCGv_i64 tmp0 = tcg_constant_i64(hk->data);
#if TARGET_LONG_BITS == 32
Expand Down
12 changes: 6 additions & 6 deletions include/libafl/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ struct libafl_hook {
struct libafl_hook* next;
};

extern struct libafl_hook* libafl_qemu_hooks[LIBAFL_TABLES_SIZE];
extern struct libafl_hook* libafl_qemu_instruction_hooks[LIBAFL_TABLES_SIZE];
extern size_t libafl_qemu_hooks_num;

size_t libafl_qemu_set_hook(target_ulong pc, void (*callback)(uint64_t data, target_ulong pc),
uint64_t data, int invalidate);
size_t libafl_qemu_remove_hooks_at(target_ulong addr, int invalidate);
int libafl_qemu_remove_hook(size_t num, int invalidate);
struct libafl_hook* libafl_search_hook(target_ulong addr);
size_t libafl_qemu_add_instruction_hooks(target_ulong pc, void (*callback)(uint64_t data, target_ulong pc),
uint64_t data, int invalidate);
size_t libafl_qemu_remove_instruction_hooks_at(target_ulong addr, int invalidate);
int libafl_qemu_remove_instruction_hook(size_t num, int invalidate);
struct libafl_hook* libafl_search_instruction_hook(target_ulong addr);

struct libafl_backdoor_hook {
void (*exec)(uint64_t data, CPUArchState* cpu, target_ulong pc);
Expand Down
22 changes: 11 additions & 11 deletions libafl/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

target_ulong libafl_gen_cur_pc;

struct libafl_hook* libafl_qemu_hooks[LIBAFL_TABLES_SIZE];
struct libafl_hook* libafl_qemu_instruction_hooks[LIBAFL_TABLES_SIZE];
size_t libafl_qemu_hooks_num = 0;

size_t libafl_qemu_set_hook(target_ulong pc, void (*callback)(uint64_t data, target_ulong pc),
uint64_t data, int invalidate)
size_t libafl_qemu_add_instruction_hooks(target_ulong pc, void (*callback)(uint64_t data, target_ulong pc),
uint64_t data, int invalidate)
{
CPUState *cpu;

Expand All @@ -39,18 +39,18 @@ size_t libafl_qemu_set_hook(target_ulong pc, void (*callback)(uint64_t data, tar
hk->helper_info.typemask = dh_typemask(void, 0) | dh_typemask(i64, 1) | dh_typemask(tl, 2);
// TODO check for overflow
hk->num = libafl_qemu_hooks_num++;
hk->next = libafl_qemu_hooks[idx];
libafl_qemu_hooks[idx] = hk;
hk->next = libafl_qemu_instruction_hooks[idx];
libafl_qemu_instruction_hooks[idx] = hk;
return hk->num;
}

size_t libafl_qemu_remove_hooks_at(target_ulong addr, int invalidate)
size_t libafl_qemu_remove_instruction_hooks_at(target_ulong addr, int invalidate)
{
CPUState *cpu;
size_t r = 0;

size_t idx = LIBAFL_TABLES_HASH(addr);
struct libafl_hook** hk = &libafl_qemu_hooks[idx];
struct libafl_hook** hk = &libafl_qemu_instruction_hooks[idx];
while (*hk) {
if ((*hk)->addr == addr) {
if (invalidate) {
Expand All @@ -70,13 +70,13 @@ size_t libafl_qemu_remove_hooks_at(target_ulong addr, int invalidate)
return r;
}

int libafl_qemu_remove_hook(size_t num, int invalidate)
int libafl_qemu_remove_instruction_hook(size_t num, int invalidate)
{
CPUState *cpu;
size_t idx;

for (idx = 0; idx < LIBAFL_TABLES_SIZE; ++idx) {
struct libafl_hook** hk = &libafl_qemu_hooks[idx];
struct libafl_hook** hk = &libafl_qemu_instruction_hooks[idx];
while (*hk) {
if ((*hk)->num == num) {
if (invalidate) {
Expand All @@ -97,11 +97,11 @@ int libafl_qemu_remove_hook(size_t num, int invalidate)
return 0;
}

struct libafl_hook* libafl_search_hook(target_ulong addr)
struct libafl_hook* libafl_search_instruction_hook(target_ulong addr)
{
size_t idx = LIBAFL_TABLES_HASH(addr);

struct libafl_hook* hk = libafl_qemu_hooks[idx];
struct libafl_hook* hk = libafl_qemu_instruction_hooks[idx];
while (hk) {
if (hk->addr == addr) {
return hk;
Expand Down

0 comments on commit 712661c

Please sign in to comment.