xHook
xHook copied to clipboard
How do I call the origianl function?
The last parameter is a void **
pointer which holds the original address. How do I call the original function?
void (*orig_printf)(const char*);
xhook_register(".so library", "printf", my_printf, (void*)&orig_printf);
To call it use:
orig_printf(...);
void (*orig_printf)(const char*); xhook_register(".so library", "printf", my_printf, (void*)&orig_printf);
To call it use:
orig_printf(...);
Hello, I want to hook an open function, but its last parameter is an indefinite parameter, how can I hook it?
int open(const char* __path, int __flags, ...)
void (*orig_printf)(const char*); xhook_register(".so library", "printf", my_printf, (void*)&orig_printf);
To call it use:
orig_printf(...);
Hello, I want to hook an open function, but its last parameter is an indefinite parameter, how can I hook it?
int open(const char* __path, int __flags, ...)
You gotta use var monitor. Here is an example:
int my_open(const char *file, int flags, ...) { int ret; va_list args; va_start(args, flags); //fetch all args after 'flags' ret = open(file, flags, args); //pass args to open(); va_end(args); //stop monitoring return ret; }
void (*orig_printf)(const char*); xhook_register(".so library", "printf", my_printf, (void*)&orig_printf);
To call it use:
orig_printf(...);
Hello, I want to hook an open function, but its last parameter is an indefinite parameter, how can I hook it? int open(const char* __path, int __flags, ...)
You gotta use var monitor. Here is an example:
int my_open(const char *file, int flags, ...) { int ret; va_list args; va_start(args, flags); //fetch all args after 'flags' ret = open(file, flags, args); //pass args to open(); va_end(args); //stop monitoring return ret; }
I also wrote this, but the program can not enter, this is my code:
typedef void *xhook_func;
extern "C" char *__origin_path = NULL; extern "C" char *__hook_path = NULL;
int new_open(const char *__path, int __flags, ...) { va_list args; va_start(args, __flags);
int r;
if (strcmp(__origin_path, __path) == 0) {
r = open(__hook_path, __flags, args);
} else {
r = open(__path, __flags, args);
}
return r;
}
extern "C" JNIEXPORT void JNICALL Java_com_qingyu_hook_Hooker_hookOpen( JNIEnv *env, jclass type, jstring origin, jstring replace) { __origin_path = (char )env->GetStringUTFChars(origin, 0); __hook_path = (char )env->GetStringUTFChars(replace, 0); //LOGW("%s",p_origin); xhook_register( ".\.so$", "open", (xhook_func)&new_open, NULL); xhook_register(".\.so$", "open64", (xhook_func)&new_open64, NULL);
xhook_refresh(0);
}
Please help me check, I was just getting started C language, thank you very much!
Don't you have any logcat to trace the exception ?
Don't you have any logcat to trace the exception ?
I got a instance here, has been successful hook, thank you for your help!