Automated leading tab to spaces conversion.

This commit is contained in:
xorstream
2017-01-21 12:28:22 +11:00
parent df41c49e2d
commit 770c5616e2
69 changed files with 3839 additions and 3839 deletions

View File

@@ -151,7 +151,7 @@ static void test_thumb(void)
int main(int argc, char **argv, char **envp)
{
// dynamically load shared library
// dynamically load shared library
#ifdef DYNLOAD
if (!uc_dyn_load(NULL, 0)) {
printf("Error dynamically loading shared library.\n");

View File

@@ -98,7 +98,7 @@ static void test_arm64(void)
int main(int argc, char **argv, char **envp)
{
// dynamically load shared library
// dynamically load shared library
#ifdef DYNLOAD
if (!uc_dyn_load(NULL, 0)) {
printf("Error dynamically loading shared library.\n");

View File

@@ -160,7 +160,7 @@ static void test_m68k(void)
int main(int argc, char **argv, char **envp)
{
// dynamically load shared library
// dynamically load shared library
#ifdef DYNLOAD
if (!uc_dyn_load(NULL, 0)) {
printf("Error dynamically loading shared library.\n");

View File

@@ -145,7 +145,7 @@ static void test_mips_el(void)
int main(int argc, char **argv, char **envp)
{
// dynamically load shared library
// dynamically load shared library
#ifdef DYNLOAD
if (!uc_dyn_load(NULL, 0)) {
printf("Error dynamically loading shared library.\n");

View File

@@ -100,7 +100,7 @@ static void test_sparc(void)
int main(int argc, char **argv, char **envp)
{
// dynamically load shared library
// dynamically load shared library
#ifdef DYNLOAD
if (!uc_dyn_load(NULL, 0)) {
printf("Error dynamically loading shared library.\n");

View File

@@ -281,7 +281,7 @@ static void test_x86_64(void)
int main(int argc, char **argv, char **envp)
{
// dynamically load shared library
// dynamically load shared library
#ifdef DYNLOAD
if (!uc_dyn_load(NULL, 0)) {
printf("Error dynamically loading shared library.\n");

View File

@@ -40,11 +40,11 @@ but that the code hook is just not occurring.
// It should loop 3 times before ending.
const uint64_t addr = 0x100000;
const unsigned char loop_test_code[] = {
0x02,0x00,0x04,0x24, // 100000: li $a0, 2
// loop1
0x00,0x00,0x00,0x00, // 100004: nop
0xFE,0xFF,0x80,0x14, // 100008: bnez $a0, loop1
0xFF,0xFF,0x84,0x24, // 10000C: addiu $a0, -1
0x02,0x00,0x04,0x24, // 100000: li $a0, 2
// loop1
0x00,0x00,0x00,0x00, // 100004: nop
0xFE,0xFF,0x80,0x14, // 100008: bnez $a0, loop1
0xFF,0xFF,0x84,0x24, // 10000C: addiu $a0, -1
};
bool test_passed_ok = false;
int loop_count = 0;
@@ -52,14 +52,14 @@ int loop_count = 0;
static void mips_codehook(uc_engine *uc, uint64_t address, uint32_t size, void *user_data)
{
if( address == 0x10000C )
test_passed_ok = true;
if( address == 0x100004 )
{
printf("\nloop %d:\n", loop_count);
loop_count++;
}
printf("Code: %"PRIx64"\n", address);
if( address == 0x10000C )
test_passed_ok = true;
if( address == 0x100004 )
{
printf("\nloop %d:\n", loop_count);
loop_count++;
}
printf("Code: %"PRIx64"\n", address);
}
@@ -67,74 +67,74 @@ int main(int argc, char **argv, char **envp)
{
uc_engine *uc;
uc_err err;
uc_hook hhc;
uint32_t val;
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
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
err = uc_mem_map(uc, addr, 0x1000, UC_PROT_ALL);
// map in a page of mem
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
// write machine code to be emulated to memory
err = uc_mem_write(uc, addr, loop_test_code, sizeof(loop_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
uc_hook_add(uc, &hhc, UC_HOOK_CODE, mips_codehook, NULL, 1, 0);
if( err )
{
if( err )
{
printf("Failed on uc_hook_add(code) with error returned: %u\n", err);
return err;
}
// execute code
printf("---- Executing Code ----\n");
err = uc_emu_start(uc, addr, addr + sizeof(loop_test_code), 0, 0);
printf("---- Executing Code ----\n");
err = uc_emu_start(uc, addr, addr + sizeof(loop_test_code), 0, 0);
if (err)
{
{
printf("Failed on uc_emu_start() with error returned %u: %s\n",
err, uc_strerror(err));
return err;
return err;
}
// done executing, print some reg values as a test
printf("---- Execution Complete ----\n\n");
uc_reg_read(uc, UC_MIPS_REG_PC, &val); printf("pc is %X\n", val);
uc_reg_read(uc, UC_MIPS_REG_A0, &val); printf("a0 is %X\n", val);
// free resources
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
printf("---- Execution Complete ----\n\n");
uc_reg_read(uc, UC_MIPS_REG_PC, &val); printf("pc is %X\n", val);
uc_reg_read(uc, UC_MIPS_REG_A0, &val); printf("a0 is %X\n", val);
// free resources
uc_close(uc);
if( test_passed_ok )
printf("\n\nTEST PASSED!\n\n");
else
printf("\n\nTEST FAILED!\n\n");
// dynamically free shared library
// dynamically free shared library
#ifdef DYNLOAD
uc_dyn_free();
#endif
return 0;
return 0;
}

View File

@@ -52,11 +52,11 @@ background.
// This should loop forever.
const uint64_t addr = 0x100000;
const unsigned char loop_test_code[] = {
0x02,0x00,0x04,0x24, // 100000: li $a0, 2
// loop1
0x00,0x00,0x00,0x00, // 100004: nop
0xFE,0xFF,0x80,0x14, // 100008: bnez $a0, loop1
0x00,0x00,0x00,0x00, // 10000C: nop
0x02,0x00,0x04,0x24, // 100000: li $a0, 2
// loop1
0x00,0x00,0x00,0x00, // 100004: nop
0xFE,0xFF,0x80,0x14, // 100008: bnez $a0, loop1
0x00,0x00,0x00,0x00, // 10000C: nop
};
bool test_passed_ok = false;
int loop_count = 0;
@@ -65,14 +65,14 @@ int loop_count = 0;
// 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("Code: %"PRIx64"\n", address);
printf("Code: %"PRIx64"\n", address);
}
typedef struct {
uc_engine *uc;
uint64_t startAddr;
uint64_t endAddr;
uc_engine *uc;
uint64_t startAddr;
uint64_t endAddr;
} EmuStarterParam_t;
// This is a thread that just runs uc_emu_start() in it.
@@ -80,38 +80,38 @@ typedef struct {
static uc_err emu_starter(void* param)
{
uc_engine *uc;
uint64_t start_addr;
uint64_t end_addr;
uc_err err;
EmuStarterParam_t* starter_params = (EmuStarterParam_t *)param;
uc = starter_params->uc;
start_addr = starter_params->startAddr;
end_addr = starter_params->endAddr;
printf("uc_emu_start()\n");
err = uc_emu_start(uc, start_addr, end_addr, 0, 0);
uint64_t start_addr;
uint64_t end_addr;
uc_err err;
EmuStarterParam_t* starter_params = (EmuStarterParam_t *)param;
uc = starter_params->uc;
start_addr = starter_params->startAddr;
end_addr = starter_params->endAddr;
printf("uc_emu_start()\n");
err = uc_emu_start(uc, start_addr, end_addr, 0, 0);
if (err)
{
{
printf("Failed on uc_emu_start() with error returned %u: %s\n",
err, uc_strerror(err));
}
return err;
return err;
}
#ifdef _WIN32
static unsigned int __stdcall win32_emu_starter(void* param)
{
uc_err err = emu_starter(param);
_endthreadex(err);
return err;
uc_err err = emu_starter(param);
_endthreadex(err);
return err;
}
#else
static void* posix_emu_starter(void* param)
{
uc_err err = emu_starter(param);
return (void*)err;
uc_err err = emu_starter(param);
return (void*)err;
}
#endif
@@ -120,124 +120,124 @@ int main(int argc, char **argv, char **envp)
{
uc_engine *uc;
uc_err err;
int ret;
uc_hook hhc;
uint32_t val;
EmuStarterParam_t starter_params;
int ret;
uc_hook hhc;
uint32_t val;
EmuStarterParam_t starter_params;
#ifdef _WIN32
HANDLE th = (HANDLE)-1;
HANDLE th = (HANDLE)-1;
#else
pthread_t th;
pthread_t th;
#endif
// 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, loop_test_code, sizeof(loop_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, 1, 0);
if( err )
{
if( err )
{
printf("Failed on uc_hook_add(code) with error returned: %u\n", err);
return err;
}
// start background thread
printf("---- Thread Starting ----\n");
starter_params.uc = uc;
starter_params.startAddr = addr;
starter_params.endAddr = addr + sizeof(loop_test_code);
// start background thread
printf("---- Thread Starting ----\n");
starter_params.uc = uc;
starter_params.startAddr = addr;
starter_params.endAddr = addr + sizeof(loop_test_code);
#ifdef _WIN32
// create thread
th = (HANDLE)_beginthreadex(NULL, 0, win32_emu_starter, &starter_params, CREATE_SUSPENDED, NULL);
if(th == (HANDLE)-1)
{
printf("Failed on _beginthreadex() with error returned: %u\n", _errno());
return -1;
}
// start thread
ret = ResumeThread(th);
if( ret == -1 )
{
printf("Failed on ResumeThread() with error returned: %u\n", _errno());
return -2;
}
// wait 3 seconds
Sleep(3 * 1000);
// create thread
th = (HANDLE)_beginthreadex(NULL, 0, win32_emu_starter, &starter_params, CREATE_SUSPENDED, NULL);
if(th == (HANDLE)-1)
{
printf("Failed on _beginthreadex() with error returned: %u\n", _errno());
return -1;
}
// start thread
ret = ResumeThread(th);
if( ret == -1 )
{
printf("Failed on ResumeThread() with error returned: %u\n", _errno());
return -2;
}
// wait 3 seconds
Sleep(3 * 1000);
#else
// add posix code to start the emu_starter() thread
ret = pthread_create(&th, NULL, posix_emu_starter, &starter_params);
if( ret )
{
printf("Failed on pthread_create() with error returned: %u\n", err);
return -2;
}
// wait 3 seconds
sleep(3);
// add posix code to start the emu_starter() thread
ret = pthread_create(&th, NULL, posix_emu_starter, &starter_params);
if( ret )
{
printf("Failed on pthread_create() with error returned: %u\n", err);
return -2;
}
// wait 3 seconds
sleep(3);
#endif
// Stop the thread after it has been let to run in the background for a while
printf("---- Thread Stopping ----\n");
printf("uc_emu_stop()\n");
err = uc_emu_stop(uc);
if( err )
{
// Stop the thread after it has been let to run in the background for a while
printf("---- Thread Stopping ----\n");
printf("uc_emu_stop()\n");
err = uc_emu_stop(uc);
if( err )
{
printf("Failed on uc_emu_stop() with error returned: %u\n", err);
return err;
}
test_passed_ok = true;
test_passed_ok = true;
// 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_A0, &val); printf("a0 is %X\n", val);
// 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);
uc_reg_read(uc, UC_MIPS_REG_A0, &val); printf("a0 is %X\n", val);
// 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
// dynamically free shared library
#ifdef DYNLOAD
uc_dyn_free();
#endif
return 0;
return 0;
}