I had a photo named photo.jpg.
I used xxd -i to generate a C++ file for my image file.
And the output is something like this:
unsigned char photo_jpg[] = {
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
0x01, 0x01, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x84,...};
unsigned int photo_jpg_len = 24821;
I embedded that file into my main.cpp file and built it to generate my executable.
How could I possibly read that part of the hex dump which is my image file from the executable?
What have I tried...?
I used xxd myfile.exe > file.txt.
When I examine the hex dump of my executable generated with xxd, I see that the bytes of my photo_jpg character array are somewhere in the executable. You can see that in the image below: It is a screenshot of my executable hex dump.
How could I read that and store it inside of a character array like it was before being embedded into my executable?
At first, I converted my zip file to a string which was with this command:
xxd -p archive.zip > myfile.txtThen I used this code to generate a multiline string in C++ of the hex dump of my zip file:
After that, I put the contents of string.txt inside a global variable. Using the below function I was able to write a program that generates a zip file.
But what is the point?
The point is you could have any kind of resource inside your zip file. In this way, you could generate needed resources with your program and do some stuff with them. I think that's pretty cool.