Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 01:32

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C++] Function Hooking.

Discussion on [C++] Function Hooking. within the CO2 Programming forum part of the Conquer Online 2 category.

Closed Thread
 
Old   #1
 
elite*gold: 0
Join Date: Sep 2008
Posts: 490
Received Thanks: 595
[C++] Function Hooking.

Well I hate writing tutorials where you need no brain at all,
but this is as simple as its gonna get!
Here's an example i whipped together for Minesweeper
Ofcourse within CO theres stuff you can do aswell, once you know a function!
(for example sending magic attacks like stig *hint hint*)

So after trying this out I suggest you to read more about this subject!
(if you're not experienced with function hooks)
And share your sources in this section!

I included everything you need and commented most things out for you.
the attachment below includes:
1) Winject (to inject the dll)
2) Detours folder (lib and header file you need to let your compiler know)
3) the project source folder
4) MineSweeper! (I had to download it because my windows doesnt have that crap)


Heres the main cpp file:

Code:
[COLOR="Green"]/////////////////////////////////////////////////////////
//*****************************************************//
//****Hooking functions and executing them*************//
//****Example for MineSweeper**************************//
//****By fobos*****************************************//
/////////////////////////////////////////////////////////

/*
 We need to include some stuff in order to include detours.h
 the compiler needs to know where the lib and .h files are.
 So first thing you do right now is right click MineSweeperHook
 in your solution explorer, click on properties.
 click on C/C++ and then add your detours folder you extracted from
 the rar file to additional include directories.
 Thats not all now click on the Linker tab, and add Detours folder
 to Additional library directories.
 Thats all to that!
*/ [/COLOR]

[COLOR="Green"]// Includes (duhh)[/COLOR]
#include <windows.h>
#include "detours.h"
#pragma comment(lib, "detours.lib")

DWORD WINAPI MyThread(LPVOID);
DWORD g_threadID;
HMODULE g_hModule;

[COLOR="Green"]//Function prototypes (duhh)[/COLOR]
int (__stdcall* PauseGame)(); 
int (__stdcall* ResumeGame)(); 

[COLOR="Green"]//Our pause function, the fun stuff begins :p[/COLOR]
int MyPauseGame() 
{
[COLOR="Green"]	//Messagebox[/COLOR]
	MessageBoxA(NULL, "Press OK and your bitch is on hold. :p", "Call PauseGame", MB_OK);
[COLOR="Green"]	//Return the real function[/COLOR]
	return PauseGame(); 
}
[COLOR="Green"]//Our resume function[/COLOR]
int MyResumeGame()
{
	[COLOR="Green"]//Messagebox[/COLOR]
	MessageBoxA(NULL, "Press OK and your bitch will resume! :p", "Call ResumeGame", MB_OK);
	//Return the real function
	return ResumeGame(); 
}


INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
	switch(Reason)
	{
	case DLL_PROCESS_ATTACH:
		[COLOR="Green"]//On attach set the hooks[/COLOR]
		PauseGame = (int (__stdcall*)())DetourFunction((PBYTE)0x0100341C, (PBYTE)MyPauseGame);
		ResumeGame = (int (__stdcall*)())DetourFunction((PBYTE)0x0100344C, (PBYTE)MyResumeGame);
		
		g_hModule = hDLL;
		DisableThreadLibraryCalls(hDLL);
		[COLOR="Green"]//Create a thread [/COLOR]
		CreateThread(NULL, NULL, &MyThread, NULL, NULL, &g_threadID);
	break;
	
	case DLL_THREAD_ATTACH:
	
	case DLL_PROCESS_DETACH:
		[COLOR="Green"]//Remove the hooks cuz we like to clean.. *cough*[/COLOR]
		DetourRemove((PBYTE)0x0100341C, (PBYTE)PauseGame);
		DetourRemove((PBYTE)0x0100344C, (PBYTE)ResumeGame);
	
	case DLL_THREAD_DETACH:
		break;
	}
	return TRUE;
}

DWORD WINAPI MyThread(LPVOID)
{
	while(true)
	{
		[COLOR="Green"]// Set F10 as our hotkey and wait do something on keypress[/COLOR]
		if(GetAsyncKeyState(VK_F10) & 1) 
		{
[COLOR="Green"]			// Execute our function
			// You could also call it directly like this:
			// PauseGame();[/COLOR]
			MyPauseGame();
		}
		[COLOR="Green"]// Set F11 as our hotkey and wait do something on keypress[/COLOR]
		else if(GetAsyncKeyState(VK_F11) & 1) 
		{
[COLOR="Green"]			// Execute our function
			// You could also call it directly like this:
			// ResumeGame();[/COLOR]
			MyResumeGame();
		}
		[COLOR="Green"]//Set F12 as our hotkey to break and remove the dll from process[/COLOR]
		else if(GetAsyncKeyState(VK_F12) & 1)
			break;
		Sleep(100);
	}
	FreeLibraryAndExitThread(g_hModule, 0);
	return 0;
}
Enjoy playing around with it, to find functions download IDA pro, find a function note down the address and what and how many parameters it takes.

I don't need thank you's or anything, all I want is this section to get more stuff about programming instead of the idiotic questions (No offense..)
(On a side note i gave a minesweeper example instead of a CO example because hell I'm not gonna chew everything for you )

So well enjoy!
Attached Files
File Type: rar Hooking.rar (3.46 MB, 914 views)
_fobos_ is offline  
Thanks
28 Users
Old 08/25/2010, 07:35   #2
 
majidemo's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 347
Received Thanks: 1,286
why does it tell me, Both injection-methods failed!
err.0
majidemo is offline  
Old 08/25/2010, 08:16   #3
 
gabrola's Avatar
 
elite*gold: 0
Join Date: Dec 2006
Posts: 1,039
Received Thanks: 1,335
Your inbox will be spammed by people now who don't know how to use function hooking in CO.
gabrola is offline  
Thanks
1 User
Old 08/25/2010, 12:56   #4

 
Kiyono's Avatar
 
elite*gold: 20
Join Date: Jun 2006
Posts: 3,296
Received Thanks: 925
Quote:
Originally Posted by gabrola View Post
Your inbox will be spammed by people now who don't know how to use function hooking in CO.
Doesn't matter, he doesn't even check e*pvp anymore.
Kiyono is offline  
Old 08/25/2010, 19:16   #5
 
gabrola's Avatar
 
elite*gold: 0
Join Date: Dec 2006
Posts: 1,039
Received Thanks: 1,335
Quote:
Originally Posted by Kiyono View Post
Doesn't matter, he doesn't even check e*pvp anymore.
Yeah, I realized that.
gabrola is offline  
Closed Thread


Similar Threads Similar Threads
[tutorial]Injection & Function Hooking
11/06/2010 - Tutorials - 5 Replies
First let me say this: This is not written by me, i found it posted on game deception a while ago and just rediscoverd it on my hd. Thought it might be interesting for some ppl here. Credits go to whoever originally wrote it. This contains a demo project for vc 2003 and a tutorial. You can find the tutorial in the readme folder!!!!!! oh, if you don't trust me, don't download it....
[VIP-function] ToxicSYS [VIP-function]
08/14/2010 - WarRock Hacks, Bots, Cheats & Exploits - 1 Replies
heeeey E-pvpers :pimp: this is a new hack by TSYS Status : UNDETECTED Functions (VIDEO) : YouTube - WarRock - Bikini event VIP hack
Text Hooking
07/09/2010 - General Coding - 5 Replies
Hallo Leute, ich wollte mal fragen ob jemand erfahrungen mit Texthooking hat? Ich und ein Team wollen eine Visual Novel übersetzen Das Problem: Wenn wir das mit den bisher herrausgefundenen Methoden machen müssen wir erst jedes Spiel 100% Durchspiel und das kostet einfach zu viel Zeit Mit OllyDbg hab ich es auch versucht nur leider ohne erfolg :/ Kann uns evtl. jemand helfen?
C++ D3D Hooking
08/24/2009 - C/C++ - 12 Replies
Hallo zusammen, ich stehe gerade vor folgendem Problem: ich habe eine DLL und einen Loader gecoded, jedoch will ich anstelle des Loader einen Injecter haben, sprich: das spiel, in das injected werden soll, soll schon laufen. Natürlich hab ich das ganze schon probiert, jedoch werden die D3D-funktionen nicht wirklich gehookt, da die DLL auf ein Direct3DCreate9 wartet. Da diese Funktion aber wahrscheinlich direkt beim Starten des "Opfer-Spiels" ausgeführt wird, werden deswegen die anderen...



All times are GMT +1. The time now is 01:32.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.