Last active
April 29, 2016 19:06
-
-
Save xire-/2a6d7ea5267e3ed808c594290c019697 to your computer and use it in GitHub Desktop.
Prints the address of args, env vars and stored eip, ebp of the main frame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
gcc -m32 -o getaddrs getaddrs.c | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void | |
p_data_string(char* string) { | |
char *p_c; | |
char c; | |
for (p_c = string; *p_c != 0; p_c++) { | |
c = *p_c; | |
if (c == '\\') { | |
printf("\\\\"); | |
} else if (c == '\n') { | |
printf("\\n"); | |
} else if (c >= 32 && c < 127) { | |
printf("%c", c); | |
} else { | |
printf("\\x%02hhx", c); | |
} | |
} | |
} | |
void | |
p_envs(char* envp[]) { | |
char* value_p; | |
printf("----[ENVS]----------------------------\n"); | |
for(; *envp != 0; envp++) { | |
value_p = strstr(*envp, "="); | |
if (value_p) value_p += 1; | |
printf("[%8p]->[ %8p - %8p\t] : ", envp, *envp, value_p); | |
p_data_string(*envp); | |
printf("\n"); | |
} | |
} | |
void | |
p_args(int argc,char *argv[]) { | |
int i; | |
printf("----[ARGS]----------------------------\n"); | |
for(i = 0; i < argc; i++) { | |
printf("ARGV[%02d] - [%8p]->[%8p] : ", i, (argv+i), *(argv+i)); | |
p_data_string(*(argv+i)); | |
printf("\n"); | |
} | |
} | |
int | |
main(int argc,char *argv[], char* envp[]) { | |
/* print envs and args */ | |
p_envs(envp); | |
p_args(argc, argv); | |
printf("----[FRAME]---------------------------\n"); | |
register unsigned int* s_ebp asm("ebp"); | |
unsigned int* s_eip = s_ebp+1; | |
printf("ARGV: %8p\n", argv); | |
printf("EBP : %8p -> %8p\n", s_ebp, (void*)*s_ebp); | |
printf("EIP : %8p -> %8p\n", s_eip, (void*)*s_eip); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment