-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
richheader_test.go
175 lines (158 loc) · 4.11 KB
/
richheader_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
// Copyright 2018 Saferwall. All rights reserved.
// Use of this source code is governed by Apache v2 license
// license that can be found in the LICENSE file.
package pe
import (
"reflect"
"testing"
)
type TestRichHeader struct {
richHeader RichHeader
compIDIndex uint8
prettyProdID string
VSVersion string
checksum uint32
}
func TestParseRichHeader(t *testing.T) {
tests := []struct {
in string
out TestRichHeader
}{
{getAbsoluteFilePath("test/kernel32.dll"),
TestRichHeader{
richHeader: RichHeader{
XORKey: 2796214951,
CompIDs: []CompID{
{
MinorCV: 27412,
ProdID: 257,
Count: 4,
Unmasked: 16870164,
},
{
MinorCV: 30729,
ProdID: 147,
Count: 193,
Unmasked: 9664521,
},
{
MinorCV: 0,
ProdID: 1,
Count: 1325,
Unmasked: 65536,
},
{
MinorCV: 27412,
ProdID: 260,
Count: 9,
Unmasked: 17066772,
},
{
MinorCV: 27412,
ProdID: 259,
Count: 3,
Unmasked: 17001236,
},
{
MinorCV: 27412,
ProdID: 256,
Count: 1,
Unmasked: 16804628,
},
{
MinorCV: 27412,
ProdID: 269,
Count: 209,
Unmasked: 17656596,
},
{
MinorCV: 27412,
ProdID: 255,
Count: 1,
Unmasked: 16739092,
},
{
MinorCV: 27412,
ProdID: 258,
Count: 1,
Unmasked: 16935700,
},
},
DansOffset: 128,
Raw: []byte{
0xe3, 0xbb, 0xc4, 0xf5, 0xa7, 0xda, 0xaa, 0xa6, 0xa7, 0xda, 0xaa, 0xa6, 0xa7, 0xda, 0xaa,
0xa6, 0xb3, 0xb1, 0xab, 0xa7, 0xa3, 0xda, 0xaa, 0xa6, 0xae, 0xa2, 0x39, 0xa6, 0x66, 0xda,
0xaa, 0xa6, 0xa7, 0xda, 0xab, 0xa6, 0x8a, 0xdf, 0xaa, 0xa6, 0xb3, 0xb1, 0xae, 0xa7, 0xae,
0xda, 0xaa, 0xa6, 0xb3, 0xb1, 0xa9, 0xa7, 0xa4, 0xda, 0xaa, 0xa6, 0xb3, 0xb1, 0xaa, 0xa7,
0xa6, 0xda, 0xaa, 0xa6, 0xb3, 0xb1, 0xa7, 0xa7, 0x76, 0xda, 0xaa, 0xa6, 0xb3, 0xb1, 0x55,
0xa6, 0xa6, 0xda, 0xaa, 0xa6, 0xb3, 0xb1, 0xa8, 0xa7, 0xa6, 0xda, 0xaa, 0xa6, 0x52, 0x69,
0x63, 0x68, 0xa7, 0xda, 0xaa, 0xa6},
},
compIDIndex: 3,
prettyProdID: "Utc1900_C",
VSVersion: "Visual Studio 2015 14.00",
checksum: 0xa6aadaa7,
}},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
ops := Options{Fast: true}
file, err := New(tt.in, &ops)
if err != nil {
t.Fatalf("New(%s) failed, reason: %v", tt.in, err)
}
err = file.Parse()
if err != nil {
t.Fatalf("Parse(%s) failed, reason: %v", tt.in, err)
}
richHeader := file.RichHeader
if !reflect.DeepEqual(richHeader, tt.out.richHeader) {
t.Errorf("rich header test failed, got %v, want %v",
richHeader, tt.out)
}
prodID := richHeader.CompIDs[tt.out.compIDIndex].ProdID
prettyProdID := ProdIDtoStr(prodID)
if prettyProdID != tt.out.prettyProdID {
t.Errorf("rich header pretty prod ID failed, got %v, want %v",
prettyProdID, tt.out.prettyProdID)
}
VSVersion := ProdIDtoVSversion(prodID)
if VSVersion != tt.out.VSVersion {
t.Errorf("rich header VS verion of prod ID failed, got %v, want %v",
VSVersion, tt.out.VSVersion)
}
checksum := file.RichHeaderChecksum()
if checksum != tt.out.checksum {
t.Errorf("rich header checksum failed, got %v, want %v",
checksum, tt.out.checksum)
}
})
}
}
func TestRichHeaderHash(t *testing.T) {
tests := []struct {
in string
out string
}{
{getAbsoluteFilePath("test/kernel32.dll"),
"4549320af6790d410f09ddc3bab86c86"},
{getAbsoluteFilePath("test/WdBoot.sys"),
"3cbccbf62a2a6a8066a5c9d294c90948"},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
file, err := New(tt.in, &Options{})
if err != nil {
t.Fatalf("New(%s) failed, reason: %v", tt.in, err)
}
err = file.Parse()
if err != nil {
t.Fatalf("Parse(%s) failed, reason: %v", tt.in, err)
}
got := file.RichHeaderHash()
if string(got) != tt.out {
t.Errorf("Authentihash(%s) got %v, want %v", tt.in, got, tt.out)
}
})
}
}