![]() |
DirectX 8 Hook
Peace alle zusammen. Ich probiere mich gerade erneut an einem DirectX 8 hook.
Zunächst eine Frage, welche ich glaube mir selbst beantworten zu können. Ich glaube, dass wenn ein spiel DirectX 8 benötigt, ich aber z.B. DirectX 10 installiert habe, logischerweise eigentlich DirectX 10 funktionen hooken muss oder? Falls dies nicht der Fall sein sollte, warum funktioniert diese Unit, welche ich geschrieben, und in meine DLL eingebunden habe, nicht?
Delphi-Quellcode:
Bislang starte ich das Spiel, und injiziere danach die DLL - das funktioniert, allerdings bekomme ich die Message nicht angezeigt. Liegt das nun daran, dass der Prozess schon gestartet und die funktion Direct3DCreate8 schon ausgeführt wurde?
unit d3d8hook;
interface uses Windows, uallHook; function HookDirect3D8 : boolean; implementation var newSetRenderState8: function(self: pointer; stateType, state: dword): dword; stdcall; newCreateDevice8 : function(self, adapter, devType, wnd, flags, params, device: pointer) : dword; stdcall; newDirect3DCreate8 : function(sdkVersion: dword) : dword; stdcall; function GetInterfaceMethod(const intf; methodIndex: dword) : pointer; begin result := pointer(pointer(dword(pointer(intf)^) + methodIndex * 4)^); end; function SetRenderState8Callback(self: pointer; stateType, state: dword) : dword; stdcall; begin end; function CreateDevice8Callback(self, adapter, devType, wnd, flags, params, device: pointer) : dword; stdcall; begin result := newCreateDevice8(self, adapter, devType, wnd, flags, params, device); if result = 0 then if @newSetRenderState8 = nil then HookCode(GetInterfaceMethod(device^, 50), @SetRenderState8Callback, @newSetRenderState8); end; function Direct3DCreate8Callback(sdkVersion: dword) : dword; stdcall; begin result := newDirect3DCreate8(sdkVersion); MessageBox(0, 'DEVICE CREATE 8', 'Hook', 0); if result <> 0 then if @newCreateDevice8 = nil then HookCode(GetInterfaceMethod(result, 15), @CreateDevice8Callback, @newCreateDevice8); end; function HookDirect3D8 : boolean; begin HookApiIAT('d3d8.dll', 'Direct3DCreate8', @Direct3DCreate8Callback,@newDirect3DCreate8); end; end. Liebe Grüße |
Re: DirectX 8 Hook
So habe wieder bissi weiter gesucht, und nun komme ich soweit, das mein Hook erfolgreich gesetzt wird - laut MessageBox
![]()
Delphi-Quellcode:
Also ich bekomme eine Message: "Direct3DCreate8 hooked", jedoch keine "callbackDirect3DCreate8". Woran könnte das liegen?
library d3dxhook;
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses Windows, SysUtils, BlueHookLib, BlueFileLog, Direct3D8, d3dx8; {$R *.res} type Direct3DCreate8 = function( D3D_SDK_VERSION: cardinal ): IDirect3D8; stdcall; var oldDirect3DCreate8 : Direct3DCreate8; newDirect3DCreate8 : Direct3DCreate8; pIDirect3D8 : IDirect3D8; function callbackDirect3DCreate8( D3D_SDK_VERSION: cardinal ): IDirect3D8; stdcall; begin Result := oldDirect3DCreate8(D3D_SDK_VERSION); MessageBox(0, 'callbackDirect3DCreate8', 'Information', MB_ICONINFORMATION); end; procedure DllMain(dwReason: DWord); var gHook : CDeepHook; gLog : CDeepLog; begin case dwReason of DLL_PROCESS_ATTACH: begin gHook := CDeepHook.Create(gLog); oldDirect3DCreate8 := GetProcAddress(GetModuleHandle('d3d8.dll'), 'Direct3DCreate8'); if not(gHook.HookJMP( @oldDirect3DCreate8, @callbackDirect3DCreate8, @newDirect3DCreate8)) then MessageBox(0, 'Direct3DCreate8 hooking failed', 'Information', MB_ICONINFORMATION); end; end; end; begin DllProc := @DllMain; DllMain(DLL_PROCESS_ATTACH); end. |
Re: DirectX 8 Hook
Sicher, dass das DX8 und nicht DX9 verwendet wird? Funktioniert die Hook Unit korrekt?
|
Re: DirectX 8 Hook
Ja sicher. Habe es mit der uAllCollection auch schon probiert.
Hook erfolgreich aber die Callbackfunktion wird nie aufgerufen. |
Re: DirectX 8 Hook
Vermutlich injizierst du die DLL nachdem die API schon aufgerufen wurde. Der normale Weg wäre, dass du den Zielprozess supendiert startest und dann direkt deine DLL injizierst.
|
Re: DirectX 8 Hook
|
Re: DirectX 8 Hook
Also das ganze ist so.
Ich injiziere eine DLL in die Anwendung die das Spiel startet. In der ersten DLL hooke ich CreateProcessW. Wenn dies Aufgerufen wird, ändere ich den Flag zu SUSPEND, injiziere die DLL in das Spiel und danach lasse ich den Thread weiter laufen. Das ganze sieht so aus.
Delphi-Quellcode:
Meine d3dxhook.dll sieht so aus:
function CallbackCreateProcess( lpApplicationName: PWideChar; lpCommandLine: PWideChar;
lpProcessAttributes, lpThreadAttributes: PSecurityAttributes; bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: Pointer; lpCurrentDirectory: PWideChar; const lpStartupInfo: TStartupInfoW; var lpProcessInformation: TProcessInformation): BOOL; stdcall; begin if (Pos('vertices',ExtractFileName(lpCommandLine)) > 0) then begin Result := newCreateProcess(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation); uAllHook.InjectLibrary(lpProcessInformation.dwProcessId, PChar(ExtractFilePath(GetModulePath) + 'd3dxhook.dll')); ResumeThread(lpProcessInformation.dwThreadId); end else Result := newCreateProcess(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation); end;
Delphi-Quellcode:
Direct3DCreate8 hooking failed bekomme ich als Message, danach startet das Game. Wenn ich nur das Spiele starte, und nicht das Programm nehme was dieses eigentlich starten soll wird der Hook gesetzt. Also ist wohl irgendwas bei dem erstellen des Prozesses schief gelaufen - aber was?
library d3dxhook;
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses Windows, SysUtils, Direct3D8, d3dx8, uAllHook; {$R *.res} type Direct3DCreate8 = function( D3D_SDK_VERSION: cardinal ): IDirect3D8; stdcall; var oldDirect3DCreate8 : Direct3DCreate8; newDirect3DCreate8 : Direct3DCreate8; pIDirect3D8 : IDirect3D8; function callbackDirect3DCreate8( D3D_SDK_VERSION: cardinal ): IDirect3D8; stdcall; begin Result := oldDirect3DCreate8(D3D_SDK_VERSION); MessageBox(0, 'callbackDirect3DCreate8', 'Information', MB_ICONINFORMATION); end; procedure DllMain(dwReason: DWord); begin case dwReason of DLL_PROCESS_ATTACH: begin oldDirect3DCreate8 := GetProcAddress(GetModuleHandle('d3d8.dll'), 'Direct3DCreate8'); if not(HookCode( @oldDirect3DCreate8, @callbackDirect3DCreate8, @newDirect3DCreate8)) then MessageBox(0, 'Direct3DCreate8 hooking failed', 'Information', MB_ICONINFORMATION); end; end; end; begin DllProc := @DllMain; DllMain(DLL_PROCESS_ATTACH); end. Es muss aber auch ohne dieses Suspend funktionieren. Xfire, und die BNet banlist, welche glaube ich von einem aus diesem Board entwickelt wurde, schaffen es beide, nachdem das Spiel gestartet ist, sich darein zu hooken. Den Thread habe ich mir schon zu Gemühte geführt aber C++ Kentnisse gehen gegen null. |
Re: DirectX 8 Hook
Code:
mache mal zu
oldDirect3DCreate8 := GetProcAddress(GetModuleHandle('d3d8.dll'), 'Direct3DCreate8');
if not(HookCode( @oldDirect3DCreate8, @callbackDirect3DCreate8, @newDirect3DCreate8)) then MessageBox(0, 'Direct3DCreate8 hooking failed', 'Information', MB_ICONINFORMATION);
Code:
und
oldDirect3DCreate8 := GetProcAddress(LoadLibrary('d3d8.dll'), 'Direct3DCreate8');
if not(HookCode( @oldDirect3DCreate8, @callbackDirect3DCreate8, @newDirect3DCreate8)) then MessageBox(0, 'Direct3DCreate8 hooking failed', 'Information', MB_ICONINFORMATION);
Code:
wird zu
function callbackDirect3DCreate8( D3D_SDK_VERSION: cardinal ): IDirect3D8; stdcall;
begin Result := oldDirect3DCreate8(D3D_SDK_VERSION); MessageBox(0, 'callbackDirect3DCreate8', 'Information', MB_ICONINFORMATION); end;
Code:
function callbackDirect3DCreate8( D3D_SDK_VERSION: cardinal ): IDirect3D8; stdcall;
begin Result := newDirect3DCreate8(D3D_SDK_VERSION); MessageBox(0, 'callbackDirect3DCreate8', 'Information', MB_ICONINFORMATION); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:35 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz