diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test-transform-dis.c | 25 | ||||
-rw-r--r-- | test/transform-dis-cases-i386.S | 11 |
2 files changed, 25 insertions, 11 deletions
diff --git a/test/test-transform-dis.c b/test/test-transform-dis.c index f55daa9..2d7de9e 100644 --- a/test/test-transform-dis.c +++ b/test/test-transform-dis.c @@ -29,11 +29,13 @@ static void do_manual(uint8_t *in, size_t in_size, int patch_size, printf("\n#if 0\n"); uint_tptr pc_patch_start = 0x10000; uint_tptr pc_patch_end = pc_patch_start + patch_size; + uint_tptr pc_trampoline = 0xf000; int ret = transform_dis_main( in, &rewritten_ptr, pc_patch_start, &pc_patch_end, + pc_trampoline, &arch, offsets); printf("=> %d\n", ret); @@ -95,12 +97,17 @@ static void do_auto(uint8_t *in, size_t in_size, struct arch_dis_ctx arch) { if (!memcmp(expect, "_ERR", 4)) { expect_err = true; in += 4; + assert(!memcmp(in, "GIVEN", 5)); + in += 5; } else { - uint8_t *next = memmem(in, end - in, "GIVEN", 5); - if (!next) - next = end; - expect_size = next - expect; - in = next; + in = memmem(in, end - in, "GIVEN", 5); + if (in) { + expect_size = in - expect; + in += 5; + } else { + in = end; + expect_size = in - expect; + } } size_t patch_size = given_size; int offsets[patch_size + 15]; @@ -108,15 +115,19 @@ static void do_auto(uint8_t *in, size_t in_size, struct arch_dis_ctx arch) { void *rewritten_ptr = out; uint_tptr pc_patch_start = 0xdead0000; uint_tptr pc_patch_end = pc_patch_start + patch_size; + uint_tptr pc_trampoline = 0xdeac0000; int ret = transform_dis_main( given, &rewritten_ptr, pc_patch_start, &pc_patch_end, + pc_trampoline, &arch, offsets); if (ret) { - if (!expect_err) { + if (expect_err) { + printf("OK\n"); + } else { print_given(given, given_size); printf("got ret %d, expected success\n\n", ret); } @@ -132,6 +143,8 @@ static void do_auto(uint8_t *in, size_t in_size, struct arch_dis_ctx arch) { printf("but expected:\n"); hex_dump(expect, expect_size); printf("\n"); + } else { + printf("OK\n"); } } diff --git a/test/transform-dis-cases-i386.S b/test/transform-dis-cases-i386.S index 31508ca..57707cc 100644 --- a/test/transform-dis-cases-i386.S +++ b/test/transform-dis-cases-i386.S @@ -2,15 +2,16 @@ #define EXPECT .ascii "EXPECT"; #define EXPECT_ERR .ascii "EXPECT_ERR"; -GIVEN call .; pop %edx +GIVEN call 0f; 0: pop %edx /* XXX the extra push isn't necessary in 32-bit mode */ -EXPECT push %eax; push %eax; mov $0xdead0005, %eax; pop %eax; pop %edx +EXPECT push %eax; push %eax; mov $0xdead0005, %eax; mov %eax, 4(%esp); pop %eax; pop %edx -GIVEN jmp 0f; 0: +GIVEN jmp 0f; 0: nop EXPECT_ERR -GIVEN jne 0xdead1000 -EXPECT jne 0f; jmp 1f; 0: jmp 0xdead1000; 1: +GIVEN jne .+0x1000 +/* we expect to generate an unnecessarily long jump, so hardcode it */ +EXPECT 2: .byte 0x0f, 0x85; .long 2; jmp 1f; 0: jmp 2b+0x1000; 1: GIVEN loopne 0xdead0080 EXPECT loopne 0f; jmp 1f; 0: jmp 0xdead1000; 1: |