Pyrasite - Inject code into a running Python process
fedorahosted.org
fedorahosted.org
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])))https://github.com/kevingadd/shootblues
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.
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 https://github.com/kevingadd/shootbluesscripts - 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.
In our case the alliance ended up using it mostly for data mining and not for anything malicious or directly in violation of the EULA, since we had thousands of players to keep track of and doing stuff by hand was tedious.
At one point I was going to try and turn the HTML5 play-from-browser feature into a product and sell it for a buck, but CCP's community team (that supposedly approves for-sale addons/tools) doesn't respond to emails and WebKit has had an unfixed bug for years that causes it to crash your browser, so I shelved it.
Here's an article describing how to do it by hand the naive way, they use minesweeper as the target: [2]
[1] http://research.microsoft.com/en-us/projects/detours/ [2] http://uninformed.org/?v=1&a=7
Tkcon (http://wiki.tcl.tk/1878) makes use of the various methods Tcl provides to great effect.
Yes, but it is a bit harder - unlike C, Python is designed to make things easily changeable at runtime.
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.
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.
(This is perhaps less less powerful for that use (since it would currently lack any sort of manual flow control), but I think the benefits of it actually being a REPL might offset that for some uses.)
Profiling too?
I still had a workable solution: I wrote a script that watched for any .py files that have been saved, and if so, ran the game for 15 seconds.