Last active
April 23, 2024 03:17
-
-
Save CCob/be7d8b66103ea50e30a7036fd8063677 to your computer and use it in GitHub Desktop.
x86 Relative String Addressing Hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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