Skip to content

Instantly share code, notes, and snippets.

@Sigmanificient
Created January 26, 2024 20:34
Show Gist options
  • Save Sigmanificient/8f4c4f5547b15906fd958ab50e91b95f to your computer and use it in GitHub Desktop.
Save Sigmanificient/8f4c4f5547b15906fd958ab50e91b95f to your computer and use it in GitHub Desktop.
Stack hack
#include <stdio.h>
static char *S[] = { "Hello ", "world!\n" };
static
void print_me(int kek, const char p[static sizeof printf])
{
(void)p;
(**((void (**)(char *, char *))
((&kek - sizeof kek) + 1)))
("%s", S[kek]);
}
__attribute__((constructor))
int main(void)
{
static int i = 0;
((int (*)(int, char *))(&print_me))
(i++, (void *)&printf);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment