Merge pull request #762 from akihikodaki/master

arm: treat ARM address as unsigned
This commit is contained in:
Nguyen Anh Quynh 2016-09-03 18:22:42 +08:00 committed by GitHub
commit e3a352e963
3 changed files with 15 additions and 15 deletions

View File

@ -721,27 +721,27 @@ 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
#define _ALIGN_DOWN(v, align_width) ((v/align_width)*align_width)
imm = _ALIGN_DOWN(imm, 4);
address = _ALIGN_DOWN(address, 4);
#undef _ALIGN_DOWN
}
} else {
imm += (int32_t)MI->address + 8;
address = (uint32_t)MI->address + 8;
}
if (imm >= 0) {
if (imm > HEX_THRESHOLD)
SStream_concat(O, "#0x%x", imm);
else
SStream_concat(O, "#%u", imm);
} else {
SStream_concat(O, "#0x%x", imm);
}
address += imm;
if (address > HEX_THRESHOLD)
SStream_concat(O, "#0x%x", address);
else
SStream_concat(O, "#%u", address);
} else {
switch(MI->flat_insn->id) {
default:

View File

@ -10,7 +10,7 @@ from xprint import to_hex, to_x, to_x_32
ARM_CODE = b"\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"
THUMB_CODE = b"\x70\x47\x00\xf0\x10\xe8\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84"
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"
@ -113,7 +113,7 @@ def test_class():
if syntax:
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 ()
print ("0x%x:\n" % (insn.address + insn.size))

View File

@ -197,7 +197,7 @@ static void test()
//#define THUMB_CODE "\x01\x47" // bx r0
//#define THUMB_CODE "\x02\x47" // bx r0
//#define THUMB_CODE "\x0a\xbf" // itet eq
#define THUMB_CODE "\x70\x47\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84"
#define THUMB_CODE "\x70\x47\x00\xf0\x10\xe8\xeb\x46\x83\xb0\xc9\x68\x1f\xb1\x30\xbf\xaf\xf3\x20\x84"
#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"
#define THUMB_MCLASS "\xef\xf3\x02\x80"
#define ARMV8 "\xe0\x3b\xb2\xee\x42\x00\x01\xe1\x51\xf0\x7f\xf5"
@ -248,7 +248,7 @@ static void test()
},
};
uint64_t address = 0x1000;
uint64_t address = 0x80001000;
cs_insn *insn;
int i;
size_t count;