[C++ASM] Problem hooking

This topic is 3659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi guys, i'm learning hooking and i have problems with parameters..... code in asm: --- push param call realfunc realfunc: jmp mycode [C++] int _stdcall mycode(int id) { ... } --- now, the problem: id is incorrect, if i push 100 another value is found in id.....why?! i can't find out the problem.... :( edit: _stdcall is because the original asm code wants the return value into eax :)

Share on other sites
Why aren't you calling mycode(int) directly? I'm pretty sure the problem here is that you are pushing the parameter, then making a call which will push the return address, then jumping (why?) to the function you really want, which will probably then have its own prologue to set up a new stack frame - leaving your desired parameter essentially in the middle of nowhere.

Just

push paramcall mycode

Share on other sites
it's because i have to hook a function that's called in more points of a program, so the "jmp mycode" is into the start of the real function......

Share on other sites
In that case, I'm guessing the problem is still the stack frame that mycode is setting up. I'm not sure what compiler you're using, but you probably want an equivalent of __declspec(naked).

Share on other sites
What you think is the parameter might be the original return address.

Share on other sites
Quote:
 Original post by TheUnbelieverIn that case, I'm guessing the problem is still the stack frame that mycode is setting up. I'm not sure what compiler you're using, but you probably want an equivalent of __declspec(naked).

i tryed to use it, but i get problems getting the parameter.....
maybe there is another declaration specification that i have to use?

Share on other sites
Quote:
 Original post by LessBreadWhat you think is the parameter might be the original return address.

Oops. Maybe I'm talking nonsense.

Share on other sites
Quote:
 Original post by LessBreadWhat you think is the parameter might be the original return address.

yes it could be, but the return works well..... (it returns to the point after the call...)

Share on other sites
What do you get as the (wrong) value of the argument?

Share on other sites
Quote:
 Original post by LessBreadWhat you think is the parameter might be the original return address.

OMG it's true, i checked right now.....how to fix this? :(

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×

Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!