Simple question I know, what I want to do is be able to get the bytes of a file to use to add those bytes to an bit array, which I can then use to write to a file named bytes.exe and launch it. I know how to read the bytes of an existing file at runtime. But I don’t know how to get the bytes of a file to copy and paste into my bitarray[] at design time.
The goal is to be able to write the bites of bitarray[] to myfile.exe at runtime, and then launch said file. There are many bitarray[]'s I’ll be using, based on many different file types, so I’m looking for an easy method.
Is there some kind of decompiler that should be used? I just looked into resource scripts, but I don’t want to attach any dependencies to my main .exe.
If you are targeting Windows, the easiest way to do this is to embed
myfile.exeas a resource, then load the resource at runtime and create a file and write the contents of the resource to your new file.If you can’t use resources, then you’ll need to create a source file (.c or .h) that initializes a byte array with the contents of
myfile.exeand include that as part of your build. Check out this answer for one possible approach:https://stackoverflow.com/a/73653/333127
EDIT: After further review, I don’t think the source code in the link I referenced above will work for binary input files. Here’s a quick alternative I just threw together: