I checked the home of Cydia Substrate, the Android Jni Hook example provided by the author is actually hooking a Java method with C code.
But what I want is to hook a C/C++ method, i.e a method in a libXXX.so in Android. Like the fork() method in /system/lib/libc.so. Information from Cydia author and XDA seems to show that Cydia can do this. I searched all around the Internet but can't find an example.
Could anyone tell me how to hook C/C++ method in Android using Cydia?
Not really sure where to put this, because it's not exactly an answer, but maybe it'll put you in the right direction. Here's some code that shim/hooks
fork()
, written in C. In this case, it was written to detect if a sandboxed program was forking more than twice, but you could obviously modify the behavior as necessary.In case anyone was curious, I compiled it like this:
Where
watchshim.c
is the file containing the shim/hook code, andwatch.c
is the process in whichfork()
is shimmed (it is also shimmed in all child processes ofwatch
."/lib64/libc.so.6"
is theso
containing the originalfork()
. I haveMAKE_CALLTHROUGH
written as a macro, because I was shimming multiple functions in the project I used this in.