Skip to content

Commit

Permalink
Add Apple Intelligence
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Sep 15, 2024
1 parent a07c02a commit 6db1e74
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 15 deletions.
27 changes: 27 additions & 0 deletions Resources/FeatureFlags_Global.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SiriUI</key>
<dict>
<key>sae</key>
<dict>
<key>Enabled</key>
<true/>
</dict>
</dict>
<key>Siri</key>
<dict>
<key>sae_override</key>
<dict>
<key>Enabled</key>
<true/>
</dict>
<key>assistant_engine_override</key>
<dict>
<key>Enabled</key>
<true/>
</dict>
</dict>
</dict>
</plist>
54 changes: 43 additions & 11 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ extension UIDocumentPickerViewController {

struct ContentView: View {
let os = ProcessInfo().operatingSystemVersion
let origMGURL, modMGURL: URL
let origMGURL, modMGURL, featFlagsURL: URL
@AppStorage("PairingFile") var pairingFile: String?
@State var featureFlagsData = Data()
@State var mobileGestalt: NSMutableDictionary
@State var minimuxerReady = false
@State var reboot = true
@State var showPairingFileImporter = false
@State var showErrorAlert = false
Expand Down Expand Up @@ -53,6 +55,8 @@ struct ContentView: View {
Toggle("Allow installing iPadOS apps", isOn: bindingForMGKeys(["9MZ5AdH43csAUajl/dU+IQ"], type: [Int].self, defaultValue: [1], enableValue: [1, 2]))
Toggle("Always on Display (18.0+)", isOn: bindingForMGKeys(["j8/Omm6s1lsmTDFsXjsBfA", "2OOJf1VhaM7NxfRok3HbWQ"]))
.disabled(requiresVersion(18))
Toggle("Apple Intelligence", isOn: bindingForAppleIntelligence())
.disabled(requiresVersion(18))
Toggle("Apple Pencil", isOn: bindingForMGKeys(["yhHcB0iH0d1XzPO/CFd3ow"]))
Toggle("Boot chime", isOn: bindingForMGKeys(["QHxt+hGLaBPbQJbXiUJX3w"]))
Toggle("Camera button (18.0rc+)", isOn: bindingForMGKeys(["CwvKxM2cEogD3p+HYgaW0Q", "oOV1jhJbdV3AddkcCg0AEA"]))
Expand All @@ -72,16 +76,18 @@ struct ContentView: View {
}
Section {
Toggle("Reboot after finish restoring", isOn: $reboot)
Button("Apply changes") {
Button(minimuxerReady ? "Apply changes" : "Waiting for minimuxer. Ensure WiFi and WireGuard is enabled.") {
try! mobileGestalt.write(to: modMGURL)
applyChanges()
}
.disabled(!minimuxerReady)
Button("Reset changes") {
try! FileManager.default.removeItem(at: modMGURL)
try! FileManager.default.copyItem(at: origMGURL, to: modMGURL)
mobileGestalt = try! NSMutableDictionary(contentsOf: modMGURL, error: ())
applyChanges()
}
.disabled(!minimuxerReady)
} footer: {
Text("""
A terrible app by @khanhduytran0. Use it at your own risk.
Expand Down Expand Up @@ -122,11 +128,18 @@ Thanks to:
pairingFile = altPairingFile
}
startMinimuxer()
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { timer in
if ready() {
timer.invalidate()
minimuxerReady = true
}
}
}
}

init() {
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
featFlagsURL = documentsDirectory.appendingPathComponent("FeatureFlags.plist", conformingTo: .data)
origMGURL = documentsDirectory.appendingPathComponent("OriginalMobileGestalt.plist", conformingTo: .data)
modMGURL = documentsDirectory.appendingPathComponent("ModifiedMobileGestalt.plist", conformingTo: .data)
if !FileManager.default.fileExists(atPath: origMGURL.path) {
Expand All @@ -137,18 +150,36 @@ Thanks to:
_mobileGestalt = State(initialValue: try! NSMutableDictionary(contentsOf: modMGURL, error: ()))

// Fix file picker
let fixMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, Selector("fix_initForOpeningContentTypes:asCopy:"))!
let origMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, Selector("initForOpeningContentTypes:asCopy:"))!
let fixMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.fix_init(forOpeningContentTypes:asCopy:)))!
let origMethod = class_getInstanceMethod(UIDocumentPickerViewController.self, #selector(UIDocumentPickerViewController.init(forOpeningContentTypes:asCopy:)))!
method_exchangeImplementations(origMethod, fixMethod)
}

func applyChanges() {
if ready() {
path.append("ApplyChanges")
} else {
lastError = "minimuxer is not ready. Ensure you have WiFi and WireGuard VPN set up."
showErrorAlert.toggle()
}
path.append("ApplyChanges")
}

func bindingForAppleIntelligence() -> Binding<Bool> {
let key = "A62OafQ85EJAiiqKn4agtg"
return Binding(
get: {
if let value = (mobileGestalt["CacheExtra"] as! NSMutableDictionary)[key] as? Int? {
return value == 1
}
return false
},
set: { enabled in
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
if enabled {
featureFlagsData = try! Data(contentsOf: Bundle.main.url(forResource: "FeatureFlags_Global", withExtension: "plist")!)
cacheExtra[key] = 1
} else {
featureFlagsData = try! PropertyListSerialization.data(fromPropertyList: [:], format: .xml, options: 0)
// just remove the key as it will be pulled from device tree if missing
cacheExtra.removeObject(forKey: key)
}
}
)
}

func bindingForMGKeys<T: Equatable>(_ keys: [String], type: T.Type = Int.self, defaultValue: T? = 0, enableValue: T? = 1) -> Binding<Bool> {
Expand All @@ -175,7 +206,8 @@ Thanks to:

func generateFilesToRestore() -> [FileToRestore] {
return [
FileToRestore(from: modMGURL, to: URL(filePath: "/var/containers/Shared/SystemGroup/systemgroup.com.apple.mobilegestaltcache/Library/Caches/NOT.apple.MobileGestalt.plist"), owner: 501, group: 501)
FileToRestore(from: modMGURL, to: URL(filePath: "/var/containers/Shared/SystemGroup/systemgroup.com.apple.mobilegestaltcache/Library/Caches/NOT.apple.MobileGestalt.plist"), owner: 501, group: 501),
FileToRestore(contents: featureFlagsData, to: URL(filePath: "/var/preferences/FeatureFlags/Global.plist"))
]
}

Expand Down
16 changes: 12 additions & 4 deletions Sources/SparseRestore/Restore.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import Foundation

class FileToRestore {
var from, to: URL
var contents: Data
var to: URL
var owner, group: Int32

init(from: URL, to: URL, owner: Int32 = 0, group: Int32 = 0) {
self.from = from
self.contents = try! Data(contentsOf: from)
self.to = to
self.owner = owner
self.group = group
}

init(contents: Data, to: URL, owner: Int32 = 0, group: Int32 = 0) {
self.contents = contents
self.to = to
self.owner = owner
self.group = group
Expand All @@ -22,11 +31,10 @@ struct Restore {

// create the links
for (index, file) in files.enumerated() {
let contents = try! Data(contentsOf: file.from)
filesList.append(ConcreteFile(
path: "Library/Preferences/temp\(index)",
domain: "RootDomain",
contents: contents,
contents: file.contents,
owner: file.owner,
group: file.group,
inode: UInt64(index)))
Expand Down

0 comments on commit 6db1e74

Please sign in to comment.