-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ntheader_test.go
145 lines (126 loc) · 3.25 KB
/
ntheader_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
// Copyright 2021 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"
"sort"
"strconv"
"testing"
)
func TestParseNtHeaderNE(t *testing.T) {
tests := []struct {
in string
out error
}{
{
// This is an NE executable file. Extracted from Windows CE 2.0.
getAbsoluteFilePath("test/_setup.dll"),
ErrImageOS2SignatureFound,
},
}
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 != tt.out {
t.Fatalf("parsing nt header failed, got %v, want %v", err, tt.out)
}
})
}
}
func TestNtHeaderMachineType(t *testing.T) {
tests := []struct {
in ImageFileHeaderMachineType
out string
}{
{
ImageFileHeaderMachineType(0x8664), "x64",
},
{
ImageFileHeaderMachineType(0xffff), "?",
},
}
for _, tt := range tests {
name := "CaseNtHeaderMachineTypeEqualTo_" + strconv.Itoa(int(tt.in))
t.Run(name, func(t *testing.T) {
got := tt.in.String()
if got != tt.out {
t.Errorf("nt header machine type assertion failed, got %v, want %v",
got, tt.out)
}
})
}
}
func TestNtHeaderCharacteristicsType(t *testing.T) {
tests := []struct {
in ImageFileHeaderCharacteristicsType
out []string
}{
{
ImageFileHeaderCharacteristicsType(0x0022), []string{"ExecutableImage", "LargeAddressAware"},
},
}
for _, tt := range tests {
name := "CaseNtHeaderCharacteristicsTypeEqualTo_" + strconv.Itoa(int(tt.in))
t.Run(name, func(t *testing.T) {
got := tt.in.String()
sort.Strings(got)
sort.Strings(tt.out)
if !reflect.DeepEqual(got, tt.out) {
t.Errorf("nt header Characteristics type assertion failed, got %v, want %v",
got, tt.out)
}
})
}
}
func TestOptionalHeaderSubsystemType(t *testing.T) {
tests := []struct {
in ImageOptionalHeaderSubsystemType
out string
}{
{
ImageOptionalHeaderSubsystemType(0x2), "Windows GUI",
},
{
ImageOptionalHeaderSubsystemType(0xff), "?",
},
}
for _, tt := range tests {
name := "CaseOptionalHeaderSubsystemTypeEqualTo_" + strconv.Itoa(int(tt.in))
t.Run(name, func(t *testing.T) {
got := tt.in.String()
if got != tt.out {
t.Errorf("optional header subsystem type assertion failed, got %v, want %v",
got, tt.out)
}
})
}
}
func TestOptionalHeaderDllCharacteristicsType(t *testing.T) {
tests := []struct {
in ImageOptionalHeaderDllCharacteristicsType
out []string
}{
{
ImageOptionalHeaderDllCharacteristicsType(0x8160),
[]string{"DynamicBase", "HighEntropyVA", "NXCompact", "TerminalServiceAware"},
},
}
for _, tt := range tests {
name := "CaseOptionalHeaderDllCharacteristicsTypeEqualTo_" + strconv.Itoa(int(tt.in))
t.Run(name, func(t *testing.T) {
got := tt.in.String()
sort.Strings(got)
sort.Strings(tt.out)
if !reflect.DeepEqual(got, tt.out) {
t.Errorf("optional header dll characteristics type assertion failed, got %v, want %v",
got, tt.out)
}
})
}
}