Last active
November 5, 2020 13:35
-
-
Save chaidhat/6d5ae1bfbc343130a0ee3d87f53d205c to your computer and use it in GitHub Desktop.
Cheating quine, but self compiles itself.
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> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <windows.h> | |
// this is all done by me, Chaidhat Chaimongkol | |
// reminiscent of mitosis | |
int SAFETY_OFFSET = 11; // filename is 11 characters long | |
int SAFETY_LIMIT = 3; // limit to a depth of | |
int MULTIPLY_BY = 2; // 2 for duplication | |
int main () { | |
for (char i = 0; i < MULTIPLY_BY; i++) | |
{ | |
// get filename | |
char ch, filename[128], filetarget[128]; | |
strcpy(filename, __FILE__); | |
// delete extension | |
int j = 0; | |
while (filename[j] != '.') {j++;} | |
filename[j] = '\0'; | |
sprintf(filename, "%s%d", filename, i); | |
// SAFETY DO NOT REMOVE | |
if (j - SAFETY_OFFSET >= SAFETY_LIMIT) | |
return 0; | |
// get entire filename as target file | |
sprintf(filetarget, "%s.c", filename); | |
// read and copy the file to target file | |
FILE *source = fopen(__FILE__, "r"); | |
FILE *target = fopen(filetarget, "w"); | |
while( ( ch = fgetc(source) ) != EOF ) | |
fputc(ch, target); | |
// recompile the source code | |
printf("Recompiling %s...\n", filename); | |
printf("SAFETY CHECK %d < %d\n", j - SAFETY_OFFSET, SAFETY_LIMIT); | |
char cmd[128]; | |
sprintf(cmd, "start cmd /c \"gcc %s.c -o %s && %s && pause", filename, filename, filename); | |
printf("%s\n", cmd); | |
system(cmd); | |
} | |
} |
copies the source code, then recompiles the source code by itself.
This strapping young lad seems like he has a bright future.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
start cmd /c \"gcc quine-virus.c -o quine-virus && quine-virus && pause
have MinGW and use command prompt