首页
社区
课程
招聘
[原创][原创]D3D HOOK 游戏透视实现
发表于: 2014-11-16 00:24 35344

[原创][原创]D3D HOOK 游戏透视实现

2014-11-16 00:24
35344
大家好 今天带来的是D3D HOOK 游戏透视实现
我是小叮当  编译 自己 下载 DX SDK 
#include <windows.h>

#include <d3d9.h>
#pragma comment(lib, "d3d9.lib")

#include <d3dx9.h>
#pragma comment(lib, "d3dx9.lib")
#include <time.h>
#include <stdlib.h>
#include <fstream>
#include <vector>    
#include <D3dx9tex.h>
#include <stdio.h> 
#include <time.h>
#include <tchar.h>
#include <iostream>
#pragma warning(disable:4996)//VC++ 2008
//-----------//
bool fCall = true;
bool Chams = false;
bool zhunxin = false;
bool bMenu = false;
int menux= 10;
int menuy= 15;

IDirect3DPixelShader9 *Front,
                      *Back;
//----------//

void DrawFont (int X, int Y, D3DCOLOR Color, char *format, ...)
{
  char buffer[256];
  va_list args; 
  va_start (args, format);
  vsprintf (buffer,format, args);
  RECT FontRect = { X, Y, X + 120, Y + 90 };//原始大小 16
  va_end (args);
}

HRESULT CreateMyShader(IDirect3DPixelShader9 **pShader, IDirect3DDevice9 *Device, float red, float green, float blue, float alpha )
{
    ID3DXBuffer *MyBuffer = NULL;
    char MyShader[ 256 ];
    sprintf( MyShader, "ps.1.1\ndef c0, %f, %f, %f, %f\nmov r0,c0", red/255, green/255, blue/255, alpha/255 );
    D3DXAssembleShader( MyShader, sizeof( MyShader ), NULL, NULL, 0, &MyBuffer , NULL );
    if( FAILED( Device->CreatePixelShader((const DWORD*)MyBuffer ->GetBufferPointer(), pShader)) )return E_FAIL;
    return S_OK;
}

//=====================================================================================

typedef HRESULT (WINAPI* CreateDevice_Prototype)        (LPDIRECT3D9, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE9*);
typedef HRESULT (WINAPI* Reset_Prototype)               (LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
typedef HRESULT (WINAPI* EndScene_Prototype)            (LPDIRECT3DDEVICE9);
typedef HRESULT (WINAPI* DrawIndexedPrimitive_Prototype)(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);
//typedef HRESULT ( WINAPI * tDrawIndexedPrimitive )( IDirect3DDevice9 * pDevice, D3DPRIMITIVETYPE dType, INT nBaseIndex, UINT uiMinIndex, UINT uiNumVerts, UINT uiStartIndex, UINT uiPrimCount );

CreateDevice_Prototype         CreateDevice_Pointer         = NULL;
Reset_Prototype                Reset_Pointer                = NULL;
EndScene_Prototype             EndScene_Pointer             = NULL;
DrawIndexedPrimitive_Prototype DrawIndexedPrimitive_Pointer = NULL;
//tDrawIndexedPrimitive oDrawIndexedPrimitive;

HRESULT WINAPI Direct3DCreate9_VMTable    (VOID);
HRESULT WINAPI CreateDevice_Detour        (LPDIRECT3D9, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS*, LPDIRECT3DDEVICE9*);
HRESULT WINAPI Reset_Detour               (LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*);
HRESULT WINAPI EndScene_Detour            (LPDIRECT3DDEVICE9);
HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);

DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatching(LPVOID);
PDWORD Direct3D_VMTable = NULL;

//=====================================================================================

BOOL WINAPI DllMain(HINSTANCE hinstModule, DWORD dwReason, LPVOID lpvReserved)
{
  if(dwReason == DLL_PROCESS_ATTACH)
  {
    DisableThreadLibraryCalls(hinstModule);

    if(Direct3DCreate9_VMTable() == D3D_OK)
    return TRUE;
  }

  return FALSE;
}

//=====================================================================================

HRESULT WINAPI Direct3DCreate9_VMTable(VOID)
{
  LPDIRECT3D9 Direct3D_Object = Direct3DCreate9(D3D_SDK_VERSION);

  if(Direct3D_Object == NULL)
  return D3DERR_INVALIDCALL;
  
  Direct3D_VMTable = (PDWORD)*(PDWORD)Direct3D_Object;
  Direct3D_Object->Release();

  DWORD dwProtect;

  if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
  {
    *(PDWORD)&CreateDevice_Pointer = Direct3D_VMTable[16];
    *(PDWORD)&Direct3D_VMTable[16] = (DWORD)CreateDevice_Detour;
    if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), dwProtect, &dwProtect) == 0)
    return D3DERR_INVALIDCALL;
  }
  else
  return D3DERR_INVALIDCALL;

  return D3D_OK;
}

//=====================================================================================

HRESULT WINAPI CreateDevice_Detour(LPDIRECT3D9 Direct3D_Object, UINT Adapter, D3DDEVTYPE DeviceType, HWND FocusWindow, 
                    DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* PresentationParameters, 
                    LPDIRECT3DDEVICE9* Returned_Device_Interface)
{
  HRESULT Returned_Result = CreateDevice_Pointer(Direct3D_Object, Adapter, DeviceType, FocusWindow, BehaviorFlags, 
                                              PresentationParameters, Returned_Device_Interface);
   
  DWORD dwProtect;

  if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), PAGE_READWRITE, &dwProtect) != 0)
  {
    *(PDWORD)&Direct3D_VMTable[16] = *(PDWORD)&CreateDevice_Pointer;
    CreateDevice_Pointer           = NULL;

    if(VirtualProtect(&Direct3D_VMTable[16], sizeof(DWORD), dwProtect, &dwProtect) == 0)
    return D3DERR_INVALIDCALL;
  }
  else
  return D3DERR_INVALIDCALL;

  if(Returned_Result == D3D_OK)
  {
    Direct3D_VMTable = (PDWORD)*(PDWORD)*Returned_Device_Interface;

    *(PDWORD)&Reset_Pointer                = (DWORD)Direct3D_VMTable[16];
    *(PDWORD)&EndScene_Pointer             = (DWORD)Direct3D_VMTable[42];
    *(PDWORD)&DrawIndexedPrimitive_Pointer = (DWORD)Direct3D_VMTable[82];

    if(CreateThread(NULL, 0, VirtualMethodTableRepatchingLoopToCounterExtensionRepatching, NULL, 0, NULL) == NULL)
    return D3DERR_INVALIDCALL;
  }
    
  return Returned_Result;
}

//=====================================================================================

HRESULT WINAPI Reset_Detour(LPDIRECT3DDEVICE9 Device_Interface, D3DPRESENT_PARAMETERS* PresentationParameters)
{
  return Reset_Pointer(Device_Interface, PresentationParameters);
}

//=====================================================================================

HRESULT WINAPI EndScene_Detour(LPDIRECT3DDEVICE9 Device_Interface)
{
  return EndScene_Pointer(Device_Interface);
}

//=====================================================================================

HRESULT WINAPI DrawIndexedPrimitive_Detour(LPDIRECT3DDEVICE9 Device_Interface, D3DPRIMITIVETYPE Type, INT BaseIndex, 
                                           UINT MinIndex, UINT NumVertices, UINT StartIndex, UINT PrimitiveCount)
{
  LPDIRECT3DVERTEXBUFFER9 Stream_Data;
  UINT Offset = 0;
  UINT Stride = 0;

  if(Device_Interface->GetStreamSource(0, &Stream_Data, &Offset, &Stride) == D3D_OK)
  Stream_Data->Release();
//函数 fCall 上色
  if(fCall)
  {
  CreateMyShader( &Front, Device_Interface,    0,   255,   0,   0 );//武器颜色渲染= 
  CreateMyShader( &Back,  Device_Interface,    255,   255,   0,   0 );//人物透视渲染=
  DrawFont( menux+1,menuy+1, D3DCOLOR_ARGB(255,255,215,0), "小叮当 透视");
  fCall = false;
  }
//-------------结束

//准心
if( GetAsyncKeyState( VK_NUMPAD2 ) & 2 ) //END 热键 1默认显示
  {

    zhunxin = !zhunxin;
  }
    if( zhunxin )
  {
    D3DVIEWPORT9 viewP;
    Device_Interface->GetViewport( &viewP );
    DWORD ScreenCenterX = viewP.Width / 2; 
    DWORD ScreenCenterY = viewP.Height / 2; 
    D3DRECT rec16 = {ScreenCenterX-5, ScreenCenterY, ScreenCenterX+ 5, ScreenCenterY+1};
    D3DRECT rec17 = {ScreenCenterX, ScreenCenterY-5, ScreenCenterX+ 1,ScreenCenterY+5};  
    Device_Interface->Clear( 1, &rec16, D3DCLEAR_TARGET, D3DXCOLOR(0, 255, 0, 0), 0,  0 );//red
    Device_Interface->Clear( 1, &rec17, D3DCLEAR_TARGET, D3DXCOLOR(255, 255, 0, 0), 0,  0 );
    
  }

//if( GetAsyncKeyState( VK_END ) & 1 ) //END 热键 1默认显示
//  {

//    bMenu = !bMenu;
//  }
//  if( bMenu )
// {
//  DrawFont( menux+10,menuy+5, D3DCOLOR_ARGB(255,0,255,255), "s文字 文字 文字");
//}

  if ( GetAsyncKeyState ( VK_NUMPAD1 ) &1 )
    {
         Chams = !Chams;
    }  

  if(Chams && (Stride == 32 && StartIndex == 0))
  {
        DWORD dwOldZEnable = D3DZB_TRUE; 
    Device_Interface->SetRenderState(D3DRS_ZENABLE,false); //1
    Device_Interface->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);//2   
    Device_Interface->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
        Device_Interface->GetRenderState(D3DRS_ZENABLE, &dwOldZEnable); 
        Device_Interface->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
        Device_Interface->SetPixelShader( Front );

        DrawIndexedPrimitive_Pointer(Device_Interface, Type, BaseIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
        Device_Interface->SetRenderState(D3DRS_ZENABLE, dwOldZEnable);
        Device_Interface->SetPixelShader( Back );
  }
//-------------结束
  return DrawIndexedPrimitive_Pointer(Device_Interface, Type, BaseIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount);
}

//=====================================================================================

DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatching(LPVOID Param)
{
  UNREFERENCED_PARAMETER(Param); 

  while(1)
  {
    Sleep(100);

    *(PDWORD)&Direct3D_VMTable[42] = (DWORD)EndScene_Detour;
    *(PDWORD)&Direct3D_VMTable[82] = (DWORD)DrawIndexedPrimitive_Detour;
    *(PDWORD)&Direct3D_VMTable[16] = (DWORD)Reset_Detour;
  }

  return 1;
}

//=====================================================================================

[课程]Linux pwn 探索篇!

收藏
免费 3
支持
分享
最新回复 (25)
雪    币: 90
活跃值: (60)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
2
自己顶一下!!
2014-11-16 00:25
0
雪    币: 7068
活跃值: (3517)
能力值: ( LV12,RANK:340 )
在线值:
发帖
回帖
粉丝
3
什么都不说,就一堆代码,连这玩意是哪个游戏的都不知道...
2014-11-16 00:29
0
雪    币: 292
活跃值: (153)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
4
针对Direct3D的游戏的,只要用了Direct3D这个接口,就Hook了, 不管什么游戏。

“if (Returned_Result == D3D_OK)”

作者的意思是。。。保护自己过。。。
2014-11-16 00:43
0
雪    币: 85
活跃值: (51)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
5
感谢分享,虽然不知道价值在哪里
2014-11-16 03:13
0
雪    币: 131
活跃值: (70)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
记得CS可以选择OpenGL的?
2014-11-16 08:30
0
雪    币: 90
活跃值: (60)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
7
被你发现了都
2014-11-16 10:01
0
雪    币: 90
活跃值: (60)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
8
适合UE3的任何游戏
2014-11-16 10:02
0
雪    币: 90
活跃值: (60)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
9
好失望,帖子居然没有加精什么的
2014-11-16 22:04
0
雪    币: 23
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
感觉看雪更注重引导型的理论教学帖子,纯技术性的东西,不怎么吸引人,呵呵
2014-11-16 22:44
0
雪    币: 4873
活跃值: (3112)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
想问下你这个代码的看点在哪。
2014-11-19 12:48
0
雪    币: 485
活跃值: (78)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
12
你这代码论坛搜就很多,为啥加精????又不是你自己第一个研究发出来的
2014-11-21 11:24
0
雪    币: 62
活跃值: (946)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
13
我觉得起码得有优秀~
2014-11-21 11:37
0
雪    币: 36
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
14
支持你呀
2014-11-21 14:16
0
雪    币: 26
活跃值: (56)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
15
看雪 现在是 纯代码贴 不加精 纯产品贴不加精

代码 +详细讲解+成品 必加精哦!!!
2014-11-24 17:39
0
雪    币: 376
活跃值: (92)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
16
这样一堆代码解释很少,新人基本看不懂,要加点说明才好
2014-11-24 18:04
0
雪    币: 229
活跃值: (94)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
17
mark学习
2014-11-24 21:28
0
雪    币: 109
活跃值: (151)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
18
测试代码可用,嘿嘿,谢谢了。
2014-11-27 16:07
0
雪    币: 293
活跃值: (239)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
19
支持一下
2014-12-1 22:57
0
雪    币: 77
活跃值: (70)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
20
http://www.baidu.com/s?wd=*(PDWORD)%26Reset_Pointer%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%20(DWORD)Direct3D_VMTable%5B16%5D%3B&ie=utf-8
原创?
2014-12-30 22:16
0
雪    币: 5
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
21
这没用   直接用开源的虚幻三引擎核心代码   去获取游戏信息    然后修改游戏信息    这段代码是微凉根据国外unknowncheats网站修改的    微凉第一次发布时2013年   2014年11月修改的这段代码   并没有放出真正实用的虚幻三引擎核心代码调用部分
2015-3-22 22:22
0
雪    币: 163
活跃值: (45)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
22
Mark
2015-3-24 20:38
0
雪    币: 21
活跃值: (18)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
23
这代码好多年前就见过了,话说这技术不是烂大街了吗
2015-3-26 10:07
0
雪    币: 238
活跃值: (196)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
24
谢谢楼主,好东西!
2015-3-26 23:59
0
雪    币: 6
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
25
不管怎么样 代码支持一下.
2015-4-6 13:22
0
游客
登录 | 注册 方可回帖
返回
//