美文网首页
亲手打造IconTool插件

亲手打造IconTool插件

作者: 一__谷__作气 | 来源:发表于2019-12-05 19:41 被阅读0次

    最近ios13.1.3可以越狱了,就把手机越狱了,却发现可用的插件少的可怜,对于开发来讲好多东西都不方便,比如查看BundleID,找到app的bundle目录,找到沙盒目录,好麻烦。之前的IconTool还失效了,一气之下就写了一个自用的IconTool。
    要想操作logo就要先找SpringBoard进程,然后用cy动态注入(iOS13 cy用不了,只能用cyrun辅助启动,大佬的东西就是好用)。
    先大致了解一下当前页面结构

    UIApp.keyWindow.recursiveDescription().toString ()
    

    瞬间太多内容,找到一个可疑的:SBIconView随便找一个,SetHidden:YES试一下,果然有一个隐藏了,那就是他了。
    找到SBIconView的头文件,有touchesBegan和touchesEnded方法,先实现捕捉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,先定下目标,一个一个实现,有copyBundleID,修改App的名字,修改角标,在Filza跳转到app的Bundle路径,跳转到沙盒路径

    -(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:@"复制BundleID" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
                pastboard.string = bundleID;
            }];
            UIAlertAction *ReNameIcon = [UIAlertAction actionWithTitle:@"图标重命名" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [self iconRenameWithBundleID:bundleID onTheApp:app];
            }];
    
    
            UIAlertAction *setBadgeAction = [UIAlertAction actionWithTitle:@"自定义角标" 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文件中发现,有个icon 属性比较可疑,就在cy中去运行一下得到另一个类:SBApplicationIcon,查看这个类的头文件就发现另一个很重要的信息applicationBundleID,cy尝试一下,果然可以。还意外的发现了一个application属性,得到了当前的程序SBApplication。第一个顺利解决!!!

    功能二:图标重命名

    在SBIconView.h文件中搜索Label,果然有一个方法

    -(void)labelView;
    

    尝试一下得到SBIconLegibilityLabelView,此类中有一个imageParameters,得到SBIconLabelImageParameters,再往下找有个text属性,找到了。那我们开始,但是要替换,必须要搞一个文件保存,就借鉴一下之前的老版的IconTool的方法,以bundleID为键,以输入的文本为值,保存在plist文件中。然后刷新UI,在加载的时候hook加载的方法,更改特定的程序名称为新值。
    下一步找加载的方法,找了好多displayname,都是readonly,无法修改,那就直接hook,找到当前的程序类SBApplication,hook该类的方法:
    -(id)displayName;

    上代码

    -(void)iconRenameWithBundleID:(NSString *)bundleID onTheApp:(id)app
    {
        SBIconLegibilityLabelView * labelView = [self labelView];
        SBIconLabelImageParameters * Parameters = [labelView imageParameters];
        NSString *title = [NSString stringWithFormat:@"%@ 图标重命名",Parameters.text];
        UIAlertController *ReNameAlertVC = [UIAlertController alertControllerWithTitle:title message:@"请输入新的名称" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction* actionDefault = [UIAlertAction actionWithTitle:@"更改" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //保存数据
            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,借用更改角标来刷新UI;
            id str = [app badgeValue];
            [app setBadgeValue:0];
            [app setBadgeValue:str];
        }];
    
        UIAlertAction* recoverDefault = [UIAlertAction actionWithTitle:@"恢复" 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,借用更改角标来刷新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
    

    第二个功能完工。

    功能三:修改角标

    这个比较简单,因为我在找修改name的时候发现了SBApplication类中有个方法:-(void)setBadgeValue;正中下怀。

    -(void)myBadgeNumberOnTheApp:(id)app
    {
        SBIconLegibilityLabelView * labelView = [self labelView];
        SBIconLabelImageParameters * Parameters = [labelView imageParameters];
        NSString *title = [NSString stringWithFormat:@"%@ 设定角标",Parameters.text];
        UIAlertController *badgeAlertVC = [UIAlertController alertControllerWithTitle:title message:@"请输入新的角标" 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];
    }
    

    功能四五:跳转到Filza中对应的bundle位置和沙盒位置

    先通过SBApplication找到程序的信息
    其中最初的SBIconView有一个方法
    -(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];
            }];
    

    全部分析完毕,至于代码我发布到了Github,但是现在仅限于iOS13.1.3,没有其他设备不能尝试。。。
    https://github.com/GFGWin/IconToolForiOS13.1.3
    希望对你们有用!!

    相关文章

      网友评论

          本文标题:亲手打造IconTool插件

          本文链接:https://www.haomeiwen.com/subject/brdjgctx.html