parent
0feab69a61
commit
5b62d436a9
@ -20,6 +20,7 @@ extern "C" {
|
||||
#include "platform.h"
|
||||
|
||||
struct uc_struct;
|
||||
typedef struct uc_struct ucengine;
|
||||
|
||||
typedef size_t uc_hook_h;
|
||||
|
||||
@ -125,24 +126,24 @@ typedef enum uc_err {
|
||||
// @address: address where the code is being executed
|
||||
// @size: size of machine instruction(s) being executed, or 0 when size is unknown
|
||||
// @user_data: user data passed to tracing APIs.
|
||||
typedef void (*uc_cb_hookcode_t)(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data);
|
||||
typedef void (*uc_cb_hookcode_t)(ucengine *uc, uint64_t address, uint32_t size, void *user_data);
|
||||
|
||||
// Callback function for tracing interrupts (for uc_hook_intr())
|
||||
// @intno: interrupt number
|
||||
// @user_data: user data passed to tracing APIs.
|
||||
typedef void (*uc_cb_hookintr_t)(struct uc_struct *uc, uint32_t intno, void *user_data);
|
||||
typedef void (*uc_cb_hookintr_t)(ucengine *uc, uint32_t intno, void *user_data);
|
||||
|
||||
// Callback function for tracing IN instruction of X86
|
||||
// @port: port number
|
||||
// @size: data size (1/2/4) to be read from this port
|
||||
// @user_data: user data passed to tracing APIs.
|
||||
typedef uint32_t (*uc_cb_insn_in_t)(struct uc_struct *uc, uint32_t port, int size, void *user_data);
|
||||
typedef uint32_t (*uc_cb_insn_in_t)(ucengine *uc, uint32_t port, int size, void *user_data);
|
||||
|
||||
// x86's handler for OUT
|
||||
// @port: port number
|
||||
// @size: data size (1/2/4) to be written to this port
|
||||
// @value: data value to be written to this port
|
||||
typedef void (*uc_cb_insn_out_t)(struct uc_struct *uc, uint32_t port, int size, uint32_t value, void *user_data);
|
||||
typedef void (*uc_cb_insn_out_t)(ucengine *uc, uint32_t port, int size, uint32_t value, void *user_data);
|
||||
|
||||
// All type of memory accesses for UC_HOOK_MEM_*
|
||||
typedef enum uc_mem_type {
|
||||
@ -171,7 +172,7 @@ typedef enum uc_hook_t {
|
||||
// @size: size of data being read or written
|
||||
// @value: value of data being written to memory, or irrelevant if type = READ.
|
||||
// @user_data: user data passed to tracing APIs
|
||||
typedef void (*uc_cb_hookmem_t)(struct uc_struct *uc, uc_mem_type type,
|
||||
typedef void (*uc_cb_hookmem_t)(ucengine *uc, uc_mem_type type,
|
||||
uint64_t address, int size, int64_t value, void *user_data);
|
||||
|
||||
// Callback function for handling memory events (for UC_HOOK_MEM_INVALID)
|
||||
@ -181,7 +182,7 @@ typedef void (*uc_cb_hookmem_t)(struct uc_struct *uc, uc_mem_type type,
|
||||
// @value: value of data being written to memory, or irrelevant if type = READ.
|
||||
// @user_data: user data passed to tracing APIs
|
||||
// @return: return true to continue, or false to stop program (due to invalid memory).
|
||||
typedef bool (*uc_cb_eventmem_t)(struct uc_struct *uc, uc_mem_type type,
|
||||
typedef bool (*uc_cb_eventmem_t)(ucengine *uc, uc_mem_type type,
|
||||
uint64_t address, int size, int64_t value, void *user_data);
|
||||
|
||||
|
||||
@ -222,13 +223,13 @@ bool uc_arch_supported(uc_arch arch);
|
||||
|
||||
@arch: architecture type (UC_ARCH_*)
|
||||
@mode: hardware mode. This is combined of UC_MODE_*
|
||||
@uc: pointer to struct uc_struct, which will be updated at return time
|
||||
@uc: pointer to ucengine, which will be updated at return time
|
||||
|
||||
@return UC_ERR_OK on success, or other value on failure (refer to uc_err enum
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_open(uc_arch arch, uc_mode mode, struct uc_struct **uc);
|
||||
uc_err uc_open(uc_arch arch, uc_mode mode, ucengine **uc);
|
||||
|
||||
/*
|
||||
Close UC instance: MUST do to release the handle when it is not used anymore.
|
||||
@ -243,7 +244,7 @@ uc_err uc_open(uc_arch arch, uc_mode mode, struct uc_struct **uc);
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_close(struct uc_struct *uc);
|
||||
uc_err uc_close(ucengine *uc);
|
||||
|
||||
/*
|
||||
Report the last error number when some API function fail.
|
||||
@ -254,7 +255,7 @@ uc_err uc_close(struct uc_struct *uc);
|
||||
@return: error code of uc_err enum type (UC_ERR_*, see above)
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_errno(struct uc_struct *uc);
|
||||
uc_err uc_errno(ucengine *uc);
|
||||
|
||||
/*
|
||||
Return a string describing given error code.
|
||||
@ -278,7 +279,7 @@ const char *uc_strerror(uc_err code);
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_reg_write(struct uc_struct *uc, int regid, const void *value);
|
||||
uc_err uc_reg_write(ucengine *uc, int regid, const void *value);
|
||||
|
||||
/*
|
||||
Read register value.
|
||||
@ -291,7 +292,7 @@ uc_err uc_reg_write(struct uc_struct *uc, int regid, const void *value);
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_reg_read(struct uc_struct *uc, int regid, void *value);
|
||||
uc_err uc_reg_read(ucengine *uc, int regid, void *value);
|
||||
|
||||
/*
|
||||
Write to a range of bytes in memory.
|
||||
@ -307,7 +308,7 @@ uc_err uc_reg_read(struct uc_struct *uc, int regid, void *value);
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_mem_write(struct uc_struct *uc, uint64_t address, const uint8_t *bytes, size_t size);
|
||||
uc_err uc_mem_write(ucengine *uc, uint64_t address, const uint8_t *bytes, size_t size);
|
||||
|
||||
/*
|
||||
Read a range of bytes in memory.
|
||||
@ -323,7 +324,7 @@ uc_err uc_mem_write(struct uc_struct *uc, uint64_t address, const uint8_t *bytes
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_mem_read(struct uc_struct *uc, uint64_t address, uint8_t *bytes, size_t size);
|
||||
uc_err uc_mem_read(ucengine *uc, uint64_t address, uint8_t *bytes, size_t size);
|
||||
|
||||
/*
|
||||
Emulate machine code in a specific duration of time.
|
||||
@ -340,7 +341,7 @@ uc_err uc_mem_read(struct uc_struct *uc, uint64_t address, uint8_t *bytes, size_
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_emu_start(struct uc_struct *uc, uint64_t begin, uint64_t until, uint64_t timeout, size_t count);
|
||||
uc_err uc_emu_start(ucengine *uc, uint64_t begin, uint64_t until, uint64_t timeout, size_t count);
|
||||
|
||||
/*
|
||||
Stop emulation (which was started by uc_emu_start() API.
|
||||
@ -353,7 +354,7 @@ uc_err uc_emu_start(struct uc_struct *uc, uint64_t begin, uint64_t until, uint64
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_emu_stop(struct uc_struct *uc);
|
||||
uc_err uc_emu_stop(ucengine *uc);
|
||||
|
||||
/*
|
||||
Register callback for a hook event.
|
||||
@ -371,7 +372,7 @@ uc_err uc_emu_stop(struct uc_struct *uc);
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_hook_add(struct uc_struct *uc, uc_hook_h *hh, uc_hook_t type, void *callback, void *user_data, ...);
|
||||
uc_err uc_hook_add(ucengine *uc, uc_hook_h *hh, uc_hook_t type, void *callback, void *user_data, ...);
|
||||
|
||||
/*
|
||||
Unregister (remove) a hook callback.
|
||||
@ -386,7 +387,7 @@ uc_err uc_hook_add(struct uc_struct *uc, uc_hook_h *hh, uc_hook_t type, void *ca
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_hook_del(struct uc_struct *uc, uc_hook_h hh);
|
||||
uc_err uc_hook_del(ucengine *uc, uc_hook_h hh);
|
||||
|
||||
typedef enum uc_prot {
|
||||
UC_PROT_NONE = 0,
|
||||
@ -412,7 +413,7 @@ typedef enum uc_prot {
|
||||
for detailed error).
|
||||
*/
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_mem_map(struct uc_struct *uc, uint64_t address, size_t size, uint32_t perms);
|
||||
uc_err uc_mem_map(ucengine *uc, uint64_t address, size_t size, uint32_t perms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ static int count = 1;
|
||||
// @address: address where the code is being executed
|
||||
// @size: size of machine instruction being executed
|
||||
// @user_data: user data passed to tracing APIs.
|
||||
void cb_hookblock(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data) {
|
||||
void cb_hookblock(ucengine *uc, uint64_t address, uint32_t size, void *user_data) {
|
||||
fprintf(stderr, "# >>> Tracing basic block at 0x%llx, block size = 0x%x\n", address, size);
|
||||
if (address != 0x1000000 && address != 0x1000200) {
|
||||
fprintf(stderr, "not ok %d - address != 0x1000000 && address != 0x1000200\n", count++);
|
||||
@ -27,7 +27,7 @@ void cb_hookblock(struct uc_struct *uc, uint64_t address, uint32_t size, void *u
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
|
||||
fprintf(stderr, "# basic block callback test\n");
|
||||
fprintf(stderr, "# there are only two basic blocks 0x1000000-0x10001ff and 0x1000200-0x10003ff\n");
|
||||
|
@ -10,7 +10,7 @@ int main()
|
||||
{
|
||||
int size;
|
||||
uint8_t *buf;
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);
|
||||
if (err) {
|
||||
fprintf (stderr, "Cannot initialize unicorn\n");
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uint8_t *buf, *buf2;
|
||||
int i;
|
||||
uc_err err;
|
||||
|
@ -36,7 +36,7 @@ bits 32
|
||||
*/
|
||||
|
||||
// callback for tracing memory access (READ or WRITE)
|
||||
static bool hook_mem_invalid(struct uc_struct *uc, uc_mem_type type,
|
||||
static bool hook_mem_invalid(ucengine *uc, uc_mem_type type,
|
||||
uint64_t address, int size, int64_t value, void *user_data)
|
||||
{
|
||||
|
||||
@ -54,7 +54,7 @@ static bool hook_mem_invalid(struct uc_struct *uc, uc_mem_type type,
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_hook_h trace1, trace2;
|
||||
uc_err err;
|
||||
uint32_t eax, ebx;
|
||||
|
@ -50,7 +50,7 @@ hlt
|
||||
static int log_num = 1;
|
||||
|
||||
// callback for tracing instruction
|
||||
static void hook_code(struct uc_struct *uc, uint64_t addr, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t addr, uint32_t size, void *user_data)
|
||||
{
|
||||
uint8_t opcode;
|
||||
if (uc_mem_read(uc, addr, &opcode, 1) != UC_ERR_OK) {
|
||||
@ -74,7 +74,7 @@ static void hook_code(struct uc_struct *uc, uint64_t addr, uint32_t size, void *
|
||||
}
|
||||
|
||||
// callback for tracing memory access (READ or WRITE)
|
||||
static void hook_mem_write(struct uc_struct *uc, uc_mem_type type,
|
||||
static void hook_mem_write(ucengine *uc, uc_mem_type type,
|
||||
uint64_t addr, int size, int64_t value, void *user_data)
|
||||
{
|
||||
printf("# write to memory at 0x%"PRIx64 ", data size = %u, data value = 0x%"PRIx64 "\n", addr, size, value);
|
||||
@ -89,7 +89,7 @@ static void hook_mem_write(struct uc_struct *uc, uc_mem_type type,
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_hook_h trace1, trace2;
|
||||
uc_err err;
|
||||
uint8_t buf1[100], readbuf[100];
|
||||
|
@ -46,7 +46,7 @@ bottom:
|
||||
*/
|
||||
|
||||
// callback for tracing instruction
|
||||
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
uint32_t esp;
|
||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||
@ -57,7 +57,7 @@ static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, voi
|
||||
}
|
||||
|
||||
// callback for tracing memory access (READ or WRITE)
|
||||
static bool hook_mem_invalid(struct uc_struct *uc, uc_mem_type type,
|
||||
static bool hook_mem_invalid(ucengine *uc, uc_mem_type type,
|
||||
uint64_t address, int size, int64_t value, void *user_data)
|
||||
{
|
||||
uint32_t esp;
|
||||
@ -94,7 +94,7 @@ static bool hook_mem_invalid(struct uc_struct *uc, uc_mem_type type,
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_hook_h trace1, trace2;
|
||||
uc_err err;
|
||||
uint8_t bytes[8];
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
int got_sigill = 0;
|
||||
|
||||
void _interrupt(struct uc_struct *uc, uint32_t intno, void *user_data)
|
||||
void _interrupt(ucengine *uc, uint32_t intno, void *user_data)
|
||||
{
|
||||
if (intno == 6) {
|
||||
uc_emu_stop(uc);
|
||||
@ -20,7 +20,7 @@ int main()
|
||||
{
|
||||
int size;
|
||||
uint8_t *buf;
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_hook_h uh_trap;
|
||||
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);
|
||||
if (err) {
|
||||
|
@ -10,7 +10,7 @@ int main()
|
||||
{
|
||||
int size;
|
||||
uint8_t *buf;
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
|
||||
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);
|
||||
if (err) {
|
||||
|
@ -24,19 +24,19 @@ https://github.com/unicorn-engine/unicorn/issues/78
|
||||
// number of seconds to wait before timeout
|
||||
#define TIMEOUT 5
|
||||
|
||||
static void hook_block(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_block(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void test_arm(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
@ -92,7 +92,7 @@ static void test_arm(void)
|
||||
|
||||
static void test_thumb(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
|
@ -15,19 +15,19 @@
|
||||
// memory address where emulation starts
|
||||
#define ADDRESS 0x10000
|
||||
|
||||
static void hook_block(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_block(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void test_arm(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
@ -83,7 +83,7 @@ static void test_arm(void)
|
||||
|
||||
static void test_thumb(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
|
@ -14,19 +14,19 @@
|
||||
// memory address where emulation starts
|
||||
#define ADDRESS 0x10000
|
||||
|
||||
static void hook_block(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_block(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void test_arm64(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
|
@ -12,19 +12,19 @@
|
||||
// memory address where emulation starts
|
||||
#define ADDRESS 0x10000
|
||||
|
||||
static void hook_block(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_block(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void test_m68k(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_hook_h trace1, trace2;
|
||||
uc_err err;
|
||||
|
||||
|
@ -15,19 +15,19 @@
|
||||
// memory address where emulation starts
|
||||
#define ADDRESS 0x10000
|
||||
|
||||
static void hook_block(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_block(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void test_mips_eb(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
@ -76,7 +76,7 @@ static void test_mips_eb(void)
|
||||
|
||||
static void test_mips_el(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
|
@ -15,19 +15,19 @@
|
||||
// memory address where emulation starts
|
||||
#define ADDRESS 0x10000
|
||||
|
||||
static void hook_block(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_block(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
static void test_sparc(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
|
@ -32,13 +32,13 @@
|
||||
#define ADDRESS 0x1000000
|
||||
|
||||
// callback for tracing basic blocks
|
||||
static void hook_block(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_block(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
printf(">>> Tracing basic block at 0x%"PRIx64 ", block size = 0x%x\n", address, size);
|
||||
}
|
||||
|
||||
// callback for tracing instruction
|
||||
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
int eflags;
|
||||
printf(">>> Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size);
|
||||
@ -52,7 +52,7 @@ static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, voi
|
||||
}
|
||||
|
||||
// callback for tracing instruction
|
||||
static void hook_code64(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code64(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
uint64_t rip;
|
||||
|
||||
@ -66,7 +66,7 @@ static void hook_code64(struct uc_struct *uc, uint64_t address, uint32_t size, v
|
||||
}
|
||||
|
||||
// callback for tracing memory access (READ or WRITE)
|
||||
static bool hook_mem_invalid(struct uc_struct *uc, uc_mem_type type,
|
||||
static bool hook_mem_invalid(ucengine *uc, uc_mem_type type,
|
||||
uint64_t address, int size, int64_t value, void *user_data)
|
||||
{
|
||||
switch(type) {
|
||||
@ -83,7 +83,7 @@ static bool hook_mem_invalid(struct uc_struct *uc, uc_mem_type type,
|
||||
}
|
||||
}
|
||||
|
||||
static void hook_mem64(struct uc_struct *uc, uc_mem_type type,
|
||||
static void hook_mem64(ucengine *uc, uc_mem_type type,
|
||||
uint64_t address, int size, int64_t value, void *user_data)
|
||||
{
|
||||
switch(type) {
|
||||
@ -101,7 +101,7 @@ static void hook_mem64(struct uc_struct *uc, uc_mem_type type,
|
||||
|
||||
// callback for IN instruction (X86).
|
||||
// this returns the data read from the port
|
||||
static uint32_t hook_in(struct uc_struct *uc, uint32_t port, int size, void *user_data)
|
||||
static uint32_t hook_in(ucengine *uc, uint32_t port, int size, void *user_data)
|
||||
{
|
||||
uint32_t eip;
|
||||
|
||||
@ -126,7 +126,7 @@ static uint32_t hook_in(struct uc_struct *uc, uint32_t port, int size, void *use
|
||||
}
|
||||
|
||||
// callback for OUT instruction (X86).
|
||||
static void hook_out(struct uc_struct *uc, uint32_t port, int size, uint32_t value, void *user_data)
|
||||
static void hook_out(ucengine *uc, uint32_t port, int size, uint32_t value, void *user_data)
|
||||
{
|
||||
uint32_t tmp;
|
||||
uint32_t eip;
|
||||
@ -154,7 +154,7 @@ static void hook_out(struct uc_struct *uc, uint32_t port, int size, uint32_t val
|
||||
}
|
||||
|
||||
// callback for SYSCALL instruction (X86).
|
||||
static void hook_syscall(struct uc_struct *uc, void *user_data)
|
||||
static void hook_syscall(ucengine *uc, void *user_data)
|
||||
{
|
||||
uint64_t rax;
|
||||
|
||||
@ -168,7 +168,7 @@ static void hook_syscall(struct uc_struct *uc, void *user_data)
|
||||
|
||||
static void test_i386(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uint32_t tmp;
|
||||
uc_hook_h trace1, trace2;
|
||||
@ -230,7 +230,7 @@ static void test_i386(void)
|
||||
|
||||
static void test_i386_jump(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
@ -275,7 +275,7 @@ static void test_i386_jump(void)
|
||||
// emulate code that loop forever
|
||||
static void test_i386_loop(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
|
||||
int r_ecx = 0x1234; // ECX register
|
||||
@ -326,7 +326,7 @@ static void test_i386_loop(void)
|
||||
// emulate code that read invalid memory
|
||||
static void test_i386_invalid_mem_read(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
@ -383,7 +383,7 @@ static void test_i386_invalid_mem_read(void)
|
||||
// emulate code that read invalid memory
|
||||
static void test_i386_invalid_mem_write(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2, trace3;
|
||||
uint32_t tmp;
|
||||
@ -455,7 +455,7 @@ static void test_i386_invalid_mem_write(void)
|
||||
// emulate code that jump to invalid memory
|
||||
static void test_i386_jump_invalid(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
@ -511,7 +511,7 @@ static void test_i386_jump_invalid(void)
|
||||
|
||||
static void test_i386_inout(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2, trace3, trace4;
|
||||
|
||||
@ -572,7 +572,7 @@ static void test_i386_inout(void)
|
||||
|
||||
static void test_x86_64(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2, trace3, trace4;
|
||||
|
||||
@ -688,7 +688,7 @@ static void test_x86_64(void)
|
||||
|
||||
static void test_x86_64_syscall(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_hook_h trace1;
|
||||
uc_err err;
|
||||
|
||||
@ -739,7 +739,7 @@ static void test_x86_64_syscall(void)
|
||||
|
||||
static void test_x86_16(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uint8_t tmp;
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#define MIN(a, b) (a < b? a : b)
|
||||
// callback for tracing instruction
|
||||
static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
static void hook_code(ucengine *uc, uint64_t address, uint32_t size, void *user_data)
|
||||
{
|
||||
int r_eip;
|
||||
char tmp[16];
|
||||
@ -43,7 +43,7 @@ static void hook_code(struct uc_struct *uc, uint64_t address, uint32_t size, voi
|
||||
#define MIN(a, b) (a < b? a : b)
|
||||
// callback for handling interrupt
|
||||
// ref: http://syscalls.kernelgrok.com/
|
||||
static void hook_intr(struct uc_struct *uc, uint32_t intno, void *user_data)
|
||||
static void hook_intr(ucengine *uc, uint32_t intno, void *user_data)
|
||||
{
|
||||
int32_t r_eax, r_ecx, r_eip;
|
||||
uint32_t r_edx, size;
|
||||
@ -88,7 +88,7 @@ static void hook_intr(struct uc_struct *uc, uint32_t intno, void *user_data)
|
||||
|
||||
static void test_i386(void)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
ucengine *uc;
|
||||
uc_err err;
|
||||
uc_hook_h trace1, trace2;
|
||||
|
||||
|
36
uc.c
36
uc.c
@ -44,7 +44,7 @@ unsigned int uc_version(unsigned int *major, unsigned int *minor)
|
||||
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_errno(struct uc_struct *uc)
|
||||
uc_err uc_errno(ucengine *uc)
|
||||
{
|
||||
return uc->errnum;
|
||||
}
|
||||
@ -121,7 +121,7 @@ bool uc_arch_supported(uc_arch arch)
|
||||
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_open(uc_arch arch, uc_mode mode, struct uc_struct **result)
|
||||
uc_err uc_open(uc_arch arch, uc_mode mode, ucengine **result)
|
||||
{
|
||||
struct uc_struct *uc;
|
||||
|
||||
@ -240,7 +240,7 @@ uc_err uc_open(uc_arch arch, uc_mode mode, struct uc_struct **result)
|
||||
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_close(struct uc_struct *uc)
|
||||
uc_err uc_close(ucengine *uc)
|
||||
{
|
||||
if (uc->release)
|
||||
uc->release(uc->tcg_ctx);
|
||||
@ -280,7 +280,7 @@ uc_err uc_close(struct uc_struct *uc)
|
||||
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_reg_read(struct uc_struct *uc, int regid, void *value)
|
||||
uc_err uc_reg_read(ucengine *uc, int regid, void *value)
|
||||
{
|
||||
if (uc->reg_read)
|
||||
uc->reg_read(uc, regid, value);
|
||||
@ -292,7 +292,7 @@ uc_err uc_reg_read(struct uc_struct *uc, int regid, void *value)
|
||||
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_reg_write(struct uc_struct *uc, int regid, const void *value)
|
||||
uc_err uc_reg_write(ucengine *uc, int regid, const void *value)
|
||||
{
|
||||
if (uc->reg_write)
|
||||
uc->reg_write(uc, regid, value);
|
||||
@ -305,7 +305,7 @@ uc_err uc_reg_write(struct uc_struct *uc, int regid, const void *value)
|
||||
|
||||
// check if a memory area is mapped
|
||||
// this is complicated because an area can overlap adjacent blocks
|
||||
static bool check_mem_area(struct uc_struct *uc, uint64_t address, size_t size)
|
||||
static bool check_mem_area(ucengine *uc, uint64_t address, size_t size)
|
||||
{
|
||||
size_t count = 0, len;
|
||||
|
||||
@ -324,7 +324,7 @@ static bool check_mem_area(struct uc_struct *uc, uint64_t address, size_t size)
|
||||
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_mem_read(struct uc_struct *uc, uint64_t address, uint8_t *bytes, size_t size)
|
||||
uc_err uc_mem_read(ucengine *uc, uint64_t address, uint8_t *bytes, size_t size)
|
||||
{
|
||||
if (!check_mem_area(uc, address, size))
|
||||
return UC_ERR_MEM_READ;
|
||||
@ -352,7 +352,7 @@ uc_err uc_mem_read(struct uc_struct *uc, uint64_t address, uint8_t *bytes, size_
|
||||
}
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_mem_write(struct uc_struct *uc, uint64_t address, const uint8_t *bytes, size_t size)
|
||||
uc_err uc_mem_write(ucengine *uc, uint64_t address, const uint8_t *bytes, size_t size)
|
||||
{
|
||||
if (!check_mem_area(uc, address, size))
|
||||
return UC_ERR_MEM_WRITE;
|
||||
@ -392,7 +392,7 @@ uc_err uc_mem_write(struct uc_struct *uc, uint64_t address, const uint8_t *bytes
|
||||
#define TIMEOUT_STEP 2 // microseconds
|
||||
static void *_timeout_fn(void *arg)
|
||||
{
|
||||
struct uc_struct *uc = (struct uc_struct *)arg;
|
||||
struct uc_struct *uc = arg;
|
||||
int64_t current_time = get_clock();
|
||||
|
||||
do {
|
||||
@ -411,7 +411,7 @@ static void *_timeout_fn(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void enable_emu_timer(struct uc_struct *uc, uint64_t timeout)
|
||||
static void enable_emu_timer(ucengine *uc, uint64_t timeout)
|
||||
{
|
||||
uc->timeout = timeout;
|
||||
qemu_thread_create(uc, &uc->timer, "timeout", _timeout_fn,
|
||||
@ -419,7 +419,7 @@ static void enable_emu_timer(struct uc_struct *uc, uint64_t timeout)
|
||||
}
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_emu_start(struct uc_struct* uc, uint64_t begin, uint64_t until, uint64_t timeout, size_t count)
|
||||
uc_err uc_emu_start(ucengine* uc, uint64_t begin, uint64_t until, uint64_t timeout, size_t count)
|
||||
{
|
||||
// reset the counter
|
||||
uc->emu_counter = 0;
|
||||
@ -502,7 +502,7 @@ uc_err uc_emu_start(struct uc_struct* uc, uint64_t begin, uint64_t until, uint64
|
||||
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_emu_stop(struct uc_struct *uc)
|
||||
uc_err uc_emu_stop(ucengine *uc)
|
||||
{
|
||||
if (uc->emulation_done)
|
||||
return UC_ERR_OK;
|
||||
@ -515,7 +515,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(ucengine *uc, int type, uint64_t begin, uint64_t end,
|
||||
void *callback, void *user_data, uc_hook_h *hh)
|
||||
{
|
||||
int i;
|
||||
@ -530,7 +530,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_hook_t type,
|
||||
static uc_err _hook_mem_access(ucengine *uc, uc_hook_t type,
|
||||
uint64_t begin, uint64_t end,
|
||||
void *callback, void *user_data, uc_hook_h *hh)
|
||||
{
|
||||
@ -546,7 +546,7 @@ static uc_err _hook_mem_access(struct uc_struct *uc, uc_hook_t type,
|
||||
}
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_mem_map(struct uc_struct *uc, uint64_t address, size_t size, uint32_t perms)
|
||||
uc_err uc_mem_map(ucengine *uc, uint64_t address, size_t size, uint32_t perms)
|
||||
{
|
||||
MemoryRegion **regions;
|
||||
|
||||
@ -579,7 +579,7 @@ uc_err uc_mem_map(struct uc_struct *uc, uint64_t address, size_t size, uint32_t
|
||||
return UC_ERR_OK;
|
||||
}
|
||||
|
||||
MemoryRegion *memory_mapping(struct uc_struct* uc, uint64_t address)
|
||||
MemoryRegion *memory_mapping(ucengine* uc, uint64_t address)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
@ -682,7 +682,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, uc_hook_h *hh, uc_hook_t type, void *callback, void *user_data, ...)
|
||||
uc_err uc_hook_add(ucengine *uc, uc_hook_h *hh, uc_hook_t type, void *callback, void *user_data, ...)
|
||||
{
|
||||
va_list valist;
|
||||
int ret = UC_ERR_OK;
|
||||
@ -738,7 +738,7 @@ uc_err uc_hook_add(struct uc_struct *uc, uc_hook_h *hh, uc_hook_t type, void *ca
|
||||
}
|
||||
|
||||
UNICORN_EXPORT
|
||||
uc_err uc_hook_del(struct uc_struct *uc, uc_hook_h hh)
|
||||
uc_err uc_hook_del(ucengine *uc, uc_hook_h hh)
|
||||
{
|
||||
return hook_del(uc, hh);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user