飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 5044|回复: 8

[iOS] Hook - 允许删除系统application

[复制链接]
  • TA的每日心情
    难过
    前天 14:49
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    发表于 2015-11-3 14:47:21 | 显示全部楼层 |阅读模式
    敬告:飘云阁论坛原创,转载请注明出处 https://www.chinapyg.com

    起因:
    在cydia安装的软件,桌面上不能删除, 造成用户体验问题

    方案:
    hook SpirngBoard 让图标出现叉叉并对删除事件进行处理

    Demo:

    [Objective-C] 纯文本查看 复制代码
    /*
     System Application 允许卸载
     作者:飘云
     日期:2015-11-03
     网站:[url=http://www.dllhook.com]www.dllhook.com[/url]
     */
    #import <UIKit/UIKit.h>
    
    #define LEAF_IDENTIFIER @"com.chinapyg.test"
    
    @interface SBIcon : NSObject
    
    - (id)leafIdentifier;
    
    @end
    
    @interface SBLeafIcon : SBIcon
    
    - (BOOL)allowsUninstall;
    - (id)leafIdentifier;
    
    @end
    
    
    @interface SBIconView : UIView
    
    - (SBIcon *)icon;
    
    @end
    
    @interface SBApplicationIcon : SBLeafIcon
    
    @end
    
    @interface SBIconModel : NSObject {
        NSDictionary *_leafIconsByIdentifier;
    }
    @property (nonatomic,retain) NSDictionary *leafIconsByIdentifier;
    @end
        
    @interface SBIconController : UIViewController {
        SBIconModel *_iconModel;
    }
    + (id)sharedInstance;
    - (void)uninstallIcon:(SBApplicationIcon *)applicationIcon animate:(char)animate;
    @end
    
    @interface SBApplication : NSObject
    
    @end
    
    @interface SBApplicationController : NSObject {
        NSMutableDictionary* _applicationsByBundleIdentifer;
    }
    - (void)uninstallApplication:(SBApplication *)application;
    @end
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    @interface PYUninstallManager : NSObject
    
    + (void)unistallIPA:(id)leafIdentifier;
    
    @end
    
    @implementation PYUninstallManager
    
    + (void)unistallIPA:(id)leafIdentifier {
        static Class clsSBIconController = nil;
        if(!clsSBIconController) {
            clsSBIconController = NSClassFromString(@"SBIconController");
        }
    
        static Class clsSBApplicationController = nil;
        if(!clsSBApplicationController) {
            clsSBApplicationController = NSClassFromString(@"SBApplicationController");
        }
    
        SBIconController *$SBIconController  = [clsSBIconController sharedInstance];
        if (!$SBIconController) {
            return;
        }
    
        SBIconModel *iconModel = [$SBIconController valueForKey:@"_iconModel"];
        if (!iconModel) {
            return;
        }
        //NSLog(@"iconModel = %@", iconModel);
        NSDictionary *leafIconsByIdentifier = [iconModel leafIconsByIdentifier];
        if (!leafIconsByIdentifier) {
            return;
        }
    
        //NSLog(@"leafIconsByIdentifier = %@", leafIconsByIdentifier);
        SBApplicationIcon *applicationIcon = [leafIconsByIdentifier objectForKey:leafIdentifier];
    
        if (!applicationIcon) {
            return;
        }
    
        // 卸载桌面图标
        [$SBIconController uninstallIcon:applicationIcon animate:YES];
    
    
        SBApplicationController *$SBApplicationController  = [clsSBApplicationController sharedInstance];
        if (!$SBApplicationController) {
            return;
        }
    
        NSMutableDictionary *applicationsByBundleIdentifer = [$SBApplicationController valueForKey:@"_applicationsByBundleIdentifer"];
        if (!applicationsByBundleIdentifer) {
            return;
        }
        NSLog(@"applicationsByBundleIdentifer = %@", applicationsByBundleIdentifer);
    
        SBApplication *application = [applicationsByBundleIdentifer objectForKey:leafIdentifier];
    
        if (!application) {
            return;
        }
        // 卸载程序
        [$SBApplicationController uninstallApplication:application];
    
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    
    %hook SBLeafIcon
    
    - (BOOL)allowsUninstall {
        %log;
        NSLog(@"[++++]into SBLeafIcon:allowsUninstall");
        NSString *nsLeafIdentifier = [self leafIdentifier];
        if([nsLeafIdentifier isEqualToString:LEAF_IDENTIFIER]) {
            NSLog(@"%@允许卸载", LEAF_IDENTIFIER);
            return YES;
        }
    
        return %orig;
    }
    
    %end
    
    %hook SBIconController
    
    - (void)iconCloseBoxTapped:(SBIconView *)iconView{
        %log;
        NSLog(@"[++++]into SBIconControl::iconCloseBoxTapped");
    
        SBIcon *icon = [iconView performSelector:@selector(icon)];
        NSLog(@"[++++]icon = %@", icon);
        
        if([icon respondsToSelector:@selector(leafIdentifier)]) {
            NSString *nsLeafIdentifier = [icon leafIdentifier];
            
            if([nsLeafIdentifier isEqualToString:LEAF_IDENTIFIER]) {
                // TODO: 这里自己实现卸载过程...
                NSLog(@"[++++]准备卸载%@....", LEAF_IDENTIFIER);
                [PYUninstallManager unistallIPA:LEAF_IDENTIFIER];
                // 这里还要做一些清理的事情--不是重点...略过
                system("rm -rf \\\"/Applications/ChinapygTest.app\\\"");
            }
        }
        
    }
    
    %end
    
    %ctor {
        NSLog(@"[++++]AllowsUninstall inject success  By PiaoYun/P.Y.G!!!");
    }
    

    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2019-3-17 22:44
  • 签到天数: 132 天

    [LV.7]常住居民III

    发表于 2015-11-3 16:50:25 | 显示全部楼层
    学习了。重装软件的话……

    点评

    这只是某项目里面需要这么做。自己玩的话 当然在Cydia里面卸载~~  详情 回复 发表于 2015-11-3 17:09
    PYG19周年生日快乐!
  • TA的每日心情
    难过
    前天 14:49
  • 签到天数: 11 天

    [LV.3]偶尔看看II

     楼主| 发表于 2015-11-3 17:09:14 | 显示全部楼层
    tree_fly 发表于 2015-11-3 16:50
    学习了。重装软件的话……

    这只是某项目里面需要这么做。自己玩的话 当然在Cydia里面卸载~~

    PYG19周年生日快乐!
  • TA的每日心情
    奋斗
    2021-9-29 15:05
  • 签到天数: 114 天

    [LV.6]常住居民II

    发表于 2015-11-3 19:09:50 | 显示全部楼层
    好像有个Cydelete插件可以实现这样的功能,老大都研究出了原理了,{:soso_e142:}

    点评

    应该和兄弟说的高科技不是一个意思。既然进cydia了就没必要弄了 哈! 我这个没啥用。只是工作中需要顺手弄了个demo纪录一下…  详情 回复 发表于 2015-11-3 21:58
    PYG19周年生日快乐!
  • TA的每日心情
    难过
    前天 14:49
  • 签到天数: 11 天

    [LV.3]偶尔看看II

     楼主| 发表于 2015-11-3 21:58:57 | 显示全部楼层
    wx_f1Jji177 发表于 2015-11-3 19:09
    好像有个Cydelete插件可以实现这样的功能,老大都研究出了原理了,

    应该和兄弟说的高科技不是一个意思。既然进cydia了就没必要弄了 哈! 我这个没啥用。只是工作中需要顺手弄了个demo纪录一下…

    点评

    https://github.com/DHowett/cydelete 就是一个插件,可以在桌面上卸载cydia安装的插件,卸载时没有进cydia  详情 回复 发表于 2015-11-4 01:13
    PYG19周年生日快乐!
  • TA的每日心情
    奋斗
    2021-9-29 15:05
  • 签到天数: 114 天

    [LV.6]常住居民II

    发表于 2015-11-4 01:13:43 | 显示全部楼层
    飘云 发表于 2015-11-3 21:58
    应该和兄弟说的高科技不是一个意思。既然进cydia了就没必要弄了 哈! 我这个没啥用。只是工作中需要顺手 ...

    https://github.com/DHowett/cydelete
    就是一个插件,可以在桌面上卸载cydia安装的插件,卸载时没有进cydia{:soso_e113:}
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2024-4-6 11:41
  • 签到天数: 1827 天

    [LV.Master]伴坛终老

    发表于 2015-11-4 07:58:40 | 显示全部楼层
    进来了解一下,向高手们学习致敬!
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2023-9-19 08:48
  • 签到天数: 35 天

    [LV.5]常住居民I

    发表于 2015-11-5 09:49:00 | 显示全部楼层
    不错,谢谢分享
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表