Archive: UpdateResource()


UpdateResource()
I want to stamp an affiliate ID into our installer without rebuilding it. I tried writing a small utility that would add a resource to the setup.exe using BeginUpdateResource(), UpdateResource(), and EndUpdateResource(), closely following the example on MSDN.

Yes, I realize I'd need to set CRCCheck off.

However, after my utility exited, I see my installer has been truncated from ~480K to ~40K. The utility works properly on itself, so it must be due to the format of the installer itself.

Anyone know how make this work?


Use !packhdr and then CRCCheck will work and the installer won't be truncated because there'll be nothing to truncate at that stage.


I'm not sure I understand.

I think I take away from your post that tweaking the resources blows up because the executable header is compressed, right?

So are you saying this problem is unique to the NSIS proprietary compression, and that say, UPX won't enable the corruption?


No, I'm saying you should execute your executable editor using !packhdr instead of executing it after the installer is created. That's what !packhdr is for. It's for modifying the stub before anything is added to it and before the CRC is calculated.


Ah! Now I understand.

Unfortunately, that doesn't fit my requirements. Forgive me if I wasn't clear in my original post, but what I want to do is to distribute the completed installer along with my resource tweek utility so that affiliates can stamp their own ID into it.

The fallback solution is to ask them to install the NSIS compiler, and distribute nsi script and install files. Then they could build the installer with their affiliate ID as an argument. But then I wouldn't need my resource tweeker to get the ID into the installer.


In this case you can use CResourceEditor from the NSIS source code, instead of UpdateResource(). It will not truncate the data tacked to the installer. Though the CRC check will still fail.


Cool, I didn't know that was there. Thanks very much!