-
Notifications
You must be signed in to change notification settings - Fork 366
Hooking into libc functions from C #73
Unanswered
nitanmarcel
asked this question in
Q&A
Replies: 1 comment · 1 reply
-
Came to this code after a while, but the init status gets set to 9:
Maybe I'm missing something important in my mk file. as mentioned I'm using the sources in my code from the added submodule:
|
Beta Was this translation helpful? Give feedback.
All reactions
1 reply
-
The following code seems to work. With the exception on apps refusing to fully start after an while #include "bytehook.h"
#include "jni.h"
#include "Logger.h"
#define BYTEHOOK_MODE_AUTOMATIC 0
#define BYTEHOOK_MODE_MANUAL 1
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
#include <stdbool.h>
bytehook_stub_t stub = NULL;
typedef int (*faccessat_t)(int fd, const char *path, int amode, int flag);
int hook_faccessat(int fd, const char *path, int amode, int flag)
{
LOGD("faccessat: %s", path);
int result = BYTEHOOK_CALL_PREV(hook_faccessat, faccessat_t, fd, path, amode, flag);
BYTEHOOK_POP_STACK();
return result;
}
void do_hook()
{
LOGD("do_hook");
int status;
status = bytehook_init(BYTEHOOK_MODE_AUTOMATIC, true);
LOGD("bytehook_init: %d", status);
stub = bytehook_hook_single(
"libc.so",
NULL,
"faccessat",
(void *)(hook_faccessat),
NULL,
NULL
);
if (stub == NULL)
{
LOGD("bytehook_hook_all failed");
return;
}
LOGD("bytehook_hook_all finished %p", stub);
}
void* hook_thread(void* arg) {
do_hook();
return NULL;
}
__attribute__((constructor))
void library_constructor() {
pthread_t detach_thread;
pthread_create(&detach_thread, NULL, hook_thread, NULL);
// pthread_join(detach_thread, NULL); // will fail again.
} Logs
|
Beta Was this translation helpful? Give feedback.
All reactions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. I'm coming here from funchook since this library is more axed on android and I can simply include it's source directly into my shared lib, which saves me a lot of time.
One issue I have is that I don't understand how to really use it, and the documentation is mostly in Chinese. What I need, is to intercept different calls from libc calls and modify their return. The following code is ported from the library I used but I guess I'm not that lucky for it to work.
Beta Was this translation helpful? Give feedback.
All reactions