|
-
February 3rd, 2010, 02:21 PM
#1
Can exe file size be calculated from PE header fields?
Feels like I've read a million articles but so far without any success in finding the answer...
The reason for wanting to know is that if the relation exists it would open for a very easy bundling of one single exe with another (binary data) file. I.e. using only the shell as the tool to create a new exe file containing customized data. Maybe this is in a way cheating on the resource concept but I know my client would love to be able to create new files himself (and so would I since that part is quite boring ).
The requirement is a single self sustained exe file for each distributed variant. So as far as I can see my options are either the concatenation way or a different build target for each variant.
All clever thoughts are welcome...
-
February 6th, 2010, 07:09 PM
#2
Re: Can exe file size be calculated from PE header fields?
Just write the size of the resource at the end of the PE, and the resource just before it.
-
February 8th, 2010, 12:01 AM
#3
Re: Can exe file size be calculated from PE header fields?
 Originally Posted by S_M_A
All clever thoughts are welcome...
Why don't you write your stuff at the end of exe file, and then - 4-byte length of it.
Then you won't need to parse PE header, just read last 4 bytes and seek back.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 8th, 2010, 02:31 AM
#4
Re: Can exe file size be calculated from PE header fields?
Thanks, I had that thought as well but discarded it since I didn't find a way of doing it with plain console commands. I think I was a bit unclear regarding this part in my post. My client does not have access to anything more than a plain Windows installation and don't want it either so providing a special tool wasn't an option.
Unfortunately the time schedule made me go for the build target solution this time. It's not as flexible as I'd wished but it gets the job done for this time.
-
February 8th, 2010, 04:33 AM
#5
Re: Can exe file size be calculated from PE header fields?
Why can't you put the variable thing in resource and create the specific exe using your own custom tool.
Regards,
Ramkrishna Pawar
-
February 8th, 2010, 04:42 AM
#6
Re: Can exe file size be calculated from PE header fields?
I could have done that but since I seeked a solution free of any other tools besides shell commands I didn't. Since now I'm doing the duplication job it's much faster to make the duplicate targets than make the tool (even though it's simple). I still think the simplicity of a plain binary attach would be a beautiful solution so maybe I do some more research during my spare time.
-
February 8th, 2010, 06:13 PM
#7
Re: Can exe file size be calculated from PE header fields?
 Originally Posted by S_M_A
I could have done that but since I seeked a solution free of any other tools besides shell commands I didn't. Since now I'm doing the duplication job it's much faster to make the duplicate targets than make the tool (even though it's simple). I still think the simplicity of a plain binary attach would be a beautiful solution so maybe I do some more research during my spare time.
Well, I still think my suggestion satisfies your requirements.
You can build your exe, get its size, create a 4-byte binary file (size.bin) with that size in it and use this shell command to create your targets:
Code:
copy /B Test.exe + /B data.bin + /B size.bin new.exe
It this scenario, after you read that size from the end of your exe, you seek from the beginning to that offset and read your data.
Am I missing anything?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 9th, 2010, 07:18 AM
#8
Re: Can exe file size be calculated from PE header fields?
Well both yes an no. Your suggestion works for me but not for my client (the end user). To be able to push the job of bundling things to the client the solution had to be even more trivial. He/she does not know how to create a size.bin with the correct content and endian.
That's why I seeked a more reliable solution, when it comes to assigning numbers properly I do trust the vc linker more than any human.
-
February 9th, 2010, 06:12 PM
#9
Re: Can exe file size be calculated from PE header fields?
This will work for your clients if YOU will provide that size.bin file.
How do you feel about hacks?
The first section of PE file is [now almost obsolete] MS DOS header that have some reserved space. You could write the exe file size into those fields.
Bottom lime is – there are few optional parts in PE file, and if there is no straight “size” filed (I don’t know if it exists), you would have to parse whole lot of data to figure that out.
Since your solution is somewhat a hack in itself, I would consider this suggestion.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|