探索AWZ——清理safari/keychain/pastboard实现

清理safari逻辑在函数中-[IFMagicMainVC cleanSafariClick:]

// 杀死进程
BKSTerminateApplicationForReasonAndReportWithDescription(__bridge CFStringRef)@"com.apple.mobilesafari", 5, 0, NULL); 
NSFileManager* man = [NSFileManager defaultManager];

// 清理cookie
NSString cookiepath = @"/var/mobile/Library/Cookies";
if ([man fileExistsAtPath:cookiepath]) {
    NSString* cmd = [NSString stringWithFormat:@"rm -rf %@/*", cookiepath];
    system(cmd);
}
cookiepath = @"/private/var/root/Library/Cookies";
if ([man fileExistsAtPath:cookiepath]) {
    NSString* cmd = [NSString stringWithFormat:@"rm -rf %@/*", cookiepath];
    system(cmd);
}

// 获取safari的沙盒路径
NSString* safaricontainer = nil;
NSString* installplist = @"/var/mobile/Library/Caches/com.apple.mobile.installation.plist";
if ([man fileExistsAtPath:]) {
    NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile:installplist];
    id obj = plist[@"User"][@"com.apple.mobilesafari"];
    if (obj == nil) {
        obj = plist[@"System"][@"com.apple.mobilesafari"];
    }
    if (obj != nil) {
        safaricontainer = obj[@"Container"];
    }
} else {
    Class* LSApplicationProxy = NSClassFromString(@"LSApplicationProxy");
    id obj = [LSApplicationProxy performSelector:applicationProxyForIdentifier: withObject:@"com.apple.mobilesafari"]);
    if (obj != nil && [obj respondsToSelector:@selector(dataContainerURL)]) {
        safaricontainer = [[obj performSelector:@selector(dataContainerURL)] path];
    }
}

// 清理library
NSString* libpath = [safaricontainer stringByAppendingPathComponent:@"Library"];
NSString* libcachepath = [libpath stringByAppendingPathComponent:@"Caches"];
if ([man fileExistsAtPath:libcachepath]) {
    NSString* cmd = [NSString stringWithFormat:@"rm -rf %@/*", libcachepath];
    system(cmd);
}
NSString* libsafaripath = [libpath stringByAppendingPathComponent:@"Safari"];
if ([man fileExistsAtPath:libsafaripath]) {
    NSString* cmd = [NSString stringWithFormat:@"rm -rf %@/History.*", libsafaripath];
    system(cmd);
    cmd = [NSString stringWithFormat:@"rm -rf %@/SuspendState.*", libsafaripath];
    system(cmd);
}

清理keychain逻辑在函数中-[IFMagicMainVC cleanKeychainClick:]

NSFileManager* man = [NSFileManager defaultManager];
if ([man fileExistsAtPath:@"/var/Keychains/keychain-2.db"]) {
  system("cp /var/Keychains/keychain-2.db /tmp/");
  void* ppDb = 0;
  char cmd[256];
  if (0 == sqlite3_open("/tmp/keychain-2.db", &ppDb)) {
    strcpy(cmd, "DELETE FROM cert WHERE agrp<>'apple' and agrp not like '%apple%' and agrp <> 'ichat' and agrp <>'lockdown-identities'");
    sqlite3_exec(ppDb, cmd, 0, 0, 0);
    strcpy(cmd, "DELETE FROM keys WHERE agrp<>'apple' and agrp not like '%apple%' and agrp <> 'ichat' and agrp <>'lockdown-identities'");
    sqlite3_exec(ppDb, cmd, 0, 0, 0);
    strcpy(cmd, "DELETE FROM inet WHERE agrp<>'apple' and agrp not like '%apple%' and agrp <> 'ichat' and agrp <>'lockdown-identities'");
    sqlite3_exec(ppDb, cmd, 0, 0, 0);
    system("cp /tmp/keychain-2.* /var/Keychains/");
  }
}

清理pasteboard逻辑在函数中-[IFMagicMainVC cleanPastboardClick:]

UIPasteboard* pb = [UIPasteboard generalPasteboard];
if (pb != nil) {
    NSArray* items = [pb items];
    if (items != nil) {
        [items removeAllObjects];
    }
    [pb setItems:items];
}

NSFileManager* man = [NSFileManager defaultManager];
NSProcessInfo* proc = [NSProcessInfo processInfo];
BOOL isbe8 = FALSE;
NSOperatingSystemVersion ver;
ver.majorVersion = 8;
ver.minorVersion = 0;
ver.patchVersion = 0;
if ([proc respondsToSelector:@selector(isOperatingSystemAtLeastVersion:&ver)]) {
    isbe8 = [proc isOperatingSystemAtLeastVersion:&ver];
}

NSString* pbplist = nil;
NSString* pbbundle = nil;
if ([man fileExistsAtPath:@"/System/Library/LaunchDaemons/com.apple.UIKit.pasteboardd.plist"]) {
    pbplist = @"/System/Library/LaunchDaemons/com.apple.UIKit.pasteboardd.plist";
    pbbundle = @"com.apple.UIKit.pasteboardd";
}
else if ([man fileExistsAtPath:@"/Library/LaunchDaemons/com.apple.UIKit.pasteboardd.plist"]) {
    pbplist = @"/Library/LaunchDaemons/com.apple.UIKit.pasteboardd.plist";
    pbbundle = @"com.apple.UIKit.pasteboardd";
}
else if ([man fileExistsAtPath:@"/System/Library/LaunchDaemons/com.apple.pasteboard.pasted.plist"]) {
    pbplist = @"/System/Library/LaunchDaemons/com.apple.pasteboard.pasted.plist";
    pbbundle = @"com.apple.pasteboard.pasted";
}

BOOL pbdbexist = [man fileExistsAtPath:@"/var/mobile/Library/Caches/com.apple.UIKit.pboard/pasteboardDB"];
NSString* pbcontainer = nil;
if ([man fileExistsAtPath:@"/var/mobile/Library/Caches/com.apple.UIKit.pboard"]) {
    pbcontainer = @"/var/mobile/Library/Caches/com.apple.UIKit.pboard";
} else if ([man fileExistsAtPath:@"/var/mobile/Library/Caches/com.apple.Pasteboard"]) {
    pbcontainer = @"/var/mobile/Library/Caches/com.apple.Pasteboard";
}
if (!isbe8 && [man fileExistsAtPath:pbplist]) {
    system("launchctl unload -w");
}
if (pbcontainer != nil && [man fileExistsAtPath:pbcontainer]) {
    NSString* cmd = [NSString stringWithFormat:@"rm -rf %@/*", pbcontainer];
    system([cmd UTF8String]);
}
if (pbdbexist) {
    NSString* cmd = [NSString stringWithFormat:@"cp %@ %@", @"/Applications/AWZ.app/pb.dat", @"/var/mobile/Library/Caches/com.apple.UIKit.pboard/pasteboardDB"];
    system([cmd UTF8String]);
    cmd = [NSString stringWithFormat:@"chown mobile:mobile %@", @"/var/mobile/Library/Caches/com.apple.UIKit.pboard/pasteboardDB"];
    system([cmd UTF8String]);

}
if (pbplist != nil && !isbe8 && [man fileExistsAtPath:pbplist]) {
    system("launchctl load -w");
}
if (isbe8 && pbbundle != nil) {
    NSString* cmd = [NSString stringWithFormat:@"launchctl kickstart -k system/%@", pbbundle];
    system([cmd UTF8String]);
}

你可能感兴趣的:(探索AWZ——清理safari/keychain/pastboard实现)