-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathmapsfile_prep.sh
More file actions
executable file
·54 lines (48 loc) · 1.28 KB
/
mapsfile_prep.sh
File metadata and controls
executable file
·54 lines (48 loc) · 1.28 KB
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
#!/bin/bash
# mapsfile_prep.sh
#
# Quick Description:
# Support script for the procmap project.
# Don't invoke this directly, run the 'procmap' wrapper instead.
#
# Author:
# Kaiwan N Billimoria
# kaiwan -at- kaiwantech -dot- com
# kaiwanTECH
# License: MIT
TMPF=/tmp/${name}/prep.$$
TMPF_R=${TMPF}.reversed
gencsv()
{
# CSV format for the foll fields:
# start_uva,end_uva,mode+p|s,offset,image_file
awk '{printf("%s,%s,%s,%s\n", $1,$2,$3,$6)}' ${infile} | tee ${TMPF} >/dev/null
#shellcheck: ^-- SC2024 (warning): sudo doesn't affect redirects. Use ..| sudo tee file
sed --in-place 's/-/,/' ${TMPF}
sed --in-place 's/ /,/' ${TMPF}
# del comment lines
sed --in-place '/^#/d' ${TMPF}
# REVERSE the order of lines, thus ordering the VAS by descending va !!
tac ${TMPF} > ${TMPF_R} || {
echo "tac(1) failed? aborting...(pl report as bug)"
exit 1
}
cp ${TMPF_R} ${outfile}
rm -f ${TMPF} ${TMPF_R} 2>/dev/null
}
##### 'main' : execution starts here #####
[ $# -lt 2 ] && {
echo "Usage: ${name} PID-of-process-for-maps-file output-filename.csv"
exit 1
}
infile=/proc/$1/maps
outfile=$2
[ ! -r ${infile} ] && {
echo "${name}: \"$1\" not readable (permissions issue)? aborting..."
exit 1
}
[ -f ${outfile} ] && {
decho "${name}: !WARNING! \"${outfile}\" exists, will be overwritten!"
}
gencsv
exit 0