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