Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling original function from within hooked function calls hooked function once again #25

Open
Bonjour123 opened this issue Dec 4, 2018 · 2 comments

Comments

@Bonjour123
Copy link

Bonjour123 commented Dec 4, 2018

I'm having a problem:

HookedFunction(hdc){
	DebugWrite("HookedFunction"+HtoString(hdc));
	return OriginalFunction(hdc);
}

Is writting:

 HookedFunction FFFFFFFF9C214357
 HookedFunction FFFFFFFF9C214357

I've noticed the problem when I got errors from the fact the Function was deleting an object that had already been deleted (because of the first call). This means that OriginalFunction is calling the HookedFunction once and then the "real"-untouched-original function.
Is it a bug or am I missing something ? This is not the first time I'm seing it, but last time I don't remember how the error disappeared.
I checked, there is no other calls to HookedFunction in my code, I 've cleaned and rebuilt my solution to be sure. And APIMonitor detects only one call to Function. And when I remove the call to OriginalFunction, I have only one "HookedFunction FFFFFFFF9C214357" instead of two in the debug file.

@Bonjour123
Copy link
Author

This time, the function is EndDoc, but I don't remember if it was the same function which was affected last time.

@Bonjour123
Copy link
Author

image

The hook is actually working good, but the problem is a conditional recursive call of EndDoc inside EndDoc, which calls obviously HookedEndDoc. To sum up, hookedEndDoc calls OriginalEndDOc (first 5 bytes of EndDoc) which in turn calls EndDoc +5 (so avoid the jump to hookedEndDoc). Then go to that **** line and call MFP_EndDoc, which is equivalent to EndDoc. So again inside hookedEndDoc, originalEndoc, EndDoc+5 but then, this time, take another branch and don't go to that line (call to MFP_EndDoc). That's why I had 2 calls to hookedEndDoc but no more.

How should I deal with it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant