diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index 3589566d..a1877dab 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -92,7 +92,7 @@ uc_hook_h = ctypes.c_size_t _setup_prototype(_uc, "uc_version", ctypes.c_uint, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)) _setup_prototype(_uc, "uc_arch_supported", ctypes.c_bool, ctypes.c_int) -_setup_prototype(_uc, "uc_open", ucerr, ctypes.c_uint, ctypes.c_uint, ctypes.POINTER(uc_engine)) +_setup_prototype(_uc, "uc_open", ucerr, ctypes.c_uint, ctypes.c_uint, ctypes.POINTER(ctypes.c_char), ctypes.POINTER(uc_engine)) _setup_prototype(_uc, "uc_close", ucerr, uc_engine) _setup_prototype(_uc, "uc_strerror", ctypes.c_char_p, ucerr) _setup_prototype(_uc, "uc_errno", ucerr, uc_engine) @@ -151,7 +151,7 @@ def uc_arch_supported(query): class Uc(object): - def __init__(self, arch, mode): + def __init__(self, arch, mode, model=None): # verify version compatibility with the core before doing anything (major, minor, _combined) = uc_version() if major != UC_API_MAJOR or minor != UC_API_MINOR: @@ -161,7 +161,7 @@ class Uc(object): self._arch, self._mode = arch, mode self._uch = ctypes.c_void_p() - status = _uc.uc_open(arch, mode, ctypes.byref(self._uch)) + status = _uc.uc_open(arch, mode, model, ctypes.byref(self._uch)) if status != UC_ERR_OK: self._uch = None raise UcError(status) diff --git a/include/uc_priv.h b/include/uc_priv.h index de2e457f..908162ed 100644 --- a/include/uc_priv.h +++ b/include/uc_priv.h @@ -71,6 +71,7 @@ struct hook_struct { struct uc_struct { uc_arch arch; uc_mode mode; + char model[32]; // CPU model, or empty ('') for default model QemuMutex qemu_global_mutex; // qemu/cpus.c QemuCond qemu_cpu_cond; // qemu/cpus.c QemuThread *tcg_cpu_thread; // qemu/cpus.c diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index b812b473..da42ea6b 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -252,13 +252,14 @@ bool uc_arch_supported(uc_arch arch); @arch: architecture type (UC_ARCH_*) @mode: hardware mode. This is combined of UC_MODE_* + @model: CPU model in string, or NULL for default model. @uc: pointer to uc_engine, 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, uc_engine **uc); +uc_err uc_open(uc_arch arch, uc_mode mode, char *model, uc_engine **uc); /* Close UC instance: MUST do to release the handle when it is not used anymore. diff --git a/qemu/hw/arm/tosa.c b/qemu/hw/arm/tosa.c index 818fe32f..d06e45ce 100644 --- a/qemu/hw/arm/tosa.c +++ b/qemu/hw/arm/tosa.c @@ -19,8 +19,13 @@ static void tosa_init(struct uc_struct *uc, MachineState *machine) { - //cpu_arm_init(uc, "pxa255"); - cpu_arm_init(uc, "cortex-a15"); // FIXME + const char *cpu_model = uc->model; + + if (cpu_model[0] == '\0') { + cpu_model = "cortex-a15"; + } + + cpu_arm_init(uc, cpu_model); } void tosa_machine_init(struct uc_struct *uc) diff --git a/qemu/hw/arm/virt.c b/qemu/hw/arm/virt.c index b9156317..7853d27b 100644 --- a/qemu/hw/arm/virt.c +++ b/qemu/hw/arm/virt.c @@ -38,10 +38,10 @@ static void machvirt_init(struct uc_struct *uc, MachineState *machine) { - const char *cpu_model = machine->cpu_model; + const char *cpu_model = uc->model; int n; - if (!cpu_model) { + if (cpu_model[0] == '\0') { cpu_model = "cortex-a57"; // ARM64 } diff --git a/samples/mem_apis.c b/samples/mem_apis.c index db0240d8..335453fe 100644 --- a/samples/mem_apis.c +++ b/samples/mem_apis.c @@ -110,7 +110,7 @@ static void do_nx_demo(bool cause_fault) printf("# Example of marking memory NX (%s)\n", cause_fault ? "faulting" : "non-faulting"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("not ok - Failed on uc_open() with error returned: %u\n", err); return; @@ -193,7 +193,7 @@ static void do_perms_demo(bool change_perms) printf("# Example of manipulating memory permissions\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("not ok - Failed on uc_open() with error returned: %u\n", err); return; @@ -271,7 +271,7 @@ static void do_unmap_demo(bool do_unmap) printf("# Example of unmapping memory\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("not ok - Failed on uc_open() with error returned: %u\n", err); return; diff --git a/samples/sample_arm.c b/samples/sample_arm.c index 48f3ebf2..b02eb477 100644 --- a/samples/sample_arm.c +++ b/samples/sample_arm.c @@ -39,7 +39,7 @@ static void test_arm(void) printf("Emulate ARM code\n"); // Initialize emulator in ARM mode - err = uc_open(UC_ARCH_ARM, UC_MODE_ARM, &uc); + err = uc_open(UC_ARCH_ARM, UC_MODE_ARM, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); @@ -92,7 +92,7 @@ static void test_thumb(void) printf("Emulate THUMB code\n"); // Initialize emulator in ARM mode - err = uc_open(UC_ARCH_ARM, UC_MODE_THUMB, &uc); + err = uc_open(UC_ARCH_ARM, UC_MODE_THUMB, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); diff --git a/samples/sample_arm64.c b/samples/sample_arm64.c index 6b0ee8db..68ba928f 100644 --- a/samples/sample_arm64.c +++ b/samples/sample_arm64.c @@ -37,7 +37,7 @@ static void test_arm64(void) printf("Emulate ARM64 code\n"); // Initialize emulator in ARM mode - err = uc_open(UC_ARCH_ARM64, UC_MODE_ARM, &uc); + err = uc_open(UC_ARCH_ARM64, UC_MODE_ARM, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); diff --git a/samples/sample_m68k.c b/samples/sample_m68k.c index cfebd8e0..120f52db 100644 --- a/samples/sample_m68k.c +++ b/samples/sample_m68k.c @@ -52,7 +52,7 @@ static void test_m68k(void) printf("Emulate M68K code\n"); // Initialize emulator in M68K mode - err = uc_open(UC_ARCH_M68K, UC_MODE_BIG_ENDIAN, &uc); + err = uc_open(UC_ARCH_M68K, UC_MODE_BIG_ENDIAN, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); diff --git a/samples/sample_mips.c b/samples/sample_mips.c index 60331737..6b313532 100644 --- a/samples/sample_mips.c +++ b/samples/sample_mips.c @@ -36,7 +36,7 @@ static void test_mips_eb(void) printf("Emulate MIPS code (big-endian)\n"); // Initialize emulator in MIPS mode - err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32 + UC_MODE_BIG_ENDIAN, &uc); + err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32 + UC_MODE_BIG_ENDIAN, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); @@ -86,7 +86,7 @@ static void test_mips_el(void) printf("Emulate MIPS code (little-endian)\n"); // Initialize emulator in MIPS mode - err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32, &uc); + err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); diff --git a/samples/sample_sparc.c b/samples/sample_sparc.c index 45c185a5..d5333d52 100644 --- a/samples/sample_sparc.c +++ b/samples/sample_sparc.c @@ -38,7 +38,7 @@ static void test_sparc(void) printf("Emulate SPARC code\n"); // Initialize emulator in Sparc mode - err = uc_open(UC_ARCH_SPARC, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_SPARC, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); diff --git a/samples/sample_x86.c b/samples/sample_x86.c index c285b31d..a912e003 100644 --- a/samples/sample_x86.c +++ b/samples/sample_x86.c @@ -179,7 +179,7 @@ static void test_i386(void) printf("Emulate i386 code\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; @@ -238,7 +238,7 @@ static void test_i386_jump(void) printf("Emulate i386 code with jump\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; @@ -285,7 +285,7 @@ static void test_i386_loop(void) printf("Emulate i386 code that loop forever\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; @@ -337,7 +337,7 @@ static void test_i386_invalid_mem_read(void) printf("Emulate i386 code that read from invalid memory\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; @@ -395,7 +395,7 @@ static void test_i386_invalid_mem_write(void) printf("Emulate i386 code that write to invalid memory\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; @@ -466,7 +466,7 @@ static void test_i386_jump_invalid(void) printf("Emulate i386 code that jumps to invalid memory\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; @@ -522,7 +522,7 @@ static void test_i386_inout(void) printf("Emulate i386 code with IN/OUT instructions\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; @@ -597,7 +597,7 @@ static void test_x86_64(void) printf("Emulate x86_64 code\n"); // Initialize emulator in X86-64bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_64, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_64, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; @@ -698,7 +698,7 @@ static void test_x86_64_syscall(void) printf("Emulate x86_64 code with 'syscall' instruction\n"); // Initialize emulator in X86-64bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_64, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_64, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; @@ -750,7 +750,7 @@ static void test_x86_16(void) printf("Emulate x86 16-bit code\n"); // Initialize emulator in X86-16bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_16, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_16, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; diff --git a/samples/shellcode.c b/samples/shellcode.c index 5377ece9..efdea394 100644 --- a/samples/shellcode.c +++ b/samples/shellcode.c @@ -96,7 +96,7 @@ static void test_i386(void) printf("Emulate i386 code\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return; diff --git a/tests/regress/block_test.c b/tests/regress/block_test.c index 9a648f07..2fca3830 100644 --- a/tests/regress/block_test.c +++ b/tests/regress/block_test.c @@ -33,7 +33,7 @@ int main() { fprintf(stderr, "# basic block callback test\n"); fprintf(stderr, "# there are only two basic blocks 0x1000000-0x10001ff and 0x1000200-0x10003ff\n"); - uc_err err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + uc_err err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err != UC_ERR_OK) { fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err)); exit(0); diff --git a/tests/regress/map_crash.c b/tests/regress/map_crash.c index f794b4d7..bd3385e6 100644 --- a/tests/regress/map_crash.c +++ b/tests/regress/map_crash.c @@ -11,7 +11,7 @@ int main() int size; uint8_t *buf; uc_engine *uc; - uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc); + uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, NULL, &uc); if (err) { fprintf (stderr, "Cannot initialize unicorn\n"); return 1; diff --git a/tests/regress/map_write.c b/tests/regress/map_write.c index 7d64cda8..4f5a5c65 100644 --- a/tests/regress/map_write.c +++ b/tests/regress/map_write.c @@ -13,7 +13,7 @@ int main() int i; uc_err err; - err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc); + err = uc_open (UC_ARCH_X86, UC_MODE_64, NULL, &uc); if (err) { printf ("uc_open %d\n", err); return 1; diff --git a/tests/regress/mem_double_unmap.c b/tests/regress/mem_double_unmap.c index 3373a5cc..849b67ab 100644 --- a/tests/regress/mem_double_unmap.c +++ b/tests/regress/mem_double_unmap.c @@ -15,7 +15,7 @@ int main(int argc, char **argv, char **envp) uc_err err; // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("not ok - Failed on uc_open() with error returned: %u\n", err); return -1; diff --git a/tests/regress/mem_exec.c b/tests/regress/mem_exec.c index db9a2bc1..def83070 100644 --- a/tests/regress/mem_exec.c +++ b/tests/regress/mem_exec.c @@ -159,7 +159,7 @@ int main(int argc, char **argv, char **envp) printf("# Memory protect test\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("not ok %d - Failed on uc_open() with error returned: %u\n", log_num++, err); return 1; diff --git a/tests/regress/mem_protect.c b/tests/regress/mem_protect.c index d29dc490..fd239c3a 100644 --- a/tests/regress/mem_protect.c +++ b/tests/regress/mem_protect.c @@ -177,7 +177,7 @@ int main(int argc, char **argv, char **envp) printf("# Memory protect test\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("not ok %d - Failed on uc_open() with error returned: %u\n", log_num++, err); return 1; diff --git a/tests/regress/mem_unmap.c b/tests/regress/mem_unmap.c index 98e209f0..a740ee59 100644 --- a/tests/regress/mem_unmap.c +++ b/tests/regress/mem_unmap.c @@ -172,7 +172,7 @@ int main(int argc, char **argv, char **envp) printf("# Memory unmapping test\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("not ok %d - Failed on uc_open() with error returned: %u\n", log_num++, err); return 1; diff --git a/tests/regress/nr_mem_test.c b/tests/regress/nr_mem_test.c index 60e97db7..00a6dfe5 100644 --- a/tests/regress/nr_mem_test.c +++ b/tests/regress/nr_mem_test.c @@ -62,7 +62,7 @@ int main(int argc, char **argv, char **envp) printf("Memory protections test\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return 1; diff --git a/tests/regress/rep_movsb.c b/tests/regress/rep_movsb.c index 17b22641..6af15d60 100644 --- a/tests/regress/rep_movsb.c +++ b/tests/regress/rep_movsb.c @@ -99,7 +99,7 @@ int main(int argc, char **argv, char **envp) memset(buf1, 'A', 20); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("not ok %d - Failed on uc_open() with error returned: %u\n", log_num++, err); return 1; diff --git a/tests/regress/ro_mem_test.c b/tests/regress/ro_mem_test.c index 7b430497..2640cfe8 100644 --- a/tests/regress/ro_mem_test.c +++ b/tests/regress/ro_mem_test.c @@ -109,7 +109,7 @@ int main(int argc, char **argv, char **envp) printf("Memory mapping test\n"); // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u\n", err); return 1; diff --git a/tests/regress/sigill.c b/tests/regress/sigill.c index 8ce230cd..1a85c10d 100644 --- a/tests/regress/sigill.c +++ b/tests/regress/sigill.c @@ -22,7 +22,7 @@ int main() uint8_t *buf; uc_engine *uc; uc_hook uh_trap; - uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc); + uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, NULL, &uc); if (err) { fprintf (stderr, "Cannot initialize unicorn\n"); return 1; diff --git a/tests/regress/sigill2.c b/tests/regress/sigill2.c index 1e5b7284..c4125664 100644 --- a/tests/regress/sigill2.c +++ b/tests/regress/sigill2.c @@ -12,7 +12,7 @@ int main() uint8_t *buf; uc_engine *uc; - uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc); + uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, NULL, &uc); if (err) { fprintf (stderr, "Cannot initialize unicorn\n"); return 1; diff --git a/tests/regress/timeout_segfault.c b/tests/regress/timeout_segfault.c index 49d9a370..e3da202c 100644 --- a/tests/regress/timeout_segfault.c +++ b/tests/regress/timeout_segfault.c @@ -48,7 +48,7 @@ static void test_arm(void) printf("Emulate ARM code\n"); // Initialize emulator in ARM mode - err = uc_open(UC_ARCH_ARM, UC_MODE_ARM, &uc); + err = uc_open(UC_ARCH_ARM, UC_MODE_ARM, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); @@ -101,7 +101,7 @@ static void test_thumb(void) printf("Emulate THUMB code\n"); // Initialize emulator in ARM mode - err = uc_open(UC_ARCH_ARM, UC_MODE_THUMB, &uc); + err = uc_open(UC_ARCH_ARM, UC_MODE_THUMB, NULL, &uc); if (err) { printf("Failed on uc_open() with error returned: %u (%s)\n", err, uc_strerror(err)); diff --git a/tests/unit/test_mem_map.c b/tests/unit/test_mem_map.c index 13b96d9d..a5147146 100644 --- a/tests/unit/test_mem_map.c +++ b/tests/unit/test_mem_map.c @@ -13,7 +13,7 @@ static int setup(void **state) { uc_engine *uc; - uc_assert_success(uc_open(UC_ARCH_X86, UC_MODE_32, &uc)); + uc_assert_success(uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc)); *state = uc; return 0; diff --git a/tests/unit/test_x86.c b/tests/unit/test_x86.c index 04441123..13cdc11e 100644 --- a/tests/unit/test_x86.c +++ b/tests/unit/test_x86.c @@ -8,7 +8,7 @@ static int setup32(void **state) { uc_engine *uc; - OK(uc_open(UC_ARCH_X86, UC_MODE_32, &uc)); + OK(uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc)); *state = uc; return 0; @@ -126,7 +126,7 @@ static void test_i386(void **state) int r_edx = 0x7890; // EDX register // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); uc_assert_success(err); // map 2MB memory for this emulation @@ -182,7 +182,7 @@ static void test_i386_jump(void **state) const uint64_t address = 0x1000000; // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); uc_assert_success(err); // map 2MB memory for this emulation @@ -284,7 +284,7 @@ static void test_i386_inout(void **state) // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); uc_assert_success(err); // map 2MB memory for this emulation @@ -349,7 +349,7 @@ static void test_i386_loop(void **state) }; // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); uc_assert_success(err); // map 2MB memory for this emulation @@ -395,7 +395,7 @@ static void test_i386_invalid_mem_read(void **state) }; // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); uc_assert_success(err); // map 2MB memory for this emulation @@ -425,7 +425,7 @@ static void test_i386_invalid_mem_write(void **state) }; // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); uc_assert_success(err); // map 2MB memory for this emulation @@ -456,7 +456,7 @@ static void test_i386_jump_invalid(void **state) }; // Initialize emulator in X86-32bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_32, NULL, &uc); uc_assert_success(err); // map 2MB memory for this emulation @@ -536,7 +536,7 @@ static void test_x86_64(void **state) // Initialize emulator in X86-64bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_64, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_64, NULL, &uc); uc_assert_success(err); // map 2MB memory for this emulation @@ -650,7 +650,7 @@ static void test_x86_64_syscall(void **state) int64_t rax = 0x100; // Initialize emulator in X86-64bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_64, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_64, NULL, &uc); uc_assert_success(err); // map 2MB memory for this emulation @@ -699,7 +699,7 @@ static void test_x86_16(void **state) int32_t esi = 6; // Initialize emulator in X86-16bit mode - err = uc_open(UC_ARCH_X86, UC_MODE_16, &uc); + err = uc_open(UC_ARCH_X86, UC_MODE_16, NULL, &uc); uc_assert_success(err); // map 8KB memory for this emulation diff --git a/uc.c b/uc.c index 02c157bc..61f2de0b 100644 --- a/uc.c +++ b/uc.c @@ -134,7 +134,7 @@ bool uc_arch_supported(uc_arch arch) UNICORN_EXPORT -uc_err uc_open(uc_arch arch, uc_mode mode, uc_engine **result) +uc_err uc_open(uc_arch arch, uc_mode mode, char *model, uc_engine **result) { struct uc_struct *uc; @@ -148,6 +148,10 @@ uc_err uc_open(uc_arch arch, uc_mode mode, uc_engine **result) uc->errnum = UC_ERR_OK; uc->arch = arch; uc->mode = mode; + if (model) { + // uc->model[] is already filled with zeros. + strncpy(uc->model, model, sizeof(uc->model) - 1); + } // uc->cpus = QTAILQ_HEAD_INITIALIZER(uc->cpus); uc->cpus.tqh_first = NULL;