From be659d201d0fdcd9509241763af2b56abbd0afd2 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Thu, 3 Sep 2015 01:12:49 +0800 Subject: [PATCH] fix confusion betweet UC_MEM_xxx & UC_HOOK_MEM_xxx. fix issue #93 --- hook.c | 21 +++++++++++---------- qemu/softmmu_template.h | 8 ++++---- uc.c | 7 ++++--- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/hook.c b/hook.c index 6a26d70d..f4690506 100644 --- a/hook.c +++ b/hook.c @@ -67,17 +67,17 @@ size_t hook_add(uch handle, int type, uint64_t begin, uint64_t end, void *callba if (begin > end) uc->hook_insn_idx = i; break; - case UC_MEM_READ: + case UC_HOOK_MEM_READ: uc->hook_mem_read = true; if (begin > end) uc->hook_read_idx = i; break; - case UC_MEM_WRITE: + case UC_HOOK_MEM_WRITE: uc->hook_mem_write = true; if (begin > end) uc->hook_write_idx = i; break; - case UC_MEM_READ_WRITE: + case UC_HOOK_MEM_READ_WRITE: uc->hook_mem_read = true; uc->hook_mem_write = true; if (begin > end) { @@ -162,12 +162,13 @@ static struct hook_struct *_hook_find(struct uc_struct *uc, int type, uint64_t a if (uc->hook_insn_idx) return &uc->hook_callbacks[uc->hook_insn_idx]; break; - case UC_MEM_READ: + case UC_HOOK_MEM_READ: // already hooked all memory read? - if (uc->hook_read_idx) + if (uc->hook_read_idx) { return &uc->hook_callbacks[uc->hook_read_idx]; + } break; - case UC_MEM_WRITE: + case UC_HOOK_MEM_WRITE: // already hooked all memory write? if (uc->hook_write_idx) return &uc->hook_callbacks[uc->hook_write_idx]; @@ -185,14 +186,14 @@ static struct hook_struct *_hook_find(struct uc_struct *uc, int type, uint64_t a return &uc->hook_callbacks[i]; } break; - case UC_MEM_READ: - if (uc->hook_callbacks[i].hook_type == UC_MEM_READ || uc->hook_callbacks[i].hook_type == UC_MEM_READ_WRITE) { + case UC_HOOK_MEM_READ: + if (uc->hook_callbacks[i].hook_type == UC_HOOK_MEM_READ || uc->hook_callbacks[i].hook_type == UC_HOOK_MEM_READ_WRITE) { if (uc->hook_callbacks[i].begin <= address && address <= uc->hook_callbacks[i].end) return &uc->hook_callbacks[i]; } break; - case UC_MEM_WRITE: - if (uc->hook_callbacks[i].hook_type == UC_MEM_WRITE || uc->hook_callbacks[i].hook_type == UC_MEM_READ_WRITE) { + case UC_HOOK_MEM_WRITE: + if (uc->hook_callbacks[i].hook_type == UC_HOOK_MEM_WRITE || uc->hook_callbacks[i].hook_type == UC_HOOK_MEM_READ_WRITE) { if (uc->hook_callbacks[i].begin <= address && address <= uc->hook_callbacks[i].end) return &uc->hook_callbacks[i]; } diff --git a/qemu/softmmu_template.h b/qemu/softmmu_template.h index 56f657a4..3def3e76 100644 --- a/qemu/softmmu_template.h +++ b/qemu/softmmu_template.h @@ -183,7 +183,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, // Unicorn: callback on memory read if (env->uc->hook_mem_read && READ_ACCESS_TYPE == MMU_DATA_LOAD) { - struct hook_struct *trace = hook_find((uch)env->uc, UC_MEM_READ, addr); + struct hook_struct *trace = hook_find((uch)env->uc, UC_HOOK_MEM_READ, addr); if (trace) { ((uc_cb_hookmem_t)trace->callback)((uch)env->uc, UC_MEM_READ, (uint64_t)addr, (int)DATA_SIZE, (int64_t)0, trace->user_data); @@ -328,7 +328,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx, // Unicorn: callback on memory read if (env->uc->hook_mem_read && READ_ACCESS_TYPE == MMU_DATA_LOAD) { - struct hook_struct *trace = hook_find((uch)env->uc, UC_MEM_READ, addr); + struct hook_struct *trace = hook_find((uch)env->uc, UC_HOOK_MEM_READ, addr); if (trace) { ((uc_cb_hookmem_t)trace->callback)((uch)env->uc, UC_MEM_READ, (uint64_t)addr, (int)DATA_SIZE, (int64_t)0, trace->user_data); @@ -511,7 +511,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, // Unicorn: callback on memory write if (uc->hook_mem_write) { - struct hook_struct *trace = hook_find((uch)uc, UC_MEM_WRITE, addr); + struct hook_struct *trace = hook_find((uch)uc, UC_HOOK_MEM_WRITE, addr); if (trace) { ((uc_cb_hookmem_t)trace->callback)((uch)uc, UC_MEM_WRITE, (uint64_t)addr, (int)DATA_SIZE, (int64_t)val, trace->user_data); @@ -649,7 +649,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, // Unicorn: callback on memory write if (uc->hook_mem_write) { - struct hook_struct *trace = hook_find((uch)uc, UC_MEM_WRITE, addr); + struct hook_struct *trace = hook_find((uch)uc, UC_HOOK_MEM_WRITE, addr); if (trace) { ((uc_cb_hookmem_t)trace->callback)((uch)uc, UC_MEM_WRITE, (uint64_t)addr, (int)DATA_SIZE, (int64_t)val, trace->user_data); diff --git a/uc.c b/uc.c index d1584b4f..c42123e0 100644 --- a/uc.c +++ b/uc.c @@ -791,16 +791,17 @@ uc_err uc_hook_add(uch handle, uch *h2, uc_hook_t type, void *callback, void *us case UC_HOOK_MEM_READ: begin = va_arg(valist, uint64_t); end = va_arg(valist, uint64_t); - ret = _hook_mem_access(handle, UC_MEM_READ, begin, end, callback, user_data, h2); + ret = _hook_mem_access(handle, UC_HOOK_MEM_READ, begin, end, callback, user_data, h2); break; case UC_HOOK_MEM_WRITE: begin = va_arg(valist, uint64_t); end = va_arg(valist, uint64_t); - ret = _hook_mem_access(handle, UC_MEM_WRITE, begin, end, callback, user_data, h2); + ret = _hook_mem_access(handle, UC_HOOK_MEM_WRITE, begin, end, callback, user_data, h2); + break; case UC_HOOK_MEM_READ_WRITE: begin = va_arg(valist, uint64_t); end = va_arg(valist, uint64_t); - ret = _hook_mem_access(handle, UC_MEM_READ_WRITE, begin, end, callback, user_data, h2); + ret = _hook_mem_access(handle, UC_HOOK_MEM_READ_WRITE, begin, end, callback, user_data, h2); break; }