forked from dsnezhkov/zombieant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdyload.c
39 lines (29 loc) · 759 Bytes
/
dyload.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
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dlfcn.h>
/*
Load shared library and invoke entry point
Optionally, pass parameters to the shared library
*/
int main(int argc, char** argv) {
if (argc < 2){
fprintf(stderr, "Usage: %s <module.so> [args]\n", argv[0]);
exit(1);
}
int i, v = 0, size = argc - 1;
void *handle;
void (*Entry)(char*);
char *str = (char *)malloc(v);
for(i = 2; i <= size; i++) {
str = (char *)realloc(str, (v + strlen(argv[i])));
strcat(str, argv[i]);
strcat(str, " ");
}
handle = dlopen(argv[1], RTLD_LAZY);
*(void**)(&Entry) = dlsym(handle, "Entry");
Entry(str);
exit(EXIT_SUCCESS);
}