Skip to content

Commit

Permalink
return gestalt information
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Jul 1, 2024
1 parent 54ee10e commit 921a087
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions Nudge/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,14 @@ struct DeviceManager {
let boardID = getIORegInfo(serviceTarget: "board-id") ?? "Unknown"
let bridgeID = getBridgeModelID()
let hardwareModelID = getIORegInfo(serviceTarget: "target-sub-type") ?? "Unknown"
let gestaltModelStringID = getKeyResultFromGestalt("HWModelStr")

LogManager.debug("Hardware Board ID: \(boardID)", logger: utilsLog)
LogManager.debug("Hardware Bridge ID: \(bridgeID)", logger: utilsLog)
LogManager.debug("Hardware Model ID: \(hardwareModelID)", logger: utilsLog)
LogManager.debug("Gestalt Hardware Model ID: \(gestaltModelStringID)", logger: utilsLog)


return [boardID.trimmingCharacters(in: .whitespacesAndNewlines), bridgeID.trimmingCharacters(in: .whitespacesAndNewlines), hardwareModelID.trimmingCharacters(in: .whitespacesAndNewlines)]
return [boardID.trimmingCharacters(in: .whitespacesAndNewlines), bridgeID.trimmingCharacters(in: .whitespacesAndNewlines), hardwareModelID.trimmingCharacters(in: .whitespacesAndNewlines), gestaltModelStringID.trimmingCharacters(in: .whitespacesAndNewlines)]
}

func getHardwareUUID() -> String {
Expand Down Expand Up @@ -706,6 +707,29 @@ struct DeviceManager {
}
}

func getKeyResultFromGestalt(_ keyname: String) -> String {
let handle = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_NOW)
guard handle != nil else {
return "Unknown"
}
defer {
dlclose(handle)
}

let symbol = dlsym(handle, "MGGetStringAnswer")
guard symbol != nil else {
return "Unknown"
}

let function = unsafeBitCast(symbol, to: (@convention(c) (String) -> String?).self)

guard let result = function(keyname) else {
return "Unknown"
}

return result
}

func getPatchOSVersion() -> Int {
let PatchOSVersion = ProcessInfo().operatingSystemVersion.patchVersion
LogManager.info("Patch OS Version: \(PatchOSVersion)", logger: utilsLog)
Expand Down

0 comments on commit 921a087

Please sign in to comment.