TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Pyrasite - Inject code into a running Python process

174 点作者 packetlss超过 13 年前

5 条评论

onedognight超过 13 年前
TL;DR The code is mostly this with a nice wrapper.<p><pre><code> gdb_cmds = [ 'PyGILState_Ensure()', # Allow payloads to import modules alongside them 'PyRun_SimpleString("import sys; sys.path.insert(0, \\"%s\\");")' % os.path.dirname(self.filename), 'PyRun_SimpleString("execfile(\\"%s\\")")' % self.filename, 'PyGILState_Release($1)', ] self._run('gdb -p %d -batch %s' % (self.pid, ' '.join(["-eval-command='call %s'" % cmd for cmd in gdb_cmds])))</code></pre>
kevingadd超过 13 年前
If you're on Windows, an old project of mine has a more sophisticated take on this:<p><a href="https://github.com/kevingadd/shootblues" rel="nofollow">https://github.com/kevingadd/shootblues</a><p>You can inject a whole collection of scripts into one or more processes hosting a Python interpreter, load/unload scripts at runtime, and communicate between host processes via an RPC mechanism.<p>The only interesting use for it I ever came up with was modding the EVE Online user interface. There are a bunch of scripts that use it at <a href="https://github.com/kevingadd/shootbluesscripts" rel="nofollow">https://github.com/kevingadd/shootbluesscripts</a> - some of them are kind of interesting, like a gateway that lets you interact with scripts via Jabber messages, and a HTML5 remote desktop that lets you play the game from a remote browser.
评论 #3015413 未加载
burgerbrain超过 13 年前
That's pretty wild. Obviously you can do similar with straight up gdb and C programs, but does this sort of thing exist with other languages? I'd be fairly interested in something like this for racket and ruby.
评论 #3014904 未加载
评论 #3015127 未加载
评论 #3015247 未加载
评论 #3014986 未加载
评论 #3015968 未加载
评论 #3016574 未加载
johnthedebs超过 13 年前
This looks like a great little trick, but I can't get it to work on OS X Lion. Has anyone else on Lion gotten this to work?<p>I've got Xcode 4.1 installed with dev tools, and it seems like the version of gdb provided doesn't support the -eval-command flag which breaks the script.<p>I'm wondering if someone else can confirm this problem, and whether there is an easy way to to install a supported version of gdb.
Davertron超过 13 年前
Can someone describe why this sort of thing would be useful? I'm not criticizing, I just can't think of a use case for this.
评论 #3015021 未加载
评论 #3015134 未加载
评论 #3017133 未加载
评论 #3015250 未加载