 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Tue Mar 22, 2011 12:21 pm Post subject: Hooking address (GCC) |
|
|
Hello,
I'm trying to hook a function, I know the address, but the problem is I'm using GCC now, I used to be using VS and my method does not work anymore,
Code: | void Hooks::EnableHooks ()
{
*(char*)ulSend = 0xE9;
*(long*)ulSend + 1 = NewSendFun - ulSend - 5; // error line
}
/* New functions for hooked Functions */
void Hooks::NewSendFun()
{
__asm__ (
"mov [ppSendPacket],%esp\n\t"
"pusha\n\t"
"call SendPacketCallback\n\t"
"popa\n\t"
"jmp *%ulSendRet]\n\t"
);
} |
The error line gives this error:
invalid use of member(did you forget the '&'?)
Hope someone can help me.
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Tue Mar 22, 2011 12:39 pm Post subject: |
|
|
Missed brackets
should be NewSendFun()
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Mar 22, 2011 3:32 pm Post subject: |
|
|
AhMunRa wrote: | Missed brackets
should be NewSendFun() |
he wants the address of the function, not the return.
you need to be explicit when you want the address of a member function in C++. it's ok to assign a function pointer like that in C but in, with member function pointers (a difference!) in C++ you'd need: &class::mf
|
|
Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Wed Mar 23, 2011 1:53 am Post subject: |
|
|
slovach wrote: | AhMunRa wrote: | Missed brackets
should be NewSendFun() |
he wants the address of the function, not the return.
you need to be explicit when you want the address of a member function in C++. it's ok to assign a function pointer like that in C but in, with member function pointers (a difference!) in C++ you'd need: &class::mf |
I made the function static in my class, at least I can compile now:)
so I've to change
&Hooks::NewFunction
|
|
Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Wed Mar 23, 2011 4:15 am Post subject: |
|
|
NoMercy wrote: | I made the function static in my class, at least I can compile now:) | You don't have to make the whole class static. Only the member receiving the callback. This is because the compiler can't just run a method of a class, which doesn't have an instance. The other way would be to tell the compiler which instance of the object to use and then call the member: ((class).*(member))(args). But seeing the case, using a static member is much more easier.
|
|
Back to top |
|
 |
Deltron Z Expert Cheater
Reputation: 1
Joined: 14 Jun 2009 Posts: 164
|
Posted: Wed Mar 23, 2011 12:23 pm Post subject: |
|
|
Jani wrote: | You don't have to make the whole class static. Only the member receiving the callback. This is because the compiler can't just run a method of a class, which doesn't have an instance. The other way would be to tell the compiler which instance of the object to use and then call the member: ((class).*(member))(args). But seeing the case, using a static member is much more easier. |
I'm not sure what you mean by "((class).*(member))(args)", because dot is used with class instance - objects, not class, you should've used :: instead. and by member I assumed you meant the function, and then I don't understand what's the dereference operator for... get the function's... value? and the call it with the arguments?
I think you meant:
((return_type (call_convention*)(void*))class::member)(&object)
for example:
((int (__cdecl*)(void*, other_params))class::member)(&object, other_param)
because "this" pointer is passed as a paramater.
Unfortunatly, the compiler didn't like me converting a class method to a pointer (int*, char*, void*, nothing...) even though it worked perfectly fine with functions that didn't belong to a class, so I had to write a warper, nothing too complicated, just a few lines of inline assembly.
Here's an example:
Code: | #include <stdio.h>
class Class
{
public:
void* __stdcall GetThisPointer() { return (void*)this; }
};
//This is how the compiler implements the function
//"this" pointer is passed as a paramater
void* GetThisPointer_Implementation(Class* object)
{
return (void*)object;
}
//Proof of Concept
int __declspec(naked) GetThisPointer_PoC(Class* object)
{
__asm
{
PUSH EBP //since we specified __declspec(naked)
MOV EBP, ESP //fix stack
//if GetThisPointer was __cdecl (by default) then
//you should've used "MOV ECX, object" instead of "PUSH object"
PUSH object //Pass "this" pointer as a parameter
LEA EAX, [Class::GetThisPointer]
CALL EAX
POP EBP
RETN 4
}
}
int main()
{
Class Object;
printf("Object (%p) = this (%p)\n", &Object, Object.GetThisPointer());
printf("Implementation: %p\n", GetThisPointer_Implementation(&Object));
printf("Proof of Concept: %p\n", GetThisPointer_PoC(&Object));
return 0;
} |
_________________
SharpDisassembler
"When I find my code in tons of trouble,
Friends and colleagues come to me...
Speaking words of wisdom:
Write in C."
#pragma message("Let there be byte!") |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|