home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_04 / Diver / Function.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  5.0 KB  |  193 lines

  1. #pragma once
  2.  
  3. //-----------------------------------------------------------------------------------//
  4. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  5. //                             ISBN  0-13-086985-6                                   //
  6. //                                                                                   //
  7. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  8. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  9. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  10. //                                                                                   //
  11. //  FileName   : function.h                                                             //
  12. //  Description: KFuncTable class                                                    //
  13. //  Version    : 1.00.000, May 31, 2000                                              //
  14. //-----------------------------------------------------------------------------------//
  15.  
  16. #include "Format.h"
  17. #include "Proxy.h"
  18. #include "Module.h"
  19.  
  20. #define spy_summary     0x01
  21. #define spy_loadlibrary 0x02
  22.  
  23. class KDumpData
  24. {
  25. public:
  26.     TCHAR cppthis[10];
  27.     TCHAR param[100];
  28. };
  29.  
  30.  
  31. class KRoutineInfo
  32. {
  33. public:
  34.     int      next;
  35.     
  36.     unsigned funcid;
  37.     unsigned rtnaddr;
  38.  
  39.     unsigned entertime;
  40.  
  41.     KDumpData dumpdata;
  42. };
  43.  
  44.  
  45. class KFunction
  46. {   
  47. public:
  48.     unsigned char    f_module;        // index to module table
  49. //    unsigned char   f_selection;    // spying selection
  50.     unsigned char   f_parano;       // no of parameters
  51.     unsigned char   f_kind;            // WIN32API, COMMETHOD, SYSCALL
  52.     unsigned char   f_hooked;        
  53.  
  54.     unsigned short  f_methodid;        // sequential method id within a COM interface    
  55.     unsigned short  f_class;        // function classification
  56.     ATOM            f_name;         // index into name table
  57.     unsigned short  f_firstpara;    // index to parameter table
  58.  
  59.     unsigned char    f_stub[10];        // stub function
  60.                                     // mov eax, index
  61.                                     // jmp newaddress
  62.  
  63.     FARPROC         f_oldaddress;    // original function
  64.  
  65.     unsigned        f_totaltime;
  66.     unsigned        f_callno;
  67.     
  68.     FARPROC            f_newaddress(void) const
  69.     {
  70.         return (FARPROC) (void *) f_stub;
  71.     }
  72.  
  73.     void InitStub(int index, FARPROC newaddress);
  74. };
  75.  
  76.  
  77. class KParameter
  78. {
  79. public:
  80.     ATOM  p_name;            // index into name table
  81.     ATOM  p_type;            // index into name table
  82. };
  83.  
  84.  
  85. const int MAX_FUNC      = 1024;
  86. const int MAX_PARA      = MAX_FUNC * 8;
  87.     
  88. class KFuncTable : public KModuleTable, public KAtomTable
  89. {
  90.     int        m_funcno;
  91.     int        m_parano;
  92.     int        m_lastfunc;
  93.                 
  94.     int  DefPara(const char * paratype, const char *name = NULL);
  95.         
  96. public:
  97.  
  98.     BOOL       m_logcall;
  99.     BOOL       m_dispcall;
  100.  
  101.     KFunction  m_func[MAX_FUNC];
  102.     KParameter m_para[MAX_PARA];
  103.     
  104.     KFuncTable()
  105.     {   
  106.         memset(m_func, 0, sizeof(m_func));
  107.  
  108.         m_funcno  = 0;
  109.         m_parano  = 0;
  110.             
  111.         m_logcall = TRUE;
  112.         m_dispcall = TRUE;
  113.     }
  114.         
  115.     void SetOptions(BOOL logcall, BOOL dispcall)
  116.     {
  117.         m_logcall  = logcall;
  118.         m_dispcall = dispcall;
  119.     }
  120.  
  121.     int GetParaNo(int f) const
  122.     {
  123.         return m_func[f].f_parano;
  124.     }
  125.  
  126.     ATOM GetParaAtom(int f, int p) const
  127.     {
  128.         return m_para[m_func[f].f_firstpara + p].p_name;
  129.     }
  130.  
  131.     ATOM GetParaTypeAtom(int f, int p) const
  132.     {
  133.         return m_para[m_func[f].f_firstpara + p].p_type;
  134.     }
  135.  
  136.     const char *GetParaName(int f, int p) 
  137.     {
  138.         return GetAtomName(m_para[m_func[f].f_firstpara + p].p_name);
  139.     }
  140.  
  141.     const char * GetParaTypeName(int f, int p)
  142.     {
  143.         return GetAtomName(m_para[m_func[f].f_firstpara + p].p_type);
  144.     }
  145.  
  146.     const char *GetFuncName(int f) 
  147.     {
  148.         return GetAtomName(m_func[f].f_name);
  149.     }
  150.  
  151.     FARPROC GetProcAddr(int funcid);
  152.                         
  153.     int AddFunc(unsigned ord, const char *name, unsigned opt, int parano, const char *paratype, int kind, const void * pOldAddr);
  154.     
  155.     void Initialize(void);
  156.     
  157.     void virtual Initialize_API(void)
  158.     {
  159.     }
  160.  
  161.     void virtual Terminate_API(void)
  162.     {
  163.     }
  164.  
  165.     void Terminate(void)
  166.     {
  167.         Terminate_API();
  168.     }
  169.  
  170.     FARPROC LookupInterceptedAPI(FARPROC address, int & id);
  171.  
  172.     int  InterceptWin32(const char *Caller,
  173.                         const char *Callee,
  174.                         PIMAGE_THUNK_DATA pName,
  175.                         PIMAGE_THUNK_DATA pThunk,
  176.                         const char *baseAddress);
  177.     
  178.     int  InterceptWin32(const char *ModuleName, const char * baseAddress);
  179.  
  180.     int  InterceptWin32(void);
  181.     int  InterceptCom(void);
  182.     int  InterceptSysCall(void);
  183.  
  184.     void virtual FuncEntryCallBack(KRoutineInfo *routine, EntryInfo *info)
  185.     {
  186.     }
  187.  
  188.     void virtual FuncExitCallBack(KRoutineInfo *routine, ExitInfo *info, unsigned leavetime, int depth)
  189.     {
  190.     }        
  191.  
  192. };
  193.