Skip to content

Instantly share code, notes, and snippets.

@rbocchinfuso
Last active June 1, 2018 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbocchinfuso/5859ee8be77fd188f78b64eaa8538c62 to your computer and use it in GitHub Desktop.
Save rbocchinfuso/5859ee8be77fd188f78b64eaa8538c62 to your computer and use it in GitHub Desktop.
Polymorphic Hello World
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void)
{
int i;
for(i=0; i<10; i++) {
char buffer[0];
// copy counter to buffer
sprintf(buffer, "%d", i);
char fname[20] = "hello";
// crate filename hello, appending counter and .com to the file name
strcat(fname,buffer);
strcat(fname,".com");
// create file
FILE *myfile = fopen(fname, "wb");
//write to file
putc(0x0E, myfile);
putc(0x1f, myfile);
putc(0xba, myfile);
putc(0x0E, myfile);
putc(0x01, myfile);
putc(0xb4, myfile);
putc(0x09, myfile);
putc(0xcd, myfile);
putc(0x21, myfile);
putc(0xb8, myfile);
putc(0x01, myfile);
putc(0x4c, myfile);
putc(0xcd, myfile);
putc(0x21, myfile);
putc(0x48, myfile); //H
putc(0x65, myfile); //e
putc(0x6c, myfile); //l
putc(0x6c, myfile); //l
putc(0x6f, myfile); //o
putc(0x20, myfile); //space
putc(0x57, myfile); //W
putc(0x6f, myfile); //o
putc(0x72, myfile); //r
putc(0x6c, myfile); //l
putc(0x64, myfile); //d
putc(0x21, myfile); //!
putc(0x24, myfile);
// close file
fclose(myfile);
// run newly created com files and produce output
printf("\n\nCreated file: %s \n", fname);
printf(" Executing: %s \n", fname);
printf(" Output: ");
system(fname);
}
printf("\n\n");
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment