I understand that you have found this, but I am posting this answer to help anyone else.
A simple example can be found in the MobileSubstrate article on the iPhone Dev Wiki, and the actual example of this in the project is on this bit of the Faker user agent.
But what is an answer without an actual explanation? Therefore we go!
void MSHookFunction(void* function, void* replacement, void** p_original); is a function definition for MSHookFunction , a magic function that makes your X() function contain Y() , for example.
That is, when the program is usually called X() , the call will be redirected to Y() . This is pretty much the main explanation for function interpolation.
Now, what are the options and their usefulness?
function is a pointer to the function you want to insert. This would be a pointer to X() in our brief explanation.replacement is a pointer to the function with which you want to set the function . In our brief explanation, this will be a function pointer to Y() .p_original is a pointer to a function pointer, which will now indicate that there used to be a function .
The reason is that it is simple: if you intend to modify the behavior, but not suppress it, you still need to name what was X() . But a generic call to X() will not work as intended, as this will result in a call to Y() instead of the standard function .
Therefore, you have a function pointer to call X() , as if it were not inserted.
Now, explaining the devwiki example:
static void (*original_CFShow)(CFTypeRef obj);
We are here:
- Pass a pointer to
CFShow , the function we want to change the default behavior from the function parameter. - Pass the pointer to the newly created
replaced_CFShow function as the replacement parameter. That is, whenever CFShow is called by default, replaced_CFShow will be called instead. - We pass the pointer to the pointer to the
original_CFShow function as the p_original parameter. Since we still want CFShow things to continue to execute on their own in our replacement function, we call this.
Matoe source share