a lot of times ago, i found an extract of C code, that could read the content of an executable file and that can store it as an array of char, in another file (ex: output.txt). It should work, but when i tried it, it corrupts the output, and it can't copy exactly the content of the exe as a char without damaging it. I don't know where could be the problem.
This is my extract of code in C
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main(int argc, char *argv[])
{
if(argc != 3)
{
fprintf(stderr, "Usage >NameProgram firstParam Executable.exe\n");
return -1;
}
FILE *output = fopen("output.txt", "a");
[..]
char* input_file = argv[2]; //the name of the exe
FILE* f_input = fopen(input_file, "rb");
fprintf(output,"char byn[] = {\n");
unsigned long n = 0;
while(!feof(f_input))
{
unsigned char c;
if(fread(&c, 1, 1, f) == 0)
break;
fprintf(output,"0x%.2X,", (int)c);
++n;
if(n % 10 == 0)
fprintf(output,"\n");
}
fclose(f_input);
fclose(output);
//truncating file
FILE *output = fopen("output.txt", "r+");
fseek(output, -1, SEEK_END);
fprintf(output,"};\n\n");
fclose(output);
[..]