From 24caaa07debc8e1660d4efe84dce29164a353836 Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Wed, 26 Aug 2015 07:32:05 -0400 Subject: [PATCH] change uch to uc_hook_h for hook handles --- hook.c | 30 ++++++++++++++--------------- include/hook.h | 2 +- include/unicorn/unicorn.h | 13 ++++++------- uc.c | 40 +++++++++++++++++++-------------------- 4 files changed, 41 insertions(+), 44 deletions(-) diff --git a/hook.c b/hook.c index 468d79b7..31fcaabf 100644 --- a/hook.c +++ b/hook.c @@ -91,47 +91,45 @@ size_t hook_add(struct uc_struct *uc, int type, uint64_t begin, uint64_t end, vo } // return 0 on success, -1 on failure -uc_err hook_del(struct uc_struct *uc, uch *h2) +uc_err hook_del(struct uc_struct *uc, uc_hook_h hh) { - if (*h2 == uc->hook_block_idx) { + if (hh == uc->hook_block_idx) { uc->hook_block_idx = 0; } - if (*h2 == uc->hook_insn_idx) { + if (hh == uc->hook_insn_idx) { uc->hook_insn_idx = 0; } - if (*h2 == uc->hook_read_idx) { + if (hh == uc->hook_read_idx) { uc->hook_read_idx = 0; } - if (*h2 == uc->hook_write_idx) { + if (hh == uc->hook_write_idx) { uc->hook_write_idx = 0; } - if (*h2 == uc->hook_mem_idx) { + if (hh == uc->hook_mem_idx) { uc->hook_mem_idx = 0; } - if (*h2 == uc->hook_intr_idx) { + if (hh == uc->hook_intr_idx) { uc->hook_intr_idx = 0; } - if (*h2 == uc->hook_out_idx) { + if (hh == uc->hook_out_idx) { uc->hook_out_idx = 0; } - if (*h2 == uc->hook_in_idx) { + if (hh == uc->hook_in_idx) { uc->hook_in_idx = 0; } - uc->hook_callbacks[*h2].callback = NULL; - uc->hook_callbacks[*h2].user_data = NULL; - uc->hook_callbacks[*h2].hook_type = 0; - uc->hook_callbacks[*h2].begin = 0; - uc->hook_callbacks[*h2].end = 0; - - *h2 = 0; + uc->hook_callbacks[hh].callback = NULL; + uc->hook_callbacks[hh].user_data = NULL; + uc->hook_callbacks[hh].hook_type = 0; + uc->hook_callbacks[hh].begin = 0; + uc->hook_callbacks[hh].end = 0; return UC_ERR_OK; } diff --git a/include/hook.h b/include/hook.h index 72e255a7..8c095b28 100644 --- a/include/hook.h +++ b/include/hook.h @@ -8,7 +8,7 @@ size_t hook_add(struct uc_struct *uc, int type, uint64_t begin, uint64_t end, void *callback, void *user_data); // return 0 on success, -1 on failure -uc_err hook_del(struct uc_struct *uc, uch *traceh); +uc_err hook_del(struct uc_struct *uc, uc_hook_h hh); // return NULL on failure struct hook_struct *hook_find(struct uc_struct *uc, int type, uint64_t address); diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index 9fd38435..d7ac2a33 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -21,8 +21,7 @@ extern "C" { struct uc_struct; -// Handle to use with all APIs -typedef size_t uch; +typedef size_t uc_hook_h; #include "m68k.h" #include "x86.h" @@ -358,7 +357,7 @@ uc_err uc_emu_stop(struct uc_struct *uc); The callback will be run when the hook event is hit. @uc: handle returned by uc_open() - @h2: hook handle returned from this registration. To be used in uc_hook_del() API + @hh: hook handle returned from this registration. To be used in uc_hook_del() API @type: hook type @callback: callback to be run when instruction is hit @user_data: user-defined data. This will be passed to callback function in its @@ -369,22 +368,22 @@ uc_err uc_emu_stop(struct uc_struct *uc); for detailed error). */ UNICORN_EXPORT -uc_err uc_hook_add(struct uc_struct *uc, uch *h2, uc_hook_t type, void *callback, void *user_data, ...); +uc_err uc_hook_add(struct uc_struct *uc, uc_hook_h *hh, uc_hook_t type, void *callback, void *user_data, ...); /* Unregister (remove) a hook callback. This API removes the hook callback registered by uc_hook_add(). NOTE: this should be called only when you no longer want to trace. - After this, @h2 is invalid, and nolonger usable. + After this, @hh is invalid, and nolonger usable. @uc: handle returned by uc_open() - @h2: handle returned by uc_hook_add() + @hh: handle returned by uc_hook_add() @return UC_ERR_OK on success, or other value on failure (refer to uc_err enum for detailed error). */ UNICORN_EXPORT -uc_err uc_hook_del(struct uc_struct *uc, uch *h2); +uc_err uc_hook_del(struct uc_struct *uc, uc_hook_h *hh); /* Map memory in for emulation. diff --git a/uc.c b/uc.c index 2a808ce8..7bb690c7 100644 --- a/uc.c +++ b/uc.c @@ -339,7 +339,7 @@ static void *_timeout_fn(void *arg) // timeout before emulation is done? if (!uc->emulation_done) { // force emulation to stop - uc_emu_stop((uch)uc); + uc_emu_stop(uc); } return NULL; @@ -441,7 +441,7 @@ uc_err uc_emu_stop(struct uc_struct *uc) static int _hook_code(struct uc_struct *uc, int type, uint64_t begin, uint64_t end, - void *callback, void *user_data, uch *h2) + void *callback, void *user_data, uc_hook_h *hh) { int i; @@ -449,7 +449,7 @@ static int _hook_code(struct uc_struct *uc, int type, uint64_t begin, uint64_t e if (i == 0) return UC_ERR_OOM; // FIXME - *h2 = i; + *hh = i; return UC_ERR_OK; } @@ -457,7 +457,7 @@ static int _hook_code(struct uc_struct *uc, int type, uint64_t begin, uint64_t e static uc_err _hook_mem_access(struct uc_struct *uc, uc_mem_type type, uint64_t begin, uint64_t end, - void *callback, void *user_data, uch *h2) + void *callback, void *user_data, uc_hook_h *hh) { int i; @@ -465,7 +465,7 @@ static uc_err _hook_mem_access(struct uc_struct *uc, uc_mem_type type, if (i == 0) return UC_ERR_OOM; // FIXME - *h2 = i; + *hh = i; return UC_ERR_OK; } @@ -507,7 +507,7 @@ bool memory_mapping(uint64_t address) } static uc_err _hook_mem_invalid(struct uc_struct* uc, uc_cb_eventmem_t callback, - void *user_data, uch *evh) + void *user_data, uc_hook_h *evh) { size_t i; @@ -526,7 +526,7 @@ static uc_err _hook_mem_invalid(struct uc_struct* uc, uc_cb_eventmem_t callback, static uc_err _hook_intr(struct uc_struct* uc, void *callback, - void *user_data, uch *evh) + void *user_data, uc_hook_h *evh) { size_t i; @@ -545,7 +545,7 @@ static uc_err _hook_intr(struct uc_struct* uc, void *callback, static uc_err _hook_insn(struct uc_struct *uc, unsigned int insn_id, void *callback, - void *user_data, uch *evh) + void *user_data, uc_hook_h *evh) { size_t i; @@ -596,7 +596,7 @@ static uc_err _hook_insn(struct uc_struct *uc, unsigned int insn_id, void *callb } UNICORN_EXPORT -uc_err uc_hook_add(struct uc_struct *uc, uch *h2, uc_hook_t type, void *callback, void *user_data, ...) +uc_err uc_hook_add(struct uc_struct *uc, uc_hook_h *hh, uc_hook_t type, void *callback, void *user_data, ...) { va_list valist; int ret = UC_ERR_OK; @@ -610,38 +610,38 @@ uc_err uc_hook_add(struct uc_struct *uc, uch *h2, uc_hook_t type, void *callback ret = UC_ERR_HOOK; break; case UC_HOOK_INTR: - ret = _hook_intr(uc, callback, user_data, h2); + ret = _hook_intr(uc, callback, user_data, hh); break; case UC_HOOK_INSN: id = va_arg(valist, int); - ret = _hook_insn(uc, id, callback, user_data, h2); + ret = _hook_insn(uc, id, callback, user_data, hh); break; case UC_HOOK_CODE: begin = va_arg(valist, uint64_t); end = va_arg(valist, uint64_t); - ret = _hook_code(uc, UC_HOOK_CODE, begin, end, callback, user_data, h2); + ret = _hook_code(uc, UC_HOOK_CODE, begin, end, callback, user_data, hh); break; case UC_HOOK_BLOCK: begin = va_arg(valist, uint64_t); end = va_arg(valist, uint64_t); - ret = _hook_code(uc, UC_HOOK_BLOCK, begin, end, callback, user_data, h2); + ret = _hook_code(uc, UC_HOOK_BLOCK, begin, end, callback, user_data, hh); break; case UC_HOOK_MEM_INVALID: - ret = _hook_mem_invalid(uc, callback, user_data, h2); + ret = _hook_mem_invalid(uc, callback, user_data, hh); break; case UC_HOOK_MEM_READ: begin = va_arg(valist, uint64_t); end = va_arg(valist, uint64_t); - ret = _hook_mem_access(uc, UC_MEM_READ, begin, end, callback, user_data, h2); + ret = _hook_mem_access(uc, UC_MEM_READ, begin, end, callback, user_data, hh); break; case UC_HOOK_MEM_WRITE: begin = va_arg(valist, uint64_t); end = va_arg(valist, uint64_t); - ret = _hook_mem_access(uc, UC_MEM_WRITE, begin, end, callback, user_data, h2); + ret = _hook_mem_access(uc, UC_MEM_WRITE, begin, end, callback, user_data, hh); case UC_HOOK_MEM_READ_WRITE: begin = va_arg(valist, uint64_t); end = va_arg(valist, uint64_t); - ret = _hook_mem_access(uc, UC_MEM_READ_WRITE, begin, end, callback, user_data, h2); + ret = _hook_mem_access(uc, UC_MEM_READ_WRITE, begin, end, callback, user_data, hh); break; } @@ -651,12 +651,12 @@ uc_err uc_hook_add(struct uc_struct *uc, uch *h2, uc_hook_t type, void *callback } UNICORN_EXPORT -uc_err uc_hook_del(struct uc_struct *uc, uch *h2) +uc_err uc_hook_del(struct uc_struct *uc, uc_hook_h *hh) { - if (*h2 == 0) + if (*hh == 0) // invalid handle return UC_ERR_HANDLE; - return hook_del(uc, h2); + return hook_del(uc, hh); }