由于最开始便从小黄书中接触到logos,所以对logos情有独钟。logos的hook逻辑写起来简单,适合吾等Script Boy。但今日想屏蔽某个App两个烦人的推荐会员弹窗时候,却遇到了问题。
由于iOS8开始Apple强推UIAlertController这个类,并且把UIAlertView标为废弃。所以在iOS8开始会出现弹窗不确定由哪个类弹出来。笔者想分别hook对应的初始化函数来确定弹窗是哪个类弹的。
UIAlertView最常用的初始化函数在Apple给的头文件中是这样的签名
- (instancetype)initWithTitle:(nullable NSString )title message:(nullable NSString )message delegate:(nullable id //)delegate cancelButtonTitle:(nullable NSString *)cancelButtonTitle otherButtonTitles:(nullable NSString *)otherButtonTitles, … NS_REQUIRES_NIL_TERMINATION NS_EXTENSION_UNAVAILABLE_IOS(“Use UIAlertController instead.”);
按照以往去掉nullable这些logos不认的修饰符以及NS_EXTENSION_UNAVAILABLE_IOS(“Use UIAlertController instead.”);这个标志废气的宏
%hook UIAlertView
-
(instancetype)initWithTitle:(NSString )title message:(NSString )message delegate:(id //)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, … {
NSLog(@“hook alertview initWithTitle method”);
%orig;
}
%end
尝试make package 出现错误
Making all for tweak zz…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (armv7)…
Tweak.xm:28:318: error: expected unqualified-id
…UIAlertView* self, SEL _cmd, NSString * title, NSString * message, id delegate, NSString * cancelButtonTitle, NSString * otherButtonTitles) _LOGOS_RETURN_RETAINED, … {
^
Tweak.xm:28:316: error: expected ‘;’ after top level declarator
…UIAlertView* self, SEL _cmd, NSString * title, NSString * message, id delegate, NSString * cancelButtonTitle, NSString * otherButtonTitles) _LOGOS_RETURN_RETAINED, … {
^
使用logos.pl处理xm为mm文件后,发现是这一步处理出现了问题
static UIAlertView* _logos_method$_ungrouped$UIAlertView$initWithTitle$message$delegate$cancelButtonTitle$otherButtonTitles$(_LOGOS_SELF_TYPE_INIT UIAlertView* self, SEL _cmd, NSString * title, NSString * message, id delegate, NSString * cancelButtonTitle, NSString * otherButtonTitles) _LOGOS_RETURN_RETAINED, … {
NSLog(@"hook alertview initWithTitle method");
_logos_orig$_ungrouped$UIAlertView$initWithTitle$message$delegate$cancelButtonTitle$otherButtonTitles$(self, _cmd, title, message, delegate, cancelButtonTitle, otherButtonTitles);
}
刚才的hook被处理为了这个样子,不知道手动修正,…进入到括号内是不是可以解决这个问题的。尝试翻阅logos的wiki,没有发现类似的疑问,可能是我关键字搜索的问题。
最终笔者通过cycript 的choose查找了类是UIAlertView 并屏蔽掉了show方法解决了问题。但是至今仍然没能想明白logos编写才能正确处理这个函数签名