Search code examples
carraysobjcopy

How can I extract an array from an executable file?


I want to do the inverse of this question.

I am embedding a file into an executable as an array, and I would later like to extract the embedded file from the executable.

It seems like objcopy might be useful here but I haven't figured out the proper incantation yet.

(Edit: clarify question, I somehow removed the crux of it in editing originally...)


Solution

  • If you place the embedded file within its own section you can use objcopy to extract that section into a raw output file, I think. Look into gcc's __attribute__((section("embedded_file") )) Or if you are getting the file into the exe some other way using the linker you should be able to get it into another section another way, but I'm not familiar with doing that.