Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gmh5225/47f070ffb1b8f3778befe627f4a579c7 to your computer and use it in GitHub Desktop.
Save gmh5225/47f070ffb1b8f3778befe627f4a579c7 to your computer and use it in GitHub Desktop.
x86 Relative String Addressing Hack
#include <stdio.h>
#ifdef _WIN64
#define DECLARE_STRING(var, str) __attribute__((section(".text"))) char var[] = "\xe8\x00\x00\x00\x00\x58\x48\x83\xc0\x06\xc3" str;
#elif _WIN32
#define DECLARE_STRING(var, str) __attribute__((section(".text"))) char var[] = "\xe8\x00\x00\x00\x00\x58\x83\xc0\x05\xc3" str;
#endif
#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