NSFileManager unable to view below certain directories
I'm trying to write some code to inspect or alter (not malicious or anything like that) other iOS apps installed on the user's device. Specifically on a Jailbroken device. On the jailbroken device I am able to view files outside of the application's sandbox, and when I look at "/private/var/mobile/Applications/" using NSFileManager, I see the list of directories (named in some sort of hexadecimal scheme). As expected.
Unfortunately, when I look at each directory, all of them return (aside from the running app itself) FALSE for isDirectory, and NULL for attributesOfItemAtPath. I need to have access to the .app inside each of these folders, but开发者_运维百科 I am unable to see below them, and each is returning invalid information.
Below is the code I am using:
NSString *path = @"/private/var/mobile/Applications/";
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager contentsOfDirectoryAtPath:path error:nil];
for(NSString *file in fileList) {
NSString *fullpath = [path stringByAppendingPathComponent:file];
NSLog(@"fullpath = %@", fullpath);
BOOL isDir = nil;
[manager fileExistsAtPath:fullpath isDirectory:(&isDir)];
if(isDir) {
NSLog(@"isDir");
//NSArray *subfiles = [self filesBeneathDirectory:fullpath withExtension:extension];
} else {
NSLog(@"!isDir");
NSDictionary *attributes = [manager attributesOfItemAtPath:fullpath error:nil];
NSLog(@"attributes = %@",attributes);
}
}
I'd appreciate any help in detecting files below these directories. I had assumed that the iPhone would have complete root access (being a jailbroken device and all).
From your application, you are only allowed to access your own sandbox. It wont do any good if you access files in other directories, there are some very good reasons why Apple restricted the access.
精彩评论