Skip to content

Instantly share code, notes, and snippets.

@un4ckn0wl3z
Created February 11, 2017 09:17
Show Gist options
  • Select an option

  • Save un4ckn0wl3z/d1e97e8b75c45b5c8f8912a83f61144a to your computer and use it in GitHub Desktop.

Select an option

Save un4ckn0wl3z/d1e97e8b75c45b5c8f8912a83f61144a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
char *ptr;
if(argc < 3) {
printf("Usage: %s <environment var> <target program name>\n", argv[0]);
exit(0);
}
ptr = getenv(argv[1]); /* Get env var location. */
ptr += (strlen(argv[0]) - strlen(argv[2]))*2; /* Adjust for program name. */
printf("%s will be at %p\n", argv[1], ptr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment