Skip to content

Instantly share code, notes, and snippets.

@CelDaemon
Created January 11, 2026 17:00
Show Gist options
  • Select an option

  • Save CelDaemon/747f44042cb4c9fc0b4ee44f138c3d9d to your computer and use it in GitHub Desktop.

Select an option

Save CelDaemon/747f44042cb4c9fc0b4ee44f138c3d9d to your computer and use it in GitHub Desktop.
Program arg and environment dumper
#include <stdio.h>
#include <assert.h>
#include <string.h>
extern char **environ;
char *get_env_end() {
char *env_end = NULL;
char *prev_end = NULL;
int i = 0;
do {
prev_end = env_end;
env_end = environ[i++];
} while(env_end != NULL);
return prev_end + strlen(prev_end);
}
int main(int argc, char *argv[]) {
fwrite(&argv[0][0], sizeof(char), get_env_end() - &argv[0][0], stdout);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment