Skip to content

Commit

Permalink
Add files for Apple Intelligence
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Sep 19, 2024
1 parent fca5e73 commit 976aa4f
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Before opening SparseBox, you have to close SideStore from app switcher. This is
- @JJTech0130: SparseRestore and backup exploit
- @PoomSmart: MobileGestalt dump
- @libimobiledevice
- [the sneakyf1shy apple intelligence tutorial](https://gist.github.com/f1shy-dev/23b4a78dc283edd30ae2b2e6429129b5#file-best_sae_trick-md)
47 changes: 47 additions & 0 deletions Resources/eligibility.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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>OS_ELIGIBILITY_DOMAIN_CALCIUM</key>
<dict>
<key>os_eligibility_answer_source_t</key>
<integer>1</integer>
<key>os_eligibility_answer_t</key>
<integer>2</integer>
<key>status</key>
<dict>
<key>OS_ELIGIBILITY_INPUT_CHINA_CELLULAR</key>
<integer>2</integer>
</dict>
</dict>
<key>OS_ELIGIBILITY_DOMAIN_GREYMATTER</key>
<dict>
<key>context</key>
<dict>
<key>OS_ELIGIBILITY_CONTEXT_ELIGIBLE_DEVICE_LANGUAGES</key>
<array>
<string>en</string>
</array>
</dict>
<key>os_eligibility_answer_source_t</key>
<integer>1</integer>
<key>os_eligibility_answer_t</key>
<integer>4</integer>
<key>status</key>
<dict>
<key>OS_ELIGIBILITY_INPUT_DEVICE_LANGUAGE</key>
<integer>3</integer>
<key>OS_ELIGIBILITY_INPUT_DEVICE_REGION_CODE</key>
<integer>3</integer>
<key>OS_ELIGIBILITY_INPUT_EXTERNAL_BOOT_DRIVE</key>
<integer>3</integer>
<key>OS_ELIGIBILITY_INPUT_GENERATIVE_MODEL_SYSTEM</key>
<integer>3</integer>
<key>OS_ELIGIBILITY_INPUT_SHARED_IPAD</key>
<integer>3</integer>
<key>OS_ELIGIBILITY_INPUT_SIRI_LANGUAGE</key>
<integer>3</integer>
</dict>
</dict>
</dict>
</plist>
59 changes: 52 additions & 7 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ struct ContentView: View {
let os = ProcessInfo().operatingSystemVersion
let origMGURL, modMGURL, featFlagsURL: URL
@AppStorage("PairingFile") var pairingFile: String?
@State var eligibilityData = Data()
@State var featureFlagsData = Data()
@State var mobileGestalt: NSMutableDictionary
@State var productType = machineName()
@State var minimuxerReady = false
@State var reboot = true
@State var showPairingFileImporter = false
Expand Down Expand Up @@ -64,7 +66,7 @@ struct ContentView: View {
Toggle("Charge limit", isOn: bindingForMGKeys(["37NVydb//GP/GrhuTN+exg"]))
.disabled(requiresVersion(17))
Toggle("Crash Detection (might not work)", isOn: bindingForMGKeys(["HCzWusHQwZDea6nNhaKndw"]))
Toggle("Dynamic Island (17.4+ method)", isOn: bindingForMGKeys(["YlEtTtHlNesRBMal1CqRaA"]))
Toggle("Dynamic Island (17.4+, might not work)", isOn: bindingForMGKeys(["YlEtTtHlNesRBMal1CqRaA"]))
.disabled(requiresVersion(17, 4))
Toggle("Internal Storage info", isOn: bindingForMGKeys(["LBJfwOEzExRxzlAnSuI7eg"]))
Toggle("Metal HUD for all apps", isOn: bindingForMGKeys(["EqrsVvjcYDdxHBiQmGhAWw"]))
Expand All @@ -73,10 +75,29 @@ struct ContentView: View {
if let isSE = UIDevice.perform(Selector("_hasHomeButton")) {
Toggle("Tap to Wake (iPhone SE)", isOn: bindingForMGKeys(["yZf3GTRMGTuwSV/lD7Cagw"]))
}
} header: {
Text("MobileGestalt")
}
Section {
Picker("Device model", selection:$productType) {
Text("unchanged").tag(ContentView.machineName())
if UIDevice.current.userInterfaceIdiom == .pad {
Text("iPad Pro 11 inch 5th Gen").tag("iPad16,3")
} else {
Text("iPhone 15 Pro Max").tag("iPhone16,2")
Text("iPhone 16 Pro Max").tag("iPhone17,2")
}
}
//.disabled(requiresVersion(18, 1))
} header: {
Text("Device spoofing")
} footer: {
Text("Only change device model if you're downloading Apple Intelligence models. Face ID may break.")
}
Section {
Toggle("Reboot after finish restoring", isOn: $reboot)
Button("Apply changes") {
saveProductType()
try! mobileGestalt.write(to: modMGURL)
applyChanges()
}
Expand Down Expand Up @@ -128,6 +149,9 @@ Thanks to:
pairingFile = altPairingFile
}
startMinimuxer()

let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
productType = cacheExtra["h9jDsbgj7xIVeIQ8S3/X3Q"] as! String
}
}

Expand Down Expand Up @@ -159,21 +183,24 @@ Thanks to:
}

func bindingForAppleIntelligence() -> Binding<Bool> {
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
let key = "A62OafQ85EJAiiqKn4agtg"
return Binding(
get: {
if let value = (mobileGestalt["CacheExtra"] as! NSMutableDictionary)[key] as? Int? {
if let value = cacheExtra[key] as? Int? {
return value == 1
}
return false
},
set: { enabled in
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
if enabled {
eligibilityData = try! Data(contentsOf: Bundle.main.url(forResource: "eligibility", withExtension: "plist")!)
cacheExtra[key] = 1
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)
eligibilityData = featureFlagsData
// just remove the key as it will be pulled from device tree if missing
cacheExtra.removeObject(forKey: key)
}
Expand All @@ -182,15 +209,15 @@ Thanks to:
}

func bindingForMGKeys<T: Equatable>(_ keys: [String], type: T.Type = Int.self, defaultValue: T? = 0, enableValue: T? = 1) -> Binding<Bool> {
Binding(
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
return Binding(
get: {
if let value = (mobileGestalt["CacheExtra"] as! NSMutableDictionary)[keys.first!] as? T?, let enableValue {
if let value = cacheExtra[keys.first!] as? T?, let enableValue {
return value == enableValue
}
return false
},
set: { enabled in
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
for key in keys {
if enabled {
cacheExtra[key] = enableValue
Expand All @@ -206,10 +233,28 @@ Thanks to:
func generateFilesToRestore() -> [FileToRestore] {
return [
FileToRestore(from: modMGURL, to: URL(filePath: "/var/containers/Shared/SystemGroup/systemgroup.com.apple.mobilegestaltcache/Library/Caches/com.apple.MobileGestalt.plist"), owner: 501, group: 501),
FileToRestore(contents: featureFlagsData, to: URL(filePath: "/var/preferences/FeatureFlags/Global.plist"))
FileToRestore(contents: eligibilityData, to: URL(filePath: "/var/db/eligibilityd/eligibility.plist")),
FileToRestore(contents: featureFlagsData, to: URL(filePath: "/var/preferences/FeatureFlags/Global.plist")),
]
}

// https://stackoverflow.com/questions/26028918/how-to-determine-the-current-iphone-device-model
// read device model from kernel
static func machineName() -> String {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
return machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
}

func saveProductType() {
let cacheExtra = mobileGestalt["CacheExtra"] as! NSMutableDictionary
cacheExtra["h9jDsbgj7xIVeIQ8S3/X3Q"] = productType
}

func startMinimuxer() {
guard pairingFile != nil else {
return
Expand Down

0 comments on commit 976aa4f

Please sign in to comment.