10.6.1 Python hello world

to start we will write a small python script for radare to just test some of the features of the API.

$ cat hello.py
print "Hello World"
seek(0)
print hex(3)
write("90 90 90")
print hex(3)
quit()

$ echo patata > file             # prepare the dummy file
$ radare -i hello.py -wnv file   # launch the script
Hello World
70 61 74 
90 90 90 

If you want a better interface for writing your scripts inside radare use the scriptedit plugin that depends on GTK+ offering a simple editor with language selector and allows to run scripts from there.

You can also use radare programatically from the python shell:

[0x4A13B8C0]> H python
python> print dir(r)
['__doc__', '__name__', 'cmd', 'eval']
python> print(r.cmd("p8 4"))
89 e0 e8 39