mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
106 lines
3.1 KiB
Swift
106 lines
3.1 KiB
Swift
//
|
|
// minimuxer.swift
|
|
// minimuxer
|
|
//
|
|
// Created by Jackson Coxson on 10/27/22.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public enum Uhoh: Error {
|
|
case Good
|
|
case Bad(code: Int32)
|
|
}
|
|
|
|
public func start_minimuxer(pairing_file: String) -> Int32 {
|
|
let pf = NSString(string: pairing_file)
|
|
let pf_pointer = UnsafeMutablePointer<CChar>(mutating: pf.utf8String)
|
|
let u = NSString(string: getDocumentsDirectory().absoluteString)
|
|
let u_ptr = UnsafeMutablePointer<CChar>(mutating: u.utf8String)
|
|
return minimuxer_c_start(pf_pointer, u_ptr)
|
|
}
|
|
|
|
public func set_usbmuxd_socket() {
|
|
target_minimuxer_address()
|
|
}
|
|
|
|
public func debug_app(app_id: String) throws -> Uhoh {
|
|
let ai = NSString(string: app_id)
|
|
let ai_pointer = UnsafeMutablePointer<CChar>(mutating: ai.utf8String)
|
|
var res = minimuxer_debug_app(ai_pointer)
|
|
var attempts = 10
|
|
while (attempts != 0 && res != 0) {
|
|
print("(JIT) ATTEMPTS: \(attempts)")
|
|
res = minimuxer_debug_app(ai_pointer)
|
|
attempts -= 1
|
|
}
|
|
if res != 0 {
|
|
throw Uhoh.Bad(code: res)
|
|
}
|
|
return Uhoh.Good
|
|
}
|
|
|
|
public func install_provisioning_profile(plist: Data) throws -> Uhoh {
|
|
let pls = String(decoding: plist, as: UTF8.self)
|
|
print(pls)
|
|
print(plist)
|
|
let x = plist.withUnsafeBytes { buf in UnsafeMutableRawPointer(mutating: buf) }
|
|
var res = minimuxer_install_provisioning_profile(x, UInt32(plist.count))
|
|
var attempts = 10
|
|
while (attempts != 0 && res != 0) {
|
|
print("(INSTALL) ATTEMPTS: \(attempts)")
|
|
res = minimuxer_install_provisioning_profile(x, UInt32(plist.count))
|
|
attempts -= 1
|
|
}
|
|
if res != 0 {
|
|
throw Uhoh.Bad(code: res)
|
|
}
|
|
return Uhoh.Good
|
|
}
|
|
|
|
public func remove_provisioning_profile(id: String) throws -> Uhoh {
|
|
let id_ns = NSString(string: id)
|
|
let id_pointer = UnsafeMutablePointer<CChar>(mutating: id_ns.utf8String)
|
|
var res = minimuxer_remove_provisioning_profile(id_pointer)
|
|
var attempts = 10
|
|
while (attempts != 0 && res != 0) {
|
|
print("(REMOVE PROFILE) ATTEMPTS: \(attempts)")
|
|
res = minimuxer_remove_provisioning_profile(id_pointer)
|
|
attempts -= 1
|
|
}
|
|
if res != 0 {
|
|
throw Uhoh.Bad(code: res)
|
|
}
|
|
return Uhoh.Good
|
|
}
|
|
|
|
public func remove_app(app_id: String) throws -> Uhoh {
|
|
let ai = NSString(string: app_id)
|
|
let ai_pointer = UnsafeMutablePointer<CChar>(mutating: ai.utf8String)
|
|
var res = minimuxer_remove_app(ai_pointer)
|
|
var attempts = 10
|
|
while (attempts != 0 && res != 0) {
|
|
print("(REMOVE APP) ATTEMPTS: \(attempts)")
|
|
res = minimuxer_remove_app(ai_pointer)
|
|
attempts -= 1
|
|
}
|
|
if res != 0 {
|
|
throw Uhoh.Bad(code: res)
|
|
}
|
|
return Uhoh.Good
|
|
}
|
|
|
|
public func auto_mount_dev_image() {
|
|
let u = NSString(string: getDocumentsDirectory().absoluteString)
|
|
let u_ptr = UnsafeMutablePointer<CChar>(mutating: u.utf8String)
|
|
minimuxer_auto_mount(u_ptr)
|
|
}
|
|
|
|
func getDocumentsDirectory() -> URL {
|
|
// find all possible documents directories for this user
|
|
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
|
|
|
|
// just send back the first one, which ought to be the only one
|
|
return paths[0]
|
|
}
|