-
Notifications
You must be signed in to change notification settings - Fork 3
/
lib.sh
117 lines (98 loc) · 2.07 KB
/
lib.sh
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
function heading()
{
local sep='-----------------------------------------------------------------------------'
echo ${sep}
echo $1
echo ${sep}
}
function alltargets()
{
find target -name fuzz.go | while read path; do
path=${path#target/}
echo ${path%/fuzz.go}
done
}
function targets()
{
alltargets | awk '$1 !~ "^exp/"'
}
function local_path()
{
echo -n "target/$1"
}
function target_import_path()
{
local repo='github.com/mmcloughlin/cryptofuzz'
echo -n "${repo}/$(local_path $1)"
}
function bin_file()
{
echo -n "$(local_path $1)/bin.zip"
}
function fuzz_files()
{
echo $(bin_file $1)
for datadir in corpus crashers suppressions; do
datapath="$(local_path $1)/${datadir}"
if [ -d ${datapath} ]; then
echo $datapath
fi
done
}
function package_dir()
{
go list -f '{{ .Dir }}' $1
}
function package_files_for_arch()
{
local pkg=$1
local arch=$2
GOOS=linux GOARCH=${arch} go list -f '
{{ join .GoFiles " "}}
{{ join .TestGoFiles " "}}
{{ join .XTestGoFiles " "}}
{{ join .SFiles " " }}
{{ join .HFiles " " }}
' ${pkg}
}
function clear_build_tags()
{
local path=$1
sed -i.bak '/+build/d' ${path}/*
rm -rf ${path}/*.bak
}
function clear_import_path_assertions()
{
local path=$1
sed -i.bak 's/\/\/ import.*//' ${path}/*
rm -rf ${path}/*.bak
}
function fork_package_for_arch()
{
local pkg=$1
local arch=$2
local dst=$3
mkdir -p ${dst}
dir=$(package_dir ${pkg})
for filename in $(package_files_for_arch ${pkg} ${arch}); do
cp -v ${dir}/${filename} ${dst}
done
clear_build_tags ${dst}
clear_import_path_assertions ${dst}
}
function clone_package()
{
local pkg=$1
local dst=$2
mkdir -p ${dst}
cp $(package_dir ${pkg})/* ${dst}
clear_import_path_assertions ${dst}
}
function rewrite_imports()
{
local path=$1
local from=$2
local to=$3
find ${path} -type f | xargs sed -i.bak "s|${from}|${to}|"
find ${path} -name '*.bak' | xargs rm -rf
}