™†™|SCROUT'Z OCSAIDER|™†™
https://2img.net/u/1317/13/95/08/smiles/143564713.gif

Welcome to G3 |GAME ONLINE COMUNITY|
Disini Anda Dapat Mencari/Share Pengetahuan Anda Dalam Bidang komputer/internet.

Silahkan Daftarkan Diri Anda Sebelumnya..

Greezo To :

ADMINISTRATOR,
™†™|SCROUT'Z OCSAIDER|™†™
https://2img.net/u/1317/13/95/08/smiles/143564713.gif

Welcome to G3 |GAME ONLINE COMUNITY|
Disini Anda Dapat Mencari/Share Pengetahuan Anda Dalam Bidang komputer/internet.

Silahkan Daftarkan Diri Anda Sebelumnya..

Greezo To :

ADMINISTRATOR,
™†™|SCROUT'Z OCSAIDER|™†™
Would you like to react to this message? Create an account in a few clicks or log in to continue.

™†™|SCROUT'Z OCSAIDER|™†™

™†™|SCROUT'Z OCSAIDER|™†™
 
IndeksIndeks  GalleryGallery  PencarianPencarian  Latest imagesLatest images  PendaftaranPendaftaran  LoginLogin  

 

 [C++] Midfunction Hook

Go down 
PengirimMessage
VGM.™ReggaeGasspol™
CO_ADMINISTRATOR
CO_ADMINISTRATOR
VGM.™ReggaeGasspol™


Jumlah posting : 44
Points : 106
Join date : 07.07.12
Age : 28
Lokasi : Karawang,Jawa Barat

[C++] Midfunction Hook Empty
PostSubyek: [C++] Midfunction Hook   [C++] Midfunction Hook EmptySat Jul 14, 2012 7:22 pm

Ini adalah hook midfunction Win7. Sebagian besar kode yang ditulis di sini adalah dasar untuk tingkat intermidiate .
Hal ini ditulis sebagai dasar untuk pembelajaran.

Manager.h
Code:
// ----------------------------- //// File Includes //
// ----------------------------- //

#include <windows.h>
#include <d3d9.h>

// ----------------------------- //
// Class: Framework //
// Helper functions & Memory Ops //
// ----------------------------- //

class Framework
{
public:

VOID WriteMemory(PVOID dwAdd, VOID *val, INT bytes);
VOID WriteFloat(DWORD dwAdd, FLOAT Value);
VOID WriteInteger(DWORD dwAdd, INT Value);
CHAR* ReadText(DWORD dwAdd);

DWORD FindPattern(DWORD dwdwAdd,DWORD dwLen,BYTE *bMask,char * szMask);
HINSTANCE lGetModuleHandle(LPCWSTR szModule);

private:
BOOL bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask);
};

extern Framework *FrmWrk;

// ----------------------------- //
// Thread: Thread_XD3DXINIT //
// ----------------------------- //

INT Thread_XD3DXINIT( );

// ----------------------------- //
// VOID Dx9Hook //
// ----------------------------- //
void Dx9Hook( LPCWSTR D3D9 );

DllMain.cpp
Code:
#include "Manager.h"

// ----------------------------- //
// BOOL DllMain //
// ----------------------------- //

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if( fdwReason == 1 ) //1 = On inject to process//
{
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Thread_XD3DXINIT, NULL, NULL, NULL);

//Thread_XD3DXINIT is now starting to execute code in a new thread//

return TRUE;
}

return FALSE;
}

Framework.cpp
Code:
#include "Manager.h"

Framework *FrmWrk;

VOID Framework::WriteMemory(PVOID dwAdd, void *val, int bytes)
{

DWORD d, ds;
VirtualProtect(dwAdd, bytes, PAGE_EXECUTE_READWRITE, &d);
memcpy(dwAdd, val, bytes);
VirtualProtect(dwAdd,bytes,d,&ds);
}

VOID Framework::WriteFloat(DWORD dwAdd,float Value)
{
*(float*)dwAdd = Value;
}

VOID Framework::WriteInteger(DWORD dwAdd, int Value)
{
*(int*)dwAdd = Value;
}

CHAR* Framework::ReadText(DWORD dwAdd)
{
CHAR* Text = (CHAR*)dwAdd; //reversal of WriteText...
return Text;
}

BOOL Framework::bCompare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for(;*szMask;++szMask,++pData,++bMask)
if(*szMask=='x' && *pData!=*bMask) return 0;
return (*szMask) == NULL;
}

DWORD Framework::FindPattern(DWORD dwdwAdd,DWORD dwLen,BYTE *bMask,char * szMask)
{
for(DWORD i=0; i<dwLen; i++)
if (this->bCompare((BYTE*)(dwdwAdd+i),bMask,szMask)) return (DWORD)(dwdwAdd+i);
return 0;
}

HINSTANCE Framework::lGetModuleHandle(LPCWSTR szModule)
{
HINSTANCE hModule = NULL;
if(!(hModule = GetModuleHandle(szModule)))
{
hModule = LoadLibrary(szModule);
}
return hModule;
}

Direct3D.cpp
Code:
#include "Manager.h"

// ----------------------------- //
// LPDIRECT3DDEVICE9 m_pD3Ddev //
// ----------------------------- //

LPDIRECT3DDEVICE9 m_pD3Ddev;

// ----------------------------- //
// DWORD * VTable //
// ----------------------------- //

DWORD * VTable;

// ----------------------------- //
// DWORD dwEndscene_hook //
// ----------------------------- //

DWORD dwEndscene_hook, dwEndscene_ret;

// ----------------------------- //
// BYTE EndSceneOpCodes[6] //
// ----------------------------- //

BYTE EndSceneOpCodes[6];

// ----------------------------- //
// Hook: MyEndscene //
// Code injected //
// Module: D3D9.DLL //
// Offset: EndScene + 0x2A (W7) //
// ----------------------------- //

__declspec(naked) void MyEndscene( )
{
__asm
{
mov dword ptr ss:[ebp - 10], esp;
mov esi, dword ptr ss:[ebp + 0x8]; //replace patched code
mov m_pD3Ddev, esi; //Get the device
}


__asm
{
jmp dwEndscene_ret; //jump back to normal endscene
}

}

// ----------------------------- //
// Thread: Thread_XD3DXINIT //
// DirectX Functions Hooked here //
// ----------------------------- //

INT Thread_XD3DXINIT( )
{
Dx9Hook(L"d3d9.dll");

FrmWrk->WriteMemory((void *)EndSceneOpCodes, (void *)"\x89\x65\xF0\x8B\x75\x08", 6);

/*while( 1 )
{
Sleep( 1000 );

if(memcmp((void *)Endscene_opcodes, (void *)dwEndscene_hook, 6) == 0 )
Detour(dwEndscene_hook, MyEndscene);

}*/

return NULL;
}

// ----------------------------- //
// VOID Dx9Hook //
// ----------------------------- //

VOID Dx9Hook( LPCWSTR D3D9 )
{
DWORD hD3D = NULL;

while (!hD3D) hD3D = (DWORD)FrmWrk->lGetModuleHandle(D3D9);
DWORD PPPDevice = FrmWrk->FindPattern(hD3D, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x 00\x00\x89\x86", "xx????xx????xx");
memcpy( &VTable, (VOID *)(PPPDevice + 2), 4);

dwEndscene_hook = VTable[42] + 0x2A;
dwEndscene_ret = dwEndscene_hook + 0x6;
Kembali Ke Atas Go down
https://www.facebook.com/reggaecoxambi
 
[C++] Midfunction Hook
Kembali Ke Atas 
Halaman 1 dari 1

Permissions in this forum:Anda tidak dapat menjawab topik
™†™|SCROUT'Z OCSAIDER|™†™ :: Daponsent | Learning :: Programming-
Navigasi: