Defining a new %property inside %group which lies within a %hook
Nosskirneh opened this issue · 2 comments
Nosskirneh commented
Hi,
So I just stumbled upon this bug:
%hook ClassToBeHooked
%property (nonatomic, retain) MyClass *baseProperty;
- (void)methodThatAlwaysShouldBeHooked {
%orig;
...
}
%group ConditionalGroup
%property (nonatomic, retain) MyClass *conditionalProperty;
- (void)conditionalMethod {
%orig;
self.conditionalProperty = ...
...
}
%end
%end
%ctor {
%init();
if ([%c(ClassToBeHooked) instancesRespondToSelector:@selector(conditionalMethod:)])
%init(ConditionalGroup);
}
}
This does not work. It computes error messages when building.
==> Compiling Tweak.xm (arm64)…
Tweak.xm:157:917: error: use of undeclared identifier '_logos_class$ConditionalGroup$ClassToBeHooked'; did you mean '_logos_class$_ungrouped$ClassToBeHooked'?
..._typeEncoding); } { char _typeEncoding[1024]; sprintf(_typeEncoding, "%s@:", @encode(SAViewController *)); class_addMethod(_logos_class$ConditionalGroup$ClassToBeHooked, @selector(conditionalProperty), (IMP)&_logos_m...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_logos_class$_ungrouped$ClassToBeHooked
Tweak.xm:157:16: note: '_logos_class$_ungrouped$ClassToBeHooked' declared here
{Class _logos_class$_ungrouped$ClassToBeHooked = objc_getClass("ClassToBeHooked"); MSHookMessageEx(_logos_class$_ungrouped$ClassToBeHooked, @selector(grabberTongueWillPresent:), (IMP)&_logos_method$_ungrouped...
^
Tweak.xm:157:1164: error: use of undeclared identifier '_logos_class$ConditionalGroup$ClassToBeHooked'; did you mean '_logos_class$_ungrouped$ClassToBeHooked'?
..._typeEncoding); sprintf(_typeEncoding, "v@:%s", @encode(SAViewController *)); class_addMethod(_logos_class$ConditionalGroup$ClassToBeHooked, @selector(setConditionalProperty:), (IMP)&_logos_method$ConditionalGroup$Cl...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_logos_class$_ungrouped$ClassToBeHooked
Tweak.xm:157:16: note: '_logos_class$_ungrouped$ClassToBeHooked' declared here
{Class _logos_class$_ungrouped$ClassToBeHooked = objc_getClass("ClassToBeHooked"); MSHookMessageEx(_logos_class$_ungrouped$ClassToBeHooked, @selector(grabberTongueWillPresent:), (IMP)&_logos_method$_ungrouped...
^
2 errors generated.
It can be solved by putting the %property
in the original %hook
'ed section and not within the conditional group.
uroboro commented
This is not the proper usage of %group
. You're not meant to put %group
s within %hook
s. Please refer to the documentation for more information.
(Logos structure is such that %group
contains %hook
s and %hookf
s, not the other way around)
Nosskirneh commented
Fair enough. I haven't dug through the documentation to be honest, but it always was possible to write
%hook ClassToBeHooked
%group SomeiOSVersion
- (void)someMethodA {
...
}
%end
%group SomeOtheriOSVersion
- (void)someMethodB {
...
}
%end
%end
which is shorter than having to do
%group SomeiOSVersion
%hook ClassToBeHooked
- (void)someMethodA {
...
}
%end
%end
%group SomeOtheriOSVersion
%hook ClassToBeHooked
- (void)someMethodB {
...
}
%end
%end
which was the reason I thought it was the desired behavior.