As promised, this weekend I wrote a simple PoC for the python code
analysis API
for radare. It is just a cached python interface to the internal
metadata provided
by few radare commands.
It is still incomplete, but can be mostly comparable to the py-idc API,
but featuring
decent function names with cleaner access to information and support to
cache information
to ease diffing or staging while analyzing code or data (which is quite
useful for
tracing and so on).
I have managed to fix some issues related to radare_cmd_str() which is
the base of the
r.cmd() python interface.
Check the src/plug/hack/analysis directory. It contains two basic files
'ranal.py' and 'test.py'.
Here's the python code that can be launched with "radare -i test.py a.out"
the code is self explanatory and i think that it is something that
people was looking for since
many time ago :P but well.
Let me know if you like that API, or which changes you will do. Patches
and enhacements for the
api are welcome :) This will come together with radare 1.4. But you can
check it in the last
snapshot:
http://radare.org/get/shot/radare-20090525.tar.gz
here's the code:
----------------------------------
import r
import radare
import sys
sys.path.append('.')
from ranal import *
print "---------------------------------"
print r.cmd("e scr.color=0")
p = Program()
print "File type: %s" % p.type
print "File size: %d bytes" % p.size
print "Entrypoint: 0x%x" % p.entrypoint
print "Virtual address: 0x%x" % p.vaddr
print "Physical address: 0x%x" % p.paddr
print "OperatingSystem: %s" % p.os
print "Architecture: %s" % p.arch
print "Endian: %s" % p.bigendian
print "Symbols:"
ss = Symbols()
for s in ss.list:
print "0x%08x: size=%s name=%s"%(s.addr, s.size, s.name)
Function.analyze(s.addr)
print "Functions:"
fs = Functions()
for f in fs.list:
print "0x%08x: size=%s name=%s"%(f.addr, f.size, f.name)
bb = BasicBlocks(f.addr)
print " ==> Basic blocks: %d"%len(bb.list)
print " ==> Disassembly:"
print r.cmd("p...@%d:%d"%(f.addr,f.size))
Graph.make_png(f.addr, "%s.png"%f.name)
print "Imports:"
ss = Imports()
for s in ss.list:
print "0x%08x: size=%s name=%s"%(s.addr, s.size, s.name)
for x in CodeXrefs(s.addr).list:
print " -> xref from 0x%08x"%(x.addr)
print "Xrefs:"
for x in CodeXrefs().list:
print " -> code xref from 0x%08x -> to 0x%08x"%(x.addr, x.endaddr)
for x in DataXrefs().list:
print " -> data xref from 0x%08x -> to 0x%08x"%(x.addr, x.endaddr)
print "Sections:"
ss = Sections()
for s in ss.list:
print "0x%08x: size=%d %s"%(s.addr, s.size, s.name)
print "---------------------------------"
radare.quit(0)
----------------------------------
--pancake
_______________________________________________
radare mailing list
[email protected]
http://lists.nopcode.org/listinfo.cgi/radare-nopcode.org