Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@CCob
Last active April 23, 2024 03:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save CCob/be7d8b66103ea50e30a7036fd8063677 to your computer and use it in GitHub Desktop.
Save CCob/be7d8b66103ea50e30a7036fd8063677 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