diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2018-11-18 07:37:09 +0200 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2018-11-18 07:37:09 +0200 |
commit | 38966a58203355d6040e9487f07d8f8289333ebe (patch) | |
tree | f6d6be2dd6dabe305b0a73acd6cad353dafed83d | |
parent | 82c61a906ec290f7404df291f83c1910cf45135c (diff) |
add src/libc-antiantidebug.c
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/libc-antiantidebug.c | 41 |
2 files changed, 42 insertions, 1 deletions
@@ -37,7 +37,7 @@ runtime/libc.so: private override CPPFLAGS += -D_GNU_SOURCE runtime/libc.so: private override LDFLAGS += -Wl,-wrap,_IO_file_xsputn runtime/libc.so: private override CFLAGS += -Wno-deprecated-declarations runtime/libc.so: private override LDLIBS += `pkg-config --libs libbsd libunwind` -runtime/libc.so: verbose src/libc.c src/libc-stdio.c src/libc-sha1.c +runtime/libc.so: verbose src/libc.c src/libc-stdio.c src/libc-sha1.c src/libc-antiantidebug.c runtime/libpthread.so: private override CPPFLAGS += -D_GNU_SOURCE runtime/libpthread.so: private override LDLIBS += -lpthread runtime/libpthread.so: src/libpthread.c diff --git a/src/libc-antiantidebug.c b/src/libc-antiantidebug.c new file mode 100644 index 0000000..940f6a1 --- /dev/null +++ b/src/libc-antiantidebug.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <string.h> +#include <assert.h> +#include <fcntl.h> + +int +bionic_open(const char *path, int oflag, ...) +{ + // Hide TracerPid from /proc/self/status for hideous apps that check for debugger. + // Note, since /proc/self/status doesn't get updated anymore, this may break some stuff. + // XXX: Turn this ON/OFF with env var maybe? + if (!strcmp(path, "/proc/self/status")) { + static FILE *faked = NULL; + + if (!faked) { + static char status[4096]; + + { + FILE *f = fopen(path, "rb"); + assert(f && "/proc/self/status failed to open :/"); + const size_t ret = fread(status, 1, sizeof(status), f); + assert(ret <= sizeof(status) && "/proc/self/status doesn't fit in 4096 bytes :/"); + fclose(f); + } + + for (char *s, *e; (s = strstr(status, "TracerPid:\t"));) { + for (e = s; (size_t)(e - status) < sizeof(status) && *e && *e != '\n'; ++e); + memmove(s, e, sizeof(status) - (e - status)); + break; + } + + printf("%s\n", status); + faked = fmemopen(status, sizeof(status), "rb"); + assert(faked && "fmemopen failed :/"); + } + + return fileno(faked); + } + + return open(path, oflag); +} |