theos / logos

Preprocessor that simplifies Objective-C hooking.
https://theos.dev/docs/logos
Other
206 stars 34 forks source link

%orig with different instance #38

Closed pixelomer closed 5 years ago

pixelomer commented 5 years ago

There should be a way to call %orig with a different instance variable while not modifying self.

// Maybe something like this?
%origs(differentInstance); // Call %orig with different self and the original arguments
%origs(differentInstance, NULL, 42, @NO); // Call %orig with different self and arguments
NSExceptional commented 5 years ago

Imo, this is too niche of a use case for Logos to add language-level support. But it has the same problem as your other issue: logos does not easily expose the original IMP for programmer use in any context. Maybe it should.

uroboro commented 5 years ago

It actually does, I just forgot to document it at the time and nobody else noticed since'. &%orig does this. This is now documented in https://github.com/theos/logos/wiki/Syntax#orig-1.

NSExceptional commented 5 years ago

It would be nice if we had a way to retrieve it without calling the method first, but that certainly takes care of a lot of use cases. Neat!

uroboro commented 5 years ago

Fetching the original function pointer from outside the hook means that you have to provide:

Then it would be some form of:

    UIImage * image = %orig_call(UIImage, "imageNamed:", @"duck"); // _ungrouped
    UIImage * image = %orig_call(myGroup, UIImage, "imageNamed:", @"rabbit");

which would require parsing the arguments to find which one is the selector string to know if there's a group being passed as first argument.

NSExceptional commented 5 years ago

Could just make the group last instead?