change uch to uc_hook_h for hook handles
This commit is contained in:
30
hook.c
30
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
|
// 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;
|
uc->hook_block_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*h2 == uc->hook_insn_idx) {
|
if (hh == uc->hook_insn_idx) {
|
||||||
uc->hook_insn_idx = 0;
|
uc->hook_insn_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*h2 == uc->hook_read_idx) {
|
if (hh == uc->hook_read_idx) {
|
||||||
uc->hook_read_idx = 0;
|
uc->hook_read_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*h2 == uc->hook_write_idx) {
|
if (hh == uc->hook_write_idx) {
|
||||||
uc->hook_write_idx = 0;
|
uc->hook_write_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*h2 == uc->hook_mem_idx) {
|
if (hh == uc->hook_mem_idx) {
|
||||||
uc->hook_mem_idx = 0;
|
uc->hook_mem_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*h2 == uc->hook_intr_idx) {
|
if (hh == uc->hook_intr_idx) {
|
||||||
uc->hook_intr_idx = 0;
|
uc->hook_intr_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*h2 == uc->hook_out_idx) {
|
if (hh == uc->hook_out_idx) {
|
||||||
uc->hook_out_idx = 0;
|
uc->hook_out_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*h2 == uc->hook_in_idx) {
|
if (hh == uc->hook_in_idx) {
|
||||||
uc->hook_in_idx = 0;
|
uc->hook_in_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uc->hook_callbacks[*h2].callback = NULL;
|
uc->hook_callbacks[hh].callback = NULL;
|
||||||
uc->hook_callbacks[*h2].user_data = NULL;
|
uc->hook_callbacks[hh].user_data = NULL;
|
||||||
uc->hook_callbacks[*h2].hook_type = 0;
|
uc->hook_callbacks[hh].hook_type = 0;
|
||||||
uc->hook_callbacks[*h2].begin = 0;
|
uc->hook_callbacks[hh].begin = 0;
|
||||||
uc->hook_callbacks[*h2].end = 0;
|
uc->hook_callbacks[hh].end = 0;
|
||||||
|
|
||||||
*h2 = 0;
|
|
||||||
|
|
||||||
return UC_ERR_OK;
|
return UC_ERR_OK;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
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
|
// 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
|
// return NULL on failure
|
||||||
struct hook_struct *hook_find(struct uc_struct *uc, int type, uint64_t address);
|
struct hook_struct *hook_find(struct uc_struct *uc, int type, uint64_t address);
|
||||||
|
@ -21,8 +21,7 @@ extern "C" {
|
|||||||
|
|
||||||
struct uc_struct;
|
struct uc_struct;
|
||||||
|
|
||||||
// Handle to use with all APIs
|
typedef size_t uc_hook_h;
|
||||||
typedef size_t uch;
|
|
||||||
|
|
||||||
#include "m68k.h"
|
#include "m68k.h"
|
||||||
#include "x86.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.
|
The callback will be run when the hook event is hit.
|
||||||
|
|
||||||
@uc: handle returned by uc_open()
|
@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
|
@type: hook type
|
||||||
@callback: callback to be run when instruction is hit
|
@callback: callback to be run when instruction is hit
|
||||||
@user_data: user-defined data. This will be passed to callback function in its
|
@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).
|
for detailed error).
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
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.
|
Unregister (remove) a hook callback.
|
||||||
This API removes the hook callback registered by uc_hook_add().
|
This API removes the hook callback registered by uc_hook_add().
|
||||||
NOTE: this should be called only when you no longer want to trace.
|
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()
|
@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
|
@return UC_ERR_OK on success, or other value on failure (refer to uc_err enum
|
||||||
for detailed error).
|
for detailed error).
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
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.
|
Map memory in for emulation.
|
||||||
|
40
uc.c
40
uc.c
@ -339,7 +339,7 @@ static void *_timeout_fn(void *arg)
|
|||||||
// timeout before emulation is done?
|
// timeout before emulation is done?
|
||||||
if (!uc->emulation_done) {
|
if (!uc->emulation_done) {
|
||||||
// force emulation to stop
|
// force emulation to stop
|
||||||
uc_emu_stop((uch)uc);
|
uc_emu_stop(uc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
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,
|
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;
|
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)
|
if (i == 0)
|
||||||
return UC_ERR_OOM; // FIXME
|
return UC_ERR_OOM; // FIXME
|
||||||
|
|
||||||
*h2 = i;
|
*hh = i;
|
||||||
|
|
||||||
return UC_ERR_OK;
|
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,
|
static uc_err _hook_mem_access(struct uc_struct *uc, uc_mem_type type,
|
||||||
uint64_t begin, uint64_t end,
|
uint64_t begin, uint64_t end,
|
||||||
void *callback, void *user_data, uch *h2)
|
void *callback, void *user_data, uc_hook_h *hh)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -465,7 +465,7 @@ static uc_err _hook_mem_access(struct uc_struct *uc, uc_mem_type type,
|
|||||||
if (i == 0)
|
if (i == 0)
|
||||||
return UC_ERR_OOM; // FIXME
|
return UC_ERR_OOM; // FIXME
|
||||||
|
|
||||||
*h2 = i;
|
*hh = i;
|
||||||
|
|
||||||
return UC_ERR_OK;
|
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,
|
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;
|
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,
|
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;
|
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,
|
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;
|
size_t i;
|
||||||
|
|
||||||
@ -596,7 +596,7 @@ static uc_err _hook_insn(struct uc_struct *uc, unsigned int insn_id, void *callb
|
|||||||
}
|
}
|
||||||
|
|
||||||
UNICORN_EXPORT
|
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;
|
va_list valist;
|
||||||
int ret = UC_ERR_OK;
|
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;
|
ret = UC_ERR_HOOK;
|
||||||
break;
|
break;
|
||||||
case UC_HOOK_INTR:
|
case UC_HOOK_INTR:
|
||||||
ret = _hook_intr(uc, callback, user_data, h2);
|
ret = _hook_intr(uc, callback, user_data, hh);
|
||||||
break;
|
break;
|
||||||
case UC_HOOK_INSN:
|
case UC_HOOK_INSN:
|
||||||
id = va_arg(valist, int);
|
id = va_arg(valist, int);
|
||||||
ret = _hook_insn(uc, id, callback, user_data, h2);
|
ret = _hook_insn(uc, id, callback, user_data, hh);
|
||||||
break;
|
break;
|
||||||
case UC_HOOK_CODE:
|
case UC_HOOK_CODE:
|
||||||
begin = va_arg(valist, uint64_t);
|
begin = va_arg(valist, uint64_t);
|
||||||
end = 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;
|
break;
|
||||||
case UC_HOOK_BLOCK:
|
case UC_HOOK_BLOCK:
|
||||||
begin = va_arg(valist, uint64_t);
|
begin = va_arg(valist, uint64_t);
|
||||||
end = 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;
|
break;
|
||||||
case UC_HOOK_MEM_INVALID:
|
case UC_HOOK_MEM_INVALID:
|
||||||
ret = _hook_mem_invalid(uc, callback, user_data, h2);
|
ret = _hook_mem_invalid(uc, callback, user_data, hh);
|
||||||
break;
|
break;
|
||||||
case UC_HOOK_MEM_READ:
|
case UC_HOOK_MEM_READ:
|
||||||
begin = va_arg(valist, uint64_t);
|
begin = va_arg(valist, uint64_t);
|
||||||
end = 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;
|
break;
|
||||||
case UC_HOOK_MEM_WRITE:
|
case UC_HOOK_MEM_WRITE:
|
||||||
begin = va_arg(valist, uint64_t);
|
begin = va_arg(valist, uint64_t);
|
||||||
end = 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:
|
case UC_HOOK_MEM_READ_WRITE:
|
||||||
begin = va_arg(valist, uint64_t);
|
begin = va_arg(valist, uint64_t);
|
||||||
end = 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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,12 +651,12 @@ uc_err uc_hook_add(struct uc_struct *uc, uch *h2, uc_hook_t type, void *callback
|
|||||||
}
|
}
|
||||||
|
|
||||||
UNICORN_EXPORT
|
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
|
// invalid handle
|
||||||
return UC_ERR_HANDLE;
|
return UC_ERR_HANDLE;
|
||||||
|
|
||||||
return hook_del(uc, h2);
|
return hook_del(uc, hh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user