Results 1 to 5 of 5
  1. #1
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky

    Post [CODE]VTable hooking

    Code:
    DWORD *hookVFunc(DWORD *vtable, int index, DWORD *newFunction)
    {
    	DWORD dwOldProt, *oldFunc;
    	VirtualProtect(&vtable[index], 4, PAGE_EXECUTE_READWRITE, &dwOldProt);
    	oldFunc=(DWORD*)vtable[index];
    	vtable[index]=(DWORD)newFunction;
    	VirtualProtect(&vtable[index], 4, dwOldProt, &dwOldProt);
    	return oldFunc;
    }
    A bit of a mess, but it works

    Example usage:
    Code:
    UINT (__stdcall *oGetAdapterCount)(void);
    UINT __stdcall xGetAdapterCount(void)
    {
    	MessageBox(0, L"hooked", L"hook", MB_OK);
    	return oGetAdapterCount();
    }
    
    int main()
    {
    	HANDLE hDll = LoadLibrary(L"d3d9.dll");
    	IDirect3D9 *pD9 = Direct3DCreate9(D3D_SDK_VERSION);
    	//the index of GetAdapterCount is 4
    	oGetAdapterCount = (UINT (__stdcall *)(void))hookVFunc(*(DWORD**)pD9, 4, (DWORD*)&xGetAdapterCount);
    	pD9->GetAdapterCount();
    	system("pause");
    	return 1;
    }
    Have fun?

    ~ Hell
    Ah we-a blaze the fyah, make it bun dem!

  2. #2
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Noice, VirtualProtect + pointers.
    Naws, gj HD, makes patching the vtable much cleaner.

    Btw, still no type definitions for those long casts? D:

    Code:
    oGetAdapterCount = (UINT (__stdcall *)(void))hookVFunc(*(DWORD**)pD9, 4, (DWORD*)&xGetAdapterCount);
    Luckily that function doesn't even take any arguments.

  3. #3
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    compile
    error: cannot cast from DWORD * to UINT (__stdcall *)(void)
    C&P the typecast
    compile
    success

    /victory.
    Ah we-a blaze the fyah, make it bun dem!

  4. #4
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    ^5[^9AU^5]^9Wesley: hookVFunc(0x40CE14, 40, (DWORD*)&yuorEndScene);
    Tweak: Yeah
    ^5[^9AU^5]^9Wesley: or *(DWORD*)0x40CE14, not sure
    ^5[^9AU^5]^9Wesley: it really cant be that hard lol
    Tweak: I believe it worked.
    Tweak: I injected, and nothing happened (no crash)
    Tweak: so
    ^5[^9AU^5]^9Wesley: k
    ^5[^9AU^5]^9Wesley: did u return orig function?
    Tweak: er
    ^5[^9AU^5]^9Wesley: shove a messagebox in there
    Tweak: In hookVFunc?
    Tweak: hmmm
    Tweak: nothing
    ^5[^9AU^5]^9Wesley: no
    ^5[^9AU^5]^9Wesley: in your hooked func >.>
    Tweak: owait
    Tweak: failme
    Tweak: I'm using it as a dll
    Tweak: and it has int main
    ^5[^9AU^5]^9Wesley: *facepalm*
    ^5[^9AU^5]^9Wesley: might wanna go read up on C++ basics
    Tweak: the code was copy pasted....
    Tweak: To see if it would work
    Ah we-a blaze the fyah, make it bun dem!

  5. The Following 3 Users Say Thank You to Hell_Demon For This Useful Post:

    'Bruno (10-31-2010),Melodia (10-31-2010),Void (10-31-2010)

  6. #5
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Quote Originally Posted by Hell_Demon View Post
    ^5[^9AU^5]^9Wesley: hookVFunc(0x40CE14, 40, (DWORD*)&yuorEndScene);
    Tweak: Yeah
    ^5[^9AU^5]^9Wesley: or *(DWORD*)0x40CE14, not sure
    ^5[^9AU^5]^9Wesley: it really cant be that hard lol
    Tweak: I believe it worked.
    Tweak: I injected, and nothing happened (no crash)
    Tweak: so
    ^5[^9AU^5]^9Wesley: k
    ^5[^9AU^5]^9Wesley: did u return orig function?
    Tweak: er
    ^5[^9AU^5]^9Wesley: shove a messagebox in there
    Tweak: In hookVFunc?
    Tweak: hmmm
    Tweak: nothing
    ^5[^9AU^5]^9Wesley: no
    ^5[^9AU^5]^9Wesley: in your hooked func >.>
    Tweak: owait
    Tweak: failme
    Tweak: I'm using it as a dll
    Tweak: and it has int main
    ^5[^9AU^5]^9Wesley: *facepalm*
    ^5[^9AU^5]^9Wesley: might wanna go read up on C++ basics
    Tweak: the code was copy pasted....
    Tweak: To see if it would work
    Wow... \:

    This is what happens when you try and help leechers.

Similar Threads

  1. [Tutorial] Vtable hooking/Vmt hooking
    By SirKinky in forum Alliance of Valiant Arms (AVA) Discussions
    Replies: 2
    Last Post: 12-13-2011, 03:31 PM
  2. [Release] Vtable hook source
    By nitega in forum All Points Bulletin Reloaded Hacks
    Replies: 26
    Last Post: 10-06-2011, 09:24 AM
  3. [Tutorial] -How to make .dll[Vtable Hook]-
    By gokhanw in forum All Points Bulletin Reloaded Hacks
    Replies: 16
    Last Post: 10-06-2011, 09:22 AM
  4. [Help] how the vtable hook works?
    By romencool in forum All Points Bulletin Reloaded Hacks
    Replies: 3
    Last Post: 09-30-2011, 03:01 PM
  5. [Source]Vtable Hook?
    By SoreBack in forum Combat Arms Hacks & Cheats
    Replies: 17
    Last Post: 01-29-2009, 11:46 AM