Go Back   UnKnoWnCheaTs - Multiplayer Game Hacks and Cheats > Anti-Cheat Software & Programming > Direct3D

- Sponsored Advertisement -
http://www.myfpscheats.com/

Welcome to the UnKnoWnCheaTs - Multiplayer Game Hacks and Cheats.
You have to register before you can post and see and access any of the advanced forum features, please click the register link to proceed to the registration form. To start viewing threads or posts, select a forum that you want to visit from the selection below.
Direct3D
hacking programming reversing
You are Unregistered, please register to gain Full access.    
Reply
 
Thread Tools

D3D9 vTable doesnt work =(
Old 05-31-2010, 04:38 PM   #1
Junior Member

MurxXxel's Avatar

Join Date: Jan 2010
Posts: 46
Reputation: 581
Rep Power: 30
MurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wall
Points: 1,892, Level: 3
Points: 1,892, Level: 3 Points: 1,892, Level: 3 Points: 1,892, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
D3D9 vTable doesnt work =(

Hey Guys^^,

I wanted to make a chams hack for d3d9, so i searched in the web and found much tutorials about this stuff.
Firstly i wanted to hook all the functions without vTable but everybody says try it with its better....
So i decided to do this with help (web,tutorials...) but im stucking here because only Endscene and Beginscene is hooked here and i dont know why :S

So please help a noob and make him happy =)

Thanks to all who are trying to help me^^

PS: and maybe u can help me with explaining it what i made wrong ()=)

PHP Code:
#include <windows.h>
//----------------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------------------------------------
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
//-----------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
//-----------------------------------------------------------------------------------------------------------------------------------
#include <fstream>
//-----------------------------------------------------------------------------------------------------------------------------------
#include "detours.h"
#pragma comment(lib,"detours.lib")
//-----------------------------------------------------------------------------------------------------------------------------------
#include <d3d9.h>
#include <d3dx9.h>
#include <vector>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
//-----------------------------------------------------------------------------------------------------------------------------------
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------
#define HOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)hk##func) //Quick Hook using MS Detour
#define UNHOOK(func,addy) o##func = (t##func)DetourFunction((PBYTE)addy,(PBYTE)o##func) //Quick Unook using MS Detour
//---------------------------------------------------------------------------------------------------------------------------------
#define ES  0 //EndScene
#define DIP 1 //DrawIndexedPrimitive
#define RES 2 //Reset
#define BS    3 //Beginscene
#define DP    4 //DrawPrimitive
#define SSS 5 //SetStreamSource


//---------------------------------------------------------------------------------------------------------------------------------
LPDIRECT3DDEVICE9 npDevice//pDevice is stored here so we can hook through the VTable
//---------------------------------------------------------------------------------------------------------------------------------
UINT myStride 0;
//---------------------------------------------------------------------------------------------------------------------------------
ofstream myfile//Used for logging to a text file
//---------------------------------------------------------------------------------------------------------------------------------


typedef HRESULT (WINAPItEndScene)(LPDIRECT3DDEVICE9 pDevice);
tEndScene oEndScene NULL;

typedef HRESULT (WINAPItDrawIndexedPrimitive)(LPDIRECT3DDEVICE9 pDeviceD3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
tDrawIndexedPrimitive oDrawIndexedPrimitive NULL;

typedef HRESULT(WINAPIBeginScene_)(LPDIRECT3DDEVICE9 pDevice);
BeginScene_ oBeginScene;

typedef HRESULT(WINAPItReset)(LPDIRECT3DDEVICE9 pDeviceD3DPRESENT_PARAMETERSpPresentationParameters);
tReset oReset NULL;

typedef HRESULT (WINAPItSetStreamSource)(LPDIRECT3DDEVICE9 pDevice,UINT StreamNumber,IDirect3DVertexBuffer9pStreamData,UINT OffsetInBytes,UINT Stride);
tSetStreamSource oSetStreamSource;
//---------------------------------------------------------------------------------------------------------------------------------
PBYTE HookVTableFunctionPDWORDdwVTablePBYTE dwHookINT Index )
{
    
DWORD dwOld 0;
    
VirtualProtect((void*)((*dwVTable) + (Index*4) ), 4PAGE_EXECUTE_READWRITE, &dwOld);

    
PBYTE pOrig = ((PBYTE)(*dwVTable)[Index]);
    (*
dwVTable)[Index] = (DWORD)dwHook;

    
VirtualProtect((void*)((*dwVTable) + (Index*4)), 4dwOld, &dwOld);

    return 
pOrig;
}

 
//-----------------------------------------------------------------------------------------------------------------------------------
HRESULT WINAPI hkEndScene(LPDIRECT3DDEVICE9 pDevice)
{
    
myfile << "EndScene is hooked\n";             //Check log
    
while(!npDevice) {
        
npDevice pDevice;                       //Here we store pDevice so we can re-hook with a VTable hook later.
    
}

    return 
oEndScene(pDevice);
}
//---------------------------------------------------------------------------------------------------------------------------------
HRESULT WINAPI hkBeginScene(LPDIRECT3DDEVICE9 pDevice)
{
    
myfile << "BeginScene is hooked\n";             //Check log
    
return oBeginScene(pDevice);
}
//---------------------------------------------------------------------------------------------------------------------------------
LPDIRECT3DTEXTURE9 texRed;
LPDIRECT3DTEXTURE9 texGreen;

HRESULT WINAPI hkDrawIndexedPrimitive(LPDIRECT3DDEVICE9 pDeviceD3DPRIMITIVETYPE PrimType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
{

    
myfile << "DrawIndexPrimitive is hooked\n";             //Check log
    
return oDrawIndexedPrimitive(pDevicePrimTypeBaseVertexIndexMinVertexIndexNumVerticesstartIndexprimCount);
}

//---------------------------------------------------------------------------------------------------------------------------------
HRESULT WINAPI hkReset(LPDIRECT3DDEVICE9 pDeviceD3DPRESENT_PARAMETERSpPresentationParameters)
{
    
myfile << "Reset is hooked\n";                //Check log
    

   
HRESULT iReturnValue oReset(pDevicepPresentationParameters);

    if(
iReturnValue == D3D_OK) {

       
    }

    return 
iReturnValue;

}

HRESULT WINAPI hkSetStreamSource(LPDIRECT3DDEVICE9 pDevice,UINT StreamNumber,IDirect3DVertexBuffer9pStreamData,UINT OffsetInBytes,UINT Stride)
{
myfile << "SetStreamSource is hooked\n";
return 
oSetStreamSource(pDevice,StreamNumber,pStreamData,OffsetInBytes,Stride);
}
//-----------------------------------------------------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){return DefWindowProc(hwnduMsgwParamlParam);}
void DX_Init(DWORDtable)
{
    
WNDCLASSEXA wc = {sizeof(WNDCLASSEX),CS_CLASSDC,MsgProc,0L,0L,GetModuleHandleA(NULL),NULL,NULL,NULL,NULL,"DX",NULL};
    
RegisterClassExA(&wc);
    
HWND hWnd CreateWindowA("DX",NULL,WS_OVERLAPPEDWINDOW,100,100,300,300,GetDesktopWindow(),NULL,wc.hInstance,NULL);
    
LPDIRECT3D9 pD3D Direct3DCreate9D3D_SDK_VERSION );
    
D3DPRESENT_PARAMETERS d3dpp;
    
ZeroMemory( &d3dppsizeof(d3dpp) );
    
d3dpp.Windowed TRUE;
    
d3dpp.SwapEffect D3DSWAPEFFECT_DISCARD;
    
d3dpp.BackBufferFormat D3DFMT_UNKNOWN;
    
LPDIRECT3DDEVICE9 pd3dDevice;
    
pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dDevice);
    
DWORDpVTable = (DWORD*)pd3dDevice;
    
pVTable = (DWORD*)pVTable[0];

    
table[ES]   = pVTable[42];                    //EndScene address
    
table[DIP]  = pVTable[82];                    //DrawIndexedPrimitive address
    
table[RES]  = pVTable[16];                    //Reset address
    
table[BS]   = pVTable[41];                    //BeginScene address
    
table[SSS] = pVTable[100];                      //SetStreamSource


    
DestroyWindow(hWnd);

    
}
//------------------------------------------------------------------------------------------------------------------------------------
DWORD WINAPI VirtualMethodTableRepatchingLoopToCounterExtensionRepatchingLPVOID  Param )
{
    while(
1) {
        
Sleep(100);
        
HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkDrawIndexedPrimitive82); //Hook DrawIndexedPrimitive
        
HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkEndScene42); //Hook EndScene
        
HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkReset16); //Hook Reset
        
HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkBeginScene41); //Hook Beginscene
        
HookVTableFunction((PDWORD*)npDevice, (PBYTE)hkSetStreamSource100);//Hook SetStreamSource
    
}

    return 
1;
}
//------------------------------------------------------------------------------------------------------------------------------------
bool hooked false;
DWORD WINAPI LoopFunctionLPVOID lpParam  )
{

    while(
1) {
        if( 
hooked == false) {
            
DWORD VTable[3] = {0};

            while(
GetModuleHandleA("d3d9.dll")==NULL) {
                
Sleep(250);
            }

            
DX_Init(VTable);
            
HOOK(EndScene,VTable[ES]);            //Hook EndScene as a device discovery hook

            
while(!npDevice) {
                
Sleep(50); //Sleep until npDevice is not equal to NULL
            
}

            
UNHOOK(EndSceneVTable[ES]);         //Unhook as soon as we have a valid pointer to pDevice
            
*(PDWORD)&oDrawIndexedPrimitive VTable[DIP];
            *(
PDWORD)&oEndScene                VTable[ES];
            *(
PDWORD)&oReset                VTable[RES];
            *(
PDWORD)&oBeginScene            VTable[BS];
            *(
PDWORD)&oSetStreamSource            VTable[SSS];
            
            
CreateThread(NULL,0,&VirtualMethodTableRepatchingLoopToCounterExtensionRepatching,NULL,0,NULL); //Create hooking thread

            
hooked true;

            
Sleep(200);

        }
    }
    return 
0;
}
//------------------------------------------------------------------------------------------------------------------------------------
BOOL WINAPI DllMain(HMODULE hModuleDWORD dwReasonLPVOID lpvReserved)
{
    if(
dwReason == DLL_PROCESS_ATTACH) {
        
CreateThread(00LoopFunction000);
        
myfile.open("C:\\Users\\pc\\Desktop\\CPP\\Hooklog.txt");
        
myfile.clear();
        
myfile << "----------Attached----------\n";
        
myfile << "\n";
    }
    else if(
dwReason == DLL_PROCESS_DETACH) {
        
myfile << "----------Detached----------";
        
myfile.close();
    }

    return 
TRUE;

__________________
MurxXxel is online now

Reply With Quote


Old 05-31-2010, 04:59 PM   #2
Supreme H4x0|2

4bply's Avatar

Join Date: Jan 2009
Location: uoy dniheB
Posts: 676
Reputation: 8706
Rep Power: 138
4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS4bply DEFINES UNKNOWNCHEATS
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (1)
Points: 8,003, Level: 10
Points: 8,003, Level: 10 Points: 8,003, Level: 10 Points: 8,003, Level: 10
Activity: 1.1%
Activity: 1.1% Activity: 1.1% Activity: 1.1%
Last Achievements
That is JoshRose source right?
__________________
"Stay on top but remain from the underground"
4bply is offline

Reply With Quote

Old 05-31-2010, 05:33 PM   #3
Junior Member

MurxXxel's Avatar

Threadstarter
Join Date: Jan 2010
Posts: 46
Reputation: 581
Rep Power: 30
MurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wall
Points: 1,892, Level: 3
Points: 1,892, Level: 3 Points: 1,892, Level: 3 Points: 1,892, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
I have it from another page it can be that that is his code^^
__________________
MurxXxel is online now

Reply With Quote

Old 05-31-2010, 05:59 PM   #4
SEGnosis
Guest

Posts: n/a
Quote:
myfile << "SetStreamSource is hooked\n";
Is very, very, very, stupid.
Having file io getting called 54000 times a minute is just going to wreak havoc in so many ways.
Quote:
VirtualMethodTableRepatchingLoopToCounterExtensionRepatching
What the fk???

So many things wrong.

Reply With Quote

Old 05-31-2010, 06:13 PM   #5
Junior Member

MurxXxel's Avatar

Threadstarter
Join Date: Jan 2010
Posts: 46
Reputation: 581
Rep Power: 30
MurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wall
Points: 1,892, Level: 3
Points: 1,892, Level: 3 Points: 1,892, Level: 3 Points: 1,892, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
Is right im learning ^^
thx for answer
__________________
MurxXxel is online now

Reply With Quote

Old 05-31-2010, 06:17 PM   #6
SEGnosis
Guest

Posts: n/a
I recommend just using strife's base that was made for logging strides

Reply With Quote

Old 05-31-2010, 06:28 PM   #7
retired moderator

JoshRose's Avatar

Join Date: Nov 2007
Location: London
Posts: 1,360
Reputation: 10674
Rep Power: 185
JoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server spaceJoshRose 's rep takes up 1 gig of server space
Air Shooter Champion
Points: 14,708, Level: 15
Points: 14,708, Level: 15 Points: 14,708, Level: 15 Points: 14,708, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
Quote:
Originally Posted by SEGnosis View Post
Is very, very, very, stupid.
Having file io getting called 54000 times a minute is just going to wreak havoc in so many ways.

What the fk???

So many things wrong.

This code was written as a base, it was not designed to be used as it is exactly, those logs are just so you know when all is working, obviously you take them out.

VirtualMethodTableRepatchingLoopToCounterExtension Repatching

is used to keep overwriting the address incase something has patched it back.
__________________
Regards and happy
Josh

__________________
JoshRose is offline

Reply With Quote

Old 05-31-2010, 06:40 PM   #8


Roverturbo's Avatar

Join Date: Feb 2005
Posts: 5,035
Reputation: 92245
Rep Power: 1108
Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (?)
I am GOD? Hmm K. God
Points: 69,888, Level: 38
Points: 69,888, Level: 38 Points: 69,888, Level: 38 Points: 69,888, Level: 38
Activity: 19.5%
Activity: 19.5% Activity: 19.5% Activity: 19.5%
Last Achievements
Quote:
Originally Posted by SEGnosis View Post
Quote:
VirtualMethodTableRepatchingLoopToCounterExtensionRepatching
What the fk???
I wrote that function for two valid reasons:

1. Depending on the game at hand, some Direct3D extension functions used restore the virtual method table and erase your detouring.
2. I wanted to break the longest function name record, did I win?

With no disrespect intended towards JoshRose's contribution, if you want something more easier to follow and understand (do you intend on trying to understand what you are doing?) then you can look at this example.

Direct3D9 Interface Hooking
__________________


I've learned that something constructive comes from every defeat.

Sometimes i say things i shouldn't, and sometimes i say what other people are thinking.

Real programmer's don't document, if it was hard to write, it should be hard to understand.

First learn computer science and all the theory, next develop a programming style, then forget all that and just hack.

Roverturbo is online now

Reply With Quote

Old 05-31-2010, 07:00 PM   #9
SEGnosis
Guest

Posts: n/a
Quote:
Originally Posted by JoshRose View Post
This code was written as a base, it was not designed to be used as it is exactly, those logs are just so you know when all is working, obviously you take them out.

VirtualMethodTableRepatchingLoopToCounterExtension Repatching

is used to keep overwriting the address incase something has patched it back.
You know you could add a simple time code check and if it gets out of sync for over a second or two with no response from reset or end scene, then you re-hook.

Instead of wasting away re hooking for no reason.

Reply With Quote

Old 05-31-2010, 07:27 PM   #10
Junior Member

MurxXxel's Avatar

Threadstarter
Join Date: Jan 2010
Posts: 46
Reputation: 581
Rep Power: 30
MurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wallMurxXxel Just put a down payment on his fire-wall
Points: 1,892, Level: 3
Points: 1,892, Level: 3 Points: 1,892, Level: 3 Points: 1,892, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
Okay thank you all xD

roverturbo thank u ill have a look at your base
and pm you if i have questions =)
__________________
MurxXxel is online now

Reply With Quote

Old 05-31-2010, 07:50 PM   #11


Roverturbo's Avatar

Join Date: Feb 2005
Posts: 5,035
Reputation: 92245
Rep Power: 1108
Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!Roverturbo has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (?)
I am GOD? Hmm K. God
Points: 69,888, Level: 38
Points: 69,888, Level: 38 Points: 69,888, Level: 38 Points: 69,888, Level: 38
Activity: 19.5%
Activity: 19.5% Activity: 19.5% Activity: 19.5%
Last Achievements
Quote:
Originally Posted by SEGnosis View Post
You know you could add a simple time code check and if it gets out of sync for over a second or two with no response from reset or end scene, then you re-hook.

Instead of wasting away re hooking for no reason.
If you research the scenario then you will find out it constantly gets erased within one second of you writing to the table. There is reason for repeative patching and no waste or resources (although someone must have a really poor system for that simple thread to effect their performance).

Quote:
Originally Posted by MurxXxel View Post
and pm you if i have questions =)
If you have questions then you ask them in the forum, not in private messages.
__________________


I've learned that something constructive comes from every defeat.

Sometimes i say things i shouldn't, and sometimes i say what other people are thinking.

Real programmer's don't document, if it was hard to write, it should be hard to understand.

First learn computer science and all the theory, next develop a programming style, then forget all that and just hack.

Roverturbo is online now

Reply With Quote

Old 06-01-2010, 06:17 AM   #12
Affiliate VIP

zoomgod's Avatar

Join Date: Aug 2007
Posts: 2,491
Reputation: 73953
Rep Power: 843
zoomgod has a huge epeen!zoomgod has a huge epeen!zoomgod has a huge epeen!zoomgod has a huge epeen!zoomgod has a huge epeen!zoomgod has a huge epeen!zoomgod has a huge epeen!zoomgod has a huge epeen!zoomgod has a huge epeen!zoomgod has a huge epeen!zoomgod has a huge epeen!
Recognitions:
Members who have contributed financial support towards UnKnoWnCheaTs. Donation (2)
The UC Member of the Month award is a prestigious award given to a single community member on a monthly basis. Based on a vote by UnKnoWnCheaTs staff, the award is given to the forum member that has shown exemplary achievement and potential in the UnKnoWnCheaTs community, and has shown great commitment to upholding the principles upon which UnKnoWnCheaTs stands for. A member who has been awarded the Member of the Month award has been distinguished as an asset to the UnKnoWnCheaTs community. Member of the Month
Points: 46,850, Level: 32
Points: 46,850, Level: 32 Points: 46,850, Level: 32 Points: 46,850, Level: 32
Activity: 43.5%
Activity: 43.5% Activity: 43.5% Activity: 43.5%
Last Achievements
Couple things to note:

1) Some A/C will unhook VMT the first time and kick the second so it depends on the game if you can even do a straight up VMT hook (I see no mention of game).

2) Why hook SetStreamSource when you can simply call GetStreamSource in DIP to get the stride. Roverturbo posted an example of that here in the past and of course less hooks means less chance of detection.
__________________
I'm like a virus, you can delete me but I am never really gone.
Links die, searching does not. (Fravia : searchlores.org)
Solving problems requires effort not a college degree.
zoomgod is offline

Reply With Quote
Reply  

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit



Tags
d3d9, vtable, work
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT +1. The time now is 10:37 AM.