I want to read binary with Python and then store the binary in a header file for a C++ program. How can I store this binary data for later use like writing it to an .exe file to execute it? What encoding should I use?
Also is for example \x00 ASCII or HEX? Can I encode the binary in ASCII then store it in a header file for later use in C++ and then convert it to binary on the go to write the variable content to a file in binary format? How can I achieve this.
A little more clarification. C++ Header file will have a variable storing binary data, but I don't know how to achieve that, since I don't think it's as simple as pouring the binary data to a char pointer like this
char *binary = "?>!#{PL{"; // Some unreadable by text editors binary data go here
I think it should be more like
char *binary = "\x00\x01\x04"; // When I encoded it in ASCII it was in this format, but I remember that HEX format was similar too maybe even the same?
Or even storing it in an array in this format
char binaryp[] = { 0x546, 0x423 etc...};
But for that I need a Separator in my Python code.
Python code:
with open("../testing.exe", "rb") as f:
with open("asd.txt", "wb") as b:
while True:
c = f.read(1)
if not c:
break
b.write("{}".format(c).encode("ascii")) # Or HEX
In general I just want to store binary in a C++ variable and it doesn't matter if it's readable or not I just want to be able to write it to a binary file in the end, without doing any kind of reading on C++ side. Think it as if you already have some binary data on a variable in C++ and you just write it down to an exe file and it works. The issue is I don't know what's the easiest way to do it and the best way. The Performance isn't as important, but if you have a better solution I'm always happy to listen!