简体   繁体   English

GUI Apps不允许OSX共享内存访问

[英]OSX Shared memory access not permitted from GUI Apps

I have a dylib on OSX I'm injecting through DYLD_INSERT_LIBRARIES and it calls 我通过DYLD_INSERT_LIBRARIES注入OSX上的dylib,它调用

shm_open("name", O_RDWR);

The shared memory was set up in another process using 共享内存是在另一个进程中使用

shm_open("name", O_RDWR|O_CREAT, 0777);

Communication from injected dyld to external app is successful when run in /bin/bash and other command line programs. 在/ bin / bash和其他命令行程序中运行时,从注入的dyld与外部应用程序的通信成功。 Testing in GUI apps such as Calculator or Preview yield an error when shm_open is called from the injected dylib. 从注入的dylib调用shm_open时,在GUI应用程序(例如Calculator或Preview)中进行测试会产生错误。 The error is "Operation not permitted". 错误是“不允许操作”。

Does anyone know the reason behind this? 有谁知道背后的原因吗?

Both of the applications that you've mentioned — Calculator and Preview — are sandboxed. 您提到的两个应用程序-计算器和预览-都已沙箱化。 One of the things this prevents them from doing is accessing shared memory (outside of certain specific circumstances which do not apply to these applications). 阻止他们执行操作的一件事是访问共享内存(某些特定情况并不适用于这些应用程序)。 See Apple's documentation " App Sandbox Design Guide: App Sandbox in Depth " for details. 有关详细信息,请参阅Apple文档“ 应用程序沙箱设计指南:深度的应用程序沙箱 ”。

If you need to communicate with arbitrary sandboxed processes, you will need to use an alternate method to do so (possibly XPC, although I'm not very familiar with that). 如果您需要与任意沙盒进程进行通信,则需要使用另一种方法进行通信(可能是XPC,尽管我对此不太熟悉)。 If you just want to test dylib injection in GUI processes, try a non-sandboxed application like Stickies (as of Mac OS 10.9). 如果只想在GUI进程中测试dylib注入,请尝试使用非沙盒式应用程序,例如Stickies(从Mac OS 10.9开始)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM