AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

DirectX 8 Hook

Ein Thema von napsterxx · begonnen am 22. Aug 2009 · letzter Beitrag vom 23. Aug 2009
Antwort Antwort
napsterxx

Registriert seit: 18. Mär 2007
Ort: Borland
556 Beiträge
 
Delphi 7 Enterprise
 
#1

DirectX 8 Hook

  Alt 22. Aug 2009, 18:13
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:
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.
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?

Liebe Grüße
Du derefernzierst p2 einmal und weißt die Adresse von i zu. Das heißt p2 (also der Zeiger auf einen Zeiger) zeigt auf den Zeiger p1 welchen du so auf i zeigen lässt.
  Mit Zitat antworten Zitat
napsterxx

Registriert seit: 18. Mär 2007
Ort: Borland
556 Beiträge
 
Delphi 7 Enterprise
 
#2

Re: DirectX 8 Hook

  Alt 23. Aug 2009, 10:23
So habe wieder bissi weiter gesucht, und nun komme ich soweit, das mein Hook erfolgreich gesetzt wird - laut MessageBox
BlueHookLib.pas
Delphi-Quellcode:
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.
Also ich bekomme eine Message: "Direct3DCreate8 hooked", jedoch keine "callbackDirect3DCreate8". Woran könnte das liegen?
Du derefernzierst p2 einmal und weißt die Adresse von i zu. Das heißt p2 (also der Zeiger auf einen Zeiger) zeigt auf den Zeiger p1 welchen du so auf i zeigen lässt.
  Mit Zitat antworten Zitat
Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#3

Re: DirectX 8 Hook

  Alt 23. Aug 2009, 12:14
Sicher, dass das DX8 und nicht DX9 verwendet wird? Funktioniert die Hook Unit korrekt?
  Mit Zitat antworten Zitat
napsterxx

Registriert seit: 18. Mär 2007
Ort: Borland
556 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: DirectX 8 Hook

  Alt 23. Aug 2009, 12:30
Ja sicher. Habe es mit der uAllCollection auch schon probiert.
Hook erfolgreich aber die Callbackfunktion wird nie aufgerufen.
Du derefernzierst p2 einmal und weißt die Adresse von i zu. Das heißt p2 (also der Zeiger auf einen Zeiger) zeigt auf den Zeiger p1 welchen du so auf i zeigen lässt.
  Mit Zitat antworten Zitat
Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#5

Re: DirectX 8 Hook

  Alt 23. Aug 2009, 13:04
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.
  Mit Zitat antworten Zitat
Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#6

Re: DirectX 8 Hook

  Alt 23. Aug 2009, 13:34
Du kannst dir auch das mal zu geühte führen (www.gamedev.net)
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat
napsterxx

Registriert seit: 18. Mär 2007
Ort: Borland
556 Beiträge
 
Delphi 7 Enterprise
 
#7

Re: DirectX 8 Hook

  Alt 23. Aug 2009, 13:53
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:
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;
Meine d3dxhook.dll sieht so aus:
Delphi-Quellcode:
 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.
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?

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.
Du derefernzierst p2 einmal und weißt die Adresse von i zu. Das heißt p2 (also der Zeiger auf einen Zeiger) zeigt auf den Zeiger p1 welchen du so auf i zeigen lässt.
  Mit Zitat antworten Zitat
Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#8

Re: DirectX 8 Hook

  Alt 23. Aug 2009, 15:45
Code:
oldDirect3DCreate8 := GetProcAddress(GetModuleHandle('d3d8.dll'), 'Direct3DCreate8');
      if not(HookCode( @oldDirect3DCreate8, @callbackDirect3DCreate8, @newDirect3DCreate8)) then
        MessageBox(0, 'Direct3DCreate8 hooking failed', 'Information', MB_ICONINFORMATION);
mache mal zu

Code:
oldDirect3DCreate8 := GetProcAddress(LoadLibrary('d3d8.dll'), 'Direct3DCreate8');
      if not(HookCode( @oldDirect3DCreate8, @callbackDirect3DCreate8, @newDirect3DCreate8)) then
        MessageBox(0, 'Direct3DCreate8 hooking failed', 'Information', MB_ICONINFORMATION);
und

Code:
function callbackDirect3DCreate8( D3D_SDK_VERSION: cardinal ): IDirect3D8; stdcall;
begin
  Result := oldDirect3DCreate8(D3D_SDK_VERSION);
  MessageBox(0, 'callbackDirect3DCreate8', 'Information', MB_ICONINFORMATION);
end;
wird zu

Code:
function callbackDirect3DCreate8( D3D_SDK_VERSION: cardinal ): IDirect3D8; stdcall;
begin
  Result := newDirect3DCreate8(D3D_SDK_VERSION);
  MessageBox(0, 'callbackDirect3DCreate8', 'Information', MB_ICONINFORMATION);
end;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:06 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz