Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

x86dis.h

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      x86dis.h
00004  *
00005  *      Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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               /* no prefix */
00028 #define X86DIS_OPCODE_CLASS_EXT         1               /* 0F */
00029 #define X86DIS_OPCODE_CLASS_EXTEXT              2               /* 0F0F */
00030 
00031 /* x86-specific styles */
00032 #define X86DIS_STYLE_EXPLICIT_MEMSIZE   0x00000001              /* IF SET: mov word ptr [0000], ax      ELSE: mov [0000], ax */
00033 #define X86DIS_STYLE_OPTIMIZE_ADDR              0x00000002              /* IF SET: mov [eax*3], ax                      ELSE: mov [eax+eax*2+00000000], ax */
00034 /*#define X86DIS_STYLE_USE16                    0x00000004
00035 #define X86DIS_STYLE_USE32                      0x00000008*/
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  *      CLASS x86dis
00053  */
00054 
00055 class x86dis: public Disassembler {
00056 public:
00057         int opsize, addrsize;
00058 protected:
00059         x86dis_insn insn;
00060         char insnstr[256];
00061 /* initme! */
00062         unsigned char *codep, *ocodep;
00063         int seg;
00064         int addr; // FIXME: int??
00065         byte c;
00066         int modrm;
00067         int sib;
00068         int maxlen;
00069 
00070 /* new */
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 /* overwritten */
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 /* __X86DIS_H__ */

Generated on Fri May 7 21:15:46 2004 by doxygen 1.3.5