Last active
June 15, 2020 11:14
-
-
Save tailriver/08218bc6da7af6da8c01 to your computer and use it in GitHub Desktop.
A sample to hook an applocation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
void hook_start() __attribute__((constructor)); | |
void hook_end() __attribute__((destructor)); | |
void hook_start() | |
{ | |
printf("hook_start. PID=%d, PPID=%d\n", getpid(), getppid()); | |
} | |
void hook_end() | |
{ | |
printf("hook_end. PID=%d, PPID=%d\n", getpid(), getppid()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
gcc main.c | |
gcc -shared -fPIC -o hook.so hook.c | |
./a.out | |
# It gets "Hello world". | |
LD_PRELOAD=hook.so ./a.out | |
# It gets "Hello world" between hook functions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
printf("Hello world.\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment