News for hackers. Stuff that matters.
Re:Skiptracing: Reversing Spotify.app by saagarjha on Sunday June 09, 2019 @03:41AM (#20137798)
> I recently learned about a process called hooking, where you can “intercept” function calls made from a target binary. I thought this would be the perfect way to track skips.

> The most common type of hook is the interpose hook.

Note that dyld has built-in support for interposing; you don't need to mess around with dlsym and RTLD_NEXT (which requires disabling the two-level namespace anyways, as you seem to have figured out, which can cause some programs to misbehave): https://opensource.apple.com/source/dyld/dyld-210.2.3/includ...

> As stated earlier, an interpose hook can only be created for an external function, so we’ll look for a function in the libc or in the Objective-C runtime.

Yes, but the Objective-C runtime lets you swizzle anything :) No need to dig around for an external C function to patch.

> Spotify opened fine but Apple’s System Integrity Protection (SIP) didn’t let us load our unsigned library :(.

No, this is not System Integrity Protection: it's Library Validation, which prevents loading libraries signed with a different Team ID than the main binary was signed with. You can remove the binary's code signature to get around this.

> We’ll first set a hook on sub_10006DE40 and then we will trigger a breakpoint from within our code. We can do this by executing the assembly instruction int 3 which is what debuggers like GDB and LLDB use to trigger breakpoints.

Or, compile with debug symbols and put a breakpoint at your function as you normally would.

> Notice that the PC will be at an offset address from the one shown in IDA (honestly, I don’t have the best grasp as to why this happens but I assume it’s due to where the process is loaded into memory).

Most binaries are compiled position-independently on macOS, and get loaded at a randomized address (but the debugger should usually turn off the randomization).

There are no comments on this comment yet.