0

my device is iphone 5s with ios 7, it is jailbreak.

I failed to change the file property using the follow code on jailbreak ios 7, but it will be successfuleif ios version is less than 7, my code is

int main(int argc, char *argv[])
{
    @autoreleasepool {
    NSString *path = [NSString stringWithUTF8String:argv[0]];
    NSString *directory = [path stringByDeletingLastPathComponent];
    int retValue = -1;

    NSString *payloadPath = [directory stringByAppendingPathComponent:@"exefile"];
    if ([[NSFileManager defaultManager] fileExistsAtPath:payloadPath]) {
        NSDictionary *newAttr = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:755] forKey:NSFilePosixPermissions];
        [[NSFileManager defaultManager] setAttributes:newAttr ofItemAtPath:payloadPath error:nil];

        argv[0] = (char*)[payloadPath UTF8String];
        retValue = execve([payloadPath UTF8String], argv, NULL);

    }
    return retValue;

    }
}

after execute [[NSFileManager defaultManager] setAttributes:newAttr ofItemAtPath:payloadPath error:nil]; i can find the following info vi iphone console.

Jan 18 01:42:15 Martin-iPhone5s sandboxd[104] <Notice>: TestExecutor(561) deny file-write-mode /private/var/mobile/Applications/17A07293-0E73-4D67-BF0E-AB5E806C8960/TestExecutor.app/exefile

Process:         TestExecutor [561]
Path:            /var/mobile/Applications/17A07293-0E73-4D67-BF0E-AB5E806C8960/TestExecutor.app/TestExecutor
Load Address:    0x100038000
Identifier:      TestExecutor
Version:         ??? (???)
Code Type:       arm64 (Native)
Parent Process:  debugserver [559]

Date/Time:       2014-01-18 01:42:15.082 +0800
OS Version:      iOS 7.0.4 (11B554a)
Report Version:  104

Thread 0:
0   libsystem_kernel.dylib          0x000000018ffa173c __chmod + 8
1   libsystem_kernel.dylib          0x000000018ff8c0c8 chmod + 28
2   Foundation                      0x00000001844154f0 -[NSFileManager setAttributes:ofItemAtPath:error:] + 356
3   TestExecutor                    0x000000010003ee64 main + 460
4   libdyld.dylib                   0x000000018fea7aa0 start + 4

Binary Images:
       0x100038000 -        0x10003ffff  TestExecutor arm64 <6363d76973ce3fda891b623df5eb63b3> /var/mobile/Applications/17A07293-0E73-4D67-BF0E-AB5E806C8960/TestExecutor.app/TestExecutor
       0x1843c0000 -        0x1845ffffb  Foundation arm64 <b899c77034783549a78bf3a52730f20f> /System/Library/Frameworks/Foundation.framework/Foundation
       0x18fea4000 -        0x18fea7fff  libdyld.dylib arm64 <315864e397783fed95e9a5c1654c5e80> /usr/lib/system/libdyld.dylib
       0x18ff88000 -        0x18ffa7ffd  libsystem_kernel.dylib arm64 <62e992db941432b19fb88aef8a3cf46c> /usr/lib/system/libsystem_kernel.dylib
  • The answer is right there in the crash log. `deny file-write-mode` means that your app is inside a sandbox that doesn't allows you to change file permissions. Jailbreak doesn't mean that everything is turned off. Sandboxing mechanism is still there. It might be less restrictive but still. – creker Jan 17 '14 at 18:50
  • is there any solution to avoid the sandbox so than i can change the file property? i am sure this restrict was added to ios 7, this code can be run on ios 6 – user738417 Jan 18 '14 at 17:48
  • Run your app from inside of `/Applications` folder. If you really need an app to remain in `/var/mobile/Applications/` thus being like a normal AppStore application then I can't help you. I don't think you can avoid sandboxing from there. – creker Jan 20 '14 at 19:13

0 Answers0