Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dlfcn.h>
- #include <limits.h>
- static volatile void (*void_function)();
- static volatile int (*int_function)();
- static volatile double (*double_function)();
- static volatile char *(*string_function)();
- static void *handle;
- static volatile int index_int;
- static volatile int signature_size;
- static volatile int int_to_stack;
- static volatile double temp;
- static volatile int *first_int_to_stack_p;
- static volatile int *second_int_to_stack_p;
- static char file_name[PATH_MAX + 24] = "./";
- static volatile int result_int = 0;
- static volatile double result_double = 0;
- static volatile char *result_string;
- static const char fmt_print_int[25] = "%d\n";
- static const char fmt_print_string[25] = "%s\n";
- static const char fmt_print_double[25] = "%.10g\n";
- static const char percent_d[25] = "%d";
- static const char percent_lf[25] = "%lf";
- static const char percent_s[25] = "%s";
- static const char symbol_i = 'i';
- static const char symbol_d = 'd';
- static const char symbol_s = 's';
- static const char symbol_v = 'v';
- static volatile int current_head = 0;
- static volatile int current_stack_before_call = 0;
- static volatile int current_stack_after_call = 0;
- int
- main(int argc, char **argv)
- {
- handle = dlopen(argv[1], RTLD_LAZY);
- if (handle == NULL) {
- strcat(file_name, argv[1]);
- handle = dlopen(file_name, RTLD_LAZY);
- if (handle == NULL) {
- fprintf(stderr, "Error! %s\n", dlerror());
- exit(1);
- }
- }
- signature_size = strlen(argv[3]);
- volatile unsigned old_stack_head = 0;
- asm
- (
- "movl %%esp, %0\n\t"
- :"=r"(old_stack_head)
- :
- :
- );
- printf("Верхушка стека: %d\n", old_stack_head);
- index_int = signature_size - 1;
- asm volatile
- (
- "pushl %1\n\t"
- "movl %%esp, %0\n\t"
- : "=r"(current_head)
- : "r"(argv[3 + index_int])
- :
- );
- printf("Добавили 4 байт %d\n", current_head);
- *(void **)(&void_function) = dlsym(handle, argv[2]);
- asm volatile
- (
- "movl %%esp, %0\n\t"
- "call *%2\n\t"
- "movl %%esp, %1\n\t"
- "mov %3, %%esp\n\t"
- : "=r"(current_stack_before_call), "=r"(current_stack_after_call)
- : "r"(void_function), "r"(old_stack_head)
- : "eax", "ecx", "edx"
- );
- printf("Стек до вызова = %d, стек после вызова = %d\n", current_stack_before_call, current_stack_after_call);
- dlclose(handle);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement