I have an odd situation where mach_inject works perfectly fine, when my app is launched through Xcode. If I launch my app directly, the target process crashes as soon as it attempts to inject:
Date/Time: 2016-09-21 22:55:58.682 +0100
OS Version: Mac OS X 10.12 (16A323)
Report Version: 12
Anonymous UUID: 8AD07C6C-3EFE-5D39-B58B-393D95473947
Time Awake Since Boot: 3400 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000e50d34ab
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]
External Modification Warnings:
Thread creation by external task.
VM Regions Near 0xe50d34ab:
Stack 00000000bf800000-00000000c0000000 [ 8192K] rw-/rwx SM=PRV
-->
Submap 00000000ffff0000-00000000ffff1000 [ 4K] r--/r-- SM=PRV process-only VM submap