#define _GNU_SOURCE 1 #include #include #include #include #include #include #include #include #include #include #include #include #include // #define DEBUG 1 static int (*libc_open)(const char *pathname, int flags, ...); static int (*libc_close)(int fd); static char logs_path[128]; static int logs_fd = -1; static void __init__() __attribute__((constructor)); static void __fini__() __attribute__((destructor)); void __init__() { libc_close = dlsym(RTLD_NEXT, "close"); libc_open = dlsym(RTLD_NEXT, "open"); #if DEBUG fprintf(stderr, "found real close %p and open %p\n", libc_close, libc_open); #endif } void __fini__ () { if (logs_fd != -1) { fprintf(stderr, "closing %d\n", logs_fd); libc_close(logs_fd); } } int close(int fd) { if (fd != logs_fd) return libc_close(fd); return 0; } int open(const char *pathname, int flags, ...) { int mode = -1; va_list ap; if (flags & O_CREAT) { va_start(ap, flags); mode = va_arg(ap, int); va_end(ap); } #if DEBUG fprintf(stderr, "caught %s\n", pathname); #endif // 25341 openat(AT_FDCWD, "/home/asmadeus/.wine/dosdevices/z:/EverQuest/Logs/eqlog_Asmadeus_antonius.txt", O_WRONLY|O_CREAT|O_NONBLOCK, 0666) = 160 if (strstr(pathname, "Logs/eqlog_")) { #if DEBUG fprintf(stderr, "found Logs/eqlog_\n"); #endif if (strncmp(pathname, logs_path, sizeof(logs_path)-1) == 0) return logs_fd; else if (logs_fd != -1) libc_close(logs_fd); strncpy(logs_path, pathname, sizeof(logs_path)); logs_fd = libc_open(pathname, flags, mode); fprintf(stderr, "new path %s, opened %d, flags %x\n", pathname, logs_fd, flags); return logs_fd; } if (mode >= 0) return libc_open(pathname, flags, mode); else return libc_open(pathname, flags); }