Results 1 to 5 of 5
  1. #1
    Departure's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    818
    Reputation
    125
    Thanks
    1,785
    My Mood
    Doh

    [Snippet] Dynamically Get VTable

    I was reading a topic here http://www.mpgh.net/forum/31-c-c-pro...-logger-4.html Which makes a good point that not everybody has the same d3d9.dll version which means you can't use a static address for hooking if you want your hack to work for all version, Stephen made a very good example of searching the vTable by using a Wild card search, for an address which has a pointer to the vTable. Anyway to cut a long story short here is my Delphi version based from his idea.

    [highlight=delphi]
    function GetD3d9Vtable(dwIndex: DWord): Cardinal;
    var
    pD3D9 : PByte;
    pVtable : ^DWord;
    cAddress: Cardinal;
    const
    //Pattern Used To scan for bytes
    baVtablePattern: array[0..15] of Byte = ($33,$C0,$C7,$06,$00,$00,$00,$00,$89,$86,$00,$00,$ 00,$00,$89,$86);
    //Mask used in WildCard $01 notes Wild cards
    baVtableMask : array[0..15] of Byte = ($00,$00,$00,$00,$01,$01,$01,$01,$00,$00,$01,$01,$ 01,$01,$00,$00);
    begin
    //Get Base Adress of D3D9.dll
    pD3D9:= PByte(GetModuleHandleA('d3d9.dll'));
    //Wild Card Search For Pointer To VTable Address
    cAddress:= WildCardSearch(pD3D9,@baVtablePattern,@baVtableMas k,SizeOf(baVtablePattern),128000,False);
    //If results Returned an Adress
    if cAddress > 0 then
    begin
    //Add 4 bytes to land on real Vtable pointer address
    cAddress:= cAddress + $4;
    //Get Vtable Index Pointer
    pVtable:= Pointer(Dword(Ptr(cAddress)^) + dwIndex * 4);
    //Return as Cardinal Index position pointer
    Result := pVtable^
    end
    else
    Result:= 0;
    end;
    [/highlight]

    How to use...
    [highlight=delphi]
    var
    dwPresent: Cardinal;
    begin
    //Checking to see if game is ready, this includes to see if d3d9.dll is loaded into memory
    Repeat
    Sleep(500);
    Until ((IsGameReadyForHook = True) and (dwThrdMain = 0));

    //Call our function to get Pointer address for hooking(Index 17 = Present)
    dwPresent:= GetD3d9Vtable(17);

    //Example hook replace "&" with "@" otherwise forum takes it a mention
    if (HookJMP(Pointer(dwPresent) , &PresentCallBack, &PresentNext)) then
    ...
    ...
    ...
    [/highlight]

    As some people know I spent a few hours wondering why my PTC method wasn't working, Its because I had a static address from debugging D3D9.dll in olly, Little did I know my D3D9.dll was updated between my last hack and this one, Hence the reason this function was created to find it dynamically. Hope it might help someone who has ran into the same problem.
    Last edited by Departure; 04-19-2011 at 04:47 AM. Reason: Updated into one function, and example use

  2. #2
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    DELPHI!!!!!!!!!!!!!!!!!!/

    it is so complex, but i understand
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  3. #3
    Departure's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    818
    Reputation
    125
    Thanks
    1,785
    My Mood
    Doh
    Delphi is not complex, Its just well structured which means it is prone for errors if using lazy coding, Lucky C++'ers can code in a lazy style and still get away with it. Saying that its easy to tell who takes care in there C++ projects by there coding style, The lazy coders make it difficult to read while other "Clean" coders make reading C++ easy for me.

  4. #4
    flameswor10's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    12,528
    Reputation
    981
    Thanks
    10,404
    My Mood
    In Love
    Quote Originally Posted by Departure View Post
    Delphi is not complex, Its just well structured which means it is prone for errors if using lazy coding, Lucky C++'ers can code in a lazy style and still get away with it. Saying that its easy to tell who takes care in there C++ projects by there coding style, The lazy coders make it difficult to read while other "Clean" coders make reading C++ easy for me.
    I code very messily
    No I do not make game hacks anymore, please stop asking.


    Been MPGH Minion: 6 July 2011 - 1 August 2012

  5. #5
    Departure's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    818
    Reputation
    125
    Thanks
    1,785
    My Mood
    Doh
    I don't I have ever seen your code flameswor10.

    Updated first post to make into one function and example how you would use it.