-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
overlay_test.go
56 lines (49 loc) · 1.27 KB
/
overlay_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
package pe
import (
"crypto/md5"
"encoding/hex"
"testing"
)
type TestOverlay struct {
overlayOffset int64
overlayLength int64
md5str string
}
var overlayTests = []struct {
in string
out TestOverlay
}{
{getAbsoluteFilePath("test/putty.exe"),
TestOverlay{
overlayOffset: 1163264,
overlayLength: 15760,
md5str: "1f46295a513e744895a6acf1029e136f",
}},
}
func TestFile_NewOverlayReader(t *testing.T) {
for _, tt := range overlayTests {
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)
}
if err := file.Parse(); err != nil {
t.Fatalf("Parse(%s) failed, reason: %v", tt.in, err)
}
if file.OverlayOffset != tt.out.overlayOffset {
t.Errorf("overlayLength failed, got %d, want %d", file.OverlayOffset, tt.out.overlayOffset)
}
overlayLength := file.OverlayLength()
if overlayLength != tt.out.overlayLength {
t.Errorf("overlayOffset failed, got %d, want %d", overlayLength, tt.out.overlayLength)
}
overlay, _ := file.Overlay()
h := md5.New()
h.Write(overlay)
md5str := hex.EncodeToString(h.Sum(nil))
if md5str != tt.out.md5str {
t.Errorf("overlayOffset failed, got %s, want %s", md5str, tt.out.md5str)
}
})
}
}