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

 

posted @ 2017-06-23 13:38  Ethan_村长  阅读(1757)  评论(0编辑  收藏  举报