-
Notifications
You must be signed in to change notification settings - Fork 3
/
probe_test.go
180 lines (145 loc) · 5.29 KB
/
probe_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package pelican_test
import (
"testing"
"github.com/itchio/headway/state"
"github.com/itchio/httpkit/eos"
"github.com/itchio/pelican"
"github.com/stretchr/testify/assert"
)
func testProbeParams(t *testing.T) pelican.ProbeParams {
return pelican.ProbeParams{
Consumer: &state.Consumer{
OnMessage: func(level string, message string) {
if level == "debug" {
return
}
t.Logf("[%s] %s", level, message)
},
},
Strict: true,
}
}
func Test_NotPeFile(t *testing.T) {
f, err := eos.Open("./testdata/hello/hello.c")
assert.NoError(t, err)
defer f.Close()
_, err = pelican.Probe(f, testProbeParams(t))
assert.Error(t, err)
}
func Test_Hello32Mingw(t *testing.T) {
f, err := eos.Open("./testdata/hello/hello32-mingw.exe")
assert.NoError(t, err)
defer f.Close()
info, err := pelican.Probe(f, testProbeParams(t))
assert.NoError(t, err)
assert.EqualValues(t, pelican.Arch386, info.Arch)
}
func Test_Hello32Msvc(t *testing.T) {
f, err := eos.Open("./testdata/hello/hello32-msvc.exe")
assert.NoError(t, err)
defer f.Close()
info, err := pelican.Probe(f, testProbeParams(t))
assert.NoError(t, err)
assert.EqualValues(t, pelican.Arch386, info.Arch)
}
func Test_Hello64Mingw(t *testing.T) {
f, err := eos.Open("./testdata/hello/hello64-mingw.exe")
assert.NoError(t, err)
defer f.Close()
info, err := pelican.Probe(f, testProbeParams(t))
assert.NoError(t, err)
assert.EqualValues(t, pelican.ArchAmd64, info.Arch)
}
func Test_Hello64Msvc(t *testing.T) {
f, err := eos.Open("./testdata/hello/hello64-msvc.exe")
assert.NoError(t, err)
defer f.Close()
info, err := pelican.Probe(f, testProbeParams(t))
assert.NoError(t, err)
assert.EqualValues(t, pelican.ArchAmd64, info.Arch)
}
func assertResources(t *testing.T, info *pelican.PeInfo) {
vp := info.VersionProperties
assert.EqualValues(t, "itch corp.", vp["CompanyName"])
assert.EqualValues(t, "Test PE file for pelican", vp["FileDescription"])
assert.EqualValues(t, "3.14", vp["FileVersion"])
assert.EqualValues(t, "resourceful", vp["InternalName"])
assert.EqualValues(t, "(c) 2018 itch corp.", vp["LegalCopyright"])
// totally a mistake, but leaving this as a reminder that
// not everything is worth fixing
assert.EqualValues(t, "butler", vp["ProductName"])
assert.EqualValues(t, "6.28", vp["ProductVersion"])
assert.Nil(t, info.AssemblyInfo)
}
func Test_Resourceful32Mingw(t *testing.T) {
f, err := eos.Open("./testdata/resourceful/resourceful32-mingw.exe")
assert.NoError(t, err)
defer f.Close()
info, err := pelican.Probe(f, testProbeParams(t))
assert.NoError(t, err)
assert.EqualValues(t, pelican.Arch386, info.Arch)
assertResources(t, info)
}
func Test_Resourceful64Mingw(t *testing.T) {
f, err := eos.Open("./testdata/resourceful/resourceful64-mingw.exe")
assert.NoError(t, err)
defer f.Close()
info, err := pelican.Probe(f, testProbeParams(t))
assert.NoError(t, err)
assert.EqualValues(t, pelican.ArchAmd64, info.Arch)
assertResources(t, info)
}
func Test_WinCDEmuInstaller(t *testing.T) {
f, err := eos.Open("./testdata/wincdemu/WinCDEmu-4.1.exe")
assert.NoError(t, err)
defer f.Close()
info, err := pelican.Probe(f, testProbeParams(t))
assert.NoError(t, err)
assert.EqualValues(t, pelican.Arch386, info.Arch)
vp := info.VersionProperties
assert.EqualValues(t, "Sysprogs OU", vp["CompanyName"])
assert.EqualValues(t, "WinCDEmu installer", vp["FileDescription"])
assert.EqualValues(t, "4.1", vp["FileVersion"])
assert.EqualValues(t, "LGPL", vp["LegalCopyright"])
assert.EqualValues(t, "WinCDEmu", vp["ProductName"])
assert.EqualValues(t, "4.1", vp["ProductVersion"])
assert.NotNil(t, info.AssemblyInfo)
assert.EqualValues(t, "requireAdministrator", info.AssemblyInfo.RequestedExecutionLevel)
assert.True(t, info.RequiresElevation())
assert.EqualValues(t, 1, len(info.DependentAssemblies))
da := info.DependentAssemblies[0]
assert.EqualValues(t, "Microsoft.Windows.Common-Controls", da.Name)
assert.EqualValues(t, "*", da.Language)
assert.EqualValues(t, "*", da.ProcessorArchitecture)
assert.EqualValues(t, "6595b64144ccf1df", da.PublicKeyToken)
}
func Test_PidginUninstaller(t *testing.T) {
f, err := eos.Open("./testdata/pidgin/pidgin-uninst.exe")
assert.NoError(t, err)
defer f.Close()
info, err := pelican.Probe(f, testProbeParams(t))
assert.NoError(t, err)
assert.EqualValues(t, pelican.Arch386, info.Arch)
vp := info.VersionProperties
assert.EqualValues(t, "Pidgin Installer", vp["FileDescription"])
assert.EqualValues(t, "2.10.11", vp["FileVersion"])
assert.EqualValues(t, "Pidgin", vp["ProductName"])
assert.EqualValues(t, "2.10.11", vp["ProductVersion"])
assert.NotNil(t, info.AssemblyInfo)
assert.EqualValues(t, "highestAvailable", info.AssemblyInfo.RequestedExecutionLevel)
assert.True(t, info.RequiresElevation())
assert.EqualValues(t, 1, len(info.DependentAssemblies))
da := info.DependentAssemblies[0]
assert.EqualValues(t, "Microsoft.Windows.Common-Controls", da.Name)
assert.EqualValues(t, "*", da.Language)
assert.EqualValues(t, "X86", da.ProcessorArchitecture)
assert.EqualValues(t, "6595b64144ccf1df", da.PublicKeyToken)
}
func Test_Stockboy(t *testing.T) {
f, err := eos.Open("./testdata/stockboy/stockboy_install_sliced.EXE")
assert.NoError(t, err)
defer f.Close()
info, err := pelican.Probe(f, testProbeParams(t))
assert.NoError(t, err)
assert.EqualValues(t, pelican.Arch386, info.Arch)
}