Combreal

getenvvar.c

Aug 10th, 2020
1,109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char *argv[]) {
  6.     char *ptr;
  7.  
  8.     if(argc < 3) {
  9.         printf("Usage: %s <environment variable> <target name program>\n", argv[0]);
  10.         exit(EXIT_FAILURE);
  11.     }
  12.  
  13.     ptr = getenv(argv[1]); /* get env var location */
  14.     ptr += (strlen(argv[0]) - strlen(argv[2]))*2; /* adjust for program name */
  15.  
  16.     printf("%s will be at %p\n", argv[1], ptr);
  17.  
  18.     return EXIT_SUCCESS;
  19. }
  20. //gcc -m32 getenvvar.c -o getenvvar
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×