File: test-r_anal.py

package info (click to toggle)
radare2 0.9.6-3.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 17,496 kB
  • ctags: 45,959
  • sloc: ansic: 240,999; sh: 3,645; makefile: 2,520; python: 1,212; asm: 312; ruby: 214; awk: 209; perl: 188; lisp: 169; java: 23; xml: 17; php: 6
file content (37 lines) | stat: -rwxr-xr-x 932 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from r2 import r_core

rc = r_core.RCore()
rc.file_open("/bin/ls", 0, 0)
rc.bin_load("")

rc.anal_all()
funcs = rc.anal.get_fcns()

for f in funcs:
	blocks = f.get_bbs()
	print("+" + (72 * "-"))
	print("| FUNCTION: %s @ 0x%x" % (f.name, f.addr))
	print("| (%d blocks)" % (len (blocks)))
	print("+" + (72 * "-"))

	for b in blocks:
		print("---[ Block @ 0x%x ]---" % (b.addr))
		print("   | size:        %d" % (b.size))
		print("   | jump:        0x%x" % (b.jump))
		print("   | conditional: %d" % (b.conditional))
		print("   | return:      %d" % (b.returnbb))

		end_byte = b.addr + b.size
		cur_byte = b.addr

		while (cur_byte < end_byte):
			#anal_op = rc.op_anal(cur_byte)
			asm_op = rc.disassemble(cur_byte)

			if asm_op.inst_len == 0:
				print("Bogus op")
				break

			#print("0x%x %s" % (anal_op.addr, anal_op.mnemonic))
			print("0x%x %s %s" % (cur_byte, asm_op.buf_hex, asm_op.buf_asm))
			cur_byte += asm_op.inst_len