Home 电脑技术 编程技术 游戏保护之乱谈
游戏保护之乱谈 E-mail
作者:洋葱圈   
周一, 09 6月 2008 21:01

前段时间无聊时,简单逆向了XX游戏保护的驱动;本来不准备写这篇文章,但搜索资料看到类似代码,想做个简单的比较,纯属娱乐,各位看官见笑

 

一 xx游戏保护驱动的实现:

 TSDeviceControl()
  IOCTL_TS_INIT(初始化游戏保护器):
   1) Irp->AssociatedIrp.SystemBuffer输入参数格式
       struct{dword dwMajorVersion;
              dword dwMinorVersion;
              dword dwServicePackMajor;
              dword dwServicePackMinor;
              dword dwNum;     //需保护进程数目
              dword dwPID[32]; //需保护进程列表
              dword decode;    //密钥
              }InitParam;

    2)TSDecodeControlParam();//对输入参数进行解密


    3)TSInitGuardProcess();//初始化需保护的进程列表
      {
       if (InitParam.dwNum <= 0)
       {
          return;
       }
       
       for(int i=0; i<InitParam.dwNum && i<LIMIT_GUARD_PROCESS_NUM; i++)
       {
         if (PsLookupProcessByProcessId(InitParam.dwPID[i], g_GuardEProcess[g_GuardEProcessNum]) == STATUS_SUCCESS)
         {
              g_GuardEProcessNum++;
         }
       }
     }
     #define  LIMIT_GUARD_PROCESS_NUM 32
     dword    g_GuardEProcessNum;
     EPROCESS g_GuardEProcess[LIMIT_GUARD_PROCESS_NUM];
 
   
    4)TSInitINTNumber();
      (1)初始化GDI(win32k.sys)中要detour的服务中断号
      (2)动态加载PsGetProcessImageFileName


    5)TSSetKernelHook();
      (1)动态加载ObOpenObjectByPointer和NtOpenProcess

      (2)查找NtOpenProcess中调用ObOpenObjectByPointer的地址(内置了一个小的反汇编引擎)
         mov     ecx, g_NtOpenProcess     ; 
         cmp     al, 0E8h                 ; is relative call
         jnz     short Loc_NoRelativeCall ;
         mov     eax, [ecx+1]             ;
         mov     g_CallObOpenObjectByPointerAddr, eax ;
         lea     eax, [eax+ecx+5];                    ; 相对转跳的位置
         cmp     eax, g_ObOpenObjectByPointer         ; 是否是ObOpenObjectByPointer的地址

         如果成功找到;detour后NtOpenProcess的实现就是:
         NTSTATUS NtOpenProcess(...)
         {
          ...
          call NewObOpenObjectByPointer();
          test eax, eax
          jz   Loc_exit;
          ...
         }

        
       (3)如果上述任何(1)/(2)步骤失败:
          (a)从ntoskrnel.exe文件中读取KeServiceDescriptorTable的service列表(服务的地址)

          (b)根据不同版本的os版本,获得NtReadVirtualMemory/NtWriteVirtualMemory的服务中断号

          (c)并分析出NtReadVirtualMemory/NtWriteVirtualMemory的地址([文件偏移->内存偏移]+ntoskrnel baseAddr)

           上述步骤成功;detour NtReadVirtualMemory/NtWriteVirtualMemorydetour后的实现就是:
           NTSTATUS NtReadVirtualMemory/NtWriteVirtualMemorydetour()
           {
            mov eax, NewFunAddr;
            jmp eax;
            .....
           }
         
   6)TSSetGDIHook()
      (1)查找KeServiceDescriptorTableShadow的地址(KeAddSystemServiceTable和KeServiceDescriptorTable匹配法)
         代码到处都有就不贴了
        (PS 方法一:GUI KTHREAD.ServiceTable; 方法二:上下空间内搜索-2k上xp下; 方法三:KeAddSystemServiceTable法)
         
      (2)根据TSInitINTNumber()获得要detour的GDI(win32k.sys中)函数地址
         (1) NtUserGetDCIndex
         (2) NtUserGetDCExIndex
         (3) NtUserBuildHwndListIndex
         (4) NtUserFindWindowExIndex
         (5) NtUserGetForegroundWindowIndex
         (6) NtUserWindowFromPointIndex
         (7) NtUserQueryWindow(此函数不detour,只为了在NewNtUserxxx中使用)

      (3)ssdt hook 上述GDI(win32k.sys中)函数

   7)附加一些保护和检查机制就不说了
     TSAntiWindbg()


二 Cheat Engine
   困了,明天再说~

 

摘自:  垃圾堆——windowssky

Trackback(0)
Comments (0)Add Comment

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

security code
Write the displayed characters


busy