inject_bundle – Issue with mach_override

So I’ve had mixed success when injection into other processes on OS X. The majority of functions will hook just fine using mach_star (intel). But I was having a particular problem hooking some functions. I wanted to get a better idea of what was actually being passed to this function. And, of course, it wouldn’t hook, ever. So I started to dive into mach_override.c a bit and realized that the instruction matching “algorithm” wasn’t conclusive. Basically what happens is mach_override will loop through the assembly at the start of the function you want to override. It will verify that you should in fact be able to override it (it needs 5 instructions to perform a JMP). This is the relevant code that was giving me trouble:

Recompiled, injected, and it works 🙂 Figured I would make a blog post considering I spent a good 2 hours trying to figure this out, I can definitely say I have a decently better understanding of what is actually going on 😉