Skip to content

Comment on Pyrasite - Inject code into a running Python process

Comments

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.

From a quick glance at the code, it looks like it is using gdb to call methods in the Python/C API. I agree, it is pretty neat.

Java (well, JVM) has method hotswapping. It's very useful for debugging and development. Because of static typing, you can't change classes to add new methods, but you can modify existing methods. (There is something called JRebel which does allow you to change classes but I find it a little hacky.)

MS Detours[1] makes this easy in win32 processes. Stuff like this is useful for reverse engineers when prototyping hacks, security research, hooking kernel-level calls for e.g. packet filtering or AV, etc. Note that your run-of-the-mill antivirus will detect this, hacking processes in production is much harder.

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

Tcl has had this capability for a very long time: http://wiki.tcl.tk/1055

Tkcon (http://wiki.tcl.tk/1878) makes use of the various methods Tcl provides to great effect.

"Obviously you can do similar with straight up gdb and C programs"

Yes, but it is a bit harder - unlike C, Python is designed to make things easily changeable at runtime.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.