Skip to content

Instantly share code, notes, and snippets.

@bxem44
Forked from mattlawer/DisableGDB.swift
Created October 23, 2018 19:45
Show Gist options
  • Save bxem44/4633d9ccc61f25110db6114a0be5f358 to your computer and use it in GitHub Desktop.
Save bxem44/4633d9ccc61f25110db6114a0be5f358 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