-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathifd_test.go
More file actions
81 lines (66 loc) · 2.53 KB
/
ifd_test.go
File metadata and controls
81 lines (66 loc) · 2.53 KB
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
package intelifd
import (
"github.com/stretchr/testify/assert"
"testing"
)
const testImage16MB = 16777216
var (
testIFDBytes = []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x5a, 0xa5, 0xf0, 0x0f, 0x03, 0x00, 0x04, 0x00, 0x08, 0x02, 0x10, 0x58, 0x30, 0x03, 0x31, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xf5, 0x00, 0x5c, 0x12, 0x21, 0x42, 0x60, 0xad, 0xb7, 0xb9, 0xc4, 0xc7, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0xff, 0x0f, 0x03, 0x00, 0x7f, 0x02, 0x01, 0x00, 0x02, 0x00,
0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00,
0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
}
testFlumap1 = []byte{0x00, 0x00, 0x02, 0xDF}
testOffset, testIFDHeader = uint32(0x10), IFDHeader{
Offset: 0x10,
Flvalsig: 0xff0a55a,
Flmap0: FLMAP0{
IFDEntry: IFDEntry{0x40003}},
Flmap1: FLMAP1{
IFDEntry: IFDEntry{0x58100208}},
Flmap2: FLMAP2{
IFDEntry: IFDEntry{0x310330}},
Flmap3: FLMAP3{
IFDEntry: IFDEntry{0xffffffff}},
Flumap1: FLUMAP1{
IFDEntry: IFDEntry{0x000002df}},
}
)
func mockIFDHeaderImage() []byte {
firmware := make([]byte, testImage16MB)
copy(firmware[:], testIFDBytes)
copy(firmware[0x10+flumapPosition:], testFlumap1)
return firmware
}
func TestFindFD(t *testing.T) {
offset, err := FindFD(testIFDBytes)
assert.Nil(t, err)
assert.Equal(t, testOffset, offset)
}
func TestFindFDFail(t *testing.T) {
ifdBytes := make([]byte, 101)
offset, err := FindFD(ifdBytes)
assert.EqualError(t, err, "could not find IFD Header 0x5AA5F00F")
assert.Equal(t, uint32(0), offset)
}
func TestParseIFDHeaderImageToSmall(t *testing.T) {
header, err := ParseIFDHeader(testIFDBytes, 0x12345678)
assert.EqualError(t, err, "image to small")
assert.Nil(t, header)
}
func TestParseIFDHeader(t *testing.T) {
header, err := ParseIFDHeader(mockIFDHeaderImage(), 0x10)
assert.Nil(t, err)
assert.Equal(t, testIFDHeader.Offset, header.Offset)
assert.Equal(t, testIFDHeader.Flvalsig, header.Flvalsig)
assert.Equal(t, testIFDHeader.Flmap0.Raw, header.Flmap0.Raw)
assert.Equal(t, testIFDHeader.Flmap1.Raw, header.Flmap1.Raw)
assert.Equal(t, testIFDHeader.Flmap2.Raw, header.Flmap2.Raw)
assert.Equal(t, testIFDHeader.Flmap3.Raw, header.Flmap3.Raw)
assert.Equal(t, testIFDHeader.Flumap1.Raw, header.Flumap1.Raw)
}