From 66bd9f17e9467b1eb5d6b2098b02241f03f8bbf6 Mon Sep 17 00:00:00 2001 From: comex Date: Tue, 15 Nov 2016 21:57:23 -0500 Subject: fix some ARM stuff including calls, and test it wow this code sucks --- test/test-transform-dis.c | 2 +- test/transform-dis-cases-arm.S | 15 +++++++++++++++ test/transform-dis-cases-arm64.S | 9 +++++---- test/transform-dis-cases-i386.S | 10 ++++------ test/transform-dis-cases.h | 4 ++++ 5 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 test/transform-dis-cases-arm.S create mode 100644 test/transform-dis-cases.h (limited to 'test') diff --git a/test/test-transform-dis.c b/test/test-transform-dis.c index 98c98e3..d147a49 100644 --- a/test/test-transform-dis.c +++ b/test/test-transform-dis.c @@ -127,7 +127,7 @@ static void do_auto(uint8_t *in, size_t in_size, struct arch_dis_ctx arch) { pc_trampoline, &arch, offsets, - TRANSFORM_DIS_BAN_CALLS); + 0);//TRANSFORM_DIS_BAN_CALLS); if (ret) { if (expect_err) { printf("OK\n"); diff --git a/test/transform-dis-cases-arm.S b/test/transform-dis-cases-arm.S new file mode 100644 index 0000000..a9e01b1 --- /dev/null +++ b/test/transform-dis-cases-arm.S @@ -0,0 +1,15 @@ +#include "transform-dis-cases.h" +#ifdef THUMB +.thumb +#endif + + +#ifndef THUMB +GIVEN blne 0f; nop; nop; 0: +EXPECT beq 1f; movw lr, #0x000c; movt lr, #0xdead; blx lr; 1: nop; nop +GIVEN bl 0f; 0: +EXPECT movw lr, #0x0004; movt lr, #0xdead; blx lr +#else +GIVEN bl 0f; 0: +EXPECT movw lr, #0x0005; movt lr, #0xdead; blx lr +#endif diff --git a/test/transform-dis-cases-arm64.S b/test/transform-dis-cases-arm64.S index cc3bd4c..99a353b 100644 --- a/test/transform-dis-cases-arm64.S +++ b/test/transform-dis-cases-arm64.S @@ -1,6 +1,4 @@ -#define GIVEN .ascii "GIVEN"; -#define EXPECT .ascii "EXPECT"; -#define EXPECT_ERR .ascii "EXPECT_ERR"; +#include "transform-dis-cases.h" /* yay clang, no semicolons allowed */ @@ -12,7 +10,10 @@ EXPECT GIVEN blr x5 nop -EXPECT_ERR +//EXPECT_ERR (with ban_calls) +EXPECT + blr x5 + GIVEN cbnz x8, .+0x100 diff --git a/test/transform-dis-cases-i386.S b/test/transform-dis-cases-i386.S index c02a044..a39ee02 100644 --- a/test/transform-dis-cases-i386.S +++ b/test/transform-dis-cases-i386.S @@ -1,6 +1,4 @@ -#define GIVEN .ascii "GIVEN"; -#define EXPECT .ascii "EXPECT"; -#define EXPECT_ERR .ascii "EXPECT_ERR"; +#include "transform-dis-cases.h" GIVEN call 0f; 0: pop %edx /* XXX the extra push isn't necessary in 32-bit mode */ @@ -10,9 +8,9 @@ GIVEN jmp 0f; 0: nop EXPECT_ERR GIVEN jne .+0x1000 -/* we expect to generate an unnecessarily long jump, so hardcode it the 0x10000 - * is because we pretend our trampoline is 0x10000 bytes before the original - * function */ +/* we expect to generate an unnecessarily long jump, so hardcode it + * the 0x10000 is because we pretend our trampoline is 0x10000 bytes before the + * original function */ EXPECT 2: .byte 0x0f, 0x85; .long 2; jmp 1f; 0: jmp .+0x10000+0x1000-8; 1: GIVEN loopne .+0x80 diff --git a/test/transform-dis-cases.h b/test/transform-dis-cases.h new file mode 100644 index 0000000..94f39bd --- /dev/null +++ b/test/transform-dis-cases.h @@ -0,0 +1,4 @@ +#pragma once +#define GIVEN .ascii "GIVEN"; +#define EXPECT .ascii "EXPECT"; +#define EXPECT_ERR .ascii "EXPECT_ERR"; -- cgit v1.2.3 From 1d821292ca89ae0d75ec9741c350ea8924137b55 Mon Sep 17 00:00:00 2001 From: comex Date: Tue, 15 Nov 2016 21:58:33 -0500 Subject: I don't remember what this test is for --- test/lol.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 test/lol.c (limited to 'test') diff --git a/test/lol.c b/test/lol.c new file mode 100644 index 0000000..846cb5d --- /dev/null +++ b/test/lol.c @@ -0,0 +1,100 @@ +#include +#include +#include +#define IF_BOTHER_WITH_MODIFY(...) __VA_ARGS__ +#include "dis.h" + +typedef struct tc { + struct dis_ctx_base base; + struct arch_dis_ctx arch; +} *tdis_ctx; +#define P(x) P_##x +#define DIS_MAY_MODIFY 0 + +static enum { + NOPPY, + JUMPY, + BAD +} type; + +NOINLINE UNUSED +static void P_data(UNUSED struct tc *ctx, unsigned o0, unsigned o1, unsigned o2, + unsigned o3, unsigned out_mask) { + unsigned ops[] = {o0, o1, o2, o3}; + type = NOPPY; + for (int i = 0; i < 4; i++) { + if (ops[i] != null_op && (out_mask & (1 << i))) { + if (ops[i] == 15) { + type = JUMPY; + break; + } else if (ops[i] != 12 && ops[i] != 9) { + type = BAD; + } + } + } +} +NOINLINE UNUSED +static void P_pcrel(UNUSED struct tc *ctx, uint32_t dpc, + UNUSED struct arch_pcrel_info info) { + return P_data(ctx, info.reg, null_op, null_op, null_op, 1); +} +NOINLINE UNUSED +static void P_thumb_it(UNUSED struct tc *ctx) { + type = NOPPY; +} + +NOINLINE UNUSED +static void P_ret(UNUSED struct tc *ctx) { + type = JUMPY; +} + +NOINLINE UNUSED +static void P_indirect_call(UNUSED struct tc *ctx) { + type = JUMPY; +} + +NOINLINE UNUSED +static void P_branch(UNUSED struct tc *ctx, uint64_t dpc, int cc) { + type = BAD; +} + +NOINLINE UNUSED +static void P_unidentified(UNUSED struct tc *ctx) { + type = BAD; +} + +NOINLINE UNUSED +static void P_bad(UNUSED struct tc *ctx) { + type = JUMPY; +} + +#include "arm/dis-main.inc.h" + +int main(UNUSED int argc, char **argv) { + struct tc ctx; + ctx.base.pc = 0xdead0000; + memset(ctx.base.newop, 0, sizeof(ctx.base.newop)); + ctx.base.modify = false; + for (uint32_t hi = 0; hi < (1 << 12); hi++) { + for (uint32_t lo = 0; lo < (1 << 13); lo++) { + uint32_t op = (0b1111 << 28) | (hi << 16) | (0b111 << 13) | lo; + + if ((op & 0x0f100010) == 0x0e100010) + continue; + + ctx.base.ptr = &op; + ctx.arch.pc_low_bit = false; + type = BAD; + P(dis)(&ctx); + if (type != JUMPY) + continue; + ctx.arch.pc_low_bit = true; + type = BAD; + P(dis)(&ctx); + if (type != NOPPY) + continue; + printf("%x\n", op); + } + } + +} -- cgit v1.2.3