Merge branch 'next' of https://github.com/aquynh/capstone into next

This commit is contained in:
Nguyen Anh Quynh 2014-01-09 10:36:38 +08:00
commit 5696d98f63
2 changed files with 38 additions and 15 deletions

View File

@ -280,7 +280,7 @@ void AArch64_init(MCRegisterInfo *MRI)
}
static DecodeStatus _getInstruction(MCInst *MI,
static DecodeStatus _getInstruction(cs_struct *ud, MCInst *MI,
const uint8_t *code, size_t code_len,
uint16_t *Size,
uint64_t Address, MCRegisterInfo *MRI)
@ -291,8 +291,12 @@ static DecodeStatus _getInstruction(MCInst *MI,
return MCDisassembler_Fail;
}
// Encoded as a small-endian 32-bit word in the stream.
uint32_t insn = (code[3] << 24) | (code[2] << 16) |
uint32_t insn;
if (ud->big_endian)
insn = (code[3] << 0) | (code[2] << 8) |
(code[1] << 16) | (code[0] << 24);
else
insn = (code[3] << 24) | (code[2] << 16) |
(code[1] << 8) | (code[0] << 0);
//printf("insn: %u\n", insn);
@ -311,7 +315,7 @@ static DecodeStatus _getInstruction(MCInst *MI,
bool AArch64_getInstruction(csh ud, unsigned char *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info)
{
DecodeStatus status = _getInstruction(instr,
DecodeStatus status = _getInstruction((cs_struct *)ud, instr,
code, code_len,
size,
address, (MCRegisterInfo *)info);

View File

@ -447,8 +447,14 @@ static DecodeStatus _ARM_getInstruction(cs_struct *ud, MCInst *MI, const uint8_t
memcpy(bytes, code, 4);
// Encoded as a small-endian 32-bit word in the stream.
uint32_t insn = (bytes[3] << 24) |
uint32_t insn;
if (ud->big_endian)
insn = (bytes[3] << 0) |
(bytes[2] << 8) |
(bytes[1] << 16) |
(bytes[0] << 24);
else
insn = (bytes[3] << 24) |
(bytes[2] << 16) |
(bytes[1] << 8) |
(bytes[0] << 0);
@ -666,7 +672,12 @@ static DecodeStatus _Thumb_getInstruction(cs_struct *ud, MCInst *MI, const uint8
memcpy(bytes, code, 2);
uint16_t insn16 = (bytes[1] << 8) | bytes[0];
uint16_t insn16;
if (ud->big_endian)
insn16 = (bytes[0] << 8) | bytes[1];
else
insn16 = (bytes[1] << 8) | bytes[0];
DecodeStatus result = decodeInstruction_2(DecoderTableThumb16, MI, insn16, Address, ud->mode);
if (result != MCDisassembler_Fail) {
*Size = 2;
@ -717,10 +728,18 @@ static DecodeStatus _Thumb_getInstruction(cs_struct *ud, MCInst *MI, const uint8
memcpy(bytes, code, 4);
uint32_t insn32 = (bytes[3] << 8) |
uint32_t insn32;
if (ud->big_endian)
insn32 = (bytes[3] << 24) |
(bytes[2] << 16) |
(bytes[1] << 8) |
(bytes[0] << 0);
else
insn32 = (bytes[3] << 8) |
(bytes[2] << 0) |
(bytes[1] << 24) |
(bytes[0] << 16);
MCInst_clear(MI);
result = decodeInstruction_4(DecoderTableThumb32, MI, insn32, Address, ud->mode);
if (result != MCDisassembler_Fail) {