-
Notifications
You must be signed in to change notification settings - Fork 7
/
sections.go
142 lines (129 loc) · 3.54 KB
/
sections.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package ciqdb
import (
"encoding/binary"
"io"
"strconv"
"strings"
)
type PRGSection struct {
Type SecType
length int
}
func (s *PRGSection) String() string {
return s.getLabel() + " - " + s.getName() + " (" + strconv.Itoa(s.getLength()) + " bytes)"
}
func (s *PRGSection) getName() string {
return s.Type.String()
}
func (s *PRGSection) getLabel() string {
label := strconv.FormatInt(int64(s.Type), 16)
if len(label) < 8 {
return strings.Repeat("0", 8-len(label)) + label
}
return label
}
func (s *PRGSection) getLength() int {
return s.length
}
func (s *PRGSection) getType() SecType {
return s.Type
}
type GenericDataSection struct {
PRGSection
data []byte
}
type SecType int
const (
SectionHead = SecType(0xd000d000)
SectionEntry = SecType(0x6060c0de) // "gogo code"
SectionData = SecType(0xda7ababe)
SectionCode = SecType(0xc0debabe)
SectionCodeTable = SecType(0xc0de7ab1)
SectionClassTable = SecType(0xc1a557b1)
SectionFoodGood = SecType(0xf00d600d)
SectionGoodBoy = SecType(0x6000db01)
SectionExceptions = SecType(0x0ece7105) // ecetios
SectionSymbols = SecType(0x5717b015) // stltbols?
SectionSettings = SecType(0x5e771465) // settings
SectionEncoded = SecType(0xe1c0de12) // elcodel
SectionUnlock = SecType(0xd011aaa5) // unlock for app trials?
SectionIQSig = SecType(0x00020833)
SectionEnd = SecType(0x00000000)
)
var secNames = map[SecType]string{
SectionHead: "Head",
SectionEntry: "Entry Points",
SectionData: "Data",
SectionCode: "Code",
SectionCodeTable: "Code Table (aka PCtoLineNum)",
SectionClassTable: "Class Table (class imports)",
SectionFoodGood: "Resources",
SectionGoodBoy: "Permissions",
SectionExceptions: "Exceptions",
SectionSymbols: "Symbols",
SectionSettings: "Settings",
SectionEncoded: "Developer Signature",
SectionUnlock: "App Unlock",
SectionIQSig: "App Store Signature",
SectionEnd: "End",
}
func (t SecType) String() string {
if name, exists := secNames[t]; exists {
return name
} else {
return "Unknown"
}
}
func readSection(p *PRG, f io.Reader) (Section, error) {
head := make([]byte, 8)
if _, err := io.ReadFull(f, head); err != nil {
return nil, err
}
secType := SecType(binary.BigEndian.Uint32(head[:4]))
secLength := int(binary.BigEndian.Uint32(head[4:]))
//to skip reading it in
// f.Seek(int64(sec.length), 1)
data := make([]byte, secLength)
if _, err := io.ReadFull(f, data); err != nil {
return nil, err
}
var sec Section
var err error
switch secType {
case SectionHead:
sec = parseHead(secType, secLength, data)
case SectionEntry:
sec, err = parseEntries(p, secType, secLength, data)
case SectionSettings:
sec = parseSettings(p, secType, secLength, data)
case SectionData:
sec = parseData(p, secType, secLength, data)
case SectionCodeTable:
sec = parsePCTable(p, secType, secLength, data)
case SectionClassTable:
sec = parseDataTable(p, secType, secLength, data)
case SectionGoodBoy:
sec = parsePermissions(p, secType, secLength, data)
case SectionExceptions:
sec = parseExceptions(p, secType, secLength, data)
case SectionSymbols:
sec = parseSymbols(p, secType, secLength, data)
case SectionEncoded:
sec = parseDevKey(p, secType, secLength, data)
default:
sec = defaultSection(secType, secLength, data)
}
if err != nil {
return nil, err
}
return sec, nil
}
func defaultSection(t SecType, length int, data []byte) *GenericDataSection {
return &GenericDataSection{
PRGSection: PRGSection{
Type: t,
length: length,
},
data: data,
}
}