dtruss 在 OS X 10.11 上的 ps 上失败

dtruss fails on ps on OS X 10.11

我试图查看 ps 使用哪个系统调用来获取 OS X 10.11 (El Capitan) 和 运行 上进程的命令行,并出现以下错误:

# dtruss ps -p 43520 -o args

dtrace: failed to execute ps: dtrace cannot control executables signed with restricted entitlements

谷歌搜索得到的建议是复制 ps 可以让我绕过这个,但这对我不起作用。为什么我不能再 运行 dtruss 任意二进制文件了,我有什么方法可以恢复旧的行为吗?

cannot control executables signed with restricted entitlements

安全完整性保护 ('rootless') 现在阻止 dtruss 在此处运行。

如果您搜索 "dtrace cannot control",您可以 disable it by booting into Recovery mode, but it looks like dtrace has specifically been blocked regardless of the state of rootless, as can be seen in the source code

从Pcreate中的评论也可以看到:

    /*
     * <rdar://problem/13969762>:
     * If the process is signed with restricted entitlements, the libdtrace_dyld
     * library will not be injected in the process. In this case we kill the
     * process and report an error.
     */

问题与代码签名有关。如果您复制一份然后用您自己的身份(或者,可能是任何非 Apple 身份)重新签名,那么 dtrace 将很好地附加到它上。

$ mkdir ~/temp
$ cp /bin/ps ~/temp/
$ codesign -f -s `whoami` ~/temp/ps
$ sudo dtruss ~/temp/ps -p 43520 -o args