现在我开发了一个拥有root权限的app,怎样清除某一个app路径下的 /Documents, /Library, /tmp, /StoreKit


#1

需求:清除某一个app路径下的 /Documents, /Library, /tmp, /StoreKit

深夜福利!越狱iOS清痕暨■■■■■■■■核心代码の无料放送
感谢狗神的分享

我模仿狗神分享的代码进行清除,发现 [fileManager removeItemAtPath:[NSString stringWithFormat:@"/var/mobile/Applications/%@", file] error:nil]; 返回0 ,后打开iFile查看 /var/mobile/Applications/ 路径下是空的 ,然后百度找到了正确的路径,原来在iOS 8以后路径变为 /var/mobile/Containers/Data/Application/,后运行代码清除了所有app的 /Documents, /Library, /tmp, /StoreKit 下的东西。

附修改后的代码:

NSFileManager *fileManager = [NSFileManager defaultManager];

NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:@"/var/mobile/Containers/Data/Application/"];

NSString *file;

while ((file = [dirEnum nextObject]))
    
    if ([file hasSuffix:@"/Documents"] || [file hasSuffix:@"/Library"] || [file hasSuffix:@"/tmp"] || [file hasSuffix:@"/StoreKit"])
    {
        [fileManager removeItemAtPath:[NSString stringWithFormat:@"/var/mobile/Containers/Data/Application/%@", file] error:nil];
        [fileManager createDirectoryAtPath:[NSString stringWithFormat:@"/var/mobile/Containers/Data/Application/%@", file] withIntermediateDirectories:NO attributes:[NSDictionary dictionaryWithObjectsAndKeys:@"mobile", NSFileOwnerAccountName, @"mobile", NSFileGroupOwnerAccountName, nil] error:nil];
    }

`
我用iFile查看 /var/mobile/Containers/Data/Application/路径下都是一些如"1FDEAXXXXXXX"的文件名,比如我要删除微信的/Documents, /Library, /tmp, /StoreKit 我不知道它是哪个?所以我想知道怎么才能知道这些文件是哪一个app的路径,想了很久没有思路,我查资料好像这些路径,如果打开app 后是会重新生成的。

环境:iPhone 10.2 安装是使用的Cydia 我发布到威锋源上的


#2

私有API可以获取对应路径


#3

谢谢啦 是不是这个 LSApplicationWorkspace ?


#4

+(NSString*)GetTartgetAppDataPath:(NSString*)BundleID{
NSFileManager * fileManger = [NSFileManager defaultManager];
NSArray * dirArray = [fileManger contentsOfDirectoryAtPath:@"/private/var/mobile/Containers/Data/Application" error:nil];
for (NSString * str in dirArray) {
NSString * ParentPath=[NSString stringWithFormat:@"/private/var/mobile/Containers/Data/Application/%@",str];
NSString* APPIDFileString=[NSString stringWithFormat:@"%@/.com.apple.mobile_container_manager.metadata.plist",ParentPath];
BOOL isExist = [fileManger fileExistsAtPath:APPIDFileString isDirectory:false];
if(isExist){
NSDictionary * APPPlists = [NSDictionary dictionaryWithContentsOfFile:APPIDFileString];
if (APPPlists) {
NSString * AppBundleID = APPPlists[@“MCMMetadataIdentifier”];
if([AppBundleID isEqual:BundleID]){
NSLog(@“Success location target App Data Path:%@”,ParentPath);
return ParentPath;
}
}
else{
NSLog(@"%@/.com.apple.mobile_container_manager.metadata.plist获取不到plist",APPIDFileString);
}
}else{
NSLog(@"%@/.com.apple.mobile_container_manager.metadata.plist不存在",ParentPath);
}
}
return @"";
}

我是这么做的


#5

亲测 可以的 谢谢


#6

附清除某一App缓存的代码:

-(void)deleteFile:(NSString *)BundleID{

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *parentPath = [self GetTartgetAppDataPath:BundleID];
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:parentPath];
for (NSString *file in dirEnum.allObjects) {
   if ([file hasSuffix:@"Documents"] || [file hasSuffix:@"Library"] || [file hasSuffix:@"tmp"] || [file hasSuffix:@"StoreKit"])
    {
    
        [fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@",parentPath,file] error:nil];
        
        [fileManager createDirectoryAtPath:[NSString stringWithFormat:@"%@/%@",parentPath,file] withIntermediateDirectories:NO attributes:[NSDictionary dictionaryWithObjectsAndKeys:@"mobile", NSFileOwnerAccountName, @"mobile", NSFileGroupOwnerAccountName, nil] error:nil];
    }
}

}

-(NSString*)GetTartgetAppDataPath:(NSString*)BundleID{

NSFileManager * fileManger = [NSFileManager defaultManager];
NSArray * dirArray = [fileManger contentsOfDirectoryAtPath:@"/private/var/mobile/Containers/Data/Application" error:nil];
for (NSString * str in dirArray) {
    NSString * ParentPath=[NSString stringWithFormat:@"/private/var/mobile/Containers/Data/Application/%@",str];
    NSString* APPIDFileString=[NSString stringWithFormat:@"%@/.com.apple.mobile_container_manager.metadata.plist",ParentPath];
    BOOL isExist = [fileManger fileExistsAtPath:APPIDFileString isDirectory:false];
    if(isExist){
        NSDictionary * APPPlists = [NSDictionary dictionaryWithContentsOfFile:APPIDFileString];
        if (APPPlists) {
            NSString * AppBundleID = APPPlists[@"MCMMetadataIdentifier"];
            if([AppBundleID isEqual:BundleID]){
                NSLog(@"Success location target App Data Path:%@",ParentPath);
                return ParentPath;
            }
        }
        else{
            NSLog(@"%@/.com.apple.mobile_container_manager.metadata.plist获取不到plist",APPIDFileString);
        }
    }else{
        NSLog(@"%@/.com.apple.mobile_container_manager.metadata.plist不存在",ParentPath);
    }
}
return @"";

}

当然Akko的 方法也可以 我从Xcode 8 中 classdump 出了 私有Api 的.h 文件。header.zip (90.9 KB)
借鉴


#7

用NSFileManager 操作 URL 比操作Path 方便很多


#8

能不能具体点??


#9

比如这样

[[NSFileManager defaultManager] removeItemAtURL:'DocumentsURL' error:NULL];

DocumentsURL 是伪代码 我就表达这一个意思

[fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@",parentPath,file] error:nil];

好一些


#10

Soga 谢谢