python应用程序和注入的DLL之间的IPC
你好堆栈溢出:有时读者,第一次发帖。
背景:
运行 XP SP3 的 Windows 机器,即将升级到 Windows 7 (MSDNAA <3)
我有一个注入的 DLL,它通过挂钩每秒调用数千次的函数来获取周期。
我想通过 python 应用程序来通信/控制这个 DLL。基本上,DLL 完成工作,Python 应用程序提供大脑/决策。
我的计划是在 DLL 中添加一个计数器和一个 if 语句。每次调用挂钩函数时, counter++ 然后跳回原始函数,直到出现类似 if ( counter == 250 ) { // dostuff(); 的内容。 }。我的虽然这背后它将允许目标应用程序基本上不受阻碍地运行,但仍然会让我做有趣的事情。
问题:
我完全不知道应该使用哪种 IPC 方法来进行通信。我们有套接字、共享内存、管道、文件映射(?)、RPC 和其他(看似)深奥的东西,例如写入剪贴板。
除了玩具示例之外,我从未实现过任何类型的 IPC。
我相当确定我需要这样的东西:
- 可以处理 python 和 DLL 之间的来回对话
- 不会阻塞/等待
- 可以检查等待数据,如果没有任何数据则继续 如果
- 涉及锁,可以继续而不是等待
- 读/写也不需要花费很多时间
有帮助吗?感谢您抽出宝贵的时间,我希望我已经提供了足够的一般信息并且没有违反任何公认的约定。
我想补充一点,相关问题框非常酷,我在发布之前仔细阅读了它。
Hello stack overflow: Sometimes reader, first time poster.
Background:
Windows box running XP SP3, soon to be upgraded to Windows Seven (MSDNAA <3)
I have an injected DLL which gets cycles by hooking a function that is called thousands of times a second.
I would like to communicate/control this DLL via a python app. Basically, the DLL does the work, the python app supplies the brains/decision making.
My game plan for doing this, is I would have a counter and an if statement in the DLL. Each time the hooked function is called, counter++ and then jump back to the original function until something like if ( counter == 250 ) { // dostuff(); }. My though behind this it will allow the target app to run mostly unimpeded, but will still let me do interesting things.
Problem:
I'm at an utter loss on which IPC method I should use to do the communication. We have sockets, shared memory, pipes, filemapping(?), RPC, and other (seemingly) esoteric stuff like writing to the clipboard.
I've NEVER implemented any kind of IPC beyond toy examples.
I'm fairly sure I need something that:
- Can handle talking back and forth between python and a DLL
- Doesn't block/wait
- Can check for waiting data, and continue if there isn't any
- If locks are involved, can continue instead of waiting
- Doesn't cost lots of time to read/write too
Help? Thank you for your time, I hope I've provided enough general information and not broken any accepted conventions.
I would like to add that the related questions box is very cool, and I did peruse it before posting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试套接字。你的需求本质上是异步操作的需求; Python 有 asyncore 模块用于套接字上的异步 IO。同时,Python 的 stdlib 看起来不能异步处理其他 IPC 事物,所以我不建议使用它们。
Try sockets. Your demands are essentially a requirement of asynchronous operating; Python has asyncore module for asynchronous IO on sockets. At the same time, it doesn't look like Python's stdlib can asynchronously handle other IPC things, so I'd not recommend using them.
如果您不关心实时性,那么您可以使用文件系统进行通信:DLL 输出的日志文件,以及时不时读取以更改 DLL 行为的配置文件。
If you don't care about realtime, then you can use the file system for communication: a log file for the DLL's output, and a config file that is read every now and then to change the DLLs behavior.