1

How to implement MD5 check into Inno Setup, so that it could verify base installer files (exe + bins) on InitializeSetup - this is standard NSIS functionality, which is quite useful as it informs if the installer is OK or corrupted?

In case of IS that would probably require to embed MD5Summer or other MD5 checker and to create MD5 sums during/after the compilation.

Sam
  • 7,252
  • 16
  • 46
  • 65
RobeN
  • 5,346
  • 1
  • 33
  • 50
  • You will need to temporary extract the file and use [`GetMD5OfFile`](http://www.jrsoftware.org/ishelp/topic_isxfunc_getmd5offile.htm) function for this. – TLama Sep 10 '12 at 12:19
  • 1
    At compilation time you can use the same named [`GetMD5OfFile`](http://www.jrsoftware.org/ispphelp/topic_getmd5offile.htm) preprocessor function and store the MD5 sums e.g. into a text file that you can load at run time. However, it's not that easy because you [`can't access file list`](http://stackoverflow.com/a/11736521/960757). – TLama Sep 10 '12 at 12:30
  • If you won't have [`dontverifychecksum`](http://www.jrsoftware.org/ishelp/topic_filessection.htm) flag specified, it should be enough to use [`ExtractTemporaryFile`](http://www.jrsoftware.org/ishelp/topic_isxfunc_extracttemporaryfile.htm) function (quick view to source). It will throw an exception when the file is sick :-) – TLama Sep 10 '12 at 13:23

2 Answers2

0

Inno already does a full integrity check of its own contents. There is no need to do an extra check.

If you're using disk spanning (implied by the existance of .bin files) then the .bin files may not be available (on different disks) and so are not scanned until setup gets to that disk.

Deanna
  • 23,876
  • 7
  • 71
  • 156
  • 1
    It does during installation. I can corrupt file and Setup will run anyway. It will inform about a problem during installation. What I want/need is to verify all files on `InitializeSetup`. So I cannot agree with your Answer. – RobeN Sep 10 '12 at 12:44
  • You've lost me. We agree that the setup validates its files. What are you trying to check for? – Deanna Sep 10 '12 at 13:29
  • Run any NSIS installer. Before displaying Wizard it will verify whole installer. If installer file is corrupted it will inform about the problem and Exit. So... the user can be sure that if setup will display Wizard, the installer is OK (not corrupted). Inno Setup setup can run even when cabinets are faulty, corrupted. It will display error during the installation. I want IS to verify installer's files before Wizard. Why? Because if the app is large - e.g. 12 BINs - I would be extremely mad encountering ERROR during extraction of last cabinet. Better to know before... – RobeN Sep 10 '12 at 13:35
  • Well, now I can tell you for sure, that the only way how to determine this is to extract all the files when the wizard starts (what can as you say, take a long time) and handle exceptions. Doing that, you should then consider to copy those etracted files from a temporary to target folder to prevent double extraction. – TLama Sep 10 '12 at 14:57
  • 3
    Since you've mentioned using .bin files, that means that you have DiskSpanning enabled. Inno doesn't do a verify on startup in this case because these files are permitted to be on separate disks/discs (hence the name) and thus aren't available at startup. If your app is small enough you should turn DiskSpanning off to avoid this. – Miral Sep 11 '12 at 21:05
  • I don't think this is correct. I deliberately truncated an inno setup EXE and it still ran normally and tried to install. There was no initial error at all. Single EXE, no BIN files. – StayOnTarget Aug 26 '22 at 12:38
0

What about creating md5 hashes for all .bin files? This should be done in 2 steps:

1) creating md5 hashes from compiled .bin(s) - hashes will be stored as text files inside setup.exe [so this is a 2 step compilation: create .bins, create hashes for .bins and compile again to include hashes into setup.exe]

2) at runtine in InitializeWizard() function using plug-in.

You can easily compare hashes with some Pascal string comparison function or simply '='. If hashes do not match you can exist the installer before any window is shown.

It is important to have small setup.exe - hashes must be always in the same place somewhere near the top of the [Files] section to have fast uncompress. And everything must be solid so adding hashes into setup.exe will not modify the md5 of .bins.

Slappy
  • 5,250
  • 1
  • 23
  • 29
  • 1) That you can do with preprocessor 2) How would that plugin extract files from the InnoSetup installation archive ? Don't forget that they are uncompressed just when the files are copied at installation. – TLama Sep 11 '12 at 10:51
  • Extracting files is easy: put file into [Files] section "Source: file.hash; Flags: dontcopy;" and extract them in InitializeWizard() function as "ExtractTemporaryFile('file.hash');" – Slappy Sep 11 '12 at 11:42