regress: fix code style
This commit is contained in:
parent
5de0d5ca70
commit
d957d1efee
@ -4,9 +4,10 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#define UC_BUG_WRITE_SIZE 13000
|
||||
#define UC_BUG_WRITE_ADDR 0x1000 // fix this by change this to 0x2000
|
||||
#define UC_BUG_WRITE_ADDR 0x1000
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
int size;
|
||||
uint8_t *buf;
|
||||
uch uh;
|
||||
|
@ -6,44 +6,45 @@
|
||||
#define SIZE 1024*64
|
||||
#define OVERFLOW 1
|
||||
|
||||
int main() {
|
||||
uch uh;
|
||||
uint8_t *buf, *buf2;
|
||||
int i;
|
||||
uc_err err;
|
||||
int main()
|
||||
{
|
||||
uch uh;
|
||||
uint8_t *buf, *buf2;
|
||||
int i;
|
||||
uc_err err;
|
||||
|
||||
err = uc_open (UC_ARCH_X86, UC_MODE_64, &uh);
|
||||
if (err) {
|
||||
printf ("uc_open %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
err = uc_mem_map (uh, ADDR, SIZE);
|
||||
if (err) {
|
||||
printf ("uc_mem_map %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
buf = calloc (SIZE*2, 1);
|
||||
buf2 = calloc (SIZE, 1);
|
||||
for (i=0;i<SIZE; i++) {
|
||||
buf[i] = i & 0xff;
|
||||
}
|
||||
/* crash here */
|
||||
err = uc_mem_write (uh, ADDR, buf, SIZE+OVERFLOW);
|
||||
if (err) {
|
||||
printf ("uc_mem_map %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
err = uc_mem_read (uh, ADDR+10, buf2, 4);
|
||||
if (err) {
|
||||
printf ("uc_mem_map %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
if (buf2[0] != 0xa) {
|
||||
printf ("mem contents are wrong\n");
|
||||
return 1;
|
||||
}
|
||||
printf ("OK\n");
|
||||
free (buf);
|
||||
free (buf2);
|
||||
return 0;
|
||||
err = uc_open (UC_ARCH_X86, UC_MODE_64, &uh);
|
||||
if (err) {
|
||||
printf ("uc_open %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
err = uc_mem_map (uh, ADDR, SIZE);
|
||||
if (err) {
|
||||
printf ("uc_mem_map %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
buf = calloc (SIZE*2, 1);
|
||||
buf2 = calloc (SIZE, 1);
|
||||
for (i=0;i<SIZE; i++) {
|
||||
buf[i] = i & 0xff;
|
||||
}
|
||||
/* crash here */
|
||||
err = uc_mem_write (uh, ADDR, buf, SIZE+OVERFLOW);
|
||||
if (err) {
|
||||
printf ("uc_mem_map %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
err = uc_mem_read (uh, ADDR+10, buf2, 4);
|
||||
if (err) {
|
||||
printf ("uc_mem_map %d\n", err);
|
||||
return 1;
|
||||
}
|
||||
if (buf2[0] != 0xa) {
|
||||
printf ("mem contents are wrong\n");
|
||||
return 1;
|
||||
}
|
||||
printf ("OK\n");
|
||||
free (buf);
|
||||
free (buf2);
|
||||
return 0;
|
||||
}
|
||||
|
@ -5,25 +5,25 @@
|
||||
#include <unicorn/unicorn.h>
|
||||
|
||||
const uint8_t PROGRAM[] =
|
||||
"\xeb\x1a\x58\x83\xc0\x04\x83\xe0\xfc\x83\xc0\x01\xc7\x00\x78\x56"
|
||||
"\x34\x12\x83\xc0\x07\xc7\x00\x21\x43\x65\x87\x90\xe8\xe1\xff\xff"
|
||||
"\xff" "xxxxAAAAxxxBBBB";
|
||||
"\xeb\x1a\x58\x83\xc0\x04\x83\xe0\xfc\x83\xc0\x01\xc7\x00\x78\x56"
|
||||
"\x34\x12\x83\xc0\x07\xc7\x00\x21\x43\x65\x87\x90\xe8\xe1\xff\xff"
|
||||
"\xff" "xxxxAAAAxxxBBBB";
|
||||
// total size: 33 bytes
|
||||
|
||||
/*
|
||||
jmp short bottom
|
||||
top:
|
||||
pop eax
|
||||
add eax, 4
|
||||
and eax, 0xfffffffc
|
||||
add eax, 1 ; unaligned
|
||||
mov dword [eax], 0x12345678 ; try to write into code section
|
||||
add eax, 7 ; aligned
|
||||
mov dword [eax], 0x87654321 ; try to write into code section
|
||||
nop
|
||||
pop eax
|
||||
add eax, 4
|
||||
and eax, 0xfffffffc
|
||||
add eax, 1 ; unaligned
|
||||
mov dword [eax], 0x12345678 ; try to write into code section
|
||||
add eax, 7 ; aligned
|
||||
mov dword [eax], 0x87654321 ; try to write into code section
|
||||
nop
|
||||
bottom:
|
||||
call top
|
||||
*/
|
||||
call top
|
||||
*/
|
||||
|
||||
// callback for tracing instruction
|
||||
static void hook_code(uch handle, uint64_t address, uint32_t size, void *user_data)
|
||||
@ -50,20 +50,20 @@ static bool hook_mem_invalid(uch handle, uc_mem_type type,
|
||||
case UC_MEM_WRITE:
|
||||
//if this is a push, esp has not been adjusted yet
|
||||
if (esp == (address + size)) {
|
||||
uint32_t upper;
|
||||
upper = (esp + 0xfff) & ~0xfff;
|
||||
printf(">>> Stack appears to be missing at 0x%"PRIx64 ", allocating now\n", address);
|
||||
// map this memory in with 2MB in size
|
||||
uc_mem_map_ex(handle, upper - 0x8000, 0x8000, UC_PROT_READ | UC_PROT_WRITE);
|
||||
// return true to indicate we want to continue
|
||||
return true;
|
||||
uint32_t upper;
|
||||
upper = (esp + 0xfff) & ~0xfff;
|
||||
printf(">>> Stack appears to be missing at 0x%"PRIx64 ", allocating now\n", address);
|
||||
// map this memory in with 2MB in size
|
||||
uc_mem_map_ex(handle, upper - 0x8000, 0x8000, UC_PROT_READ | UC_PROT_WRITE);
|
||||
// return true to indicate we want to continue
|
||||
return true;
|
||||
}
|
||||
printf(">>> Missing memory is being WRITTEN at 0x%"PRIx64 ", data size = %u, data value = 0x%"PRIx64 "\n",
|
||||
address, size, value);
|
||||
address, size, value);
|
||||
return false;
|
||||
case UC_MEM_WRITE_RO:
|
||||
printf(">>> RO memory is being WRITTEN at 0x%"PRIx64 ", data size = %u, data value = 0x%"PRIx64 "\n",
|
||||
address, size, value);
|
||||
address, size, value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -72,14 +72,15 @@ static bool hook_mem_invalid(uch handle, uc_mem_type type,
|
||||
#define STACK 0x500000
|
||||
#define STACK_SIZE 0x5000
|
||||
|
||||
int main(int argc, char **argv, char **envp) {
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
uch handle, trace1, trace2;
|
||||
uc_err err;
|
||||
uint8_t bytes[8];
|
||||
uint32_t esp;
|
||||
int result;
|
||||
int map_stack = 0;
|
||||
|
||||
|
||||
if (argc == 2 && strcmp(argv[1], "--map-stack") == 0) {
|
||||
map_stack = 1;
|
||||
}
|
||||
@ -97,10 +98,10 @@ int main(int argc, char **argv, char **envp) {
|
||||
uc_mem_map(handle, 0x200000, 0x2000);
|
||||
uc_mem_map(handle, 0x300000, 0x3000);
|
||||
uc_mem_map_ex(handle, 0x400000, 0x4000, UC_PROT_READ);
|
||||
|
||||
|
||||
if (map_stack) {
|
||||
printf("Pre-mapping stack\n");
|
||||
uc_mem_map_ex(handle, STACK, STACK_SIZE, UC_PROT_READ | UC_PROT_WRITE);
|
||||
printf("Pre-mapping stack\n");
|
||||
uc_mem_map_ex(handle, STACK, STACK_SIZE, UC_PROT_READ | UC_PROT_WRITE);
|
||||
}
|
||||
else {
|
||||
printf("Mapping stack on first invalid memory access\n");
|
||||
@ -190,6 +191,6 @@ int main(int argc, char **argv, char **envp) {
|
||||
}
|
||||
|
||||
uc_close(&handle);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -8,14 +8,16 @@
|
||||
|
||||
int got_sigill = 0;
|
||||
|
||||
void _interrupt(uch handle, uint32_t intno, void *user_data) {
|
||||
void _interrupt(uch handle, uint32_t intno, void *user_data)
|
||||
{
|
||||
if (intno == 6) {
|
||||
uc_emu_stop (handle);
|
||||
got_sigill = 1;
|
||||
got_sigill = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
int size;
|
||||
uint8_t *buf;
|
||||
uch uh;
|
||||
@ -34,7 +36,7 @@ int main() {
|
||||
memset (buf, 0, size);
|
||||
if (!uc_mem_map (uh, UC_BUG_WRITE_ADDR, size)) {
|
||||
uc_mem_write (uh, UC_BUG_WRITE_ADDR,
|
||||
(const uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff", 8);
|
||||
(const uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff", 8);
|
||||
}
|
||||
uc_hook_add (uh, &uh_trap, UC_HOOK_INTR, _interrupt, NULL);
|
||||
uc_emu_start (uh, UC_BUG_WRITE_ADDR, UC_BUG_WRITE_ADDR+8, 0, 1);
|
||||
|
@ -20,7 +20,7 @@ int main()
|
||||
size = UC_BUG_WRITE_SIZE;
|
||||
if (!uc_mem_map (uh, UC_BUG_WRITE_ADDR, size)) {
|
||||
uc_mem_write (uh, UC_BUG_WRITE_ADDR,
|
||||
(const uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff", 8);
|
||||
(const uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff", 8);
|
||||
}
|
||||
err = uc_emu_start (uh, UC_BUG_WRITE_ADDR, UC_BUG_WRITE_ADDR+8, 0, 1);
|
||||
uc_close (&uh);
|
||||
|
Loading…
Reference in New Issue
Block a user