regress: update C programs to use new API
This commit is contained in:
parent
db563bfcdb
commit
e74bc0db88
@ -12,7 +12,7 @@ static int count = 1;
|
|||||||
// @address: address where the code is being executed
|
// @address: address where the code is being executed
|
||||||
// @size: size of machine instruction being executed
|
// @size: size of machine instruction being executed
|
||||||
// @user_data: user data passed to tracing APIs.
|
// @user_data: user data passed to tracing APIs.
|
||||||
void cb_hookblock(uch handle, uint64_t address, uint32_t size, void *user_data) {
|
void cb_hookblock(struct uc_struct *uc, uint64_t address, uint32_t size, void *user_data) {
|
||||||
fprintf(stderr, "# >>> Tracing basic block at 0x%llx, block size = 0x%x\n", address, size);
|
fprintf(stderr, "# >>> Tracing basic block at 0x%llx, block size = 0x%x\n", address, size);
|
||||||
if (address != 0x1000000 && address != 0x1000200) {
|
if (address != 0x1000000 && address != 0x1000200) {
|
||||||
fprintf(stderr, "not ok %d - address != 0x1000000 && address != 0x1000200\n", count++);
|
fprintf(stderr, "not ok %d - address != 0x1000000 && address != 0x1000200\n", count++);
|
||||||
@ -27,19 +27,19 @@ void cb_hookblock(uch handle, uint64_t address, uint32_t size, void *user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
uch u;
|
struct uc_struct *uc;
|
||||||
|
|
||||||
fprintf(stderr, "# basic block callback test\n");
|
fprintf(stderr, "# basic block callback test\n");
|
||||||
fprintf(stderr, "# there are only two basic blocks 0x1000000-0x10001ff and 0x1000200-0x10003ff\n");
|
fprintf(stderr, "# there are only two basic blocks 0x1000000-0x10001ff and 0x1000200-0x10003ff\n");
|
||||||
|
|
||||||
uc_err err = uc_open(UC_ARCH_X86, UC_MODE_32, &u);
|
uc_err err = uc_open(UC_ARCH_X86, UC_MODE_32, &uc);
|
||||||
if (err != UC_ERR_OK) {
|
if (err != UC_ERR_OK) {
|
||||||
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "ok %d - uc_open\n", count++);
|
fprintf(stderr, "ok %d - uc_open\n", count++);
|
||||||
|
|
||||||
err = uc_mem_map(u, 0x1000000, 4096);
|
err = uc_mem_map(uc, 0x1000000, 4096);
|
||||||
if (err != UC_ERR_OK) {
|
if (err != UC_ERR_OK) {
|
||||||
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -55,23 +55,23 @@ int main() {
|
|||||||
memset(code, 0x90, sizeof(code));
|
memset(code, 0x90, sizeof(code));
|
||||||
memcpy(code + 1024 - 5, "\xe9\x00\xfe\xff\xff", 5);
|
memcpy(code + 1024 - 5, "\xe9\x00\xfe\xff\xff", 5);
|
||||||
|
|
||||||
err = uc_mem_write(u, 0x1000000, code, sizeof(code));
|
err = uc_mem_write(uc, 0x1000000, code, sizeof(code));
|
||||||
if (err != UC_ERR_OK) {
|
if (err != UC_ERR_OK) {
|
||||||
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "ok %d - uc_mem_write\n", count++);
|
fprintf(stderr, "ok %d - uc_mem_write\n", count++);
|
||||||
|
|
||||||
uch h1, h2;
|
uc_hook_h h1, h2;
|
||||||
|
|
||||||
err = uc_hook_add(u, &h1, UC_HOOK_BLOCK, cb_hookblock, NULL, (uint64_t)1, (uint64_t)0);
|
err = uc_hook_add(uc, &h1, UC_HOOK_BLOCK, cb_hookblock, NULL, (uint64_t)1, (uint64_t)0);
|
||||||
if (err != UC_ERR_OK) {
|
if (err != UC_ERR_OK) {
|
||||||
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "ok %d - uc_hook_add\n", count++);
|
fprintf(stderr, "ok %d - uc_hook_add\n", count++);
|
||||||
|
|
||||||
err = uc_emu_start(u, 0x1000000, 0x1000000 + sizeof(code), 0, 1030);
|
err = uc_emu_start(uc, 0x1000000, 0x1000000 + sizeof(code), 0, 1030);
|
||||||
if (err != UC_ERR_OK) {
|
if (err != UC_ERR_OK) {
|
||||||
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
fprintf(stderr, "not ok %d - %s\n", count++, uc_strerror(err));
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
int main() {
|
int main() {
|
||||||
int size;
|
int size;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
uch uh;
|
struct uc_struct *uc;
|
||||||
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uh);
|
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);
|
||||||
if (err) {
|
if (err) {
|
||||||
fprintf (stderr, "Cannot initialize unicorn\n");
|
fprintf (stderr, "Cannot initialize unicorn\n");
|
||||||
return 1;
|
return 1;
|
||||||
@ -22,9 +22,9 @@ int main() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
memset (buf, 0, size);
|
memset (buf, 0, size);
|
||||||
if (!uc_mem_map (uh, UC_BUG_WRITE_ADDR, size)) {
|
if (!uc_mem_map(uc, UC_BUG_WRITE_ADDR, size)) {
|
||||||
uc_mem_write (uh, UC_BUG_WRITE_ADDR, buf, size);
|
uc_mem_write(uc, UC_BUG_WRITE_ADDR, buf, size);
|
||||||
}
|
}
|
||||||
uc_close (&uh);
|
uc_close(uc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
int got_sigill = 0;
|
int got_sigill = 0;
|
||||||
|
|
||||||
void _interrupt(uch handle, uint32_t intno, void *user_data) {
|
void _interrupt(struct uc_struct *uc, uint32_t intno, void *user_data) {
|
||||||
if (intno == 6) {
|
if (intno == 6) {
|
||||||
uc_emu_stop (handle);
|
uc_emu_stop(uc);
|
||||||
got_sigill = 1;
|
got_sigill = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,9 +18,9 @@ void _interrupt(uch handle, uint32_t intno, void *user_data) {
|
|||||||
int main() {
|
int main() {
|
||||||
int size;
|
int size;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
uch uh;
|
struct uc_struct *uc;
|
||||||
uch uh_trap;
|
uc_hook_h uh_trap;
|
||||||
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uh);
|
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);
|
||||||
if (err) {
|
if (err) {
|
||||||
fprintf (stderr, "Cannot initialize unicorn\n");
|
fprintf (stderr, "Cannot initialize unicorn\n");
|
||||||
return 1;
|
return 1;
|
||||||
@ -32,13 +32,13 @@ int main() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
memset (buf, 0, size);
|
memset (buf, 0, size);
|
||||||
if (!uc_mem_map (uh, UC_BUG_WRITE_ADDR, size)) {
|
if (!uc_mem_map(uc, UC_BUG_WRITE_ADDR, size)) {
|
||||||
uc_mem_write (uh, UC_BUG_WRITE_ADDR,
|
uc_mem_write(uc, 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_hook_add(uc, &uh_trap, UC_HOOK_INTR, _interrupt, NULL);
|
||||||
uc_emu_start (uh, UC_BUG_WRITE_ADDR, UC_BUG_WRITE_ADDR+8, 0, 1);
|
uc_emu_start(uc, UC_BUG_WRITE_ADDR, UC_BUG_WRITE_ADDR+8, 0, 1);
|
||||||
uc_close (&uh);
|
uc_close(uc);
|
||||||
printf ("Correct: %s\n", got_sigill? "YES": "NO");
|
printf ("Correct: %s\n", got_sigill? "YES": "NO");
|
||||||
return got_sigill? 0: 1;
|
return got_sigill? 0: 1;
|
||||||
}
|
}
|
||||||
|
@ -10,20 +10,20 @@ int main()
|
|||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
uch uh;
|
struct uc_struct *uc;
|
||||||
uch uh_trap;
|
|
||||||
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uh);
|
uc_err err = uc_open (UC_ARCH_X86, UC_MODE_64, &uc);
|
||||||
if (err) {
|
if (err) {
|
||||||
fprintf (stderr, "Cannot initialize unicorn\n");
|
fprintf (stderr, "Cannot initialize unicorn\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
size = UC_BUG_WRITE_SIZE;
|
size = UC_BUG_WRITE_SIZE;
|
||||||
if (!uc_mem_map (uh, UC_BUG_WRITE_ADDR, size)) {
|
if (!uc_mem_map(uc, UC_BUG_WRITE_ADDR, size)) {
|
||||||
uc_mem_write (uh, UC_BUG_WRITE_ADDR,
|
uc_mem_write(uc, 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);
|
err = uc_emu_start(uc, UC_BUG_WRITE_ADDR, UC_BUG_WRITE_ADDR+8, 0, 1);
|
||||||
uc_close (&uh);
|
uc_close(uc);
|
||||||
printf ("Error = %u (%s)\n", err, uc_strerror(err));
|
printf ("Error = %u (%s)\n", err, uc_strerror(err));
|
||||||
return err? -1: 0;
|
return err? -1: 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user