2015-08-27 01:19:12 +03:00
|
|
|
#include <unicorn/unicorn.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define ADDR 0x00400000
|
|
|
|
#define SIZE 1024*64
|
|
|
|
#define OVERFLOW 1
|
|
|
|
|
2015-08-28 13:21:36 +03:00
|
|
|
int main()
|
|
|
|
{
|
2016-10-25 18:47:55 +03:00
|
|
|
uc_engine *uc = NULL;
|
|
|
|
uint8_t *buf = NULL, *buf2 = NULL;
|
2015-08-28 13:21:36 +03:00
|
|
|
int i;
|
|
|
|
uc_err err;
|
2015-08-27 01:19:12 +03:00
|
|
|
|
2015-09-03 04:25:59 +03:00
|
|
|
err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);
|
2015-08-28 13:21:36 +03:00
|
|
|
if (err) {
|
|
|
|
printf ("uc_open %d\n", err);
|
2016-10-25 18:47:55 +03:00
|
|
|
goto exit;
|
2015-08-28 13:21:36 +03:00
|
|
|
}
|
2015-09-03 04:25:59 +03:00
|
|
|
err = uc_mem_map (uc, ADDR, SIZE, UC_PROT_ALL);
|
2015-08-28 13:21:36 +03:00
|
|
|
if (err) {
|
|
|
|
printf ("uc_mem_map %d\n", err);
|
2016-10-25 18:47:55 +03:00
|
|
|
goto exit;
|
2015-08-28 13:21:36 +03:00
|
|
|
}
|
|
|
|
buf = calloc (SIZE*2, 1);
|
|
|
|
buf2 = calloc (SIZE, 1);
|
|
|
|
for (i=0;i<SIZE; i++) {
|
|
|
|
buf[i] = i & 0xff;
|
|
|
|
}
|
|
|
|
/* crash here */
|
2015-09-03 04:25:59 +03:00
|
|
|
err = uc_mem_write (uc, ADDR, buf, SIZE+OVERFLOW);
|
2015-08-28 13:21:36 +03:00
|
|
|
if (err) {
|
2016-10-25 18:47:55 +03:00
|
|
|
printf ("uc_mem_write %d\n", err);
|
|
|
|
goto exit;
|
2015-08-28 13:21:36 +03:00
|
|
|
}
|
2015-09-03 04:25:59 +03:00
|
|
|
err = uc_mem_read (uc, ADDR+10, buf2, 4);
|
2015-08-28 13:21:36 +03:00
|
|
|
if (err) {
|
2016-10-25 18:47:55 +03:00
|
|
|
printf ("uc_mem_read %d\n", err);
|
|
|
|
goto exit;
|
2015-08-28 13:21:36 +03:00
|
|
|
}
|
|
|
|
if (buf2[0] != 0xa) {
|
|
|
|
printf ("mem contents are wrong\n");
|
2016-10-25 18:47:55 +03:00
|
|
|
goto exit;
|
2015-08-28 13:21:36 +03:00
|
|
|
}
|
|
|
|
printf ("OK\n");
|
2016-10-25 18:47:55 +03:00
|
|
|
|
|
|
|
exit:
|
|
|
|
if (uc)
|
|
|
|
uc_close (uc);
|
2015-08-28 13:21:36 +03:00
|
|
|
free (buf);
|
|
|
|
free (buf2);
|
2016-10-25 18:47:55 +03:00
|
|
|
return err ? 1 : 0;
|
2015-08-27 01:19:12 +03:00
|
|
|
}
|