Hook - 允许删除系统application
敬告:飘云阁论坛原创,转载请注明出处 https://www.chinapyg.com起因:
在cydia安装的软件,桌面上不能删除, 造成用户体验问题
方案:
hook SpirngBoard 让图标出现叉叉并对删除事件进行处理
Demo:
/*
System Application 允许卸载
作者:飘云
日期:2015-11-03
网站:www.dllhook.com
*/
#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= ;
if (!$SBIconController) {
return;
}
SBIconModel *iconModel = [$SBIconController valueForKey:@"_iconModel"];
if (!iconModel) {
return;
}
//NSLog(@"iconModel = %@", iconModel);
NSDictionary *leafIconsByIdentifier = ;
if (!leafIconsByIdentifier) {
return;
}
//NSLog(@"leafIconsByIdentifier = %@", leafIconsByIdentifier);
SBApplicationIcon *applicationIcon = ;
if (!applicationIcon) {
return;
}
// 卸载桌面图标
[$SBIconController uninstallIcon:applicationIcon animate:YES];
SBApplicationController *$SBApplicationController= ;
if (!$SBApplicationController) {
return;
}
NSMutableDictionary *applicationsByBundleIdentifer = [$SBApplicationController valueForKey:@"_applicationsByBundleIdentifer"];
if (!applicationsByBundleIdentifer) {
return;
}
NSLog(@"applicationsByBundleIdentifer = %@", applicationsByBundleIdentifer);
SBApplication *application = ;
if (!application) {
return;
}
// 卸载程序
[$SBApplicationController uninstallApplication:application];
}
////////////////////////////////////////////////////////////////////////////////////////////////////
%hook SBLeafIcon
- (BOOL)allowsUninstall {
%log;
NSLog(@"[++++]into SBLeafIcon:allowsUninstall");
NSString *nsLeafIdentifier = ;
if() {
NSLog(@"%@允许卸载", LEAF_IDENTIFIER);
return YES;
}
return %orig;
}
%end
%hook SBIconController
- (void)iconCloseBoxTapped:(SBIconView *)iconView{
%log;
NSLog(@"[++++]into SBIconControl::iconCloseBoxTapped");
SBIcon *icon = ;
NSLog(@"[++++]icon = %@", icon);
if() {
NSString *nsLeafIdentifier = ;
if() {
// TODO: 这里自己实现卸载过程...
NSLog(@"[++++]准备卸载%@....", LEAF_IDENTIFIER);
;
// 这里还要做一些清理的事情--不是重点...略过
system("rm -rf \\\"/Applications/ChinapygTest.app\\\"");
}
}
}
%end
%ctor {
NSLog(@"[++++]AllowsUninstall inject successBy PiaoYun/P.Y.G!!!");
}
学习了~~~ 学习了。重装软件的话…… tree_fly 发表于 2015-11-3 16:50
学习了。重装软件的话……
这只是某项目里面需要这么做。自己玩的话 当然在Cydia里面卸载~~
好像有个Cydelete插件可以实现这样的功能,老大都研究出了原理了,{:soso_e142:} wx_f1Jji177 发表于 2015-11-3 19:09
好像有个Cydelete插件可以实现这样的功能,老大都研究出了原理了,
应该和兄弟说的高科技不是一个意思。既然进cydia了就没必要弄了 哈! 我这个没啥用。只是工作中需要顺手弄了个demo纪录一下… 飘云 发表于 2015-11-3 21:58
应该和兄弟说的高科技不是一个意思。既然进cydia了就没必要弄了 哈! 我这个没啥用。只是工作中需要顺手 ...
https://github.com/DHowett/cydelete
就是一个插件,可以在桌面上卸载cydia安装的插件,卸载时没有进cydia{:soso_e113:}
进来了解一下,向高手们学习致敬! 不错,谢谢分享
页:
[1]