View previous topic :: View next topic |
Author |
Message |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Wed Mar 30, 2011 5:15 am Post subject: Problems inside a class |
|
|
Hello,
I've got a problem while I'm trying to hook a function, which did work in C, but I'm converting it to C++ and it becomes a bit harder now. I'll show you my code.
Hooks.h
Code: | #ifndef HOOKS_H
#define HOOKS_H
#include "Packet.h"
#include <Windows.h>
class Hooks
{
public:
Hooks(); // Constructor
void EnableHookSend ();
void EnableHookRecv ();
void DisableHookSend();
void DisableHookRecv();
private:
/* Functions */
static void NewSendFun();
static void NewRecvFun();
static void DispatchSend();
static void DispatchRecv();
/* Variables, in Construcot initialized */
DWORD dwSend;
DWORD dwRecv;
static DWORD dwSendRet;
static DWORD dwRecvRet;
/* Clean bytes from Send/Recv function */
static BYTE CleanSend;
static BYTE CleanRecv;
/* Send Packet Struct */
SENT_PACKET* StructSendPacket;
/* Recv Packet Struct */
};
#endif // HOOKS_H
|
Parts of Hooks.cpp
Code: | void Hooks::EnableHookSend ()
{
*(BYTE*) dwSend = 0xE9;
*(DWORD*)(dwSend + 1) = (((LONG_PTR)(&Hooks::NewSendFun))-((LONG_PTR)dwSend))- 5;
// is this all right coded?
}
void __declspec(naked) Hooks::NewSendFun()
{
__asm
{
mov dword ptr [StructSendPacket],esp // gives me error
pushad
call DispatchSend
popad
jmp dword ptr[dwSendRet] // gives me error to
}
}
|
I made some // things in there which shows where it goes wrong,
mov dword ptr [StructSendPacket],esp
Gives:
Hooks.cpp(40): error C2415: improper operand type
If I leave that line out,
Code: | jmp dword ptr[dwSendRet] |
Gives:
Quote: | Hooks.obj : error LNK2019: unresolved external symbol "private: static unsigned long Hooks::dwRecvRet" (?dwRecvRet@Hooks@@0KA) referenced in function "public: __thiscall Hooks::Hooks(void)" (??0Hooks@@QAE@XZ)
Hooks.obj : error LNK2019: unresolved external symbol "private: static unsigned long Hooks::dwSendRet" (?dwSendRet@Hooks@@0KA) referenced in function "public: __thiscall Hooks::Hooks(void)" (??0Hooks@@QAE@XZ) |
Code: |
Hope someone knows something,
anyways thanks,
|
Last edited by NoMercy on Wed Mar 30, 2011 1:48 pm; edited 1 time in total |
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed Mar 30, 2011 9:43 am Post subject: |
|
|
Could be wrong but here goes.
/* Send Packet Struct */
SENT_PACKET StructSendPacket;
Error
Hooks.cpp(40): error C2415: improper operand type
Call
mov dword ptr [StructSendPacket],esp // gives me error
What's the type of StructSendPacket?
Struct C++ resource.
http://www.cplusplus.com/doc/tutorial/structures/
Can only assume from your header you meant to create a struct for StructSendPacket
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Wed Mar 30, 2011 10:00 am Post subject: |
|
|
AhMunRa wrote: | Could be wrong but here goes.
/* Send Packet Struct */
SENT_PACKET StructSendPacket;
Error
Hooks.cpp(40): error C2415: improper operand type
Call
mov dword ptr [StructSendPacket],esp // gives me error
What's the type of StructSendPacket?
Struct C++ resource.
http://www.cplusplus.com/doc/tutorial/structures/
Can only assume from your header you meant to create a struct for StructSendPacket |
No the structure is SENT_PACKET.
mov [StructSendPacket],esp is the orginal one, dword ptr is a try.
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed Mar 30, 2011 10:35 am Post subject: |
|
|
Did you specify a type inside the structure?
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Wed Mar 30, 2011 1:16 pm Post subject: |
|
|
Code: | struct EMS_PACKET_STRUCT {
BYTE Command;
BYTE Data[1];
};
struct MSPacket
{
DWORD dwUnknown1;
union {
LPBYTE lpvData;
LPBYTE lpBytes;
EMS_PACKET_STRUCT* EMSStruct;
};
DWORD dwSize;
DWORD dwUnknown2;
};
struct SENT_PACKET
{
LPVOID lpvReturnAddress;
MSPacket* lpPacket;
}; |
This is it,[/code]
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed Mar 30, 2011 2:17 pm Post subject: |
|
|
push eax
mov eax, esp
mov StructSendPacket, eax
pop eax
If that doesn't work, I'm stumped.
Also what are you making this in? I know C++ but are you using the Bloodshed Dev C++? It's based on gcc so you will have to make sure your asm call follows the gcc compilers requirements for inline asm.
From what I'm finding you can not use inline asm to copy memory to memory.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Wed Mar 30, 2011 3:01 pm Post subject: |
|
|
AhMunRa wrote: | push eax
mov eax, esp
mov StructSendPacket, eax
pop eax
If that doesn't work, I'm stumped.
Also what are you making this in? I know C++ but are you using the Bloodshed Dev C++? It's based on gcc so you will have to make sure your asm call follows the gcc compilers requirements for inline asm.
From what I'm finding you can not use inline asm to copy memory to memory. |
It does not work, I'm using VS 2010.
I think it has something to do with the class, cause in functions it works fine with a global variable of SEND_PACKET. Same for the jmp back, it does not know the variables or something.
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed Mar 30, 2011 4:57 pm Post subject: |
|
|
Got me. I wasn't aware you could use inline in the VS series. I use C# and I know that doesn't allow it in managed code.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
Innovation Grandmaster Cheater
Reputation: 12
Joined: 14 Aug 2008 Posts: 617
|
Posted: Wed Mar 30, 2011 7:05 pm Post subject: |
|
|
Initialize the static members of the class in the definition.
|
|
Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Thu Mar 31, 2011 3:31 pm Post subject: |
|
|
Everything works now, except for the strcture. I declared it in global scope outside the class now, I would appriciate it, when someone could help me with that.
|
|
Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Thu Mar 31, 2011 6:03 pm Post subject: |
|
|
If you did not intend 'StructSendPacket' to be static also.. you should be accessing it through an object of Hooks.
|
|
Back to top |
|
 |
|