Created
June 2, 2011 17:03
-
-
Save thomie/1004814 to your computer and use it in GitHub Desktop.
Self replicating code
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
x = 'print "x = " + chr(39) + x + chr(39) + "; exec(x)"'; exec(x) |
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> | |
#define CODE "#include <stdio.h>%c#define CODE %c%s%c%cint main(void){ return printf(CODE, 10, 34, CODE, 34, 10, 10); }%c" | |
int main(void){ return printf(CODE, 10, 34, CODE, 34, 10, 10); } |
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> | |
#define CODE int main(void){ return printf("#include <stdio.h>\n\n#define CODE %s\n\n/* http://gcc.gnu.org/onlinedocs/cpp/Stringification.html */\n#define XQUOTE(x) QUOTE(x)\n#define QUOTE(x) #x\n\nconst char* SOURCE = XQUOTE(CODE);\nCODE\n", SOURCE); } | |
/* http://gcc.gnu.org/onlinedocs/cpp/Stringification.html */ | |
#define XQUOTE(x) QUOTE(x) | |
#define QUOTE(x) #x | |
const char* SOURCE = XQUOTE(CODE); | |
CODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment