Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save invokethreatguy/6712cb8080d7fb1a5d63fa57aaa5c020 to your computer and use it in GitHub Desktop.
Save invokethreatguy/6712cb8080d7fb1a5d63fa57aaa5c020 to your computer and use it in GitHub Desktop.
x86 Relative String Addressing Hack
#include <stdio.h>
#define DECLARE_STRING(var, str) __attribute__((section(".text"))) char var[] = "\xe8\x00\x00\x00\x00\x58\x83\xc0\x05\xc3" str;
#define REF_STRING(var) ((char*(*)())var)()
DECLARE_STRING(data1, "Hello, World!\n");
DECLARE_STRING(data2, "Goodbye, World!\n");
int main(int , char** )
{
printf("%s", REF_STRING(data1));
printf("%s", REF_STRING(data2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment