theos/logos

Can't hook functions with a ... arg

Closed this issue · 4 comments

Attempting to hook a function with a ... argument will throw a syntax error when you try to call %orig.

For example, the code:

%hookf (id, objc_msgSend, id self, SEL op, ...)
{
    NSLog(@"test");
    return %orig;
}

will throw the error:

error: expected expression
    return _logos_orig$_ungrouped$objc_msgSend(self, op, ...);
                                                         ^

Hooking vararg functions is very much nontrivial. It would have to either parse out va_args and and regenerate the arguments dynamically to make orig work, probably requiring ASM code, or have asm code to only hook when the number of args are a known value. I don’t really think this is something logos should be expected to be able to just do for you. If you have the other thing where you can have a pointer to orig and call it yourself it would probably allow you to implement something like this yourself... when I did it, I used a custom ASM hook to only intercept calls for one specific thing where I knew the number of arguments.

I realise, uroboro explained the whole thing to me before I made the issue, but asked me to make it anyway so he could reference it later. He said he might add support for it if it was at all feasible and if he had enough time on his hands to manually make a function to move all the elements in the va_list to the correct registers and manually call the function etc.

I asked @Muirey03 to make this issue so that I can emit a warning when hooking variadic functions. %orig wouldn’t work unless you explicitly pass arguments to it.

f86ba42 emits a warning when lacking explicit arguments.