Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions StikJIT/StikJITApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ class MountingProgress: ObservableObject {
mountingThread = Thread {
let mount = mountPersonalDDI(imagePath: URL.documentsDirectory.appendingPathComponent("DDI/Image.dmg").path, trustcachePath: URL.documentsDirectory.appendingPathComponent("DDI/Image.dmg.trustcache").path, manifestPath: URL.documentsDirectory.appendingPathComponent("DDI/BuildManifest.plist").path, pairingFilePath: pairingpath)

if !mount {
showAlert(title: "Error", message: "An Error Occured when Mounting the DDI", showOk: true, showTryAgain: true) { cool in
if mount != 0 {
showAlert(title: "Error", message: "An Error Occured when Mounting the DDI\nError Code: " + String(mount), showOk: true, showTryAgain: true) { cool in
if cool {
self.mount()
}
Expand Down
24 changes: 12 additions & 12 deletions StikJIT/Utilities/mountDDI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func isMounted() -> Bool {
}
}

func mountPersonalDDI(deviceIP: String = "10.7.0.1", imagePath: String, trustcachePath: String, manifestPath: String, pairingFilePath: String) -> Bool {
func mountPersonalDDI(deviceIP: String = "10.7.0.1", imagePath: String, trustcachePath: String, manifestPath: String, pairingFilePath: String) -> Int {
idevice_init_logger(Debug, Disabled, nil)

print("Mounting \(imagePath) \(trustcachePath) \(manifestPath)")
Expand All @@ -124,7 +124,7 @@ func mountPersonalDDI(deviceIP: String = "10.7.0.1", imagePath: String, trustcac
let trustcache = readFile(path: trustcachePath),
let buildManifest = readFile(path: manifestPath) else {
print("Failed to read one or more files")
return false
return 1 // EC: 1
}

var addr = sockaddr_in()
Expand All @@ -135,47 +135,47 @@ func mountPersonalDDI(deviceIP: String = "10.7.0.1", imagePath: String, trustcac

guard inet_pton(AF_INET, deviceIP, &addr.sin_addr) == 1 else {
print("Invalid IP address")
return false
return 2 // EC: 2
}

var pairingFile: IdevicePairingFile?
let err = idevice_pairing_file_read(pairingFilePath.cString(using: .utf8), &pairingFile)
if err != IdeviceSuccess {
print("Failed to read pairing file: \(err)")
return false
return 3 // EC: 3
}


var provider: TcpProviderHandle?
let providerError = idevice_tcp_provider_new(sockaddrPointer, pairingFile, "ImageMounterTest".cString(using: .utf8), &provider)
if providerError != IdeviceSuccess {
print("Failed to create TCP provider: \(providerError)")
return false
return 4 // EC: 4
}


var pairingFile2: IdevicePairingFile?
let P2err = idevice_pairing_file_read(pairingFilePath.cString(using: .utf8), &pairingFile2)
if P2err != IdeviceSuccess {
print("Failed to read pairing file: \(err)")
return false
return 5 // EC: 5
}

var lockdownClient: LockdowndClientHandle?
guard lockdownd_connect_tcp(provider, &lockdownClient) == IdeviceSuccess else {
print("Failed to connect to lockdownd")
return false
return 6 // EC: 6
}

guard lockdownd_start_session(lockdownClient, pairingFile2) == IdeviceSuccess else {
print("Failed to start session")
return false
return 7 // EC: 7
}

var uniqueChipIDPlist: plist_t?
guard lockdownd_get_value(lockdownClient, "UniqueChipID".cString(using: .utf8), &uniqueChipIDPlist) == IdeviceSuccess else {
print("Failed to get UniqueChipID")
return false
return 8 // EC: 8
}

var uniqueChipID: UInt64 = 0
Expand All @@ -187,7 +187,7 @@ func mountPersonalDDI(deviceIP: String = "10.7.0.1", imagePath: String, trustcac
var mounterClient: ImageMounterHandle?
guard image_mounter_connect_tcp(provider, &mounterClient) == IdeviceSuccess else {
print("Failed to connect to image mounter")
return false
return 9 // EC: 9
}

let result = image.withUnsafeBytes { imagePtr in
Expand All @@ -214,9 +214,9 @@ func mountPersonalDDI(deviceIP: String = "10.7.0.1", imagePath: String, trustcac
if result != IdeviceSuccess {
print(result)
print("Failed to mount personalized image")
return false
return 10 // EC: 10
} else {
print("Successfully mounted personalized image!")
return true
return 0 // no EC
}
}