-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
47 lines (35 loc) · 987 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <dlfcn.h>
#include "patcher.h"
int gDidPatch = 0;
void sneakAttack()
{
printf("MAIN: sneak attack!\n");
}
extern void internalFunction()
{
printf("MAIN: internalFunction\n");
if( gDidPatch == 0 ) {
printf("MAIN: patching theLib.so...\n");
int result = patchFunctionForLib("./theLib.so", "internalFunction", &sneakAttack);
printf("MAIN: patch result: %s\n", result == 0 ? "SUCCESS!" : "FAILURE!");
gDidPatch = 1;
}
}
int main(int argc, void **argv)
{
printf("opening theLib.so\n");
void * lib = dlopen("./theLib.so", RTLD_LAZY);
if( lib == 0 ) {
printf("Couldn't open theLib.so\n");
return 1;
}
printf("MAIN: calling externalFunction\n");
void(*externalFunction)() = dlsym(lib, "externalFunction");
externalFunction();
printf("MAIN: calling my internalFunction\n");
internalFunction();
return 0;
}