首页
社区
课程
招聘
未解决 [求助]十万为什么 之 HOOK D3D9 谁来救救孩子
发表于: 2019-4-14 17:23 2292

未解决 [求助]十万为什么 之 HOOK D3D9 谁来救救孩子

2019-4-14 17:23
2292
前面制作了hook messagebox  知道了hook的大概流程 想尝试一下hookd3d9~~可是发现没有成功
dll注入了cs1.6  使用Dbgview监视  理想应该是打印OutputDebugStringA("OK\r\n"); ok没有出来!!

// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <d3d9.h>
#include <D3dx9core.h>
#include <d3dx9math.h>
#pragma comment(lib, "D3D9.lib")
#pragma comment(lib, "D3Dx9.lib") 


ULONG_PTR onHookInit();
bool hookDrawIndexedPrimitive();
DWORD oldProtect;
DWORD jmp = NULL;

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
	hookDrawIndexedPrimitive();
    return TRUE;
}
//定义原函数
HRESULT WINAPI or_DrawIndexedPrimitive(
	LPDIRECT3DDEVICE9 m_Device,
	D3DPRIMITIVETYPE type ,
	INT BaseVertexIndex,
	UINT MinIndex,
	UINT NumVertices,
	UINT StartIndex,
	UINT PrimitiveCount
) {
	_asm {
				mov edi,edi
				push ebp
				mov ebp,esp
				mov eax,jmp
				jmp eax

			}
};

//定义自己的函数
HRESULT WINAPI My_DrawIndexedPrimitive(
	LPDIRECT3DDEVICE9 m_Device,
	D3DPRIMITIVETYPE type,
	INT BaseVertexIndex,
	UINT MinIndex,
	UINT NumVertices,
	UINT StartIndex,
	UINT PrimitiveCount
)
{
	OutputDebugStringA("OK\r\n");
	return or_DrawIndexedPrimitive(m_Device, type,BaseVertexIndex,MinIndex, NumVertices,StartIndex,PrimitiveCount);

};

//获取模块地址 原函数地址
ULONG_PTR onHookInit()
{
	ULONG_PTR addr = 0;
	HMODULE hModule = LoadLibraryA("D3D9.dll");
	addr = (ULONG_PTR) GetProcAddress(hModule, "Direct3DCreate9");
	return addr;
	
}

//开始hook
bool hookDrawIndexedPrimitive()
{
	ULONG_PTR addr = onHookInit();
	jmp = addr + 5;
	if (addr == 0)
	{
		MessageBoxA(NULL, "error", NULL, 0);
	}
	if (VirtualProtect((LPVOID)addr, 5, PAGE_EXECUTE_READWRITE, &oldProtect))
	{		
		DWORD value = (DWORD)My_DrawIndexedPrimitive - addr - 5;
		_asm {

			mov eax, addr
			mov byte ptr[eax], 0x9
			add  eax, 1
			mov ebx,value
			mov dword ptr[eax], ebx
				}
		VirtualProtect((LPVOID)addr, 5, oldProtect, &oldProtect);
	}

}


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2019-4-14 17:28 被叽叽‘and1=1编辑 ,原因:
收藏
免费 0
支持
分享
最新回复 (11)
雪    币: 2055
活跃值: (486)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
2
_asm {
 
            mov eax, addr
            mov byte ptr[eax], 0x9      -------------------------------------->>          这里应该是0xE9
            add  eax, 1
            mov ebx,value ------------------------->如果value这个值计算正确的话就HOOK成功了
            mov dword ptr[eax], ebx
       }

or_DrawIndexedPrimitive 这个函数你应该定义成裸函数

hook失败的时候自己用CE  OD 之类的去看看汇编代码 一秒破案
最后于 2019-4-14 17:43 被不吃麻婆豆腐编辑 ,原因:
2019-4-14 17:40
0
雪    币: 203
活跃值: (912)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
3
CS1.6  D3D是低版本的 没有Direct3DCreate9 接口 而且 建议Hook Opengl 或引擎
2019-4-14 18:43
0
雪    币: 553
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
老哥,新手求救赎,帮我看看我的求助帖子呗,为啥我的hook不生效啊
https://bbs.pediy.com/thread-250776.htm
2019-4-14 18:52
0
雪    币: 12848
活跃值: (9108)
能力值: ( LV9,RANK:280 )
在线值:
发帖
回帖
粉丝
5
cs1.6的视频模式=OpenGL 使用opengl32.dll
视频模式=D3D 使用d3d7.dll
你hook d3d9 想啥呢?
2019-4-14 20:05
0
雪    币: 446
活跃值: (595)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6

最后于 2019-4-14 20:17 被叽叽‘and1=1编辑 ,原因:
2019-4-14 20:11
0
雪    币: 446
活跃值: (595)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7

最后于 2019-4-14 20:15 被叽叽‘and1=1编辑 ,原因:
2019-4-14 20:12
0
雪    币: 446
活跃值: (595)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
hzqst cs1.6的视频模式=OpenGL 使用opengl32.dll 视频模式=D3D 使用d3d7.dll 你hook d3d9 想啥呢?
我看它加载了 d3d9。。。。。
2019-4-14 20:14
0
雪    币: 446
活跃值: (595)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
不吃麻婆豆腐 _asm&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& ...
0x9  真没注意到!!!!
2019-4-14 20:15
0
雪    币: 446
活跃值: (595)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
SakuraCode CS1.6 D3D是低版本的 没有Direct3DCreate9 接口 而且 建议Hook Opengl 或引擎

2019-4-14 20:16
0
雪    币: 446
活跃值: (595)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
murundong 老哥,新手求救赎,帮我看看我的求助帖子呗,为啥我的hook不生效啊 https://bbs.pediy.com/thread-250776.htm [em_9][em_9][em_9][em_9]
我也没用过你这函数hook  (我也菜鸟
2019-4-14 20:17
0
雪    币: 553
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
wx_讚 我也没用过你这函数hook&nbsp;&nbsp;(我也菜鸟)
好吧,感觉脑壳痛
2019-4-14 21:01
0
游客
登录 | 注册 方可回帖
返回
//