2006-04-27 19:11:45 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2010-05-23 23:17:41 +04:00
|
|
|
// $Id: dis_decode.cc,v 1.56 2010-05-23 19:17:41 sshwarts Exp $
|
2006-04-27 19:11:45 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-10-15 00:45:29 +04:00
|
|
|
//
|
|
|
|
// Copyright (c) 2005-2009 Stanislav Shwartsman
|
|
|
|
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-04-27 19:11:45 +04:00
|
|
|
|
2003-12-24 23:32:59 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "disasm.h"
|
|
|
|
#include "dis_tables.h"
|
|
|
|
|
2005-12-23 17:15:13 +03:00
|
|
|
#define OPCODE(entry) ((BxDisasmOpcodeInfo_t*) entry->OpcodeInfo)
|
|
|
|
#define OPCODE_TABLE(entry) ((BxDisasmOpcodeTable_t*) entry->OpcodeInfo)
|
|
|
|
|
2003-12-24 23:32:59 +03:00
|
|
|
static const unsigned char instruction_has_modrm[512] = {
|
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
/* ------------------------------- */
|
2008-02-06 01:33:35 +03:00
|
|
|
/* 00 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
|
|
|
|
/* 10 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
|
|
|
|
/* 20 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
|
|
|
|
/* 30 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
|
|
|
|
/* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
/* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
/* 60 */ 0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,
|
|
|
|
/* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
/* 80 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
|
|
/* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
/* A0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
/* B0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
/* C0 */ 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
|
|
|
|
/* D0 */ 1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,
|
|
|
|
/* E0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
2003-12-24 23:32:59 +03:00
|
|
|
/* F0 */ 0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,
|
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
/* ------------------------------- */
|
|
|
|
1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1, /* 0F 00 */
|
2007-11-17 19:19:14 +03:00
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 10 */
|
2003-12-24 23:32:59 +03:00
|
|
|
1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1, /* 0F 20 */
|
2006-04-05 21:31:35 +04:00
|
|
|
0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, /* 0F 30 */
|
2003-12-24 23:32:59 +03:00
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 40 */
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 50 */
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 60 */
|
2007-03-23 17:35:50 +03:00
|
|
|
1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,1, /* 0F 70 */
|
2003-12-24 23:32:59 +03:00
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0F 80 */
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F 90 */
|
|
|
|
0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1, /* 0F A0 */
|
2007-09-19 23:38:10 +04:00
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F B0 */
|
2003-12-24 23:32:59 +03:00
|
|
|
1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, /* 0F C0 */
|
2005-06-16 20:59:36 +04:00
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F D0 */
|
2003-12-24 23:32:59 +03:00
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0F E0 */
|
2005-06-16 20:59:36 +04:00
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 /* 0F F0 */
|
2003-12-24 23:32:59 +03:00
|
|
|
/* ------------------------------- */
|
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
|
|
|
|
};
|
|
|
|
|
2006-02-05 22:48:29 +03:00
|
|
|
unsigned disassembler::disasm(bx_bool is_32, bx_bool is_64, bx_address base, bx_address ip, const Bit8u *instr, char *disbuf)
|
2005-11-14 21:09:22 +03:00
|
|
|
{
|
2006-02-05 22:48:29 +03:00
|
|
|
x86_insn insn = decode(is_32, is_64, base, ip, instr, disbuf);
|
|
|
|
return insn.ilen;
|
2005-11-14 21:09:22 +03:00
|
|
|
}
|
|
|
|
|
2006-02-05 22:48:29 +03:00
|
|
|
x86_insn disassembler::decode(bx_bool is_32, bx_bool is_64, bx_address base, bx_address ip, const Bit8u *instr, char *disbuf)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2007-01-13 00:53:48 +03:00
|
|
|
if (is_64) is_32 = 1;
|
2005-12-23 17:15:13 +03:00
|
|
|
x86_insn insn(is_32, is_64);
|
2006-02-05 22:48:29 +03:00
|
|
|
const Bit8u *instruction_begin = instruction = instr;
|
2003-12-24 23:32:59 +03:00
|
|
|
resolve_modrm = NULL;
|
2005-12-23 17:15:13 +03:00
|
|
|
|
|
|
|
db_eip = ip;
|
|
|
|
db_base = base; // cs linear base (base for PM & cs<<4 for RM & VM)
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
disbufptr = disbuf; // start sprintf()'ing into beginning of buffer
|
|
|
|
|
2003-12-24 23:32:59 +03:00
|
|
|
#define SSE_PREFIX_NONE 0
|
|
|
|
#define SSE_PREFIX_66 1
|
2010-05-23 23:17:41 +04:00
|
|
|
#define SSE_PREFIX_F3 2
|
|
|
|
#define SSE_PREFIX_F2 3 /* only one SSE prefix could be used */
|
2009-05-15 22:47:34 +04:00
|
|
|
unsigned sse_prefix = SSE_PREFIX_NONE, sse_opcode = 0;
|
|
|
|
unsigned rex_prefix = 0, prefixes = 0;
|
2003-12-24 23:32:59 +03:00
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
2005-12-23 17:15:13 +03:00
|
|
|
insn.b1 = fetch_byte();
|
2009-05-15 22:47:34 +04:00
|
|
|
prefixes++;
|
2005-12-23 17:15:13 +03:00
|
|
|
|
|
|
|
switch(insn.b1) {
|
|
|
|
case 0x40: // rex
|
|
|
|
case 0x41:
|
|
|
|
case 0x42:
|
|
|
|
case 0x43:
|
|
|
|
case 0x44:
|
|
|
|
case 0x45:
|
|
|
|
case 0x46:
|
|
|
|
case 0x47:
|
|
|
|
case 0x48:
|
|
|
|
case 0x49:
|
|
|
|
case 0x4A:
|
|
|
|
case 0x4B:
|
|
|
|
case 0x4C:
|
|
|
|
case 0x4D:
|
|
|
|
case 0x4E:
|
|
|
|
case 0x4F:
|
|
|
|
if (! is_64) break;
|
2007-01-25 22:09:41 +03:00
|
|
|
rex_prefix = insn.b1;
|
2005-12-23 17:15:13 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0x26: // ES:
|
|
|
|
case 0x2e: // CS:
|
|
|
|
case 0x36: // SS:
|
|
|
|
case 0x3e: // DS:
|
2008-06-12 01:05:38 +04:00
|
|
|
if (! is_64) insn.seg_override = (insn.b1 >> 3) & 3;
|
2007-01-25 22:09:41 +03:00
|
|
|
rex_prefix = 0;
|
2005-12-23 17:15:13 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0x64: // FS:
|
|
|
|
case 0x65: // GS:
|
2008-06-12 01:05:38 +04:00
|
|
|
insn.seg_override = insn.b1 & 0xf;
|
2007-01-25 22:09:41 +03:00
|
|
|
rex_prefix = 0;
|
2005-12-23 17:15:13 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0x66: // operand size override
|
|
|
|
if (!insn.os_64) insn.os_32 = !is_32;
|
2006-05-12 21:04:19 +04:00
|
|
|
if (!sse_prefix) sse_prefix = SSE_PREFIX_66;
|
2007-01-25 22:09:41 +03:00
|
|
|
rex_prefix = 0;
|
2005-12-23 17:15:13 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0x67: // address size override
|
|
|
|
if (!is_64) insn.as_32 = !is_32;
|
|
|
|
insn.as_64 = 0;
|
2007-01-25 22:09:41 +03:00
|
|
|
rex_prefix = 0;
|
2005-12-23 17:15:13 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0xf0: // lock
|
2007-01-25 22:09:41 +03:00
|
|
|
rex_prefix = 0;
|
2005-12-23 17:15:13 +03:00
|
|
|
continue;
|
|
|
|
|
2006-05-12 21:04:19 +04:00
|
|
|
case 0xf2: // repne
|
2008-06-12 01:05:38 +04:00
|
|
|
case 0xf3: // rep
|
2010-05-23 23:17:41 +04:00
|
|
|
sse_prefix = (insn.b1 & 0xf) ^ 1;
|
2007-01-25 22:09:41 +03:00
|
|
|
rex_prefix = 0;
|
2006-05-12 21:04:19 +04:00
|
|
|
continue;
|
|
|
|
|
2005-12-23 17:15:13 +03:00
|
|
|
// no more prefixes
|
|
|
|
default:
|
|
|
|
break;
|
2004-12-10 02:19:48 +03:00
|
|
|
}
|
2005-12-23 17:15:13 +03:00
|
|
|
|
|
|
|
break;
|
2003-12-24 23:32:59 +03:00
|
|
|
}
|
|
|
|
|
2005-12-23 17:15:13 +03:00
|
|
|
if (insn.b1 == 0x0f)
|
2003-12-24 23:32:59 +03:00
|
|
|
{
|
2005-12-23 17:15:13 +03:00
|
|
|
insn.b1 = 0x100 | fetch_byte();
|
|
|
|
}
|
|
|
|
|
2007-01-25 22:09:41 +03:00
|
|
|
if (rex_prefix) {
|
|
|
|
insn.extend8b = 1;
|
|
|
|
if (rex_prefix & 0x8) {
|
|
|
|
insn.os_64 = 1;
|
|
|
|
insn.os_32 = 1;
|
|
|
|
}
|
|
|
|
if (rex_prefix & 0x4) insn.rex_r = 8;
|
|
|
|
if (rex_prefix & 0x2) insn.rex_x = 8;
|
|
|
|
if (rex_prefix & 0x1) insn.rex_b = 8;
|
|
|
|
}
|
|
|
|
|
2005-12-23 17:15:13 +03:00
|
|
|
const BxDisasmOpcodeTable_t *opcode_table, *entry;
|
|
|
|
|
|
|
|
if (is_64) {
|
|
|
|
if (insn.os_64)
|
|
|
|
opcode_table = BxDisasmOpcodes64q;
|
|
|
|
else if (insn.os_32)
|
|
|
|
opcode_table = BxDisasmOpcodes64d;
|
|
|
|
else
|
|
|
|
opcode_table = BxDisasmOpcodes64w;
|
|
|
|
} else {
|
|
|
|
if (insn.os_32)
|
|
|
|
opcode_table = BxDisasmOpcodes32;
|
|
|
|
else
|
|
|
|
opcode_table = BxDisasmOpcodes16;
|
2003-12-24 23:32:59 +03:00
|
|
|
}
|
|
|
|
|
2005-12-23 17:15:13 +03:00
|
|
|
entry = opcode_table + insn.b1;
|
|
|
|
|
|
|
|
if (instruction_has_modrm[insn.b1])
|
|
|
|
{
|
2010-02-09 22:44:25 +03:00
|
|
|
// take 3rd byte for 3-byte opcode
|
|
|
|
if (entry->Attr == _GRP3BOP) {
|
|
|
|
entry = &(OPCODE_TABLE(entry)[fetch_byte()]);
|
|
|
|
}
|
2008-02-29 08:39:40 +03:00
|
|
|
|
2005-12-23 17:15:13 +03:00
|
|
|
decode_modrm(&insn);
|
|
|
|
}
|
2003-12-24 23:32:59 +03:00
|
|
|
|
|
|
|
int attr = entry->Attr;
|
2008-02-06 01:33:35 +03:00
|
|
|
while(attr)
|
2003-12-24 23:32:59 +03:00
|
|
|
{
|
|
|
|
switch(attr) {
|
|
|
|
case _GROUPN:
|
2009-01-14 01:40:16 +03:00
|
|
|
entry = &(OPCODE_TABLE(entry)[insn.nnn & 7]);
|
2003-12-24 23:32:59 +03:00
|
|
|
break;
|
|
|
|
|
2010-01-31 12:45:27 +03:00
|
|
|
case _GRPSSE66:
|
|
|
|
/* SSE opcode group with only prefix 0x66 allowed */
|
|
|
|
sse_opcode = 1;
|
|
|
|
if (sse_prefix != SSE_PREFIX_66)
|
2010-01-31 13:17:42 +03:00
|
|
|
entry = &(BxDisasmGroupSSE_ERR[sse_prefix]);
|
|
|
|
attr = 0;
|
|
|
|
continue;
|
2010-01-31 12:45:27 +03:00
|
|
|
|
|
|
|
case _GRPSSEF2:
|
|
|
|
/* SSE opcode group with only prefix 0xF2 allowed */
|
|
|
|
sse_opcode = 1;
|
|
|
|
if (sse_prefix != SSE_PREFIX_F2)
|
2010-01-31 13:17:42 +03:00
|
|
|
entry = &(BxDisasmGroupSSE_ERR[sse_prefix]);
|
|
|
|
attr = 0;
|
|
|
|
continue;
|
2010-01-31 12:45:27 +03:00
|
|
|
|
2010-02-09 22:44:25 +03:00
|
|
|
case _GRPSSEF3:
|
|
|
|
/* SSE opcode group with only prefix 0xF3 allowed */
|
|
|
|
sse_opcode = 1;
|
|
|
|
if (sse_prefix != SSE_PREFIX_F3)
|
|
|
|
entry = &(BxDisasmGroupSSE_ERR[sse_prefix]);
|
|
|
|
attr = 0;
|
|
|
|
continue;
|
|
|
|
|
2003-12-24 23:32:59 +03:00
|
|
|
case _GRPSSE:
|
2009-05-15 22:47:34 +04:00
|
|
|
sse_opcode = 1;
|
2008-02-06 01:33:35 +03:00
|
|
|
/* For SSE opcodes, look into another 4 entries table
|
2006-05-12 21:04:19 +04:00
|
|
|
with the opcode prefixes (NONE, 0x66, 0xF2, 0xF3) */
|
|
|
|
entry = &(OPCODE_TABLE(entry)[sse_prefix]);
|
2003-12-24 23:32:59 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _SPLIT11B:
|
2005-12-23 17:15:13 +03:00
|
|
|
entry = &(OPCODE_TABLE(entry)[insn.mod != 3]); /* REG/MEM */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _GRPRM:
|
2009-01-14 01:40:16 +03:00
|
|
|
entry = &(OPCODE_TABLE(entry)[insn.rm & 7]);
|
2003-12-24 23:32:59 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _GRPFP:
|
2005-12-23 17:15:13 +03:00
|
|
|
if(insn.mod != 3)
|
2003-12-24 23:32:59 +03:00
|
|
|
{
|
2009-01-14 01:40:16 +03:00
|
|
|
entry = &(OPCODE_TABLE(entry)[insn.nnn & 7]);
|
2004-12-10 02:19:48 +03:00
|
|
|
} else {
|
2005-12-23 17:15:13 +03:00
|
|
|
int index = (insn.b1-0xD8)*64 + (insn.modrm & 0x3f);
|
2003-12-24 23:32:59 +03:00
|
|
|
entry = &(BxDisasmOpcodeInfoFP[index]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _GRP3DNOW:
|
2009-09-04 14:51:31 +04:00
|
|
|
entry = &(BxDisasm3DNowGroup[fetch_byte()]);
|
2003-12-24 23:32:59 +03:00
|
|
|
break;
|
|
|
|
|
2007-04-19 20:12:21 +04:00
|
|
|
case _GRP64B:
|
2007-09-19 23:38:10 +04:00
|
|
|
entry = &(OPCODE_TABLE(entry)[insn.os_64 ? 2 : insn.os_32]);
|
2007-04-19 20:12:21 +04:00
|
|
|
break;
|
|
|
|
|
2003-12-24 23:32:59 +03:00
|
|
|
default:
|
2005-12-23 17:15:13 +03:00
|
|
|
printf("Internal disassembler error - unknown attribute !\n");
|
2006-02-05 22:48:29 +03:00
|
|
|
return x86_insn(is_32, is_64);
|
2003-12-24 23:32:59 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2003-12-24 23:32:59 +03:00
|
|
|
/* get additional attributes from group table */
|
|
|
|
attr = entry->Attr;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-12-23 17:15:13 +03:00
|
|
|
#define BRANCH_NOT_TAKEN 0x2E
|
|
|
|
#define BRANCH_TAKEN 0x3E
|
|
|
|
|
|
|
|
unsigned branch_hint = 0;
|
|
|
|
|
2003-12-24 23:32:59 +03:00
|
|
|
// print prefixes
|
2009-05-15 22:47:34 +04:00
|
|
|
for(unsigned i=0;i<prefixes;i++)
|
2004-12-10 02:19:48 +03:00
|
|
|
{
|
2005-12-23 17:15:13 +03:00
|
|
|
Bit8u prefix_byte = *(instr+i);
|
|
|
|
|
2007-01-25 22:09:41 +03:00
|
|
|
if (prefix_byte == 0xF0) {
|
2005-12-23 17:15:13 +03:00
|
|
|
const BxDisasmOpcodeTable_t *prefix = &(opcode_table[prefix_byte]);
|
|
|
|
dis_sprintf("%s ", OPCODE(prefix)->IntelOpcode);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-01-28 00:01:21 +03:00
|
|
|
if (insn.b1 == 0x90 && !insn.rex_b && prefix_byte == 0xF3)
|
|
|
|
continue;
|
|
|
|
|
2007-01-25 22:09:41 +03:00
|
|
|
if (prefix_byte == 0xF3 || prefix_byte == 0xF2) {
|
2009-05-15 22:47:34 +04:00
|
|
|
if (! sse_opcode) {
|
2007-01-25 22:09:41 +03:00
|
|
|
const BxDisasmOpcodeTable_t *prefix = &(opcode_table[prefix_byte]);
|
|
|
|
dis_sprintf("%s ", OPCODE(prefix)->IntelOpcode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-23 17:15:13 +03:00
|
|
|
// branch hint for jcc instructions
|
|
|
|
if ((insn.b1 >= 0x070 && insn.b1 <= 0x07F) ||
|
|
|
|
(insn.b1 >= 0x180 && insn.b1 <= 0x18F))
|
2004-12-10 17:04:57 +03:00
|
|
|
{
|
2008-02-06 01:33:35 +03:00
|
|
|
if (prefix_byte == BRANCH_NOT_TAKEN || prefix_byte == BRANCH_TAKEN)
|
2005-12-23 17:15:13 +03:00
|
|
|
branch_hint = prefix_byte;
|
2004-12-10 17:04:57 +03:00
|
|
|
}
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-12-23 17:15:13 +03:00
|
|
|
const BxDisasmOpcodeInfo_t *opcode = OPCODE(entry);
|
|
|
|
|
|
|
|
// patch jecx opcode
|
|
|
|
if (insn.b1 == 0xE3 && insn.as_32 && !insn.as_64)
|
|
|
|
opcode = &Ia_jecxz_Jb;
|
|
|
|
|
2006-04-05 21:31:35 +04:00
|
|
|
// fix nop opcode
|
2009-01-28 00:01:21 +03:00
|
|
|
if (insn.b1 == 0x90) {
|
|
|
|
if (sse_prefix == SSE_PREFIX_F3)
|
|
|
|
opcode = &Ia_pause;
|
|
|
|
else if (!insn.rex_b)
|
|
|
|
opcode = &Ia_nop;
|
2006-04-05 21:31:35 +04:00
|
|
|
}
|
|
|
|
|
2004-12-10 17:04:57 +03:00
|
|
|
// print instruction disassembly
|
2004-12-08 21:54:15 +03:00
|
|
|
if (intel_mode)
|
2005-12-23 17:15:13 +03:00
|
|
|
print_disassembly_intel(&insn, opcode);
|
2004-12-08 21:54:15 +03:00
|
|
|
else
|
2005-12-23 17:15:13 +03:00
|
|
|
print_disassembly_att (&insn, opcode);
|
|
|
|
|
|
|
|
if (branch_hint == BRANCH_NOT_TAKEN)
|
|
|
|
{
|
|
|
|
dis_sprintf(", not taken");
|
|
|
|
}
|
|
|
|
else if (branch_hint == BRANCH_TAKEN)
|
|
|
|
{
|
|
|
|
dis_sprintf(", taken");
|
|
|
|
}
|
2008-02-06 01:33:35 +03:00
|
|
|
|
2006-02-05 22:48:29 +03:00
|
|
|
insn.ilen = (unsigned)(instruction - instruction_begin);
|
|
|
|
|
|
|
|
return insn;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-04-27 23:47:12 +04:00
|
|
|
void disassembler::dis_sprintf(const char *fmt, ...)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(disbufptr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
disbufptr += strlen(disbufptr);
|
|
|
|
}
|
2004-12-15 20:15:43 +03:00
|
|
|
|
|
|
|
void disassembler::dis_putc(char symbol)
|
|
|
|
{
|
|
|
|
*disbufptr++ = symbol;
|
|
|
|
*disbufptr = 0;
|
|
|
|
}
|