Hello to everybody,
I know C/C++ for quite a while now and it's embarrassing for me not to be able to solve my problem.
I wanted to write a program, that reads data from a linked in binary object, writes to executale and executes it (for now with the "system()" function, maybe Windows API later).
The Program to be executed is a simple HelloWorld-Program. However, if I store a normal text file in my target program, its no problem and the output file IS the same MD5 as the input. I link the file with the command "ld -r -b binary -o HelloWorld.o HelloWorld.exe" (-r for relocatable, -b binary for explicit binary, and the rest is input and output.
My code is therefore:
using namespace std;
extern char binary_HelloWorld_exe_start;
extern char binary_HelloWorld_exe_end;
cout << "#Stream started" << endl;
for(char *p = &binary_HelloWorld_exe_start; p < &binary_HelloWorld_exe_end; p++)
file1 << *p;
cout << "#File written" << endl;
I really hope someone to tell me what i am doing wrong. The mistake is surely quite easy, that I would never mind ;)
Thanks in advance,
EDIT: The real error is: Windows cant execute the copied program, because unsupported 16-bit Application, what isnt the real thing, I think something went wrong with a header, etc., However, the output file is some ~200 bytes larger than the original "HelloWorld.exe".