Advertisement
Guest User

getenvmemory

a guest
Jun 17th, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc,char**argv)
  6. {
  7. char *ptr;
  8.  
  9. if(argc<3){
  10. printf("Usage: %s <environment var> <target program name>\n", argv[0]);
  11. exit(0);
  12. }
  13.  
  14. ptr = getenv(argv[1]);
  15.  
  16. //there is an increment of 2 bytes for every bytes added to the name of the program (pg.141 ericson, or see example at the end)
  17. ptr += (strlen(argv[0]) - strlen(argv[2]))*2;
  18.  
  19. printf("%s will be at %p\n",argv[1],ptr);
  20.  
  21. // or this also work
  22. printf("%08x", getenv(argv[1]));
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement