theos / logos

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

Remove superfluous `LHHookFunctions` when no C hooks are present #103

Closed L1ghtmann closed 10 months ago

L1ghtmann commented 1 year ago

What does this implement/fix? Explain your changes.

See title

Does this close any currently open issues?

Nope

Any relevant logs, error output, etc?

Any other comments?

On two separate setups -- iOS and Linux (WSL) -- building a simple one hook, one method tweak with the libhooker generator seems to append a LHHookFunctions() call at the end of the normal hooking logic. This causes a compiler error as the first arg is blank due to an empty structs array.

Am unsure if that call should be removed outright or not, and don't believe I am familiar enough with the codebase to fix that, so went ahead and added a fallback arg.

Where has this been tested?

Operating System:

Linux (WSL) & iP7 iOS 14.3 u0

Platform:

Target Platform:

Toolchain Version:

SDK Version:

uroboro commented 1 year ago

Do you have the source file and the logos'd output? I don't think an empty LHHookFunctions() call should be generated if there are no hooks to be made, and if there are hooks to be made then it should have had a struct argument.

L1ghtmann commented 1 year ago

test.x

%hook class
-(void)method{}
%end

$THEOS/bin/logos.pl -c generator=libhooker test.x

test.x.m

#line 1 "test.x"

@import libhooker.libblackjack;
@import ObjectiveC.runtime;
#if defined(__clang__)
#if __has_feature(objc_arc)
#define _LOGOS_SELF_TYPE_NORMAL __unsafe_unretained
#define _LOGOS_SELF_TYPE_INIT __attribute__((ns_consumed))
#define _LOGOS_SELF_CONST const
#define _LOGOS_RETURN_RETAINED __attribute__((ns_returns_retained))
#else
#define _LOGOS_SELF_TYPE_NORMAL
#define _LOGOS_SELF_TYPE_INIT
#define _LOGOS_SELF_CONST
#define _LOGOS_RETURN_RETAINED
#endif
#else
#define _LOGOS_SELF_TYPE_NORMAL
#define _LOGOS_SELF_TYPE_INIT
#define _LOGOS_SELF_CONST
#define _LOGOS_RETURN_RETAINED
#endif

@class class; 
static void (*_logos_orig$_ungrouped$class$method)(_LOGOS_SELF_TYPE_NORMAL class* _LOGOS_SELF_CONST, SEL); static void _logos_method$_ungrouped$class$method(_LOGOS_SELF_TYPE_NORMAL class* _LOGOS_SELF_CONST, SEL); 

#line 1 "test.x"

static void _logos_method$_ungrouped$class$method(_LOGOS_SELF_TYPE_NORMAL class* _LOGOS_SELF_CONST __unused self, SEL __unused _cmd){}

static __attribute__((constructor)) void _logosLocalInit() {
{Class _logos_class$_ungrouped$class = objc_getClass("class"); LBHookMessage(_logos_class$_ungrouped$class, @selector(method), (void *)&_logos_method$_ungrouped$class$method, (void *)&_logos_orig$_ungrouped$class$method);LHHookFunctions(, 0);} }
#line 4 "test.x"