aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorcomex2015-01-17 22:24:13 -0500
committercomex2015-01-17 22:24:13 -0500
commitd281e5233f304dab603d638a623ae54af8117ce7 (patch)
tree6605309de4f0e0728f7d9171528f376906af00f0 /test
parentmisc. objc trimmings (diff)
downloadsubstitute-d281e5233f304dab603d638a623ae54af8117ce7.tar.gz
improve test; thumb2 fixes
Diffstat (limited to 'test')
-rw-r--r--test/insns-arm.S8
-rw-r--r--test/test-jump-dis.c1
-rw-r--r--test/test-td-simple.c1
-rw-r--r--test/test-transform-dis.c48
4 files changed, 54 insertions, 4 deletions
diff --git a/test/insns-arm.S b/test/insns-arm.S
index 62b4b48..b5a2cce 100644
--- a/test/insns-arm.S
+++ b/test/insns-arm.S
@@ -17,7 +17,7 @@ add r0, pc, #123
mcr p15,0,pc,c14,c3,0
str r3, [pc, #5]
str pc, [pc, #5]
-#ifdef THUMB2 // it shouldn't be, though
+#ifdef THUMB2 /* it shouldn't be, though */
strht r0, [r3]
#endif
ldr r0, [pc]
@@ -35,13 +35,13 @@ ldrsb r1, [pc]
ldrh r1, [pc]
ldrsh r1, [pc]
ldr r1, [pc]
-ldrd r1, r2, [pc]
+ldrd r0, r1, [pc]
str r1, [pc]
-strd r1, r2, [pc]
+strd r0, r1, [pc]
push {r0-r3, pc}
push {r0-r3, lr}
-pop {r0-r3, pc}
+/* pop {r0-r3, pc} */
1:
.long 0xdeadbeef
diff --git a/test/test-jump-dis.c b/test/test-jump-dis.c
index 1afa4e5..1a34bc0 100644
--- a/test/test-jump-dis.c
+++ b/test/test-jump-dis.c
@@ -5,6 +5,7 @@
int main(UNUSED int argc, char **argv) {
static char buf[1048576];
UNUSED size_t size = fread(buf, 1, sizeof(buf), stdin);
+ printf("size=%zd\n", size);
int patch_size = atoi(argv[1]);
int thumb = atoi(argv[2]);
bool bad = P(main)(buf, 0x10000, 0x10000 + patch_size, thumb);
diff --git a/test/test-td-simple.c b/test/test-td-simple.c
index 4464091..6347359 100644
--- a/test/test-td-simple.c
+++ b/test/test-td-simple.c
@@ -17,6 +17,7 @@ typedef struct tc {
#define P(x) P_##x
#define TDIS_CTX_MODIFY(ctx) ((ctx)->modify)
#define TDIS_CTX_NEWVAL(ctx, n) ((ctx)->newval[n])
+#define TDIS_CTX_NEWOP(ctx) ((ctx)->newop)
#define TDIS_CTX_SET_NEWOP(ctx, new) ((ctx)->newop = (new))
NOINLINE UNUSED
diff --git a/test/test-transform-dis.c b/test/test-transform-dis.c
new file mode 100644
index 0000000..d7c44d6
--- /dev/null
+++ b/test/test-transform-dis.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#define TRANSFORM_DIS_VERBOSE 1
+#include "transform-dis.c"
+#include <stdlib.h>
+int main(UNUSED int argc, char **argv) {
+ static uint8_t in[1048576];
+ UNUSED size_t size = fread(in, 1, sizeof(in), stdin);
+ int patch_size = atoi(argv[1]);
+ int thumb = atoi(argv[2]);
+ uint8_t out[patch_size * 10];
+ int offsets[patch_size + 1];
+ void *rewritten_ptr = out;
+ printf("\n#if 0\n");
+ int ret = transform_dis_main(
+ in,
+ &rewritten_ptr,
+ 0x10000,
+ 0x10000 + patch_size,
+ thumb,
+ offsets);
+ printf("=> %d\n", ret);
+ printf("#endif\n");
+ int print_out_idx = 0;
+ int print_in_idx = 0;
+ if (!ret) {
+ printf("// total length: %zd\n", (uint8_t *) rewritten_ptr - out);
+ for(int ii = 0; ii <= patch_size; ii++) {
+ int oi = offsets[ii];
+ if(oi != -1) {
+ int in_size = ii - print_in_idx;
+ int out_size = oi - print_out_idx;
+ if (in_size != out_size || memcmp(out + print_out_idx, in + print_in_idx, in_size)) {
+ printf("at_%x: nop; nop; nop\n", print_in_idx);
+ printf(" .byte ");
+ while(print_in_idx++ < ii)
+ printf("0x%02x%s", in[print_in_idx-1], print_in_idx == ii ? "" : ", ");
+ printf("\nnop // -->\n .byte ");
+ while(print_out_idx++ < oi)
+ printf("0x%02x%s", out[print_out_idx-1], print_out_idx == oi ? "" : ", ");
+ printf("\n");
+ }
+ print_in_idx = ii;
+ print_out_idx = oi;
+ printf("/* 0x%x: 0x%x */\n", ii, oi);
+ }
+ }
+ }
+}