Swift iOS: dyld: dyld_sim cannot be loaded in a restricted process

落花浮王杯 提交于 2019-12-11 07:46:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!