iOS越獄系統使用root權限運行命令

                //命令原型:sh -c "echo 密碼 | su -c 'ls --help' "
                //轉載請註明:http://www.cnblogs.com/bandy/p/7069503.html
                NSTask *task = [NSTask new];
                [task setLaunchPath:@"/bin/sh"];
                [task setArguments:[NSArray arrayWithObjects:@"-c", @"/bin/echo alpine | /bin/su -c '/bin/ls --help' ", nil]];
                NSPipe *pipe = [NSPipe pipe];
                [task setStandardOutput:pipe];
                [task launch];
                NSData *data = [[pipe fileHandleForReading] readDataToEndOfFile];
                [task waitUntilExit];
                NSString * string;
                string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];//root
                NSLog(@"Result: %@", string);
                //轉載請註明:http://www.cnblogs.com/bandy/p/7069503.html
相關文章
相關標籤/搜索