Skip to content

Instantly share code, notes, and snippets.

@mattlawer
Created December 25, 2016 17:13
Show Gist options
  • Save mattlawer/d391c5137f987d109c54b58a7ce36a04 to your computer and use it in GitHub Desktop.
Save mattlawer/d391c5137f987d109c54b58a7ce36a04 to your computer and use it in GitHub Desktop.
Disable GDB with Swift 3
import Foundation
func disable_gdb() {
let PT_DENY_ATTACH: CInt = 31
let handle = dlopen("/usr/lib/libc.dylib", RTLD_NOW)
let sym = dlsym(handle, "ptrace")
typealias PtraceAlias = @convention(c) (CInt, pid_t, CInt, CInt) -> CInt
let ptrace = unsafeBitCast(sym, to: PtraceAlias.self)
_ = ptrace(PT_DENY_ATTACH, 0, 0, 0)
dlclose(handle)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment