indentation

This commit is contained in:
Nguyen Anh Quynh 2015-12-20 12:16:03 +08:00
parent 3327ccd507
commit 63e227a585

View File

@ -36,10 +36,10 @@ Test for uc_emu_stop() in code hook not always stopping the emu at the current i
// This should loop forever.
const uint64_t addr = 0x100000;
const unsigned char test_code[] = {
0x00,0x00,0x00,0x00, // 100000: nop
0x00,0x00,0x00,0x00, // 100004: nop
0x00,0x00,0x00,0x00, // 100008: nop
0x00,0x00,0x00,0x00, // 10000C: nop
0x00,0x00,0x00,0x00, // 100000: nop
0x00,0x00,0x00,0x00, // 100004: nop
0x00,0x00,0x00,0x00, // 100008: nop
0x00,0x00,0x00,0x00, // 10000C: nop
};
bool test_passed_ok = false;
@ -47,12 +47,12 @@ bool test_passed_ok = false;
// This hook is used to show that code is executing in the emulator.
static void mips_codehook(uc_engine *uc, uint64_t address, uint32_t size, void *user_data)
{
printf("Executing: %llX\n", address);
if( address == 0x100008 )
{
printf("Stopping at: %llX\n", address);
uc_emu_stop(uc);
}
printf("Executing: %llX\n", address);
if( address == 0x100008 )
{
printf("Stopping at: %llX\n", address);
uc_emu_stop(uc);
}
}
@ -60,74 +60,74 @@ int main(int argc, char **argv, char **envp)
{
uc_engine *uc;
uc_err err;
int ret;
uc_hook hhc;
uint32_t val;
int ret;
uc_hook hhc;
uint32_t val;
// dynamically load shared library
// dynamically load shared library
#ifdef DYNLOAD
uc_dyn_load(NULL, 0);
uc_dyn_load(NULL, 0);
#endif
// Initialize emulator in MIPS 32bit little endian mode
// Initialize emulator in MIPS 32bit little endian mode
printf("uc_open()\n");
err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32, &uc);
err = uc_open(UC_ARCH_MIPS, UC_MODE_MIPS32, &uc);
if (err)
{
{
printf("Failed on uc_open() with error returned: %u\n", err);
return err;
}
// map in a page of mem
printf("uc_mem_map()\n");
err = uc_mem_map(uc, addr, 0x1000, UC_PROT_ALL);
// map in a page of mem
printf("uc_mem_map()\n");
err = uc_mem_map(uc, addr, 0x1000, UC_PROT_ALL);
if (err)
{
{
printf("Failed on uc_mem_map() with error returned: %u\n", err);
return err;
}
// write machine code to be emulated to memory
printf("uc_mem_write()\n");
// write machine code to be emulated to memory
printf("uc_mem_write()\n");
err = uc_mem_write(uc, addr, test_code, sizeof(test_code));
if( err )
{
if( err )
{
printf("Failed on uc_mem_write() with error returned: %u\n", err);
return err;
}
// hook all instructions by having @begin > @end
printf("uc_hook_add()\n");
printf("uc_hook_add()\n");
uc_hook_add(uc, &hhc, UC_HOOK_CODE, mips_codehook, NULL, (uint64_t)1, (uint64_t)0);
if( err )
{
if( err )
{
printf("Failed on uc_hook_add(code) with error returned: %u\n", err);
return err;
}
// start executing code
printf("uc_emu_start()\n");
uc_emu_start(uc, addr, addr+sizeof(test_code), 0, 0);
// start executing code
printf("uc_emu_start()\n");
uc_emu_start(uc, addr, addr+sizeof(test_code), 0, 0);
// done executing, print some reg values as a test
uc_reg_read(uc, UC_MIPS_REG_PC, &val); printf("pc is %X\n", val);
test_passed_ok = val == 0x100008;
// free resources
printf("uc_close()\n");
uc_close(uc);
if( test_passed_ok )
printf("\n\nTEST PASSED!\n\n");
else
printf("\n\nTEST FAILED!\n\n");
// done executing, print some reg values as a test
uc_reg_read(uc, UC_MIPS_REG_PC, &val); printf("pc is %X\n", val);
test_passed_ok = val == 0x100008;
// dynamically free shared library
// free resources
printf("uc_close()\n");
uc_close(uc);
if( test_passed_ok )
printf("\n\nTEST PASSED!\n\n");
else
printf("\n\nTEST FAILED!\n\n");
// dynamically free shared library
#ifdef DYNLOAD
uc_dyn_free();
#endif
return 0;
return 0;
}