Created
November 16, 2020 09:00
-
-
Save micampe/ff8b1473f2948dbfc1c6786d9e9afee6 to your computer and use it in GitHub Desktop.
Test if process is being debugged in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isDebuggerAttached: Bool = { | |
var kinfo = kinfo_proc() | |
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()] | |
var size = MemoryLayout<kinfo_proc>.stride | |
let result = sysctl(&mib, UInt32(mib.count), &kinfo, &size, nil, 0) | |
assert(result == 0, "sysctl failed") | |
return (kinfo.kp_proc.p_flag & P_TRACED) != 0 | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment