views:

81

answers:

2

I have a hack program; it injects some functions into a target process to control it. The program is written in C++ with inline assembly.

class GameProcMain {
 // this just a class
};

GameProcMain* mainproc; // there is no problem I can do =(GameProcMain*)0xC1EA90

Now I want to define a class function (which set ecx to class pointer) instead of writing assembly.

PPLYDATA GetNearblyMob(__Vector3* cordinate) {
    __asm {
    mov ecx, 0xC1EA90
    enter code here
    push cordinate
    mov edi, 0x4A8010
    call edi
    }
}

I want to define it and call it like.

PPLYDATA (DLPL::*GetNearblyMob)(__Vector3* cordinate);

mainproc->GetNearblyMob(ADDR_CHRB->kordinat)

When I try GetNearblyMob=(PPLYDATA (DLPL::*)(__Vector3*)) 0x4A8010;

It says something like error: invalid type conversion: "int" to "PPLYDATA (DLPL::*)(int, int)"

but I can do this to set the pointer:

void initializeHack() {
__asm {
LEA edi, GetNearblyMob
MOV eax, 0x4A8010
MOV [edi], eax
}
}

Now I want to learn "how I can set GetNearblyMob without using assembly and legitimately in C++".

+1  A: 

I am a bit surprised that it won't you cast like that.

You can try to do something like

GetNearblyMob=reinterpret_cast<PPLYDATA (DLPL::*)(__Vector3*)> (0x4A8010);

If that still does not work, try

*(int*)(&GetNearblyMob) = 0x4A8010;
Thanks for you answer.first is gives this error.error: invalid type conversion: "int" to "PPLYDATA (DLPL::*)(int, int)"1> GetNearblyMob=reinterpret_cast<PPLYDATA (DLPL::*)(int, int)>(0x4A8010);the second is gives expression is non editable, when i remove
p.s. i want to click the answer is useful button but it doesn't work on my account yet:)
The second option works for me in gcc. "Expression is non editable"? That is a strange error. What is the exact wording? Maybe the function pointer is declared as const?
wow sorry, yes. i was tried (int)( i forgot to * operator :D \*(int\*)( it works thank you so much !
+1  A: 

The problem is that member functions automatically get an extra parameter for the this pointer. Sometimes you can cast between member and non-member functions, but I don't see the need to cast anything.

Typically it's easier to reverse-engineer into C functions than into C++. C typically has a more straightforward ABI, so you can keep the data structures straight as you work them out.

So, I would recommend

PPLYDATA (*GetNearblyMob)(DLPL *main_obj, __Vector3* cordinate) = 0x12345UL;

and then define your own function

class DLPL {
    GetNearblyMob( __Vector3* cordinate ) {
        return ::GetNearblyMob( this, cordinate );
    }
    // ... other program functions
};
Potatoswatter
thank you, i will use that.