-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStage2.c
54 lines (39 loc) · 1.34 KB
/
Stage2.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
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "Stage2.h"
typedef void *Stage3_t;
const char *stage2_blep(const char *foo) {
void *handle = dlopen("./libstage3.so", RTLD_LAZY | RTLD_LOCAL);
if (!handle)
printf("Stage 3 dlopen error: %s\n", dlerror());
printf("Stage 2: %s\n", foo);
Stage3_t *(*stage3_create)();
void (*stage3_delete)(Stage3_t *);
const char *(*stage3_blep)(Stage3_t *, const char *);
stage3_create = (Stage3_t *(*)()) dlsym(handle, "stage3_create");
stage3_delete = (void (*)(Stage3_t *)) dlsym(handle, "stage3_delete");
stage3_blep = (const char *(*)(Stage3_t *, const char *)) dlsym(handle, "stage3_blep");
Stage3_t *st = stage3_create();
const char *cres = stage3_blep(st, foo);
stage3_delete(st);
printf("Return value[2]: %s\n", cres);
return cres;
}
int main(int argc, char **argv) {
if (argc < 2)
return 1;
printf("%s\n", stage2_blep(argv[1]));
return 0;
}
JNIEXPORT jstring JNICALL Java_Stage2_blep (JNIEnv *env, jobject obj, jstring foo)
{
const char *cfoo = (*env)->GetStringUTFChars(env, foo, 0);
jstring res = (*env)->NewStringUTF(env, stage2_blep(cfoo));
(*env)->ReleaseStringUTFChars(env, foo, cfoo);
return res;
}
JNIEXPORT void JNICALL Java_Stage2_diedieDIE (JNIEnv *env, jobject obj)
{
exit(0);
}