-
Notifications
You must be signed in to change notification settings - Fork 7
/
entries.go
89 lines (76 loc) · 1.8 KB
/
entries.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
package ciqdb
import (
"encoding/binary"
"encoding/hex"
"fmt"
"strconv"
"strings"
)
type EntrySection struct {
PRGSection
Entries []EntryPoint
}
func (e *EntrySection) String() string {
var buf strings.Builder
buf.WriteString(e.PRGSection.String())
for i, ep := range e.Entries {
buf.WriteString("\n Entry Point " + strconv.Itoa(i))
buf.WriteString(ep.String())
}
return buf.String()
}
//go:generate stringer -type=AppType
type AppType uint8
const (
WatchFace AppType = iota
App
DataField
Widget
BackgroundApp
AudioProvider
)
type EntryPoint struct {
uuid string
module int
symbol int
label int
icon int
apptype AppType
}
func (e *EntryPoint) String() string {
return `
UUID: ` + e.uuid + `
Type: ` + fmt.Sprint(e.apptype) + `
` + apidb(e.label) + `: ` + apidb(e.symbol) + `
Module: ` + apidb(e.module) + `
icon: ` + strconv.FormatInt(int64(e.icon), 16)
}
func parseEntries(p *PRG, t SecType, length int, data []byte) (*EntrySection, error) {
e := EntrySection{
PRGSection: PRGSection{
Type: t,
length: length,
},
}
n := int(binary.BigEndian.Uint16(data[:2]))
for i := 0; i < n; i++ {
entry, err := parseEntry(p.Filename, data[i*36+2:(i+1)*36+2])
if err != nil {
return nil, err
}
e.Entries = append(e.Entries, *entry)
}
return &e, nil
}
func parseEntry(filename string, data []byte) (*EntryPoint, error) {
entry := EntryPoint{
uuid: hex.EncodeToString(data[:16]),
module: int(binary.BigEndian.Uint32(data[16:20])),
symbol: int(binary.BigEndian.Uint32(data[20:24])),
label: int(binary.BigEndian.Uint32(data[24:28])),
icon: int(binary.BigEndian.Uint32(data[28:32])),
apptype: AppType(binary.BigEndian.Uint32(data[32:36])),
}
// for symbol, label, also see .prg.debug : <symbolTable><entry id="X"/>
return &entry, nil
}