Skip to content

Instantly share code, notes, and snippets.

View micampe's full-sized avatar

Michele Campeotto micampe

View GitHub Profile
@micampe
micampe / Debug.swift
Created November 16, 2020 09:00
Test if process is being debugged in Swift
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
}()

Keybase proof

I hereby claim:

  • I am micampe on github.
  • I am micampe (https://keybase.io/micampe) on keybase.
  • I have a public key whose fingerprint is 9034 E80E 6611 548B 3B3B C340 4DEB 1CF4 BC10 C078

To claim this, I am signing this object: