xHook icon indicating copy to clipboard operation
xHook copied to clipboard

How do I call the origianl function?

Open tousifosman opened this issue 5 years ago • 7 comments

The last parameter is a void ** pointer which holds the original address. How do I call the original function?

tousifosman avatar Nov 16 '19 03:11 tousifosman

void (*orig_printf)(const char*);
xhook_register(".so library", "printf", my_printf, (void*)&orig_printf);

To call it use: orig_printf(...);

michio-mada avatar Nov 25 '19 14:11 michio-mada

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, ...)

buffcow avatar Aug 03 '20 02:08 buffcow

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; }

moonoiza avatar Aug 03 '20 08:08 moonoiza

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!

buffcow avatar Aug 03 '20 10:08 buffcow

Don't you have any logcat to trace the exception ?

moonoiza avatar Aug 03 '20 15:08 moonoiza

Don't you have any logcat to trace the exception ?

Xhook will appear with these logs. screenshot

buffcow avatar Aug 03 '20 19:08 buffcow

Don't you have any logcat to trace the exception ?

I got a instance here, has been successful hook, thank you for your help!

buffcow avatar Aug 04 '20 04:08 buffcow