Here goes. It requires one command-line argument, which is the name to which the exe code is copied. Compiled and works under Borland C 4.5
#include
#include
#include
#include
#include
#define BACKSLASH '\\'
int main (int argc, char *argv[])
{
int i;
char *ptr;
char newname[256];
FILE *executable;
FILE *copy;
struct stat statbuf;
char *contentbuffer;
long count;
strcpy (newname, argv[0]);
ptr = newname;
while (*ptr) ptr++;
ptr--;
while ((*ptr != BACKSLASH) && (ptr > newname)) ptr--;
if (*ptr == BACKSLASH)
{
ptr++;
*ptr = 0;
strcat (newname, argv[1]);
strcat (newname, ".exe");
}
if ((executable = fopen(argv[0], "rb")) == NULL)
{
fprintf(stderr, "Cannot open executable file.\n");
return 1;
}
if ((copy = fopen(newname, "wb")) == NULL)
{
fprintf(stderr, "Cannot open copy of executable.\n");
return 2;
}
stat(argv[0], &statbuf);
contentbuffer = farmalloc (statbuf.st_size + 32);
if (contentbuffer == NULL)
{
fprintf(stderr, "Malloc error.\n");
return 3;
}
count = fread(contentbuffer, 1, statbuf.st_size, executable);
if (count != statbuf.st_size)
{
fprintf(stderr, "File read error. count = %d and buffer = %d\n", count, statbuf.st_size);
return 4;
}
count = fwrite(contentbuffer, 1, statbuf.st_size, copy);
if (count != statbuf.st_size)
{
fprintf(stderr, "File write error. count = %d and buffer = %d\n", count, statbuf.st_size);
return 5;
}
return 0;
}
2007-11-03 00:44:04
·
answer #1
·
answered by Anonymous
·
1⤊
1⤋
Searhc for Reverse Compilers.
2007-11-03 00:16:46
·
answer #2
·
answered by Shariq (http://coinsindia.info) 5
·
0⤊
2⤋
A decompiler? There were such a thing for unscrambled Java but I only heard of disassembler for Assemblies not working decompilers for others.
Such a thing would cause the digital equivalent of Hiroshima.
2007-11-03 00:28:50
·
answer #3
·
answered by Andy T 7
·
0⤊
2⤋
A COMPILER! LOL
Seriously though, you dont want to do this!
It will eventually put programmers out of work if computers can write their own code!
2007-11-03 00:02:42
·
answer #4
·
answered by adam_adams_25 3
·
0⤊
2⤋
It is not that easy. May be you can contact a C expert at websites like http://homeworkhelp.co.in/
2007-11-03 02:20:43
·
answer #5
·
answered by John R 4
·
0⤊
1⤋
I do not see what you are trying to achieve, there is no possible useful purpose to this.
2007-11-03 00:05:50
·
answer #6
·
answered by Anonymous
·
0⤊
2⤋