fixup! refactor hooks
This commit is contained in:
parent
6efafc2d44
commit
749db2de75
@ -9,9 +9,12 @@
|
|||||||
#include "libafl/exit.h"
|
#include "libafl/exit.h"
|
||||||
#include "libafl/hook.h"
|
#include "libafl/hook.h"
|
||||||
|
|
||||||
|
typedef uint64_t (*libafl_jmp_gen_cb)(uint64_t data, target_ulong src, target_ulong dst);
|
||||||
|
typedef void (*libafl_jmp_exec_cb)(uint64_t data, target_ulong src, target_ulong dst, uint64_t id);
|
||||||
|
|
||||||
struct libafl_jmp_hook {
|
struct libafl_jmp_hook {
|
||||||
uint64_t (*gen)(uint64_t data, target_ulong src, target_ulong dst);
|
libafl_jmp_gen_cb gen_cb;
|
||||||
void (*exec)(uint64_t data, target_ulong src, target_ulong dst, uint64_t id);
|
libafl_jmp_exec_cb exec_cb;
|
||||||
uint64_t data;
|
uint64_t data;
|
||||||
size_t num;
|
size_t num;
|
||||||
TCGHelperInfo helper_info;
|
TCGHelperInfo helper_info;
|
||||||
@ -20,8 +23,8 @@ struct libafl_jmp_hook {
|
|||||||
|
|
||||||
extern struct libafl_jmp_hook* libafl_jmp_hooks;
|
extern struct libafl_jmp_hook* libafl_jmp_hooks;
|
||||||
|
|
||||||
size_t libafl_add_jmp_hook(uint64_t (*gen)(uint64_t data, target_ulong src, target_ulong dst),
|
size_t libafl_add_jmp_hook(uint64_t (*gen_cb)(uint64_t data, target_ulong src, target_ulong dst),
|
||||||
void (*exec)(uint64_t data, target_ulong src, target_ulong dst, uint64_t id),
|
void (*exec_cb)(uint64_t data, target_ulong src, target_ulong dst, uint64_t id),
|
||||||
uint64_t data);
|
uint64_t data);
|
||||||
|
|
||||||
void libafl_gen_jmp(target_ulong src, target_ulong dst);
|
void libafl_gen_jmp(target_ulong src, target_ulong dst);
|
||||||
|
@ -11,20 +11,20 @@ static TCGHelperInfo libafl_exec_jmp_hook_info = {
|
|||||||
struct libafl_jmp_hook* libafl_jmp_hooks;
|
struct libafl_jmp_hook* libafl_jmp_hooks;
|
||||||
size_t libafl_jmp_hooks_num = 0;
|
size_t libafl_jmp_hooks_num = 0;
|
||||||
|
|
||||||
size_t libafl_add_jmp_hook(uint64_t (*gen)(uint64_t data, target_ulong src, target_ulong dst),
|
size_t libafl_add_jmp_hook(uint64_t (*gen_cb)(uint64_t data, target_ulong src, target_ulong dst),
|
||||||
void (*exec)(uint64_t data, target_ulong src, target_ulong dst, uint64_t id),
|
void (*exec_cb)(uint64_t data, target_ulong src, target_ulong dst, uint64_t id),
|
||||||
uint64_t data)
|
uint64_t data)
|
||||||
{
|
{
|
||||||
struct libafl_jmp_hook* hook = calloc(sizeof(struct libafl_jmp_hook), 1);
|
struct libafl_jmp_hook* hook = calloc(sizeof(struct libafl_jmp_hook), 1);
|
||||||
hook->gen = gen;
|
hook->gen_cb = gen_cb;
|
||||||
hook->exec = exec;
|
hook->exec_cb = exec_cb;
|
||||||
hook->num = libafl_jmp_hooks_num++;
|
hook->num = libafl_jmp_hooks_num++;
|
||||||
hook->data = data;
|
hook->data = data;
|
||||||
hook->next = libafl_jmp_hooks;
|
hook->next = libafl_jmp_hooks;
|
||||||
libafl_jmp_hooks = hook;
|
libafl_jmp_hooks = hook;
|
||||||
|
|
||||||
memcpy(&hook->helper_info, &libafl_exec_jmp_hook_info, sizeof(TCGHelperInfo));
|
memcpy(&hook->helper_info, &libafl_exec_jmp_hook_info, sizeof(TCGHelperInfo));
|
||||||
hook->helper_info.func = exec;
|
hook->helper_info.func = exec_cb;
|
||||||
return hook->num;
|
return hook->num;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,9 +34,9 @@ void libafl_gen_jmp(target_ulong src, target_ulong dst)
|
|||||||
struct libafl_jmp_hook* hook = libafl_jmp_hooks;
|
struct libafl_jmp_hook* hook = libafl_jmp_hooks;
|
||||||
while (hook) {
|
while (hook) {
|
||||||
uint64_t cur_id = 0;
|
uint64_t cur_id = 0;
|
||||||
if (hook->gen)
|
if (hook->gen_cb)
|
||||||
cur_id = hook->gen(hook->data, src, dst);
|
cur_id = hook->gen_cb(hook->data, src, dst);
|
||||||
if (cur_id != (uint64_t)-1 && hook->exec) {
|
if (cur_id != (uint64_t)-1 && hook->exec_cb) {
|
||||||
TCGv_i64 tmp0 = tcg_constant_i64(hook->data);
|
TCGv_i64 tmp0 = tcg_constant_i64(hook->data);
|
||||||
TCGv_i64 tmp1 = tcg_constant_i64(src);
|
TCGv_i64 tmp1 = tcg_constant_i64(src);
|
||||||
TCGv_i64 tmp2 = tcg_constant_i64(dst);
|
TCGv_i64 tmp2 = tcg_constant_i64(dst);
|
||||||
@ -57,9 +57,9 @@ void libafl_gen_jmp_dynamic(target_ulong src, TCGv_i32 dst)
|
|||||||
struct libafl_jmp_hook* hook = libafl_jmp_hooks;
|
struct libafl_jmp_hook* hook = libafl_jmp_hooks;
|
||||||
while (hook) {
|
while (hook) {
|
||||||
uint64_t cur_id = 0;
|
uint64_t cur_id = 0;
|
||||||
if (hook->gen)
|
if (hook->gen_cb)
|
||||||
cur_id = hook->gen(hook->data, src, 0); // target is not statically known, signal with 0
|
cur_id = hook->gen_cb(hook->data, src, 0); // target is not statically known, signal with 0
|
||||||
if (cur_id != (uint64_t)-1 && hook->exec) {
|
if (cur_id != (uint64_t)-1 && hook->exec_cb) {
|
||||||
TCGv_i64 tmp0 = tcg_constant_i64(hook->data);
|
TCGv_i64 tmp0 = tcg_constant_i64(hook->data);
|
||||||
TCGv_i64 tmp1 = tcg_constant_i64(src);
|
TCGv_i64 tmp1 = tcg_constant_i64(src);
|
||||||
// TCGv_i32 tmp2 = dst;
|
// TCGv_i32 tmp2 = dst;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user