Skip to content

Commit

Permalink
C app and shared library for hooking examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamled committed May 4, 2019
1 parent 3c96d1e commit 7975ea9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions c/.gitignore
@@ -0,0 +1,2 @@
/app/app
/target/libtarget.so
7 changes: 7 additions & 0 deletions c/app/build.sh
@@ -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
3 changes: 3 additions & 0 deletions c/app/run.sh
@@ -0,0 +1,3 @@
#!/usr/bin/bash

LD_LIBRARY_PATH="../target/" ./app "$@"
15 changes: 15 additions & 0 deletions c/app/src/app.c
@@ -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);
}
10 changes: 10 additions & 0 deletions c/target/build.sh
@@ -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
3 changes: 3 additions & 0 deletions c/target/include/target.h
@@ -0,0 +1,3 @@
#pragma once

void maybe_say(int num);
13 changes: 13 additions & 0 deletions c/target/src/target.c
@@ -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();
}
}

0 comments on commit 7975ea9

Please sign in to comment.