Archive: Can an NSIS installer read data appended to installer .exe after it was created?


Can an NSIS installer read data appended to setup.exe after it was created?
  I would like to append a small chunk of data (less than 256 bytes) to the setup.exe file generated by the NSIS compiler (i.e. after the NSIS script has been compiled, possibly with compression).

I know that this is possible, that the small chunk of data won't be CRC'ed, and that the modified setup.exe will run as if that small chunk of data was not appended.

However, I am interested in being able to read it from within the NSIS script when the user runs the installer. Is this possible? If so, is there already a plugin (or even built-in API) that helps facilitate that?

For example, can I use NSIS's FileSeek and FileRead to accomplish the above, although these operations are to be performed on the same setup.exe that does those two operations?


This wiki article might help.


Originally posted by Comperio
This wiki article might help.
OMG - you are so good! That is exactly what I was looking for. Thank you very much, Comperio.

Tips to anyone who might be looking to use the excellent article written by Andrey Tarantsov:

http://nsis.sourceforge.net/ReadCustomerData

It works very well. However, it works only if you don't compile the NSIS script with a compressor

In my case the compressed result is not much smaller than the uncompressed so it makes no difference for me (I am happy :)).


Originally posted by nsnb
It works very well. However, it works only if you don't compile the NSIS script with a compressor
Sorry, I have to take back what I just wrote above. My "discovery" documented above was due to a bug in my implementation of Function ReadCustomerData.

Andrey Tarantsov uses a very robust method to search for CUSTDATA:

loop:

FileSeek $1 $2 END
FileRead$1 $3 $4
StrCmp$3 $R1 found
IntOp$2 $2 + 1
IntCmp$2 0 loop loop
>
But it is also very slow. This is because it keeps reading the file 1024 times to search for CUSTDATA...

I thought of accelerating this by reading the last 1024 bytes in the file only once, then searching for the string in memory. It worked, but is not as robust as Trantsov's: in my implementation compression effects whether CUSTDATA is found. This is clearly my bug.