-
Notifications
You must be signed in to change notification settings - Fork 1
/
patcher.go
171 lines (128 loc) · 4.55 KB
/
patcher.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package main
import (
"encoding/json"
"io/fs"
"os"
"path/filepath"
"strings"
"github.com/mholt/archiver"
)
type Manifest struct {
Metadata struct {
Build string `json:"build"`
Commit string `json:"commit"`
ConfirmUpdate bool `json:"confirm_update"`
} `json:"metadata"`
Hashes map[string]string `json:"hashes"`
}
func setSupportedDevices() {
logger.Debug("Setting supported devices...")
delete(info, "UISupportedDevices")
logger.Info("Supported devices set.")
}
func setAppName() {
logger.Debug("Setting app name...")
info["CFBundleName"] = "Unbound"
info["CFBundleDisplayName"] = "Unbound"
logger.Info("App name set.")
}
func setFileAccess() {
logger.Debug("Setting file access...")
info["UISupportsDocumentBrowser"] = true
info["UIFileSharingEnabled"] = true
logger.Info("File access enabled.")
}
func setIcons() {
logger.Debug("Downloading app icons...")
icons := filepath.Join(assets, "icons.zip")
download("https://assets.unbound.rip/icons/ios.zip", icons)
logger.Info("Downloaded app icons.")
logger.Debug("Applying app icons...")
info["CFBundleIcons"].(map[string]interface{})["CFBundlePrimaryIcon"].(map[string]interface{})["CFBundleIconName"] = "UnboundIcon"
info["CFBundleIcons"].(map[string]interface{})["CFBundlePrimaryIcon"].(map[string]interface{})["CFBundleIconFiles"] = []string{"UnboundIcon60x60"}
info["CFBundleIcons~ipad"].(map[string]interface{})["CFBundlePrimaryIcon"].(map[string]interface{})["CFBundleIconName"] = "UnboundIcon"
info["CFBundleIcons~ipad"].(map[string]interface{})["CFBundlePrimaryIcon"].(map[string]interface{})["CFBundleIconFiles"] = []string{"UnboundIcon60x60", "UnboundIcon76x76"}
zip := archiver.Zip{OverwriteExisting: true}
discord := filepath.Join(directory, "Payload", "Discord.app")
if err := zip.Unarchive(icons, discord); err == nil {
logger.Info("Applied app icons.")
} else {
logger.Errorf("Failed to apply app icons: %v", err)
exit()
}
}
func setReactNavigationName() {
logger.Debug("Attempting to rename React Navigation...")
modulesPath := filepath.Join(directory, "Payload", "Discord.app", "assets", "_node_modules", ".pnpm")
if exists, _ := exists(modulesPath); !exists {
logger.Debug("React Navigation does not exist, no need to rename it.")
return
}
manifestPath := filepath.Join(directory, "Payload", "Discord.app", "manifest.json")
if exists, _ := exists(manifestPath); !exists {
logger.Debug("React Navigation does not exist, no need to rename it.")
return
}
content, err := os.ReadFile(manifestPath)
if err != nil {
logger.Errorf("Couldn't find manifest.json inside the IPA payload. %v", err)
exit()
}
manifest := Manifest{}
if err := json.Unmarshal(content, &manifest); err != nil {
logger.Errorf("Failed to unmarshal manifest.json. %v", err)
exit()
}
if manifest.Hashes == nil {
logger.Infof("No hashes found in manifest.json. Skipping React Navigation rename.")
return
}
// Change manifest hash path
for key := range manifest.Hashes {
if !strings.Contains(key, "@react-navigation+elements") {
continue
}
value := manifest.Hashes[key]
split := strings.Split(key, "/")
for idx, segment := range split {
if !strings.Contains(segment, "@react-navigation+elements") {
continue
}
split[idx] = "@react-navigation+elements@patched"
}
delete(manifest.Hashes, key)
newKey := strings.Join(split, "/")
manifest.Hashes[newKey] = value
}
content, err = json.Marshal(manifest)
if err != nil {
logger.Errorf("Failed to marshal modified manifest structure. %v", err)
return
}
err = os.WriteFile(manifestPath, content, 0644)
if err != nil {
logger.Errorf("Failed to write modified manifest.json file. %v", err)
return
} else {
logger.Info("Wrote modified manifest.json file.")
}
// Rename node_modules module folder(s)
files, err := os.ReadDir(modulesPath)
if err != nil {
logger.Errorf("Failed to read node_modules directory. Skipping React Navigation rename. %v", err)
return
}
directories := filter(files, func(entry fs.DirEntry) bool {
return strings.Contains(entry.Name(), "@react-navigation+elements")
})
for _, directory := range directories {
currentName := filepath.Join(modulesPath, directory.Name())
newName := filepath.Join(modulesPath, "@react-navigation+elements@patched")
if err := os.Rename(currentName, newName); err != nil {
logger.Errorf("Failed to rename React Navigation directory: %v %v", directory.Name(), err)
} else {
logger.Infof("Renamed React Navigation directory: %v", directory.Name())
}
}
logger.Info("Successfully renamed React Navigation directories.")
}