File: r2.awk

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 (58 lines) | stat: -rwxr-xr-x 1,674 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/awk -f

# Configuration
BEGIN {
	file=""
	arch="arm"
	port=0
	host="localhost"
	bits=32
	offset=0
	iova=1
}

# API
function sys(_cmd) {
	_res = ""
	_n=0
	while((_cmd|getline _line)>0) {
		_n++
 		_res=_res""_line"\n"
	}
	if(_n==0) return 0
	return _res
}

function chop(_x) {
	gsub(/\n/,"",_x);
	return _x
}

function round(a) {a=(a < int(a)+0.5) ? int(a) : int(a+1)}
function ceil(a) {a=(a == int(a)) ? a : int(a)+1}
function dis(x) { return sys("rasm2 -o "offset" -b "bits" -a "arch" -d '"x"'"); }
function asm(x) { return sys("rasm2 -o "offset" -b "bits" -a "arch" '"x"'"); }
function symbols() { return sys("rabin2 -vqs '"file"'"); }
function entries() { return sys("rabin2 -vqe '"file"'"); }
function imports() { return sys("rabin2 -vqi '"file"'"); }
function strings() { return sys("rabin2 -vqz '"file"'"); }
function sections() { return sys("rabin2 -vqS '"file"'"); }
function num(x) { return 0+x }
function cmd(c) { return sys("r2 -qc '"cmd"' '"file"'") }
function read(off,num) { return sys("r2 -qc 'p8 "num"@"off"' '"file"'") }
function write(off,x) { return sys("r2 -wqc 'wx "x"@"off"' '"file"'") }
function string(off) { return chop(sys("r2 -qc 'psz@"off"' '"file"'")) }
function prompt(x) {printf(x);getline y; return chop(y); }
function search_hex(x) { return sys("rafind2 -x '"x"' '"file"'") }
function search_str(x) { return sys("rafind2 -s '"x"' '"file"'") }

# session server
function r2open() {
	srand()rand()
	port=1024+int(8192*rand())
	if(system("r2 -qc .:"port" "file" >/dev/null 2>&1 &"))
		return 0
	return port
}
function r2cmd(port, cmd) { return sys("r2 -qc'\".:"host":"port" "cmd"\"' -") }
function r2close(port) { r2cmd(port,"q!") }