From 5b62d436a9dad171c495f7dac3a00b6ee26eee2e Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Wed, 2 Sep 2015 21:44:43 -0400 Subject: [PATCH] change public APIs to use `ucengine` See #52. --- include/unicorn/unicorn.h | 39 +++++++++++++++++++------------------- regress/block_test.c | 4 ++-- regress/map_crash.c | 2 +- regress/map_write.c | 2 +- regress/nr_mem_test.c | 4 ++-- regress/rep_movsb.c | 6 +++--- regress/ro_mem_test.c | 6 +++--- regress/sigill.c | 4 ++-- regress/sigill2.c | 2 +- regress/timeout_segfault.c | 8 ++++---- samples/sample_arm.c | 8 ++++---- samples/sample_arm64.c | 6 +++--- samples/sample_m68k.c | 6 +++--- samples/sample_mips.c | 8 ++++---- samples/sample_sparc.c | 6 +++--- samples/sample_x86.c | 36 +++++++++++++++++------------------ samples/shellcode.c | 6 +++--- uc.c | 36 +++++++++++++++++------------------ 18 files changed, 95 insertions(+), 94 deletions(-) diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index e72399a7..40a32e0e 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -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 } diff --git a/regress/block_test.c b/regress/block_test.c index 0d1ddf9f..06a0fa21 100644 --- a/regress/block_test.c +++ b/regress/block_test.c @@ -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"); diff --git a/regress/map_crash.c b/regress/map_crash.c index b25c2b00..e7fbf38c 100644 --- a/regress/map_crash.c +++ b/regress/map_crash.c @@ -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"); diff --git a/regress/map_write.c b/regress/map_write.c index 400b4719..40fada8d 100644 --- a/regress/map_write.c +++ b/regress/map_write.c @@ -8,7 +8,7 @@ int main() { - struct uc_struct *uc; + ucengine *uc; uint8_t *buf, *buf2; int i; uc_err err; diff --git a/regress/nr_mem_test.c b/regress/nr_mem_test.c index 1f45cb1d..0e70829b 100644 --- a/regress/nr_mem_test.c +++ b/regress/nr_mem_test.c @@ -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; diff --git a/regress/rep_movsb.c b/regress/rep_movsb.c index 0b36e07c..97b00c15 100644 --- a/regress/rep_movsb.c +++ b/regress/rep_movsb.c @@ -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]; diff --git a/regress/ro_mem_test.c b/regress/ro_mem_test.c index 75b0d9bf..51b94b2f 100644 --- a/regress/ro_mem_test.c +++ b/regress/ro_mem_test.c @@ -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]; diff --git a/regress/sigill.c b/regress/sigill.c index 72e3be49..ad7af47f 100644 --- a/regress/sigill.c +++ b/regress/sigill.c @@ -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) { diff --git a/regress/sigill2.c b/regress/sigill2.c index 406dd750..1d955144 100644 --- a/regress/sigill2.c +++ b/regress/sigill2.c @@ -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) { diff --git a/regress/timeout_segfault.c b/regress/timeout_segfault.c index 5c31483a..2632a51f 100644 --- a/regress/timeout_segfault.c +++ b/regress/timeout_segfault.c @@ -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; diff --git a/samples/sample_arm.c b/samples/sample_arm.c index 1da06fc8..38e8590a 100644 --- a/samples/sample_arm.c +++ b/samples/sample_arm.c @@ -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; diff --git a/samples/sample_arm64.c b/samples/sample_arm64.c index de24ab37..61a58f20 100644 --- a/samples/sample_arm64.c +++ b/samples/sample_arm64.c @@ -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; diff --git a/samples/sample_m68k.c b/samples/sample_m68k.c index a640da72..049041cb 100644 --- a/samples/sample_m68k.c +++ b/samples/sample_m68k.c @@ -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; diff --git a/samples/sample_mips.c b/samples/sample_mips.c index 6fc13229..0806f60e 100644 --- a/samples/sample_mips.c +++ b/samples/sample_mips.c @@ -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; diff --git a/samples/sample_sparc.c b/samples/sample_sparc.c index b9c2404e..36536680 100644 --- a/samples/sample_sparc.c +++ b/samples/sample_sparc.c @@ -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; diff --git a/samples/sample_x86.c b/samples/sample_x86.c index af99075b..9bdd8232 100644 --- a/samples/sample_x86.c +++ b/samples/sample_x86.c @@ -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; diff --git a/samples/shellcode.c b/samples/shellcode.c index 62fe30e5..f185db97 100644 --- a/samples/shellcode.c +++ b/samples/shellcode.c @@ -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; diff --git a/uc.c b/uc.c index efe02622..cc25918a 100644 --- a/uc.c +++ b/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); }