This one needs a little explaining. A while back I was in the middle of a major life crisis and things where looking real bad for me, in a nutshell I couldn't sleep. I was put on ambien by my doctor, and found I did not go to sleep while on it. Instead I turned into a zombie of a person that walked into walls ocassionally. This is something I coded while awake on ambien.
//-----Generate Self Extracting patch installer----->
if(generatePatch && numDiffs > 0){//-b flag
//construct base source files
system("mkdir /tmp/builder");
system("echo '#include <stdio.h>' > /tmp/builder/headers.c");
system("echo '#include <stdlib.h>' >> /tmp/builder/headers.c");
system("echo \" \" >> /tmp/builder/headers.c");//space
system("echo \" \" > /tmp/builder/decompile.c");//space
system("echo 'int main(){' >> /tmp/builder/decompile.c");
system("echo 'FILE *fp = fopen(\"TMP.tar.gz\",\"wb\");' >> /tmp/builder/decompile.c");
system("echo 'fwrite(xxx, sizeof(xxx[0]), sizeof xxx/sizeof(xxx[0]), fp);' >> /tmp/builder/decompile.c");
system("echo 'fclose(fp);' >> /tmp/builder/decompile.c");
//do any additional installation work here-->
system("ST=\\\"\necho \"system(${ST}> .install.py${ST});//create installer script\" >> /tmp/builder/decompile.c");//create script file
//write python install script here-->
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'from Tkinter import * ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'from tkFileDialog import askdirectory ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'import os ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'def askd(): ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo ' dir1 = askdirectory() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo ' if dir1: ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo ' print ${STT}Directory ${STT} + dir1 + ${STT} Will Be Patched.${STT}' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo ' os.system(${STT}tar -zxf ./TMP.tar.gz -C .${STT}) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo ' os.system(${STT}mv -f .gamepatch.diff* ${STT} + dir1) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo ' os.system(${STT}rm ./TMP.tar.gz${STT}) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo ' os.system(${STT}cd dir1\\\\\\\ngamepatch -p 10000${STT}) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");//patch system to latest patch
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo ' quit() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");//exit tkinter
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo ' exit() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");//exit python
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'top = Frame() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'top.pack() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'Label(top, text=${STT}${STT}${STT}This patch is only designed for a specific game. ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'Do Not Use If Unsure What Game This Is For! ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo '${STT}${STT}${STT}).pack(side=TOP) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'widget = Button(top, text=${STT}Choose Game Directory To Patch${STT}, command=askd) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'widget.pack(side=BOTTOM) ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
system("STT=\\\\\\\"\nST=\\\"\necho \"system(${ST}echo 'top.mainloop() ' >> .install.py${ST});\" >> /tmp/builder/decompile.c");
//---------------------------------->
system("ST=\\\"\necho \"system(${ST}gnome-terminal -e 'python ./.install.py'${ST});\" >> /tmp/builder/decompile.c");//run script file
system("ST=\\\"\necho \"system(${ST}rm .install.py${ST});\" >> /tmp/builder/decompile.c");//remove script file
//------------------------------------------>
system("echo 'return 0;}' >> /tmp/builder/decompile.c");
//build and merge source files
system("tar -zcf /tmp/builder/TMP.tar.gz .gamepatch.diff*");
system("cat /tmp/builder/TMP.tar.gz | ( echo \"unsigned char xxx[] = {\"; xxd -i; echo \"};\" ) > /tmp/builder/output_file.c");
system("cat /tmp/builder/headers.c /tmp/builder/output_file.c /tmp/builder/decompile.c > /tmp/builder/builder.c");
//compile source file
if(path==NULL){
system("gcc /tmp/builder/builder.c -o ./patcher");
}
else{
sprintf(buffer, "%s%s","gcc /tmp/builder/builder.c -o ",path);
system(buffer);
}
printf("\n-->Patch Installer Has Been Generated\n");
}
//-------------------------------------------------->