一土涝、去掉桌面App的紅色BadgeValue數(shù)字
桌面是一個App恩尾,叫做SpringBoard烁峭,路徑在/System/Library/CoreServices/SpringBoard.app
1囱稽、導(dǎo)出頭文件
class-dump -H SpringBoard -o headers
2郊尝、由于Reveal不能查看SpringBoard界面,所有我們使用cycript來獲取紅色BadgeValue視圖類型為SBIconParallaxBadgeView战惊。
3流昏、編寫tweak文件
%hook SBIconParallaxBadgeView
- (id)init {
return nil;
}
%end
4、打包并安裝插件
make package install
二吞获、喜馬拉雅App賬號頁面添加兩行文字
tweak項目的圖片資源路徑
相關(guān)代碼Tweak.xm文件內(nèi)容
#define CHNPath(path) (@"/Library/PreferenceLoader/Preferences/chnabc/" #path)
#define CHNUserDefault [NSUserDefaults standardUserDefaults]
#define CHNADKey (@"CHN_AD_Key")
%hook XMMeViewController
- (long long)numberOfSectionsInTableView:(id)arg1 {
return %orig + 1;
}
- (long long)tableView:(id)arg1 numberOfRowsInSection:(long long)section {
if (section == [self numberOfSectionsInTableView:arg1]-1) {
return 2;
}
return %orig;
}
- (double)tableView:(id)arg1 heightForRowAtIndexPath:(id)indexPath {
if ([indexPath section] == [self numberOfSectionsInTableView:arg1]-1) {
return 44;
}
return %orig;
}
- (id)tableView:(id)tableView cellForRowAtIndexPath:(id)indexPath {
if ([indexPath section] == [self numberOfSectionsInTableView:tableView]-1) {
NSString *cellId = nil;
if ([indexPath row] == 0) {
cellId = @"switchCellId";
}else{
cellId = @"quitCellId";
}
UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:cellId];
if (nil == cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
cell.backgroundColor = [UIColor whiteColor];
cell.imageView.image = [UIImage imageNamed:CHNPath(hot.png)];
}
if ([indexPath row] == 0) {
cell.textLabel.text = @"關(guān)閉廣告";
UISwitch *s = [[UISwitch alloc] init];
[s addTarget:self action:@selector(changeAdState:) forControlEvents:UIControlEventValueChanged];
s.on = [CHNUserDefault boolForKey:CHNADKey];
cell.accessoryView = s;
}else{
cell.textLabel.text = @"推出喜馬拉雅";
}
return cell;
}
return %orig;
}
- (void)tableView:(id)tableView didSelectRowAtIndexPath:(id)indexPath {
if ([indexPath section] == [self numberOfSectionsInTableView:tableView]-1) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([indexPath row] == 1) {
abort();
}
return;
}
%orig;
}
%new
- (void)changeAdState:(UISwitch *)s {
[CHNUserDefault setBool:s.isOn forKey:CHNADKey];
[CHNUserDefault synchronize];
}
%end
注意:
如果需要取消自己修改的功能况凉,在/Library/MobileSubstrate/DynamicLibraries路徑下刪除對應(yīng)的動態(tài)庫和plist文件即可。
三各拷、tweak原理
1刁绒、安裝過程
- make
將tweak項目代碼編譯生成一個動態(tài)庫,***.dylib - make package
將動態(tài)庫等文件壓縮打包成deb文件 - make install
將deb文件傳到iPhone上烤黍,iPhone的Cydia中的Cydia Substrate插件將deb文件解壓放到/Library/MobileSubstrate/DynamicLibraries路徑下
2知市、運行原理
iPhone將對應(yīng)的app運行起來后傻盟,如果/Library/MobileSubstrate/DynamicLibraries里面的plist文件中有對應(yīng)bundleid的plist文件,會將/Library/MobileSubstrate/DynamicLibraries下面的dylib動態(tài)庫加載到內(nèi)存中,在實際調(diào)用相關(guān)修改的函數(shù)時嫂丙,會去調(diào)用dylib包里面我們自己實現(xiàn)的函數(shù)娘赴。
所以,tweak知識修改了內(nèi)存中運行的程序跟啤,app本身的可執(zhí)行文件并沒有改變筝闹。
四、花生地鐵去廣告
//去掉廣告
%hook AdvertisementModel
- (id)init {
return nil;
}
%end
//刪除右側(cè)抽獎廣告
UIView *_susupendBannerBgView;
%hook NewsViewController
- (id)susupendBannerBgView {
[_susupendBannerBgView removeFromSuperview];
return nil;
}
%end
//刪除啟動廣告
%hook HSNativeInterstitialView
- (id)initWithSpotNumber:(id)arg1 sourceViewController:(id)arg2 {
return nil;
}
%end