-
Notifications
You must be signed in to change notification settings - Fork 7
/
find-addresses
executable file
·89 lines (80 loc) · 1.57 KB
/
find-addresses
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/awk -f
function add_size(name, size, vma, lma, fa)
{
scns[idx, "name"] = name
scns[idx, "size"] = size
scns[idx, "vma"] = vma
scns[idx, "lma"] = lma
scns[idx, "fa"] = fa
if (found != 1) {
if ($1 == "Idx")
found = 1
next
}
}
function load(idx)
{
return match(scns[idx, "flags"], /LOAD/)
}
function alloc(idx)
{
return match(scns[idx, "flags"], /ALLOC/)
}
function max(a, b)
{
return a > b ? a : b
}
function start(idx)
{
#print scns[idx, "name"] " vma:" scns[idx, "vma"] " lma:" scns[idx, "lma"] " fa:" scns[idx, "fa"] " max: " \
# max(scns[idx, "vma"],
# max(scns[idx, "lma"], scns[idx, "fa"]))
return max(scns[idx, "vma"],
max(scns[idx, "lma"], scns[idx, "fa"]))
}
function end(idx)
{
return start(idx) + scns[idx, "size"]
}
BEGIN {
maxidx = 0
idx = 0
found = 0
pos = 0
}
{
#print "FNR:" FNR " $0:" $0
if (pos % 2 == 0) {
add_size($2, strtonum("0x"$3), strtonum("0x"$4),
strtonum("0x"$5), strtonum("0x"$6))
indices[idx] = idx
} else {
scns[idx, "flags"] = $0
#print "scns[" idx "]:" scns[idx, "name"] " " scns[idx, "flags"]
idx++
}
pos++
}
END {
maxidx = 0
for (idx in indices)
{
if (!load(idx) && !alloc(idx)) {
#print "scns[" idx ", flags]:" scns[idx, "flags"]
continue
}
#print "name:" scns[idx, "name"] " start:" start(idx) " end:" end(idx)
if (end(idx) > end(maxidx))
{
#print "updating maxidx " idx " -> " maxidx
maxidx = idx
}
}
db = end(maxidx)
if (db % 4096 != 0)
db += 4096 - (db % 4096)
dbx = db + dbsz
if (dbx % 4096 != 0)
dbx += 4096 - (dbx % 4096)
printf "0x%x 0x%x\n", db, dbx
}