親手打造IconTool插件

最近ios13.1.3可以越獄了,就把手機(jī)越獄了,卻發(fā)現(xiàn)可用的插件少的可憐,對(duì)于開發(fā)來講好多東西都不方便,比如查看BundleID,找到app的bundle目錄,找到沙盒目錄,好麻煩。之前的IconTool還失效了,一氣之下就寫了一個(gè)自用的IconTool。
要想操作logo就要先找SpringBoard進(jìn)程,然后用cy動(dòng)態(tài)注入(iOS13 cy用不了,只能用cyrun輔助啟動(dòng),大佬的東西就是好用)。
先大致了解一下當(dāng)前頁面結(jié)構(gòu)

UIApp.keyWindow.recursiveDescription().toString ()

瞬間太多內(nèi)容,找到一個(gè)可疑的:SBIconView隨便找一個(gè),SetHidden:YES試一下,果然有一個(gè)隱藏了,那就是他了。
找到SBIconView的頭文件,有touchesBegan和touchesEnded方法,先實(shí)現(xiàn)捕捉logo上滑的操作。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{
    %orig;
    UITouch *touch = [touches anyObject];
    gestureStartPoint= [touch locationInView:[(UIView *)self superview]];//開始觸摸
}


-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    %orig;
    UITouch *touch = [touches anyObject];
    
    CGPoint currentPosition = [touch locationInView:[(UIView *)self superview]];
    
    CGFloat deltaX = (gestureStartPoint.x - currentPosition.x);
    
    CGFloat deltaY = gestureStartPoint.y - currentPosition.y;
    
    float MINDISTANCE = sqrt(deltaX * deltaX + deltaY * deltaY)/2; 
    if(fabs(deltaY) > fabs(deltaX))
    {
        if (deltaY > MINDISTANCE)
        {
            [self handleSwipeFrom];
        }      
    }
}

上滑之后彈出UIAlertController,先定下目標(biāo),一個(gè)一個(gè)實(shí)現(xiàn),有copyBundleID,修改App的名字,修改角標(biāo),在Filza跳轉(zhuǎn)到app的Bundle路徑,跳轉(zhuǎn)到沙盒路徑

-(void)handleSwipeFrom
{
    NSString * bundleID = [[self icon] applicationBundleID];
    id app = [[self icon] application];
    if (bundleID)
    {
        currentVC = [self getCurrentVC];
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:bundleID message:nil preferredStyle: UIAlertControllerStyleActionSheet];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        UIAlertAction *archiveAction = [UIAlertAction actionWithTitle:@"復(fù)制BundleID" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
            pastboard.string = bundleID;
        }];
        UIAlertAction *ReNameIcon = [UIAlertAction actionWithTitle:@"圖標(biāo)重命名" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self iconRenameWithBundleID:bundleID onTheApp:app];
        }];


        UIAlertAction *setBadgeAction = [UIAlertAction actionWithTitle:@"自定義角標(biāo)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self myBadgeNumberOnTheApp:app];
        }];
        UIAlertAction *getBundleAction = [UIAlertAction actionWithTitle:@"在Filza中打開(App)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString * bundlePath = [(NSURL *)[self applicationBundleURL] path];
            [self jumpToApp:bundlePath];
        }];
        UIAlertAction *getSandBoxAction = [UIAlertAction actionWithTitle:@"在Filza中打開(Data)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString * homePath = [(NSURL *)[[app info] dataContainerURL] path];
            [self jumpToApp:homePath];
        }];

        [alertController addAction:cancelAction];
        [alertController addAction:archiveAction];
        [alertController addAction:ReNameIcon];
        [alertController addAction:setBadgeAction];
        [alertController addAction:getBundleAction];
        [alertController addAction:getSandBoxAction];
        [currentVC presentViewController:alertController animated:YES completion:nil];
    }
}

功能一:獲取BundleID

在dump出的SBIconView.h文件中發(fā)現(xiàn),有個(gè)icon 屬性比較可疑,就在cy中去運(yùn)行一下得到另一個(gè)類:SBApplicationIcon,查看這個(gè)類的頭文件就發(fā)現(xiàn)另一個(gè)很重要的信息applicationBundleID,cy嘗試一下,果然可以。還意外的發(fā)現(xiàn)了一個(gè)application屬性,得到了當(dāng)前的程序SBApplication。第一個(gè)順利解決?。?!

功能二:圖標(biāo)重命名

在SBIconView.h文件中搜索Label,果然有一個(gè)方法

-(void)labelView;

嘗試一下得到SBIconLegibilityLabelView,此類中有一個(gè)imageParameters,得到SBIconLabelImageParameters,再往下找有個(gè)text屬性,找到了。那我們開始,但是要替換,必須要搞一個(gè)文件保存,就借鑒一下之前的老版的IconTool的方法,以bundleID為鍵,以輸入的文本為值,保存在plist文件中。然后刷新UI,在加載的時(shí)候hook加載的方法,更改特定的程序名稱為新值。
下一步找加載的方法,找了好多displayname,都是readonly,無法修改,那就直接hook,找到當(dāng)前的程序類SBApplication,hook該類的方法:
-(id)displayName;

上代碼

-(void)iconRenameWithBundleID:(NSString *)bundleID onTheApp:(id)app
{
    SBIconLegibilityLabelView * labelView = [self labelView];
    SBIconLabelImageParameters * Parameters = [labelView imageParameters];
    NSString *title = [NSString stringWithFormat:@"%@ 圖標(biāo)重命名",Parameters.text];
    UIAlertController *ReNameAlertVC = [UIAlertController alertControllerWithTitle:title message:@"請(qǐng)輸入新的名稱" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* actionDefault = [UIAlertAction actionWithTitle:@"更改" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //保存數(shù)據(jù)
        NewIconName = [ReNameAlertVC.textFields firstObject].text;
        NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithContentsOfFile:@kSettingsFilePath];
        if (dic.allKeys>0)
        {
            [dic setObject:NewIconName forKey:bundleID];
            [dic writeToFile:@kSettingsFilePath atomically:YES];
        }else
        {
            NSMutableDictionary * dic1 = [[NSMutableDictionary alloc]init];
            [dic1 setObject:NewIconName forKey:bundleID];
            [dic1 writeToFile:@kSettingsFilePath atomically:YES];
        }
                
        //刷新UI,借用更改角標(biāo)來刷新UI;
        id str = [app badgeValue];
        [app setBadgeValue:0];
        [app setBadgeValue:str];
    }];

    UIAlertAction* recoverDefault = [UIAlertAction actionWithTitle:@"恢復(fù)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithContentsOfFile:@kSettingsFilePath];
        if (dic.allKeys>0)
        {
            if ([dic.allKeys containsObject:bundleID])
            {
                [dic removeObjectForKey:bundleID];
                [dic writeToFile:@kSettingsFilePath atomically:YES];
            }
        }      
        //刷新UI,借用更改角標(biāo)來刷新UI;
        id str = [app badgeValue];
        [app setBadgeValue:0];
        [app setBadgeValue:str];
    }]; 

    UIAlertAction* actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [ReNameAlertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

    }];

    [ReNameAlertVC addAction:actionDefault];
    [ReNameAlertVC addAction:recoverDefault];
    [ReNameAlertVC addAction:actionCancel];
    [currentVC presentViewController:ReNameAlertVC animated:YES completion:nil];
}

%hook SBApplication
- (id)displayName{
    NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithContentsOfFile:@kSettingsFilePath];
    if (dic.allKeys>0)
    {
       for (int i = 0; i < dic.allKeys.count; i++)
       {
           if ([self.bundleIdentifier isEqualToString:dic.allKeys[i]])
           {
               return [dic objectForKey:dic.allKeys[i]];
           }
       }
    }
    return %orig;
}
%end

第二個(gè)功能完工。

功能三:修改角標(biāo)

這個(gè)比較簡(jiǎn)單,因?yàn)槲以谡倚薷膎ame的時(shí)候發(fā)現(xiàn)了SBApplication類中有個(gè)方法:-(void)setBadgeValue;正中下懷。

-(void)myBadgeNumberOnTheApp:(id)app
{
    SBIconLegibilityLabelView * labelView = [self labelView];
    SBIconLabelImageParameters * Parameters = [labelView imageParameters];
    NSString *title = [NSString stringWithFormat:@"%@ 設(shè)定角標(biāo)",Parameters.text];
    UIAlertController *badgeAlertVC = [UIAlertController alertControllerWithTitle:title message:@"請(qǐng)輸入新的角標(biāo)" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* actionDefault = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        id number = [badgeAlertVC.textFields firstObject].text;
        [app setBadgeValue:number];
    }];
            
    UIAlertAction* actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [badgeAlertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

    }];
    [badgeAlertVC addAction:actionDefault];
    [badgeAlertVC addAction:actionCancel];
    [currentVC presentViewController:badgeAlertVC animated:YES completion:nil];
}

功能四五:跳轉(zhuǎn)到Filza中對(duì)應(yīng)的bundle位置和沙盒位置

先通過SBApplication找到程序的信息
其中最初的SBIconView有一個(gè)方法
-(id)applicationBundleURL;
剛好可以得到bundle地址。
至于沙盒路徑通過SBApplication的info屬性得到SBApplicationInfo類,SBApplicationInfo類找到
-(id)dataContainerURL;
分析完畢。

UIAlertAction *getBundleAction = [UIAlertAction actionWithTitle:@"在Filza中打開(App)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString * bundlePath = [(NSURL *)[self applicationBundleURL] path];
            [self jumpToApp:bundlePath];
        }];
        UIAlertAction *getSandBoxAction = [UIAlertAction actionWithTitle:@"在Filza中打開(Data)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSString * homePath = [(NSURL *)[[app info] dataContainerURL] path];
            [self jumpToApp:homePath];
        }];

全部分析完畢,至于代碼我發(fā)布到了Github,但是現(xiàn)在僅限于iOS13.1.3,沒有其他設(shè)備不能嘗試。。。
https://github.com/GFGWin/IconToolForiOS13.1.3
希望對(duì)你們有用??!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴(yán)謹(jǐn) 對(duì)...
    cosWriter閱讀 11,632評(píng)論 1 32
  • 工具 class-dump 用來提取已經(jīng)砸過殼的 app 的頭文件 下載地址 http://stevenygard...
    輝g_9274閱讀 2,804評(píng)論 1 7
  • 2016-2017年是插件化遍地開花的一年,各家大廠都開源了自己的插件化框架、熱修復(fù)技術(shù),網(wǎng)上也已經(jīng)有許多介紹和分...
    Geek帆哥閱讀 3,000評(píng)論 2 9
  • 8.第一個(gè)逆向程序 創(chuàng)建tweak工程? iOS /opt/theos/bin/nic.pl NIC 2.0 -...
    Flonger閱讀 3,109評(píng)論 0 1
  • 因果必報(bào)是符合自然法規(guī)就比如春天把種子埋在地里經(jīng)過溫度陽光雨水的滋潤它就發(fā)芽開花結(jié)果因果必報(bào)是需要時(shí)間過程不能因?yàn)?..
    孟現(xiàn)捧閱讀 183評(píng)論 0 0

友情鏈接更多精彩內(nèi)容