免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 发帖

SSDT

  1. #pragma once


  2. typedef struct _ServiceDescriptorTable
  3. {
  4.     PVOID           ServiceTableBase;       //System Service Dispatch Table 的基地址
  5.     PVOID           ServiceCounterTable;    //包含着 SSDT 中每个服务被调用次数的计数器。这个计数器一般由sysenter 更新。
  6.     unsigned int    NumberOfServices;       //由 ServiceTableBase 描述的服务的数目。
  7.     PVOID           ParamTableBase;         //包含每个系统服务参数字节数表的基地址-系统服务参数表

  8. }*PServiceDescriptorTable;


  9. extern "C" PServiceDescriptorTable KeServiceDescriptorTable;


  10. extern ULONG GetSSDTAddr(ULONG uIndex);
  11. extern VOID UnHookSSDT(ULONG* pOriginalAddr, ULONG uIndex);
  12. extern BOOLEAN HookSSDT(ULONG* pOriginalAddr, ULONG uNewAddr, ULONG uIndex);
复制代码
  1. #include "StdAfx.h"
  2. #include "SSDT.h"
  3. #include "common.h"

  4. ULONG GetSSDTAddr(ULONG uIndex)
  5. {
  6.     ULONG uAddr = 0;


  7.     __asm
  8.     {
  9.         push eax
  10.         push ecx

  11.         mov ecx, uIndex
  12.         mov eax, KeServiceDescriptorTable
  13.         mov eax, [eax]
  14.         lea eax, [eax + ecx*4]
  15.         mov eax, [eax]
  16.         mov uAddr, eax

  17.         pop ecx
  18.         pop eax

  19.     }

  20.     return uAddr;
  21. }

  22. BOOLEAN HookSSDT(ULONG* pOriginalAddr, ULONG uNewAddr, ULONG uIndex)
  23. {
  24.     ULONG uServiceTableBase = (ULONG)KeServiceDescriptorTable->ServiceTableBase;

  25.     *pOriginalAddr = ((ULONG*)uServiceTableBase)[uIndex];

  26.     DisableWP();

  27.     ((ULONG*)uServiceTableBase)[uIndex] = uNewAddr;

  28.     EnableWP();

  29.     return TRUE;
  30. }

  31. VOID UnHookSSDT(ULONG* pOriginalAddr, ULONG uIndex)
  32. {
  33.     ULONG uServiceTableBase = (ULONG)KeServiceDescriptorTable->ServiceTableBase;

  34.     DisableWP();

  35.     ((ULONG*)uServiceTableBase)[uIndex] = *pOriginalAddr;

  36.     EnableWP();   
  37. }
复制代码
  1. #include "stdafx.h"
  2. #include "common.h"


  3. VOID DisableWP()
  4. {
  5.     __asm
  6.     {
  7.         cli
  8.         push eax
  9.         mov eax, cr0
  10.         and eax, 0x0FFFEFFFF
  11.         mov cr0,eax
  12.         pop eax
  13.     }
  14. }

  15. VOID EnableWP()
  16. {
  17.     __asm
  18.     {
  19.         push eax
  20.         mov eax, cr0
  21.         or eax, 0x00010000
  22.         mov cr0, eax
  23.         pop eax
  24.         sti
  25.     }
  26. }
复制代码

返回列表