-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhead.go
60 lines (51 loc) · 1.11 KB
/
head.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
package ciqdb
import (
"encoding/binary"
"strconv"
)
/*
D000D000 label
0000000D length (13 - possibly static)
00 - constant
02 04 05 - API version
00 00 00 00 mBackgroundDataOffset
00 00 00 00 mBackgroundCodeOffset
00 mEnableAppTrial
*/
type Version struct {
major uint8
minor uint8
patch uint8
}
func (v *Version) String() string {
return strconv.Itoa(int(v.major)) + "." + strconv.Itoa(int(v.minor)) + "." + strconv.Itoa(int(v.patch))
}
type Head struct {
PRGSection
CIQVersion Version
BGDataOffset int
BGCodeOffset int
AppTrial bool
}
func (h *Head) String() string {
return h.PRGSection.String() + `
CIQ version: ` + h.CIQVersion.String() + `
App Trial Enabled: ` + strconv.FormatBool(h.AppTrial)
}
func parseHead(t SecType, length int, data []byte) *Head {
h := Head{
PRGSection: PRGSection{
Type: t,
length: length,
},
CIQVersion: Version{data[1], data[2], data[3]},
}
if length > 4 {
h.BGDataOffset = int(binary.BigEndian.Uint32(data[4:8]))
h.BGCodeOffset = int(binary.BigEndian.Uint32(data[8:12]))
if length > 12 {
h.AppTrial = data[12] == 1
}
}
return &h
}