-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
personalized_image.go
78 lines (69 loc) · 1.68 KB
/
personalized_image.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
package imagemounter
import (
"fmt"
"howett.net/plist"
"os"
"strconv"
"strings"
)
type buildManifest struct {
BuildIdentities []buildIdentity
}
func loadBuildManifest(p string) (buildManifest, error) {
f, err := os.Open(p)
if err != nil {
return buildManifest{}, fmt.Errorf("loadBuildManifest: faild to open manifest file: %w", err)
}
defer f.Close()
dec := plist.NewDecoder(f)
var m buildManifest
err = dec.Decode(&m)
if err != nil {
return buildManifest{}, fmt.Errorf("loadBuildManifest: could not decode manifest file: %w", err)
}
return m, nil
}
func (m buildManifest) findIdentity(identifiers personalizationIdentifiers) (buildIdentity, error) {
for _, i := range m.BuildIdentities {
if i.ApBoardID() == identifiers.BoardId && i.ApChipID() == identifiers.ChipID {
return i, nil
}
}
return buildIdentity{}, fmt.Errorf("findIdentity: failed to find identity for ApBoardId 0x%x and ApChipId 0x%x", identifiers.BoardId, identifiers.ChipID)
}
type buildIdentity struct {
BoardID string `plist:"ApBoardID"`
ChipID string `plist:"ApChipID"`
Manifest struct {
LoadableTrustCache struct {
Digest []byte
Info struct {
Path string
}
}
PersonalizedDmg struct {
Digest []byte
Info struct {
Path string
}
} `plist:"PersonalizedDMG"`
}
}
func (b buildIdentity) ApBoardID() int {
return hexToInt(b.BoardID)
}
func (b buildIdentity) ApChipID() int {
return hexToInt(b.ChipID)
}
type personalizationIdentifiers struct {
BoardId int
ChipID int
SecurityDomain int
}
func hexToInt(s string) int {
i, err := strconv.ParseInt(strings.ReplaceAll(strings.ToLower(s), "0x", ""), 16, 32)
if err != nil {
return 0
}
return int(i)
}