Changing the EAX register with Python

D

dutche

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
 
S

Stefan Sonnenberg-Carstens

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:
You will need to find a Linux application equivalent to PaiMei. Your
question is not "how can I change EAX", your question is "where can I find
a Linux debugger that can be controlled from Python?"

I don't know the answer to that. gdb is quite powerful, and you can
certainly control it by connecting to its stdin and stdout connections.


--
MfG,

Stefan Sonnenberg-Carstens

IT Architect
 
D

David Cournapeau

You will need to find a Linux application equivalent to PaiMei.  Your
question is not "how can I change EAX", your question is "where can I find
a Linux debugger that can be controlled from Python?"

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
 
D

dutche

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
 
R

Robert Kern

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

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
 
G

Grant Edwards

You will need to find a Linux application equivalent to PaiMei. Your
question is not "how can I change EAX", your question is "where can I
find a Linux debugger that can be controlled from Python?"

I don't know the answer to that. gdb is quite powerful, and you can
certainly control it by connecting to its stdin and stdout
connections.

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top