Skip to content

Comment on Pyrasite - Inject code into a running Python process

Comments

TL;DR The code is mostly this with a nice wrapper.

       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])))
AboutSource Built by g1lg1l

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