Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Problems inside a class

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Wed Mar 30, 2011 5:15 am    Post subject: Problems inside a class Reply with quote

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
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed Mar 30, 2011 9:43 am    Post subject: Reply with quote

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
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Wed Mar 30, 2011 10:00 am    Post subject: Reply with quote

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
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed Mar 30, 2011 10:35 am    Post subject: Reply with quote

Did you specify a type inside the structure?
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Wed Mar 30, 2011 1:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed Mar 30, 2011 2:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Wed Mar 30, 2011 3:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed Mar 30, 2011 4:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Wed Mar 30, 2011 7:05 pm    Post subject: Reply with quote

Initialize the static members of the class in the definition.
Back to top
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Thu Mar 31, 2011 3:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Thu Mar 31, 2011 6:03 pm    Post subject: Reply with quote

If you did not intend 'StructSendPacket' to be static also.. you should be accessing it through an object of Hooks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites