I have a (so-called) function with multiple entry points but only one
I am trying to understand how to add a hook to the function.
The main problem I'm facing is the code that is placed right after this function - it can be executed at any time so I need to make sure that it won't crash the program.
My idea was to replace the
ret instruction with a
nop instruction, and then jump to my hook. At this point I'll check whether the return address matches a call to the said function, or to the function that occurs after the
I am not satisfied with this because I can't be sure that the code after
ret is the prologue of a function - it may be any code, and I have no idea how the stack will look at this point - meaning that maybe the data that was pushed into it matches a call to the function I am trying to hook.
Does anyone here have a better idea?
Edit: Forgot to mention that I can't add more than 2 jumps.