00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __X86DIS_H__
00022 #define __X86DIS_H__
00023
00024 #include "asm.h"
00025 #include "x86opc.h"
00026
00027 #define X86DIS_OPCODE_CLASS_STD 0
00028 #define X86DIS_OPCODE_CLASS_EXT 1
00029 #define X86DIS_OPCODE_CLASS_EXTEXT 2
00030
00031
00032 #define X86DIS_STYLE_EXPLICIT_MEMSIZE 0x00000001
00033 #define X86DIS_STYLE_OPTIMIZE_ADDR 0x00000002
00034
00035
00036
00037 struct x86dis_insn {
00038 bool invalid;
00039 char lockprefix;
00040 char repprefix;
00041 char segprefix;
00042 byte size;
00043 int opcode;
00044 int opcodeclass;
00045 int eopsize;
00046 int eaddrsize;
00047 char *name;
00048 x86_insn_op op[3];
00049 };
00050
00051
00052
00053
00054
00055 class x86dis: public Disassembler {
00056 public:
00057 int opsize, addrsize;
00058 protected:
00059 x86dis_insn insn;
00060 char insnstr[256];
00061
00062 unsigned char *codep, *ocodep;
00063 int seg;
00064 int addr;
00065 byte c;
00066 int modrm;
00067 int sib;
00068 int maxlen;
00069
00070
00071 void decode_insn(x86opc_insn *insn);
00072 void decode_modrm(x86_insn_op *op, char size, int allow_reg, int allow_mem, int mmx);
00073 void decode_op(x86_insn_op *op, x86opc_insn_op *xop);
00074 void decode_sib(x86_insn_op *op, int mod);
00075 int esizeaddr(char c);
00076 int esizeop(char c);
00077 byte getbyte();
00078 word getword();
00079 dword getdword();
00080 int getmodrm();
00081 int getsib();
00082 void invalidate();
00083 int isfloat(char c);
00084 void prefixes();
00085 int special_param_ambiguity(x86dis_insn *disasm_insn);
00086 void str_format(char **str, char **format, char *p, char *n, char *op[3], int oplen[3], char stopchar, int print);
00087 virtual void str_op(char *opstr, int *opstrlen, x86dis_insn *insn, x86_insn_op *op, bool explicit_params);
00088 public:
00089 x86dis();
00090 x86dis(int opsize, int addrsize);
00091 virtual ~x86dis();
00092
00093
00094 virtual dis_insn *decode(byte *code, int maxlen, CPU_ADDR addr);
00095 virtual dis_insn *duplicateInsn(dis_insn *disasm_insn);
00096 virtual void getOpcodeMetrics(int &min_length, int &max_length, int &min_look_ahead, int &avg_look_ahead, int &addr_align);
00097 virtual char *getName();
00098 virtual byte getSize(dis_insn *disasm_insn);
00099 int load(ht_object_stream *f);
00100 virtual OBJECT_ID object_id() const;
00101 virtual char *str(dis_insn *disasm_insn, int options);
00102 virtual char *strf(dis_insn *disasm_insn, int options, char *format);
00103 virtual void store(ht_object_stream *f);
00104 virtual bool validInsn(dis_insn *disasm_insn);
00105 };
00106
00107 class x86dis_vxd: public x86dis {
00108 protected:
00109 virtual void str_op(char *opstr, int *opstrlen, x86dis_insn *insn, x86_insn_op *op, bool explicit_params);
00110 public:
00111 x86dis_vxd();
00112 x86dis_vxd(int opsize, int addrsize);
00113 virtual ~x86dis_vxd();
00114
00115 virtual dis_insn *decode(byte *code, byte maxlen, CPU_ADDR addr);
00116 virtual OBJECT_ID object_id() const;
00117 };
00118
00119 #endif