Created
January 3, 2020 11:06
-
-
Save WiesnerPeti/7d5a2380e831833102726dee0d422180 to your computer and use it in GitHub Desktop.
iOS Swift Check if debugger is attached
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
func debuggerAttached() -> Bool { | |
var process_info:kinfo_proc = kinfo_proc() | |
var process_info_len:size_t = MemoryLayout<kinfo_proc>.size | |
var process_info_mib:[Int32] = [ | |
CTL_KERN, | |
KERN_PROC, | |
KERN_PROC_PID, | |
getpid() | |
]; | |
let pointer: UnsafeMutablePointer<Int32> = UnsafeMutablePointer(&process_info_mib) | |
if (sysctl(pointer, UInt32(process_info_mib.count), &process_info, &process_info_len, nil, 0) != 0) { | |
if (errno == ENOENT){ | |
print("Unexpected sysctl error %d: %s", errno, strerror(errno)); | |
} | |
return false | |
} | |
return (process_info.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