敬告:飘云阁论坛原创,转载请注明出处 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!!!");
}
|