From 958ba656e9e461df247de47f5289717e104844b3 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Sun, 4 Sep 2016 00:13:50 +0900 Subject: [PATCH] arm: treat ARM address as unsigned It should be unsigned because: * It does arithmetic operations * Format strings have "%u" instead of "%d" # Conflicts: # arch/ARM/ARMInstPrinter.c # bindings/python/test_arm.py # tests/test_arm.c --- arch/ARM/ARMInstPrinter.c | 10 ++++++---- bindings/python/test_arm.py | 4 ++-- tests/test_arm.c | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/ARM/ARMInstPrinter.c b/arch/ARM/ARMInstPrinter.c index 9422a1ea..91d3846c 100644 --- a/arch/ARM/ARMInstPrinter.c +++ b/arch/ARM/ARMInstPrinter.c @@ -850,18 +850,20 @@ static void printOperand(MCInst *MI, unsigned OpNo, SStream *O) // add 8 in ARM mode, or 4 in Thumb mode // printf(">> opcode: %u\n", MCInst_getOpcode(MI)); if (ARM_rel_branch(MI->csh, opc)) { + uint32_t address; + // only do this for relative branch if (MI->csh->mode & CS_MODE_THUMB) { - imm += (int32_t)MI->address + 4; + address = (uint32_t)MI->address + 4; if (ARM_blx_to_arm_mode(MI->csh, opc)) { // here need to align down to the nearest 4-byte address - imm &= ~3; + address &= ~3; } } else { - imm += (int32_t)MI->address + 8; + address = (uint32_t)MI->address + 8; } - printUInt32Bang(O, imm); + printUInt32Bang(O, address + imm); } else { switch(MI->flat_insn->id) { default: diff --git a/bindings/python/test_arm.py b/bindings/python/test_arm.py index 17742ecf..8f11ce43 100755 --- a/bindings/python/test_arm.py +++ b/bindings/python/test_arm.py @@ -10,7 +10,7 @@ from xprint import to_hex, to_x_32 ARM_CODE = b"\x86\x48\x60\xf4\xED\xFF\xFF\xEB\x04\xe0\x2d\xe5\x00\x00\x00\x00\xe0\x83\x22\xe5\xf1\x02\x03\x0e\x00\x00\xa0\xe3\x02\x30\xc1\xe7\x00\x00\x53\xe3\x00\x02\x01\xf1\x05\x40\xd0\xe8\xf4\x80\x00\x00" ARM_CODE2 = b"\xd1\xe8\x00\xf0\xf0\x24\x04\x07\x1f\x3c\xf2\xc0\x00\x00\x4f\xf0\x00\x01\x46\x6c" -THUMB_CODE = b"\x70\x47\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84\x52\xf8\x23\xf0" +THUMB_CODE = b"\x70\x47\x00\xf0\x10\xe8\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84\x52\xf8\x23\xf0" THUMB_CODE2 = b"\x4f\xf0\x00\x01\xbd\xe8\x00\x88\xd1\xe8\x00\xf0\x18\xbf\xad\xbf\xf3\xff\x0b\x0c\x86\xf3\x00\x89\x80\xf3\x00\x8c\x4f\xfa\x99\xf6\xd0\xff\xa2\x01" THUMB_MCLASS = b"\xef\xf3\x02\x80" ARMV8 = b"\xe0\x3b\xb2\xee\x42\x00\x01\xe1\x51\xf0\x7f\xf5" @@ -140,7 +140,7 @@ def test_class(): if syntax is not None: md.syntax = syntax md.detail = True - for insn in md.disasm(code, 0x1000): + for insn in md.disasm(code, 0x80001000): print_insn_detail(insn) print () except CsError as e: diff --git a/tests/test_arm.c b/tests/test_arm.c index 89a622cc..5069778b 100644 --- a/tests/test_arm.c +++ b/tests/test_arm.c @@ -245,7 +245,7 @@ static void test() //#define THUMB_CODE "\x02\x47" // bx r0 //#define THUMB_CODE "\x0a\xbf" // itet eq -#define THUMB_CODE "\x60\xf9\x1f\x04\xe0\xf9\x4f\x07\x70\x47\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84\x52\xf8\x23\xf0" +#define THUMB_CODE "\x60\xf9\x1f\x04\xe0\xf9\x4f\x07\x70\x47\x00\xf0\x10\xe8\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84\x52\xf8\x23\xf0" //#define THUMB_CODE "\xe0\xf9\x4f\x07" #define THUMB_CODE2 "\x4f\xf0\x00\x01\xbd\xe8\x00\x88\xd1\xe8\x00\xf0\x18\xbf\xad\xbf\xf3\xff\x0b\x0c\x86\xf3\x00\x89\x80\xf3\x00\x8c\x4f\xfa\x99\xf6\xd0\xff\xa2\x01" @@ -298,7 +298,7 @@ static void test() }, }; - uint64_t address = 0x1000; + uint64_t address = 0x80001000; cs_insn *insn; int i; size_t count;