Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C app and shared library for hooking examples
- Loading branch information
Showing
7 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/app/app | ||
/target/libtarget.so |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/bash | ||
|
||
if [[ -f ./app ]]; then | ||
rm ./app | ||
fi | ||
|
||
clang -I../target/include -L../target/ -ltarget src/app.c -o app |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/bash | ||
|
||
LD_LIBRARY_PATH="../target/" ./app "$@" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "target.h" | ||
|
||
int main(int argc, char **argv) { | ||
if(argc < 2) { | ||
printf("Usage: %s <integer>\n", argv[0]); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
int input = atoi(argv[1]); | ||
maybe_say(input); | ||
|
||
exit(EXIT_SUCCESS); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/bash | ||
|
||
if [[ -f ./libtarget.so ]]; then | ||
rm ./libtarget.so | ||
fi | ||
|
||
clang -shared -I./include/ ./src/target.c -o ./libtarget.so | ||
|
||
# Don't include the local function symbol | ||
strip -N say_something ./libtarget.so |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
void maybe_say(int num); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "target.h" | ||
|
||
static void __attribute__((__noinline__)) say_something() { | ||
puts("This is really something!\n"); | ||
} | ||
|
||
void maybe_say(int num) { | ||
if(num == rand()) { | ||
say_something(); | ||
} | ||
} |