Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何钩住C/C++;Android中使用Cydia底物的方法_Android_C_Hook_Cydia Substrate - Fatal编程技术网

如何钩住C/C++;Android中使用Cydia底物的方法

如何钩住C/C++;Android中使用Cydia底物的方法,android,c,hook,cydia-substrate,Android,C,Hook,Cydia Substrate,我查看了Cydia Subscriber的主页,作者提供的Android Jni钩子示例实际上是用C代码钩住Java方法 但我想要的是钩住一个C/C++方法,即Android中libXXX.so中的一个方法。与/system/lib/libc.so中的fork()方法类似。来自Cydia作者和XDA的信息似乎表明Cydia可以做到这一点。我在网上到处搜索,但找不到一个例子 有谁能告诉我如何使用Cydia在Android中钩住C/C++方法吗?不太确定该放在哪里,因为这不是一个确切的答案,但也许它

我查看了Cydia Subscriber的主页,作者提供的Android Jni钩子示例实际上是用C代码钩住Java方法

但我想要的是钩住一个C/C++方法,即Android中libXXX.so中的一个方法。与/system/lib/libc.so中的fork()方法类似。来自Cydia作者和XDA的信息似乎表明Cydia可以做到这一点。我在网上到处搜索,但找不到一个例子


有谁能告诉我如何使用Cydia在Android中钩住C/C++方法吗?

不太确定该放在哪里,因为这不是一个确切的答案,但也许它会让你走上正确的方向。这里有一些代码是用C编写的,用于shim/hooks
fork()
。在本例中,编写这些代码是为了检测沙盒程序的fork是否超过两次,但显然可以根据需要修改行为

#define MAKE_CALLTHROUGH(fx, libfx)                                            \
    do{                                                                        \
        void *handle = NULL;                                                   \
        if(!libfx){                                                            \
            handle = dlopen("/lib64/libc.so.6", RTLD_LAZY);                    \
            if(!handle){                                                       \
                fputs(dlerror(), stderr);                                      \
                exit(1);                                                       \
                return 0;                                                      \
            }                                                                  \
            libfx = dlsym(handle, fx);                                         \
            if(dlerror() != NULL){                                             \
                fprintf(stderr, "Could not make handle for function %s\n", fx);\
                exit(1);                                                       \
            }                                                                  \
        }                                                                      \
    }while(0);

const int MAX_FORKS = 2;
int forks = 0;

int fork(){
    static int (*libfork) (void) = NULL;
    MAKE_CALLTHROUGH("fork", libfork);
    if(forks++ > 2){
        fprintf(stderr, "Illegally exceeded 2 forks.\n");
        killpg(0, 9);
    }
    return libfork();
}
如果有人好奇,我会这样编译:

gcc -g -Wall -Wextra -fPIC -c watchshim.c -o watchshim.o
gcc -g -Wall -Wextra -fPIC -shared -ldl watchshim.o -o watchshim.so 

gcc -g -Wall -Wextra -pthread -o watch watch.c 
其中,
watchshim.c
是包含shim/hook代码的文件,
watch.c
是填充
fork()
的进程(在
watch
“/lib64/libc.so.6”的所有子进程中也填充
so
包含原始
fork())
。我将
MAKE_CALLTHROUGH
作为宏编写,因为我在使用该宏的项目中填充了多个函数