Unten habe ich diesen Schalterfall:
Code: Select all
securityChannel.setMethodCallHandler { [weak self] (call, result) in
guard let self = self else { return }
switch call.method {
case "isEmulator":
result(self.isProbablyEmulator())
case "isDebuggerAttached":
result(self.isDebuggerAttached())
case "hasFrida":
result(self.hasFridaLoaded())
case "isDeviceRooted":
result(self.isJailbroken())
case "hasHookingFramework":
result(self.hasSubstrateLikeHooks())
case "isInstalledFromTrustedDistribution":
result(self.isInstalledFromTrustedDistribution())
default:
result(FlutterMethodNotImplemented)
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
Code: Select all
private func isProbablyEmulator() -> Bool {
#if targetEnvironment(simulator)
return true
#else
if ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != nil { return true }
return false
#endif
}
private func isDebuggerAttached() -> Bool {
var info = kinfo_proc()
var size = MemoryLayout.stride
var name: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
let rc = name.withUnsafeMutableBufferPointer { ptr -> Int32 in
sysctl(ptr.baseAddress, u_int(ptr.count), &info, &size, nil, 0)
}
if rc != 0 { return false }
return (info.kp_proc.p_flag & P_TRACED) != 0
}
private func hasFridaLoaded() -> Bool {
let suspicious = ["frida", "re.frida", "libfrida", "frida-gadget", "gum-js-loop"]
let count = _dyld_image_count()
for i in 0.. Bool {
#if targetEnvironment(simulator)
return false
#else
let suspicious = [
"/Applications/Cydia.app",
"/Library/MobileSubstrate/MobileSubstrate.dylib",
"/bin/bash",
"/usr/sbin/sshd",
"/etc/apt"
].contains { FileManager.default.fileExists(atPath: $0) }
let cydia = UIApplication.shared.canOpenURL(URL(string: "cydia://package/com.example.package")!)
let writeTest: Bool = {
let p = "/private/\(UUID().uuidString)"
do {
try "x".write(toFile: p, atomically: true, encoding: .utf8)
try FileManager.default.removeItem(atPath: p);
return true
} catch { return false }
}()
let dyld = getenv("DYLD_INSERT_LIBRARIES") != nil
return suspicious || cydia || writeTest || dyld
#endif
}
private func hasSubstrateLikeHooks() -> Bool {
let suspects = ["substrate", "libsubstrate", "fishhook"]
let count = _dyld_image_count()
for i in 0.. Bool {
if Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") != nil {
return false
}
guard let receiptURL = Bundle.main.appStoreReceiptURL else { return false }
let last = receiptURL.lastPathComponent
if last == "sandboxReceipt" {
return true
}
let hasReceipt = FileManager.default.fileExists(atPath: receiptURL.path)
return hasReceipt
}
Gibt es in diesem Fall ein Problem, das identifiziert werden kann? Gibt es bei einer dieser Methoden einen „Overkill“ für das Blockieren?
Mobile version