Changing the EAX register with Python

Discussion in 'Python' started by dutche, Nov 18, 2010.

  1. dutche

    dutche Guest

    Hi folks, I have a unusual question here.

    How can I change the value of EAX register under python under Linux??
    As paimei does under Windows.

    My project is to have a python program that loads a C program and sets
    a breakpoint at some address, and then with this breakpoint I change
    the EAX register and then continue the program execution.

    With Windows and paimei I did that, but under Linux I don't know yet.

    Any ideas?

    Thank you
     
    dutche, Nov 18, 2010
    #1
    1. Advertisements

  2. Hi,
    just read my mail :)
    You can just build an debugger in python yourself.
    The script I posted should give you an idea.

    Am Fr, 19.11.2010, 08:17 schrieb Tim Roberts:

    --
    MfG,

    Stefan Sonnenberg-Carstens

    IT Architect
     
    Stefan Sonnenberg-Carstens, Nov 19, 2010
    #2
    1. Advertisements

  3. Well, gdb may just be the tool you are looking for: since version 7.0
    at least, you can script gdb using python,

    http://sourceware.org/gdb/wiki/PythonGdb

    cheers,

    David
     
    David Cournapeau, Nov 19, 2010
    #3
  4. dutche

    dutche Guest

    Well, I think using ptrace is really the best way, at least what I
    have found on Google told me that.

    Stefan, your answer will fit perfectlly for me, it was what I'm
    searching.

    Thank you
     
    dutche, Nov 19, 2010
    #4
  5. dutche

    Robert Kern Guest

    You may also want to look into pinktrace for another wrapper around ptrace. I
    haven't used it myself, but it's worth looking into.

    http://dev.exherbo.org/~alip/pinktrace/

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, Nov 19, 2010
    #5
  6. If you're going to do that, you want to run gdb in "machine interface"
    mode, which makes it a lot easier to talk to programatically. I've
    not done it in Python, but it's easy enough in C, so in Python it
    ought to be trivial:

    http://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI.html#GDB_002fMI

    If you don't want to write code to talk the gdb/mi "command language",
    then another option is to use a library like libmigdb:

    http://sourceforge.net/projects/libmigdb/

    You can probably call the library functions using cytpes:

    http://docs.python.org/library/ctypes.html
     
    Grant Edwards, Nov 19, 2010
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.