-
Notifications
You must be signed in to change notification settings - Fork 3
/
srch_strings_pipe
executable file
·74 lines (65 loc) · 1.57 KB
/
srch_strings_pipe
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
#!/bin/bash
# Written by: Dave Lassalle
# Accepts srch_strings output in a pipeline and adds block number and
# byte offset within the block to the output
FSSTAT_CMD="/usr/local/bin/fsstat"
GREP_CMD="/bin/grep"
AWK_CMD="/usr/bin/awk"
BC_CMD="/usr/bin/bc"
PASTE_CMD="/usr/bin/paste"
RM_CMD="/bin/rm"
usage()
{
cat << EOF
usage: $0 [-h] -b blocksize
$0 can be used in a pipeline to add the block number and offset within the block to
"srch_strings -t d". Reads from stdin.
OPTIONS:
-h Print this help message
-b block size of filesystem in imagefile (not needed if -i is used)
-o output file, will output to stdout if not specified
EOF
}
BLOCKSIZE=
OUTFILE=
while getopts “hb:o:” OPTION; do
case $OPTION in
h)
usage
exit 1
;;
b)
BLOCKSIZE=$OPTARG
;;
o)
OUTFILE=$OPTARG
;;
\?)
usage
exit
;;
esac
done
if [[ -z $BLOCKSIZE ]]
then
usage
exit 1
fi
$RM_CMD srch_blocks.tmp
$RM_CMD srch_offset.tmp
$RM_CMD srch_strings.tmp
while read data; do
echo $data | $AWK_CMD '{print $1"/'$BLOCKSIZE'"}' | $BC_CMD >> srch_blocks.tmp
echo $data | $AWK_CMD '{print $1"%'$BLOCKSIZE'"}' | $BC_CMD >> srch_offset.tmp
echo $data >> srch_strings.tmp
done
if [[ -z $OUTFILE ]]
then
$PASTE_CMD srch_blocks.tmp srch_offset.tmp | $PASTE_CMD - srch_strings.tmp
else
$PASTE_CMD srch_blocks.tmp srch_offset.tmp | $PASTE_CMD - srch_strings.tmp > $OUTFILE
fi
$RM_CMD srch_blocks.tmp
$RM_CMD srch_offset.tmp
$RM_CMD srch_strings.tmp
exit 0