问题
I'm making an iOS app for jailbroken devices running iOS 12 or newer.
I need my app to run a command line command, so to achieve that I use a custom Objective-C header file which creates the object NSTask and everything it needs, and then, using Bridging Headers I expose it to Swift.
So, to run a task I use the following function:
func task(launchPath: String, arguments: String...) -> NSString {
let task = NSTask.init()
task?.setLaunchPath(launchPath)
task?.arguments = arguments
// Create a Pipe and make the task
// put all the output there
let pipe = Pipe()
task?.standardOutput = pipe
// Launch the task
task?.launch()
task?.waitUntilExit()
// Get the data
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
return output!
}
And call it like this:
installPackage = task(launchPath: "/usr/bin/dpkg", arguments: "-i", packageID, "control")
I noted that this wasn't doing anything, so I wanted to check what was the command really doing.
To do this, I printed installPackage
.
This should have printed the dpkg command output, but instead, it printed the following:
print(installPackage)
~> dyld: dyld_sim cannot be loaded in a restricted process
I've read that to fix this you need to turn off Thread Sanitizer or change the Build Configuration to Release, but it keeps showing the same message.
What can I do to fix this?
来源:https://stackoverflow.com/questions/56633056/swift-ios-dyld-dyld-sim-cannot-be-loaded-in-a-restricted-process