views:

260

answers:

3

I want to append some binary data to the end of my executable. This is just to make my program into a single file. I tried using UpdateResource but I hit some bug inside it with my specific data, so I have to use another solution. So I need to know the original file size to determine if there is actually any data appended to it. Is it possible to obtain this information from the PE headers?

Thanks!

A: 

You might be able to, if you can get the size of each chunk. This may be of assistance:

http://msdn.microsoft.com/en-us/library/ms809762.aspx

taspeotis
I tried summing the size of each chunk and sometimes it almost works, sometimes it gives result which is double the file size.
bobef
Taking back the double file size thing. It was due to loading file at different path than I thought. You also need to add nt_header.OptionalHeader.SizeOfHeaders to the calculation and then it seems to work for some files :)
bobef
+2  A: 

I found my solution here http://www.strchr.com/creating_self-extracting_executables

bobef
A: 

You may find this PE file reader useful. You should be able to extract the appropriate value from the PE header using this software. Full source supplied.

http://www.objectmedia.ltd.uk/freeSoftware/peFileDLL.html

There is also a PE File Explorer (with source) on the same site. I can't post more than one URL at present because I don't have enough status points, so you'll have to work it out.

The PE File Explorer allows you to browse the contents of the PE file.

I wrote the software I am referring to (which in turn was inspired, many, many moons ago by a software tool by Matt Pietrek call LIPOsuction).

Stephen Kellett