After reading several posts on StackOverflow, I've gathered enough information on how to actually implement API hooking for macOS using C++ primarily. However, there's several questions that I have not managed to find a full/complete answer to after maybe months of searching on and off. Hopefully someone has some level of experience in this.
What I'm doing is writing a general purpose GPU performance tool similar to Fraps and GPU-z for macOS. In order for this to work, API hooking APIs in existing programs is absolutely necessary. So, the APIs being hooked are primarily gfx ones like OpenGL and Metal. This is actually quite simple to do on Windows but for macOS, it appears to be trickier, especially if the app being hooked is already running.
So, I've found a handful of ways to hook libraries, but so far the only one that offers the functionality I need is mach_inject. From what I'm told, this works but since El Capitan due to restrictions on calling task_for_pid(), you need to have SIP disabled, have root access or be added to procmon I believe it's called? So, that doesn't sound like something that would be "user friendly", at least not out of the box.Is there some sort of entitlement I can add to make things easier or what? According to this link here, I can add this entitlement and run w/ a sudo command (I actually just found this as I was gathering the information for this thread). Since it's only the background processes that need to run w/ a sudo command I'm okay with this but can you launch a program from your main app with such privileges programmatically so that task_for_pid() will run?
Also, keep in mind that I do not have a Mac that supports anything beyond El Capitan atm, so I'll likely get a Mac Mini with a Mojave/Catalina dualboot. The reason for the dual boot is that I want this to work for both 32-bit and 64-bit apps which will require two separate processes anyway, only on Catalina the 32-bit side just will not be run since it's not supported anyway.
It's really late here so I'm sorry if I sloppily wrote this and I should attempt this again in the morning and continue my research on this. Any ideas? Thanks.
Shogun
What I'm doing is writing a general purpose GPU performance tool similar to Fraps and GPU-z for macOS. In order for this to work, API hooking APIs in existing programs is absolutely necessary. So, the APIs being hooked are primarily gfx ones like OpenGL and Metal. This is actually quite simple to do on Windows but for macOS, it appears to be trickier, especially if the app being hooked is already running.
So, I've found a handful of ways to hook libraries, but so far the only one that offers the functionality I need is mach_inject. From what I'm told, this works but since El Capitan due to restrictions on calling task_for_pid(), you need to have SIP disabled, have root access or be added to procmon I believe it's called? So, that doesn't sound like something that would be "user friendly", at least not out of the box.
Also, keep in mind that I do not have a Mac that supports anything beyond El Capitan atm, so I'll likely get a Mac Mini with a Mojave/Catalina dualboot. The reason for the dual boot is that I want this to work for both 32-bit and 64-bit apps which will require two separate processes anyway, only on Catalina the 32-bit side just will not be run since it's not supported anyway.
It's really late here so I'm sorry if I sloppily wrote this and I should attempt this again in the morning and continue my research on this. Any ideas? Thanks.
Shogun