Created
April 14, 2016 18:38
-
-
Save radare/f0e26fbfeba327729e2778c9ca08d40a to your computer and use it in GitHub Desktop.
python r2pipe script to enumerate all branches (calls and jumps)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ejecutar asi: r2 -qi calls.py /bin/ls | |
import r2pipe | |
r2 = r2pipe.open() | |
r2.cmd('s $S @ entry0') # ir al principio de la seccion de codigo | |
# direccion minima y maxima de la seccion de codigo | |
addr = int(r2.cmd('?v $S'), 16) | |
addr_end = int(r2.cmd('?v $S + $SS'), 16) | |
while addr < addr_end: | |
r2.cmd('s %s'%(addr)) | |
try: | |
# analizamos el opcode | |
op = r2.cmdj('aoj')[0] | |
# si es de tipo jmp, cjmp o call | |
if op['type'] in ['jmp', 'call', 'cjmp']: | |
print "%s -> %s"%(op['addr'], op['jump']) | |
# ir al siguiente opcode | |
opsize = op['size']; | |
except: | |
# si la instruccion es invalida asumimos q el tamaño minimo | |
# de instruccion es 1, en no-x86 puede ser 2 o 4 | |
opsize = 1 | |
# calcula la siguiente direccion | |
addr = addr + opsize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment