illegal call of non-static member function

Jun 24, 2008 at 9:27pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class CObfuscator 
{
public:
	int doit_tramp(int, int); 
	int doit_detour(int opcode, int flag);
};

int CObfuscator::doit_detour(int opcode, int flag)
{
#if 0
	if (EQ_BEGIN_ZONE == opcode) {
		DebugSpewAlways("EQ_BEGIN_ZONE");
	} else {
		DebugSpewAlways("opcode %d", opcode);
	}
#endif
	if (opcode==EQ_BEGIN_ZONE) PluginsBeginZone(); 
	if (opcode==EQ_END_ZONE) PluginsEndZone();
	return doit_tramp(opcode, flag);
};

DETOUR_TRAMPOLINE_EMPTY(int CObfuscator::doit_tramp(int, int));

unsigned int Encrypt(unsigned int opcode) 
{
	DWORD ret = CObfuscator::doit_detour(opcode, 0);
return(ret);
}


1
2
3
4
5
6
7
8
9
typedef struct _TestStructure {
/* 0x00 */    CHAR name;
/* 0x04 */    DWORD MyID;
} TestStruct;

void SendPacket(DWORD OPCode, DWORD Data, DWORD Size)
    unsigned int EncryptedOPCode = Encrypt(OPCode);
....
Code here that will send the encrypted opcode with the data


Example..
1
2
3
4
5
6
TestStruct ts;
ZeroMemory(&ts,sizeof(ts));
ts.name = "My Name";
ts.MyID = "40015";

SendPacket(0x64, DWORD(&ts), sizeof(ts));


That example should encrypt the packet "0x64", then send it containing the data and size of the structure I declared. How can I fix this error, or am I doing it in the wrong way?
Last edited on Jun 24, 2008 at 9:27pm
Jun 24, 2008 at 9:34pm
On top of that I am trying to call a trampoline in my inline assembly code that will contain the Sending Packets class. Looks like this..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
typedef struct _SendOp {
      WORD opcode;
} SendOp;

BOOL PluginsSendPacket(DWORD Type, DWORD Packet, DWORD Size) {
	typedef BOOL (__cdecl *fMQSendPacket)(DWORD, DWORD, DWORD);
	bool bSend = true;
	PMQPLUGIN pPlugin = pPlugins;
	while(pPlugin) {
		 fMQSendPacket SendPacket = (fMQSendPacket)GetProcAddress(pPlugin->hModule, "OnSendPacket");
		 if (SendPacket)
			if (!SendPacket(Type, Packet, Size)) bSend = false;
		 pPlugin = pPlugin->pNext;
	}
	return bSend;
}

class Packets {
public:
	DWORD SendTramp(DWORD,DWORD,DWORD); 
	DWORD SendDetour(DWORD flag,DWORD pkt, DWORD size)
	{
		GOpcode *opst = (GOpcode *)pkt;
		if (PluginsSendPacket((DWORD)opst->opcode,pkt,size)) {
			return(SendTramp(flag,pkt,size));
		} else {
			return(12);
		}
	}
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

	__asm
	{
             ....full assembly code not shown
                jz NormalCall;
		call Packets::SendTramp;
		jmp Exit;

		NormalCall:
			mov eax, OpSendMessage;
			call eax;

		Exit:
			pop ecx;
			pop eax;
	}


I get 3 errors on that one call to my trampoline. They are as follows..
1
2
3
error C2420: 'Packets' : illegal symbol in first operand
error C2415: improper operand type
error C2400: inline assembler syntax error in 'second operand'; found 'bad token'


I then get 1 error/1 warning on the next line that does a jmp Exit.
1
2
error C2400: inline assembler syntax error in 'opcode'; found 'bad token'
warning C4405: 'jmp' : identifier is reserved word


Should I put the assembly in the trampoline?
Last edited on Jun 24, 2008 at 9:44pm
Jun 24, 2008 at 10:10pm
I would think that you would have an issue in your BOOL PluginsSendPacket function because it's trying to use the Packets class before it's defined.

That should be the cause for your illegal symbol error.
Jun 24, 2008 at 10:28pm
Actually the Packets class uses BOOL PluginsSendPacket, not the other way around and it is in the right order.
Jun 24, 2008 at 10:31pm
Ahhhh sorry, I read that code wrong. :)
Jun 24, 2008 at 10:32pm
Where is ur implementation of Packets::SendTramp?
Jun 24, 2008 at 10:36pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Packets {
public:
	DWORD SendTramp(DWORD,DWORD,DWORD); 
	DWORD SendDetour(DWORD flag,DWORD pkt, DWORD size)
	{
		GOpcode *opst = (GOpcode *)pkt;
		if (PluginsSendPacket((DWORD)opst->opcode,pkt,size)) {
			return(SendTramp(flag,pkt,size));
		} else {
			return(12);
		}
	}
};

DETOUR_TRAMPOLINE_EMPTY(DWORD Packets::SendTramp(DWORD,DWORD,DWORD)); 


Did I miss something? The actual detour is on the DLL initialization, looks like this..

1
2
3
4
5
6
7
// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
	DebugSpewAlways("Initializing MQ2PacketAPI");
	EzDetour(__SendPacket,&Packets::SendDetour,&Packets::SendTramp);
        EzDetour(CObfuscator__doit,&CObfuscator::doit_detour,&CObfuscator::doit_tramp); 
}


Just in case this is needed for help and I didn't mention it before, this is an addon plugin DLL source for the MacroQuest2 program (macroquest2.com).

PS: Zaita if you have IM, Yahoo or any other instant messenger and would be willing to work with me and I can share the full source with you then I will pay whatever you think is fair because this is really bugging me. Just send a PM or reply to this thread.
Last edited on Jun 24, 2008 at 10:42pm
Jun 24, 2008 at 10:43pm
Ok. I am not too familiar with the implementation of Trampolines. However, you have not put any Implementation for SendTramp. You have defined the function, but it's empty.

I can help through the forum initially, if it needs to go further I maybe able to help via IM. Atm I am at work, so no IM access :)
Jun 24, 2008 at 10:56pm
Well I am not 100% on detours myself, I have only ever implemented them in code as an MQ2 plugin addon. MQ2 has their own detour functions, and this is how they are all set up. Let me give you an example of a detour plugin that works..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "../MQ2Plugin.h"   //include file required for all MQ2 plugins

#define __SendPacket		0x624550

typedef struct _SendOp {
      WORD opcode;
} SendOp;

BOOL PluginsSendPacket(DWORD Type, DWORD Packet, DWORD Size) {
	typedef BOOL (__cdecl *fMQSendPacket)(DWORD, DWORD, DWORD);
	bool bSend = true;
	PMQPLUGIN pPlugin = pPlugins;
	while(pPlugin) {
		 fMQSendPacket SendPacket = (fMQSendPacket)GetProcAddress(pPlugin->hModule, "OnSendPacket");
		 if (SendPacket)
			if (!SendPacket(Type, Packet, Size)) bSend = false;
		 pPlugin = pPlugin->pNext;
	}
	return bSend;
}

class Packets {
public:
	DWORD SendTramp(DWORD,DWORD,DWORD); 
	DWORD SendDetour(DWORD flag,DWORD pkt, DWORD size)
	{
		GOpcode *opst = (GOpcode *)pkt;
		if (PluginsSendPacket((DWORD)opst->opcode,pkt,size)) {
			return(SendTramp(flag,pkt,size));
		} else {
			return(12);
		}
	}
};
DETOUR_TRAMPOLINE_EMPTY(DWORD Packets::SendTramp(DWORD,DWORD,DWORD));

// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
	DebugSpewAlways("Initializing MQ2PacketAPI");
	EzDetour(__SendPacket,&Packets::SendDetour,&Packets::SendTramp); 
}


This will successfully initialize a portion of the PacketAPI known as OnSendPacket. This means that it will perform a certain function upon sending the declared packet, here is an example..

1
2
3
4
5
6
7
PLUGIN_API BOOL OnSendPacket(DWORD Type, DWORD Packet, DWORD Size)
{     
	if (Type == 0x65) {
           WriteChatf("Packet: 0x65 has been sent, OnSendPacket code successfully initialized.");
          }                  
   return true;
}


That will print out "Packet: 0x65 has been sent, OnSendPacket code successfully initialized" every time your client sends the packet 0x65 to the server.

Also, I am going to be heading out soon so hopefully when I get back you will be home from work and we can talk about this further. My IM is KryptoniteCoder and I should be online sometime tonight, what time would I expect you to be on? I also need a little help with inline assembly, if you're any good with that and like I said I will pay you whatever you think is fair.
Last edited on Jun 24, 2008 at 11:01pm
Jun 24, 2008 at 11:01pm
Last edited on Jun 24, 2008 at 11:05pm
Jun 24, 2008 at 11:05pm
Well I know using DETOUR_TRAMPOLINE_EMPTY initializes it, but the only way I and everyone I know has ever used detours would be to alter a function whenever it comes up. I have never called a class from a detour, nor have I ever really had time to mess with inline assembly so this is quite confusing to me.

EDIT: Just saw that link you gave me, and yes that's another plugin for MQ2 ;)
Last edited on Jun 24, 2008 at 11:07pm
Jun 26, 2008 at 2:38pm
Zaita is there some time I can get on AIM so you can send me an IM and we can talk further about this?
Jun 26, 2008 at 6:33pm
I don't use AIM, only MSN. I am also in New Zealand, so my timing is a little off compared to most.


In a nutshell, "Illegal Call to non-static method" Means somewhere you have passed in the address of a function you would like to be called. But that function has not been declared as a static function when it infact should have been.

If you have msn, drop me an email with your address through to public01@zaita.com
Jun 28, 2008 at 11:56pm
Whenever I try to add you I get error message because you don't have a .NET passport? I thought MSN messenger could only be used by yahoo, hotmail, msn, etc., not any email like zaita.com -- but I could be wrong.
Jun 29, 2008 at 6:46pm
Send me an email to public01@zaita.com telling me what your MSN address is. I won't post my MSN address here because it'll likely get spammed :) Public01 is an address I can close down later with no problems because it's only an alias :)
Topic archived. No new replies allowed.