Jump to content
Tuts 4 You

Function Pointer Member?


high6

Recommended Posts

Posted

I am trying to emulate this assembly in C++ (to make it more readable then a hacky inline assembly).

MOV EAX,DWORD PTR DS:[5D91B4]
PUSH ESI
LEA ECX,DWORD PTR DS:[EAX+89C08]
CALL 0047F3F8

So I have this psuedo code

	class MAIN
{
public:
class FUNCLIST
{
public:
bool (* FuncListContains)(int idx,bool) = (bool (*)(int,bool))0x0047EE03;
int FuncListGetItem(int idx)
{
return idx*2;
}
};
FUNCLIST* FuncList = (FUNCLIST*)(this+0x00089C08);
};
MAIN* Main = (MAIN*)0x005D91B4;

Of course this doesn't work because the function pointer isn't static.

Is there anyway to set the function pointer as a constant but keeping it as a member?

Summary:

I am injecting a dll and I want to have that assembly above as C++ so I can easily call it from my dll without a hacky inline assembly segment.

Posted

If I understood you correctly, this should work:

	class FUNCLIST
{
public:
bool (* FuncListContains)(int idx,bool);
// ....
};
FUNCLIST::FuncListContains = (bool (*)(int,bool))0x0047EE03;

Why can't you set it to static anyway?

I'm not sure if the above actually works, I think it only does with statics.

However, you can init vars in the constructor:

		class FUNCLIST
{
public:
bool (* FuncListContains)(int idx,bool)= (bool (*)(int,bool))0x0047EE03;
int FuncListGetItem(int idx)
{
return idx*2;
}
FUNCLIST() : FuncListContains((bool (*)(int,bool))0x0047EE03) {};
};
Posted

"Why can't you set it to static anyway?"

Because, I need it to set "ECX" ("this" in C++) to the address of the classes data.

Is there any way to not use contructors? And ya the top snippet only works if it is static.

Posted (edited)

Still not satisfied with this way but I think it will work.

static const int FuncListContainsAddr = 0x0047EE03;
bool FuncListContains(int a, int B)
{
return ((bool (*)(int,bool))FuncListContainsAddr)(a,B);
}
Edited by high6
Posted

I guess I will have to do it like that unless I can declare a constant function pointer in a class. Forgot that a function pointer stores the destination so changing the location of "this" would break it.

Posted

Almost works, just need to figure out how to set FuncListContains to 0x0047EE03.

	class MAIN
{
public:
char bump1[0x00089C08];
class FUNCLIST
{
public:
bool FuncListContains(int idx,bool b)
{
return ((bool (*)(int,bool))0x0047EE03)(idx,b);
}
int FuncListGetItem(int idx)
{
return idx*2;
}
};
FUNCLIST* FuncList;
};
static MAIN* Main = (MAIN*)0x005D91B4;

Would making "FuncListContains" virtual allow me to set it's address?

Posted

why does this work

bool FuncListContains(int idx,bool b)
{
return ((bool (*)(int,bool))0x0047EE03)(idx,b);
}

But not this

bool FuncListContains(int idx,bool b)
{
return ((bool (FUNCLIST::*)(int,bool))0x0047EE03)(idx,b);
}

?

It says that it cannot typecast an int to "bool (FUNCLIST::*)(int,bool)".

Basically I want to call an address as a member without having a function pointer stored that takes up space in the classes memory.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...