-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfingerprint_test.go
137 lines (131 loc) · 3.44 KB
/
fingerprint_test.go
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package fingerprint
import (
"encoding/json"
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestBinaries(t *testing.T) {
generate := os.Getenv("GENERATE") == "1"
binaries := []string{
// pe
"calc.exe",
"calc.packed.exe",
"helloworld.exe",
"avcodec.dll",
// macho
"main",
"main.fat",
"sqlite3.fat.packed",
// elf
"hello.linux.stripped",
"hello.linux.packed.stripped",
"libxml2.so",
// lnk
"lnk/local.directory.seven.lnk",
"lnk/local.directory.xp.lnk",
"lnk/local.file.darwin.lnk",
"lnk/local.file.env.lnk",
"lnk/local.file.exec.lnk",
"lnk/local.file.icoset.lnk",
"lnk/local.file.seven.lnk",
"lnk/local.file.xp.lnk",
"lnk/local_cmd.lnk",
"lnk/local_unicode.lnk",
"lnk/local_win31j.lnk",
"lnk/microsoft.lnk",
"lnk/native.2008srv.01.lnk",
"lnk/native.2008srv.02.lnk",
"lnk/native.2008srv.03.lnk",
"lnk/native.2008srv.04.lnk",
"lnk/native.2008srv.05.lnk",
"lnk/native.2008srv.06.lnk",
"lnk/native.2008srv.07.lnk",
"lnk/native.2008srv.08.lnk",
"lnk/native.2008srv.09.lnk",
"lnk/native.2008srv.10.lnk",
"lnk/native.2008srv.11.lnk",
"lnk/native.2008srv.12.lnk",
"lnk/native.2008srv.13.lnk",
"lnk/native.2008srv.14.lnk",
"lnk/native.2008srv.15.lnk",
"lnk/native.2008srv.16.lnk",
"lnk/native.2008srv.17.lnk",
"lnk/native.2008srv.18.lnk",
"lnk/native.2008srv.19.lnk",
"lnk/native.2008srv.20.lnk",
"lnk/native.seven.01.lnk",
"lnk/native.seven.02.lnk",
"lnk/native.seven.03.lnk",
"lnk/native.seven.04.lnk",
"lnk/native.seven.05.lnk",
"lnk/native.seven.06.lnk",
"lnk/native.seven.07.lnk",
"lnk/native.seven.08.lnk",
"lnk/native.seven.09.lnk",
"lnk/native.seven.10.lnk",
"lnk/native.seven.11.lnk",
"lnk/native.seven.12.lnk",
"lnk/native.seven.13.lnk",
"lnk/native.seven.14.lnk",
"lnk/native.seven.15.lnk",
"lnk/native.seven.16.lnk",
"lnk/native.seven.17.lnk",
"lnk/native.seven.18.lnk",
"lnk/native.seven.19.lnk",
"lnk/native.seven.20.lnk",
"lnk/native.xp.01.lnk",
"lnk/native.xp.02.lnk",
"lnk/native.xp.03.lnk",
"lnk/native.xp.04.lnk",
"lnk/native.xp.05.lnk",
"lnk/native.xp.06.lnk",
"lnk/native.xp.07.lnk",
"lnk/native.xp.08.lnk",
"lnk/native.xp.09.lnk",
"lnk/native.xp.10.lnk",
"lnk/native.xp.11.lnk",
"lnk/native.xp.12.lnk",
"lnk/native.xp.13.lnk",
"lnk/native.xp.14.lnk",
"lnk/native.xp.15.lnk",
"lnk/native.xp.16.lnk",
"lnk/native.xp.17.lnk",
"lnk/native.xp.18.lnk",
"lnk/native.xp.19.lnk",
"lnk/native.xp.20.lnk",
"lnk/net_unicode.lnk",
"lnk/net_unicode2.lnk",
"lnk/net_win31j.lnk",
"lnk/remote.directory.xp.lnk",
"lnk/remote.file.aidlist.lnk",
"lnk/remote.file.xp.lnk",
}
for _, binary := range binaries {
t.Run(binary, func(t *testing.T) {
f, err := os.Open("./fixtures/" + binary)
require.NoError(t, err)
defer f.Close()
fileInfo, err := f.Stat()
require.NoError(t, err)
info, err := Parse(f, int(fileInfo.Size()))
require.NoError(t, err)
expectedFile := "./fixtures/" + binary + ".fingerprint"
if generate {
data, err := json.MarshalIndent(info, "", " ")
require.NoError(t, err)
require.NoError(t, ioutil.WriteFile(expectedFile, data, 0644))
} else {
fixture, err := os.Open(expectedFile)
require.NoError(t, err)
defer fixture.Close()
expected, err := ioutil.ReadAll(fixture)
require.NoError(t, err)
data, err := json.Marshal(info)
require.NoError(t, err)
require.JSONEq(t, string(expected), string(data))
}
})
}
}