SKELETON.C
上传用户:lx1888888
上传日期:2007-01-04
资源大小:136k
文件大小:3k
源码类别:

驱动编程

开发平台:

Visual C++

  1. #include <basedef.h>
  2. #include <vmm.h>
  3. #include <debug.h>
  4. #include "vxdcall.h"
  5. #include <vxdwraps.h>
  6. #include <wrappers.h>
  7. #include "intrinsi.h"
  8. #ifdef DEBUG
  9. #define DPRINTF(buf, fmt, arg1, arg2)  _Sprintf(buf, fmt, arg1, arg2 ); Out_Debug_String( buf )
  10. #else
  11. #define DPRINTF(buf, fmt, arg1, arg2)
  12. #endif
  13. typedef struct tcb_s *PTCB;
  14. BOOL OnSysVmInit(VMHANDLE hVM);
  15. VOID OnSysVmTerminate(VMHANDLE hVM);
  16. BOOL OnCreateVm(VMHANDLE hVM);
  17. VOID OnDestroyVm(VMHANDLE hVM);
  18. BOOL OnCreateThread(PTCB hThread);
  19. VOID OnDestroyThread(PTCB hThread);
  20. #pragma VxD_LOCKED_DATA_SEG
  21. DWORD filepos = 0;
  22. HANDLE fh;
  23. char  buf[80];
  24. #pragma VxD_LOCKED_CODE_SEG
  25. BOOL OnSysVmInit(VMHANDLE hVM)
  26. {
  27.    BYTE  action;
  28.    WORD  err;
  29.    int      count=0;
  30.    PTCB  tcb;
  31.    tcb = Get_Initial_Thread_Handle(hVM);
  32.    DPRINTF(buf, "SysVMInit: VM=%x tcb=%xrn", hVM, tcb );
  33.    fh = IFSMgr_Ring0_OpenCreateFile(FALSE, "vxdskel.log", 
  34.                            0x0002, 0x0000, 0x12, 0x00, 
  35.                            &err, &action);
  36.    if (!fh)
  37.    {
  38.       DPRINTF(buf, "Error %x opening file %sn", err, "vxdskel.log" );
  39.    }
  40.    else
  41.    {
  42.       _Sprintf(buf, "SysVMInit: VM=%x tcb=%xrn", hVM, tcb );
  43.       count = IFSMgr_Ring0_WriteFile(FALSE, fh, buf, strlen(buf), filepos, &err);
  44.       filepos += count;
  45.    }
  46.    return TRUE;
  47. }
  48. VOID OnSysVmTerminate(VMHANDLE hVM)
  49. {
  50.    WORD  err;
  51.    int      count=0;
  52.    PTCB  tcb;
  53.    tcb = Get_Initial_Thread_Handle(hVM);
  54.    DPRINTF( buf, "SysVmTerminate VM=%x tcb=%xrn", hVM, tcb );
  55.       _Sprintf( buf, "SysVmTerminate VM=%x tcb=%xrn", hVM, tcb );
  56.    count = IFSMgr_Ring0_WriteFile(FALSE, fh, buf, strlen(buf), filepos, &err);
  57.    filepos += count;
  58.    IFSMgr_Ring0_CloseFile( fh, &err );
  59. }
  60. BOOL OnCreateVm(VMHANDLE hVM)
  61. {
  62.    PTCB  tcb;
  63.    WORD  err;
  64.    int      count=0;
  65.    tcb = Get_Initial_Thread_Handle(hVM);
  66.     DPRINTF(buf, "Create_VM: VM=%x, tcb=%xrn", hVM, tcb); 
  67.     _Sprintf(buf, "Create_VM: VM=%x, tcb=%xrn", hVM, tcb);   
  68.    count = IFSMgr_Ring0_WriteFile(FALSE, fh, buf, strlen(buf), filepos, &err);
  69.    filepos += count;
  70.    return TRUE;
  71. }
  72. VOID OnDestroyVm(VMHANDLE hVM)
  73. {
  74.    WORD  err;
  75.    int      count;
  76.    PTCB  tcb;
  77.    tcb = Get_Initial_Thread_Handle(hVM);
  78.     DPRINTF(buf, "Destroy_VM: VM=%x tcb=%xrn", hVM, tcb );   
  79.     _Sprintf(buf, "Destroy_VM: VM=%x tcb=%xrn", hVM, tcb );  
  80.    count = IFSMgr_Ring0_WriteFile(FALSE, fh, buf, strlen(buf), filepos, &err);
  81.    filepos += count;
  82. }
  83. BOOL OnCreateThread(PTCB tcb)
  84. {
  85.    WORD  err;
  86.    int      count;
  87.    DPRINTF(buf, "Create_Thread: VM=%x, tcb=%xrn", tcb->TCB_VMHandle, tcb);  
  88.    _Sprintf(buf, "Create_Thread: VM=%x, tcb=%xrn", tcb->TCB_VMHandle, tcb); 
  89.    count = IFSMgr_Ring0_WriteFile(FALSE, fh, buf, strlen(buf), filepos, &err);
  90.    filepos += count;
  91.    return TRUE;
  92. }
  93. VOID OnDestroyThread(PTCB tcb)
  94. {
  95.    WORD  err;
  96.    int      count;
  97.    DPRINTF( buf, "Destroy_Thread VM=%x, tcb=%xrn", tcb->TCB_VMHandle, tcb );
  98.    _Sprintf( buf, "Destroy_Thread VM=%x, tcb=%xrn", tcb->TCB_VMHandle, tcb );
  99.    count = IFSMgr_Ring0_WriteFile(FALSE, fh, buf, strlen(buf), filepos, &err);
  100.    filepos += count;
  101. }