views:

52

answers:

3

I have tried to read the main application via several methodes 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

+2  A: 

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.

unset
+1  A: 

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.

tc.
+1 NSBundle provides all the methods you need to locate files within the app bundle. There is no valid reason, however, to read the executable itself. Therefore, I would guess that even the attempt to do so may get the app rejected by apple.
TechZen
There are plenty of potentially valid reasons (namely DRM), but I you have to be a little carful there (the binary's encrypted, for one). It's also not going to be easy to check if you're reading the executable via static analysis. And at the end of the day, your binary will be loaded/decrypted at address 0x1000, so you can just read memory.
tc.
A: 

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.

pendor