Help with midhook

Posts 1–8 of 8 · Page 1 of 1
Help with midhook
Hello,

I'm making a midhook but I never did it. So some part I never did before.
I can't get the addie to the function that I want to load.

I want to load this function:
Code:
DWORD test() {
	std::cout << "test";
}
Yes I know, I need to asm the jmp back and more. But I want to do this first.

I want to get the addie to that function this way:

Code:
DWORD pointertofunction;
DWORD (*pointertofunction)() = test; //Destination
I get they's errors:

Code:
1>main.cpp(31): error C2373: 'pointertofunction' : redefinition; different type modifiers
1>          main.cpp(29) : see declaration of 'pointertofunction'
Can some one tel me how to do this ride? Or can some one give me from a other game a midhook that works? Becouse I want to learn how to do it, I don't want the code.


I dont know soo much on C++ coding sry, i cant helpe u
Quote Originally Posted by Coder[Vb10e] View Post


I dont know soo much on C++ coding sry, i cant helpe u

if you cant help him then dont post here?
this is a detected method
don't use a jmp or xtrap will give you a message and close the game -.-
anyway if you want this method here is a function
Code:
void *DetourCreate(BYTE *src, const BYTE *dst, const int len)
{
	BYTE *jmp = (BYTE*)malloc(len+5);
	DWORD dwBack;

	VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
	memcpy(jmp, src, len);	
	jmp += len;
	jmp[0] = 0xE9;
	*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
	src[0] = 0xE9;
	*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
	for (int i=5; i<len; i++)  src[i]=0x90;
	VirtualProtect(src, len, dwBack, &dwBack);
	return (jmp-len);
}
so you can use this code
Code:
DetourCreate((BYTE*)pointertofunction, (BYTE*)test, 5);
Quote Originally Posted by giniyat202 View Post
this is a detected method
don't use a jmp or xtrap will give you a message and close the game -.-
anyway if you want this method here is a function
Code:
void *DetourCreate(BYTE *src, const BYTE *dst, const int len)
{
	BYTE *jmp = (BYTE*)malloc(len+5);
	DWORD dwBack;

	VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwBack);
	memcpy(jmp, src, len);	
	jmp += len;
	jmp[0] = 0xE9;
	*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
	src[0] = 0xE9;
	*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
	for (int i=5; i<len; i++)  src[i]=0x90;
	VirtualProtect(src, len, dwBack, &dwBack);
	return (jmp-len);
}
so you can use this code
Code:
DetourCreate((BYTE*)pointertofunction, (BYTE*)test, 5);
that code is....o my it's just gross im sorry but holy crap, countless flaws in it omg...and why did you give him a jmp, if you just said it was detected 0.o
Quote Originally Posted by ~FALLEN~ View Post
that code is....o my it's just gross im sorry but holy crap, countless flaws in it omg...and why did you give him a jmp, if you just said it was detected 0.o
Haha, indeed. But that wasn't my question. And I already have a Detour function. My question was, how to get the address of a own function. And how do do this with a naked function:

__declspec(naked) void _functionh()
Quote Originally Posted by nonameav View Post
Haha, indeed. But that wasn't my question. And I already have a Detour function. My question was, how to get the address of a own function. And how do do this with a naked function:

__declspec(naked) void _functionh()
you must declare the function first (_declspec comes before detour)
and use the name of function without ()
Quote Originally Posted by Coder[Vb10e] View Post
i want to reach 100 posts :P
What a noob spammer, -1+ reported for spam, enjoy your ban
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us