Microsoft Word - iOSAppReverseEngineering.docx

(Romina) #1

² %ctor


The constructor of a tweak, it is the first function to be called in the tweak. If we don’t


define a constructor explicitly, Theos will create one for us automatically, and call


%init(_ungrouped) inside it.


%hook SpringBoard


  • (void)reboot
    {
    NSLog(@"If rebooting doesn’t work then I’m screwed.");
    %orig;
    }
    %end


The above code works fine, because Theos has called %init implicitly like this:


%ctor
{
%init(_ungrouped);
}

However,


%hook SpringBoard


  • (void)reboot
    {
    NSLog(@"If rebooting doesn’t work then I’m screwed.");
    %orig;
    }
    %end


%ctor
{
// Need to call %init explicitly!
}

This %hook never works, because we’ve defined %ctor explicitly without calling %init


explicitly, there lacks a %group(_ungrouped). Generally, %ctor is used to call %init and


MSHookFunction, for example:


#ifndef kCFCoreFoundationVersionNumber_iOS_8_0
#define kCFCoreFoundationVersionNumber_iOS_8_0 1140.10
#endif

%ctor
{
%init;
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0 &&
kCFCoreFoundationVersionNumber <
kCFCoreFoundationVersionNumber_iOS_8_0) %init(iOS7Hook);
if (kCFCoreFoundationVersionNumber >=
kCFCoreFoundationVersionNumber_iOS_8_0) %init(iOS8Hook);
MSHookFunction((void *)&AudioServicesPlaySystemSound,
(void *)&replaced_AudioServicesPlaySystemSound,
(void **)&original_AudioServicesPlaySystemSound);
}
Attention, %ctor doesn’t end with %end.
Free download pdf