From 2c0556826f8ca99a907de7f5007c2621ab2ff9b1 Mon Sep 17 00:00:00 2001 From: Jonathon Reinhart Date: Mon, 7 Sep 2015 13:09:05 -0400 Subject: [PATCH] samples: remove (uint8_t*) casts to mem API calls These casts are now unnecessary. --- samples/sample_arm.c | 4 ++-- samples/sample_arm64.c | 2 +- samples/sample_m68k.c | 2 +- samples/sample_mips.c | 4 ++-- samples/sample_sparc.c | 2 +- samples/sample_x86.c | 26 +++++++++++++------------- samples/shellcode.c | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/samples/sample_arm.c b/samples/sample_arm.c index de0c970b..48f3ebf2 100644 --- a/samples/sample_arm.c +++ b/samples/sample_arm.c @@ -50,7 +50,7 @@ static void test_arm(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - uc_mem_write(uc, ADDRESS, (uint8_t *)ARM_CODE, sizeof(ARM_CODE) - 1); + uc_mem_write(uc, ADDRESS, ARM_CODE, sizeof(ARM_CODE) - 1); // initialize machine registers uc_reg_write(uc, UC_ARM_REG_R0, &r0); @@ -103,7 +103,7 @@ static void test_thumb(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - uc_mem_write(uc, ADDRESS, (uint8_t *)THUMB_CODE, sizeof(THUMB_CODE) - 1); + uc_mem_write(uc, ADDRESS, THUMB_CODE, sizeof(THUMB_CODE) - 1); // initialize machine registers uc_reg_write(uc, UC_ARM_REG_SP, &sp); diff --git a/samples/sample_arm64.c b/samples/sample_arm64.c index b0d53e07..6b0ee8db 100644 --- a/samples/sample_arm64.c +++ b/samples/sample_arm64.c @@ -48,7 +48,7 @@ static void test_arm64(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - uc_mem_write(uc, ADDRESS, (uint8_t *)ARM_CODE, sizeof(ARM_CODE) - 1); + uc_mem_write(uc, ADDRESS, ARM_CODE, sizeof(ARM_CODE) - 1); // initialize machine registers uc_reg_write(uc, UC_ARM64_REG_X11, &x11); diff --git a/samples/sample_m68k.c b/samples/sample_m68k.c index a584c18d..cfebd8e0 100644 --- a/samples/sample_m68k.c +++ b/samples/sample_m68k.c @@ -63,7 +63,7 @@ static void test_m68k(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - uc_mem_write(uc, ADDRESS, (uint8_t *)M68K_CODE, sizeof(M68K_CODE) - 1); + uc_mem_write(uc, ADDRESS, M68K_CODE, sizeof(M68K_CODE) - 1); // initialize machine registers uc_reg_write(uc, UC_M68K_REG_D0, &d0); diff --git a/samples/sample_mips.c b/samples/sample_mips.c index 0b6e1a1b..60331737 100644 --- a/samples/sample_mips.c +++ b/samples/sample_mips.c @@ -47,7 +47,7 @@ static void test_mips_eb(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - uc_mem_write(uc, ADDRESS, (uint8_t *)MIPS_CODE_EB, sizeof(MIPS_CODE_EB) - 1); + uc_mem_write(uc, ADDRESS, MIPS_CODE_EB, sizeof(MIPS_CODE_EB) - 1); // initialize machine registers uc_reg_write(uc, UC_MIPS_REG_1, &r1); @@ -97,7 +97,7 @@ static void test_mips_el(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - uc_mem_write(uc, ADDRESS, (uint8_t *)MIPS_CODE_EL, sizeof(MIPS_CODE_EL) - 1); + uc_mem_write(uc, ADDRESS, MIPS_CODE_EL, sizeof(MIPS_CODE_EL) - 1); // initialize machine registers uc_reg_write(uc, UC_MIPS_REG_1, &r1); diff --git a/samples/sample_sparc.c b/samples/sample_sparc.c index 803bdfd7..2cdc4915 100644 --- a/samples/sample_sparc.c +++ b/samples/sample_sparc.c @@ -49,7 +49,7 @@ static void test_sparc(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - uc_mem_write(uc, ADDRESS, (uint8_t *)SPARC_CODE, sizeof(SPARC_CODE) - 1); + uc_mem_write(uc, ADDRESS, SPARC_CODE, sizeof(SPARC_CODE) - 1); // initialize machine registers uc_reg_write(uc, UC_SPARC_REG_G1, &g1); diff --git a/samples/sample_x86.c b/samples/sample_x86.c index 1062aa15..c6662dfe 100644 --- a/samples/sample_x86.c +++ b/samples/sample_x86.c @@ -189,7 +189,7 @@ static void test_i386(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, ADDRESS, (uint8_t *)X86_CODE32, sizeof(X86_CODE32) - 1)) { + if (uc_mem_write(uc, ADDRESS, X86_CODE32, sizeof(X86_CODE32) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; } @@ -220,7 +220,7 @@ static void test_i386(void) printf(">>> EDX = 0x%x\n", r_edx); // read from memory - if (!uc_mem_read(uc, ADDRESS, (uint8_t *)&tmp, 4)) + if (!uc_mem_read(uc, ADDRESS, &tmp, sizeof(tmp))) printf(">>> Read 4 bytes from [0x%x] = 0x%x\n", ADDRESS, tmp); else printf(">>> Failed to read 4 bytes from [0x%x]\n", ADDRESS); @@ -248,7 +248,7 @@ static void test_i386_jump(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, ADDRESS, (uint8_t *)X86_CODE32_JUMP, + if (uc_mem_write(uc, ADDRESS, X86_CODE32_JUMP, sizeof(X86_CODE32_JUMP) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; @@ -295,7 +295,7 @@ static void test_i386_loop(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, ADDRESS, (uint8_t *)X86_CODE32_LOOP, sizeof(X86_CODE32_LOOP) - 1)) { + if (uc_mem_write(uc, ADDRESS, X86_CODE32_LOOP, sizeof(X86_CODE32_LOOP) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; } @@ -347,7 +347,7 @@ static void test_i386_invalid_mem_read(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, ADDRESS, (uint8_t *)X86_CODE32_MEM_READ, sizeof(X86_CODE32_MEM_READ) - 1)) { + if (uc_mem_write(uc, ADDRESS, X86_CODE32_MEM_READ, sizeof(X86_CODE32_MEM_READ) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; } @@ -405,7 +405,7 @@ static void test_i386_invalid_mem_write(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, ADDRESS, (uint8_t *)X86_CODE32_MEM_WRITE, sizeof(X86_CODE32_MEM_WRITE) - 1)) { + if (uc_mem_write(uc, ADDRESS, X86_CODE32_MEM_WRITE, sizeof(X86_CODE32_MEM_WRITE) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; } @@ -439,12 +439,12 @@ static void test_i386_invalid_mem_write(void) printf(">>> EDX = 0x%x\n", r_edx); // read from memory - if (!uc_mem_read(uc, 0xaaaaaaaa, (uint8_t *)&tmp, 4)) + if (!uc_mem_read(uc, 0xaaaaaaaa, &tmp, sizeof(tmp))) printf(">>> Read 4 bytes from [0x%x] = 0x%x\n", 0xaaaaaaaa, tmp); else printf(">>> Failed to read 4 bytes from [0x%x]\n", 0xffffffaa); - if (!uc_mem_read(uc, 0xffffffaa, (uint8_t *)&tmp, 4)) + if (!uc_mem_read(uc, 0xffffffaa, &tmp, sizeof(tmp))) printf(">>> Read 4 bytes from [0x%x] = 0x%x\n", 0xffffffaa, tmp); else printf(">>> Failed to read 4 bytes from [0x%x]\n", 0xffffffaa); @@ -476,7 +476,7 @@ static void test_i386_jump_invalid(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, ADDRESS, (uint8_t *)X86_CODE32_JMP_INVALID, sizeof(X86_CODE32_JMP_INVALID) - 1)) { + if (uc_mem_write(uc, ADDRESS, X86_CODE32_JMP_INVALID, sizeof(X86_CODE32_JMP_INVALID) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; } @@ -532,7 +532,7 @@ static void test_i386_inout(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, ADDRESS, (uint8_t *)X86_CODE32_INOUT, sizeof(X86_CODE32_INOUT) - 1)) { + if (uc_mem_write(uc, ADDRESS, X86_CODE32_INOUT, sizeof(X86_CODE32_INOUT) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; } @@ -607,7 +607,7 @@ static void test_x86_64(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, ADDRESS, (uint8_t *)X86_CODE64, sizeof(X86_CODE64) - 1)) { + if (uc_mem_write(uc, ADDRESS, X86_CODE64, sizeof(X86_CODE64) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; } @@ -708,7 +708,7 @@ static void test_x86_64_syscall(void) uc_mem_map(uc, ADDRESS, 2 * 1024 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, ADDRESS, (uint8_t *)X86_CODE64_SYSCALL, sizeof(X86_CODE64_SYSCALL) - 1)) { + if (uc_mem_write(uc, ADDRESS, X86_CODE64_SYSCALL, sizeof(X86_CODE64_SYSCALL) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; } @@ -760,7 +760,7 @@ static void test_x86_16(void) uc_mem_map(uc, 0, 8 * 1024, UC_PROT_ALL); // write machine code to be emulated to memory - if (uc_mem_write(uc, 0, (uint8_t *)X86_CODE16, sizeof(X86_CODE64) - 1)) { + if (uc_mem_write(uc, 0, X86_CODE16, sizeof(X86_CODE64) - 1)) { printf("Failed to write emulation code to memory, quit!\n"); return; } diff --git a/samples/shellcode.c b/samples/shellcode.c index d8ef6385..5377ece9 100644 --- a/samples/shellcode.c +++ b/samples/shellcode.c @@ -23,7 +23,7 @@ static void hook_code(uc_engine *uc, uint64_t address, uint32_t size, void *user_data) { int r_eip; - char tmp[16]; + uint8_t tmp[16]; printf("Tracing instruction at 0x%"PRIx64 ", instruction size = 0x%x\n", address, size); @@ -31,10 +31,10 @@ static void hook_code(uc_engine *uc, uint64_t address, uint32_t size, void *user printf("*** EIP = %x ***: ", r_eip); size = MIN(sizeof(tmp), size); - if (!uc_mem_read(uc, address, (uint8_t *)tmp, size)) { + if (!uc_mem_read(uc, address, tmp, size)) { int i; for (i=0; i