Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <limits.h>
- #include <string.h>
- #include <time.h>
- #include <dirent.h>
- #include <dlfcn.h>
- #include <stdint.h>
- enum
- {
- ARGS_SIZE = 64 / sizeof(uint64_t),
- DOUBLE = 'd',
- STRING = 's',
- INT = 'i',
- VOID = 'v'
- };
- typedef unsigned char uchar;
- void
- parse_args(uchar *args, char *argv[], int ind, char *sign)
- {
- for (sign += 1; *sign; ++sign) {
- char type = *sign;
- if (type == DOUBLE) {
- double temp;
- sscanf(argv[ind], "%lf", &temp);
- memcpy(args, &temp, sizeof(temp));
- args += sizeof(temp);
- } else if (type == STRING) {
- char *temp = argv[ind];
- memcpy(args, &temp, sizeof(temp));
- args += sizeof(temp);
- } else if (type == INT) {
- int temp;
- sscanf(argv[ind], "%d", &temp);
- memcpy(args, &temp, sizeof(temp));
- args += sizeof(temp);
- }
- ++ind;
- }
- }
- int
- main(int argc, char *argv[])
- {
- void *handle = dlopen(argv[1], RTLD_LAZY);
- if (handle == NULL) {
- fprintf(stderr, "Error error...\n");
- return 1;
- }
- void *sym = dlsym(handle, argv[2]);
- if (sym == NULL) {
- fprintf(stderr, "Error error...\n");
- return 1;
- }
- uint64_t args[ARGS_SIZE];
- parse_args((void *)args, argv, 4, argv[3]);
- char type = argv[3][0];
- if (type == VOID) {
- void (*func)(uint64_t, uint64_t, uint64_t, uint64_t,
- uint64_t, uint64_t, uint64_t, uint64_t) = sym;
- func(args[0], args[1], args[2], args[3],
- args[4], args[5], args[6], args[7]);
- } else if (type == DOUBLE) {
- double (*func)(uint64_t, uint64_t, uint64_t, uint64_t,
- uint64_t, uint64_t, uint64_t, uint64_t) = sym;
- double res = func(args[0], args[1], args[2], args[3],
- args[4], args[5], args[6], args[7]);
- printf("%.10g\n", res);
- } else if (type == INT) {
- int (*func)(uint64_t, uint64_t, uint64_t, uint64_t,
- uint64_t, uint64_t, uint64_t, uint64_t) = sym;
- int res = func(args[0], args[1], args[2], args[3],
- args[4], args[5], args[6], args[7]);
- printf("%d\n", res);
- } else {
- char *(*func)(uint64_t, uint64_t, uint64_t, uint64_t,
- uint64_t, uint64_t, uint64_t, uint64_t) = sym;
- char *str = func(args[0], args[1], args[2], args[3],
- args[4], args[5], args[6], args[7]);
- printf("%s\n", str);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement