tags:

views:

59

answers:

2

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...)

+1  A: 

Put a recognizable pattern at the beginning of the array to help you find the data in the file.

If you're creating a Windows executable, put the data into a binary resource in the executable instead of just encoding it into an array -- you can then use normal Windows resource functions (FindResource, LoadResource, etc.) to get the data (though this is a bit trickier to get working correctly than it initially seems like it should be).

Jerry Coffin
This is a linux (elf32-powerpc) executable. I'm looking for something more robust than pattern hunting.
bstpierre
@bstpierre:A few people have done projects to add resource-like capabilities with Unix executable formats. You might want to look at: http://www.taniwha.com/~paul/res/ for one example.
Jerry Coffin
Thanks for the pointer, I'll check it out.
bstpierre
+2  A: 

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.

nategoose
Thanks. I looked at this a bit too, I'll give it a try.
bstpierre