parent
9d2197b73b
commit
712661c820
@ -168,7 +168,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
|
|||||||
|
|
||||||
//// --- Begin LibAFL code ---
|
//// --- 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) {
|
if (hk) {
|
||||||
TCGv_i64 tmp0 = tcg_constant_i64(hk->data);
|
TCGv_i64 tmp0 = tcg_constant_i64(hk->data);
|
||||||
#if TARGET_LONG_BITS == 32
|
#if TARGET_LONG_BITS == 32
|
||||||
|
@ -31,14 +31,14 @@ struct libafl_hook {
|
|||||||
struct libafl_hook* next;
|
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;
|
extern size_t libafl_qemu_hooks_num;
|
||||||
|
|
||||||
size_t libafl_qemu_set_hook(target_ulong pc, void (*callback)(uint64_t data, target_ulong pc),
|
size_t libafl_qemu_add_instruction_hooks(target_ulong pc, void (*callback)(uint64_t data, target_ulong pc),
|
||||||
uint64_t data, int invalidate);
|
uint64_t data, int invalidate);
|
||||||
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);
|
||||||
int libafl_qemu_remove_hook(size_t num, int invalidate);
|
int libafl_qemu_remove_instruction_hook(size_t num, int invalidate);
|
||||||
struct libafl_hook* libafl_search_hook(target_ulong addr);
|
struct libafl_hook* libafl_search_instruction_hook(target_ulong addr);
|
||||||
|
|
||||||
struct libafl_backdoor_hook {
|
struct libafl_backdoor_hook {
|
||||||
void (*exec)(uint64_t data, CPUArchState* cpu, target_ulong pc);
|
void (*exec)(uint64_t data, CPUArchState* cpu, target_ulong pc);
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
|
|
||||||
target_ulong libafl_gen_cur_pc;
|
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_hooks_num = 0;
|
||||||
|
|
||||||
size_t libafl_qemu_set_hook(target_ulong pc, void (*callback)(uint64_t data, target_ulong pc),
|
size_t libafl_qemu_add_instruction_hooks(target_ulong pc, void (*callback)(uint64_t data, target_ulong pc),
|
||||||
uint64_t data, int invalidate)
|
uint64_t data, int invalidate)
|
||||||
{
|
{
|
||||||
CPUState *cpu;
|
CPUState *cpu;
|
||||||
|
|
||||||
@ -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);
|
hk->helper_info.typemask = dh_typemask(void, 0) | dh_typemask(i64, 1) | dh_typemask(tl, 2);
|
||||||
// TODO check for overflow
|
// TODO check for overflow
|
||||||
hk->num = libafl_qemu_hooks_num++;
|
hk->num = libafl_qemu_hooks_num++;
|
||||||
hk->next = libafl_qemu_hooks[idx];
|
hk->next = libafl_qemu_instruction_hooks[idx];
|
||||||
libafl_qemu_hooks[idx] = hk;
|
libafl_qemu_instruction_hooks[idx] = hk;
|
||||||
return hk->num;
|
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;
|
CPUState *cpu;
|
||||||
size_t r = 0;
|
size_t r = 0;
|
||||||
|
|
||||||
size_t idx = LIBAFL_TABLES_HASH(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) {
|
while (*hk) {
|
||||||
if ((*hk)->addr == addr) {
|
if ((*hk)->addr == addr) {
|
||||||
if (invalidate) {
|
if (invalidate) {
|
||||||
@ -70,13 +70,13 @@ size_t libafl_qemu_remove_hooks_at(target_ulong addr, int invalidate)
|
|||||||
return r;
|
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;
|
CPUState *cpu;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
|
|
||||||
for (idx = 0; idx < LIBAFL_TABLES_SIZE; ++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) {
|
while (*hk) {
|
||||||
if ((*hk)->num == num) {
|
if ((*hk)->num == num) {
|
||||||
if (invalidate) {
|
if (invalidate) {
|
||||||
@ -97,11 +97,11 @@ int libafl_qemu_remove_hook(size_t num, int invalidate)
|
|||||||
return 0;
|
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);
|
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) {
|
while (hk) {
|
||||||
if (hk->addr == addr) {
|
if (hk->addr == addr) {
|
||||||
return hk;
|
return hk;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user