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>
- char*
- parse_arg( char* string )
- {
- if(!strncmp( string, "(int)", 5 ))
- {
- if(!strncmp( string+5, "0x", 2 ))
- return (char*)strtol( string+7, NULL, 16 );
- else
- return (char*)atoi( string );
- }
- else
- return string;
- }
- int
- main(int argc,char **argv)
- {
- FILE* dll;
- void* (*sym)();
- int i, j;
- int ret = -1;
- if(!argv[1])
- return 1;
- dll = dlopen( "libc.so.6", RTLD_GLOBAL | RTLD_NOW);
- sym = dlsym( dll, argv[1] );
- for(i = 0;i < argc - 2;i++)
- argv[i + 2] = parse_arg( argv[i + 2] );
- for(i = 0,j = 0;i < argc - 2;i++, j += 4)
- //printf("movl %p, (%%esp,%d)\n", (parse_arg(argv[i + 2])), (j) );
- asm("movl %0, (%%esp,%1)" : :"r"(argv[i + 2]), "r"(j) );
- asm("call *%0" : :"r"(sym));
- asm("movl %%eax,%0" :"=r"(ret));
- printf("ret: %d ( 0x%08x )\n", ret, ret );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement