I have tried to read the main application via several me开发者_Python百科thodes but i got nothing back Using NSFileHandle it returns nothing with the folowing code :
NSFilemanager *filemanager = [ filemanager defaultmanager ] ;
NSString *myfile = [ [ NSBundle mainBundle ] bundlePath ] ;
if ( [ filemanager isReadableFileAtPath:myfile ] )
NSLog(@" myfile is readable ") ;
if ( [ filemanager isWritableFileAtPath:myfile ])
NSLog(@"myfile is wrieable ") ;
NSFileHandle *filehandle= [ NSFileHandle fileHandleForReadingAtPath:myfile ] ;
if (myfile == nil) {
[ filehandle closeFile ] ;
}else {
NSData *filedata = [ filehandle readDataToEndOfFile ] ;
NSString *filestrdata = [ [ NSString alloc ] initWithData:filedata encoding:NSUTF8StringEncoding ] ;
NSLog(@"string data \n %@ " , filedata) ;
}
But i got nothing back so my question is is it possible to access executable files for reading-writing and if yes how could we done that ? Thank you
In previous versions of the iPhone OS it was possible to write/change files in your application bundle, but your application was unlaunchable after that (because your bundle-signature wasnt proper anymore). In the current version it is simply impossible to write/change files in your application bundle.
The "bundle path" points to MyApp.app, which is a directory (which contains Info.plist, the executable, and the app's resources). If you want the app's binary, use the executable path:
NSString * path = [[NSBundle mainBundle] executablePath];
NSData * filedata = [NSData dataWithContentsOfFile:path];
You will not be able to read it as a UTF-8 string because it is not valid UTF-8 data.
I can confirm that attempting to read the executable has caused a rejection for me in the past.
I originally had code which attempted to determine if the executable had been modified (to detect piracy). While the code was originally accepted, around the time of the iPad initial launch I received a rejection for doing so. I've since removed the code as it didn't really have an impact on piracy levels anyways.
精彩评论