Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

x86dasm.h

Go to the documentation of this file.
00001 /*
00002 PeRdr - PE file disassembler
00003 Copyright (C) 1999-2003 Frediano Ziglio
00004 -----
00005 
00006 This program is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
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 INFORMATION
00022   www: https://freddy77.tripod.com/perdr/
00023   e-mail: freddy77@angelfire.com
00024 */
00025 #ifndef FILE_X86DASM_H
00026 #define FILE_X86DASM_H
00027 
00028 #include "x86instr.h"
00029 #include "module.h"
00030 
00031 // dimensione di un indirizzo
00032 extern int addr_bytes;
00033 
00034 // abilita istruzioni PentiumIII
00035 extern bool p3enable;
00036 // abilita istruzioni 3DNow
00037 extern bool k6_3DNow_enable;
00038 // abilita istruzioni 3DNow enhanched
00039 extern bool k6_en_3DNow_enable;
00040 // abilita istruzioni Athlon
00041 extern bool athlon_enable;
00042 
00043 // !!! add class processor status like
00044 // --UML------
00045 //  ProcessorStatus
00046 // -----------
00047 //  16/32 bit
00048 //  type flag (386/486, 3DNow!...)
00049 // -----------
00050 // -----------
00051 
00052 class RelocationInfos;
00053 class InstructionDecoder
00054 {
00055 public:
00056   InstructionDecoder(const RelocationInfos& r):
00057       reloc(r),reader(NULL)
00058   {};
00059   int Decode(Instruction& instruction,ObjectModule::DataReader& reader);
00060 protected:
00061   const RelocationInfos& reloc;
00062         ObjectModule::DataReader* reader;
00063 private:
00064   // table information
00065   typedef int (*DecodeProc)(InstructionDecoder*, uchar, int, Instruction&);
00066   // contain relocation, current address, buffer, etc
00067   struct InstTable {               //-- Instruction Table --
00068     DecodeProc rtn;                // Rtn to process byte
00069     int     special;               // Data to pass to rtnn
00070     int     instruction;           // Data to pass to rtn
00071   };
00072   static const InstTable instrTable[];
00073   static const InstTable exInstrTable[];
00074   inline void CheckTables();
00075 
00076   // read 1 byte and check for no relocation, return true if error
00077   bool get_checkc( uint32_t* offset );
00078         // read 2/4 bytes
00079   uint32_t ReadVar( int flag );
00080   // read 2/4 bytes and relocation info
00081   bool getv_rel( Param& param, int flag );
00082 
00083   // read memory info
00084   int do_sib( uchar* base, Param& param );
00085   int mod0( int sib_offset, uchar r_m, bool* size_known, Param& param );
00086   int mod1( int sib_offset, uchar r_m, Param& param );
00087   int mod2( int sib_offset, uchar r_m, bool* size_known, Param& param );
00088   int do_mod_rm( uchar mod, uchar r_m, int reg_size, 
00089                  Param::MemoryTypes memType, bool size_needed, Param& param );
00090 
00091   // scan other table instruction
00092   int check_forward( const InstTable* inst_table, Instruction& instruction );
00093 
00094   int mod_reg2 ( uchar opcode, int special, int mod_reg, 
00095                  Instruction& instruction );
00096 #define INSTPROCDECL(proc) \
00097   static int proc(InstructionDecoder* _this, uchar opcode, \
00098                   int special, Instruction& instruction)
00099 
00100   INSTPROCDECL(stub);
00101   INSTPROCDECL(unimpl);
00102 
00103   INSTPROCDECL(conv_byte);
00104   INSTPROCDECL(one_byte);
00105   INSTPROCDECL(two_byte);
00106   INSTPROCDECL(two_sbyte);
00107   INSTPROCDECL(three_byte);
00108   INSTPROCDECL(five_byte);
00109 
00110   INSTPROCDECL(one_a);
00111   INSTPROCDECL(two_a);
00112   INSTPROCDECL(three_a);
00113 
00114   INSTPROCDECL(in_out);
00115   INSTPROCDECL(string_byte);
00116   INSTPROCDECL(enter);
00117   INSTPROCDECL(two_bcd);
00118 
00119   INSTPROCDECL(disp8);
00120   INSTPROCDECL(disp16);
00121 
00122   INSTPROCDECL(wait);
00123   INSTPROCDECL(prefix);
00124   INSTPROCDECL(prefixf3);
00125   INSTPROCDECL(seg_over);
00126 
00127   INSTPROCDECL(opsize_over);
00128   INSTPROCDECL(adrsize_over);
00129 
00130   INSTPROCDECL(mod_reg);
00131   INSTPROCDECL(mod_xmm);
00132   INSTPROCDECL(mod_reg_p3);
00133   INSTPROCDECL(seg_reg);
00134   INSTPROCDECL(group1);
00135   INSTPROCDECL(group2);
00136   INSTPROCDECL(group3);
00137   INSTPROCDECL(group4);
00138   INSTPROCDECL(group5);
00139   INSTPROCDECL(group6);
00140   INSTPROCDECL(group7);
00141   INSTPROCDECL(group8);
00142   INSTPROCDECL(group9);
00143   INSTPROCDECL(groupA);
00144   INSTPROCDECL(group15);
00145   INSTPROCDECL(group16);
00146   INSTPROCDECL(mov_special);
00147   INSTPROCDECL(mov_creg);
00148 
00149   INSTPROCDECL(esc);
00150   INSTPROCDECL(extra);
00151 
00152   // 3D Now!
00153   INSTPROCDECL(one_byte_k63d);
00154   INSTPROCDECL(k6_3dnow);
00155   INSTPROCDECL(prefetch_k63d);
00156 #undef INSTPROCDECL
00157 };
00158 
00159 #endif

Generated on Mon Jan 13 22:20:34 2003 for perdr by doxygen1.2.15