-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinf.go
53 lines (45 loc) · 1.06 KB
/
inf.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
package main
import (
"bytes"
"encoding/binary"
)
// INF represents the INF1/INFO format within a BMG.
type INF struct {
INFHeader
Entries []INFEntry
}
// INFHeader represents the initial header of an INF1 block.
type INFHeader struct {
EntryCount uint16
// This is the length of an INFEntry.
// We assume a size of 8 and hardcode such.
// It's unknown where values may differ.
EntryLength uint16
GroupID uint16
DefaultColor uint8
_ uint8
}
// INFEntry represents an info entry within the INF1 block.
// It's assumed every entry's size is 8. Tweak accordingly if such is fale.
type INFEntry struct {
Offset uint32
Attributes [4]byte
}
func NewINF(data []byte) (*INF, error) {
// Parse initial header
readable := bytes.NewReader(data)
var header INFHeader
err := binary.Read(readable, binary.BigEndian, &header)
if err != nil {
return nil, err
}
entries := make([]INFEntry, header.EntryCount)
err = binary.Read(readable, binary.BigEndian, &entries)
if err != nil {
return nil, err
}
return &INF{
header,
entries,
}, nil
}