issig.bat 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. @echo off
  2. rem Inno Setup
  3. rem Copyright (C) 1997-2025 Jordan Russell
  4. rem Portions by Martijn Laan
  5. rem For conditions of distribution and use, see LICENSE.TXT.
  6. rem
  7. rem Batch file to embed the user's public key from compilesettings.bat in
  8. rem TrustFunc.AllowedPublicKeys.inc and to export it as def02.ispublickey
  9. rem (before compilation) or to sign files using it (after compilation)
  10. rem
  11. rem Also used by build(-ce).bat to verify some precompiled files
  12. rem
  13. rem If the user's private key is missing it will be generated
  14. setlocal
  15. cd /d %~dp0
  16. if exist compilesettings.bat goto compilesettingsfound
  17. :compilesettingserror
  18. echo compilesettings.bat is missing or incomplete. It needs to contain
  19. echo the following line, adjusted for your system:
  20. echo.
  21. echo set ISSIGTOOL_KEY_FILE=x:\path\MyKey.isprivatekey
  22. echo.
  23. echo Keep the path outside of your source tree!
  24. goto failed2
  25. :compilesettingsfound
  26. set ISSIGTOOL_KEY_FILE=
  27. call .\compilesettings.bat
  28. if "%ISSIGTOOL_KEY_FILE%"=="" goto compilesettingserror
  29. rem -------------------------------------------------------------------------
  30. if not exist "%ISSIGTOOL_KEY_FILE%" (
  31. echo Missing key file
  32. Files\ISSigTool.exe generate-private-key
  33. if errorlevel 1 goto failed
  34. if not exist "%ISSIGTOOL_KEY_FILE%" goto failed
  35. echo Generating key file done - do not share with others!
  36. )
  37. if "%1"=="embed" goto embed
  38. if "%1"=="sign" goto signorverify
  39. if "%1"=="verify" goto signorverify
  40. if not "%1"=="" goto failed
  41. :embed
  42. set publickeyfile=def02.ispublickey
  43. Files\ISSigTool.exe --allow-overwrite export-public-key "%publickeyfile%"
  44. if errorlevel 1 goto failed
  45. if not exist "%publickeyfile%" goto failed
  46. set targetfile=Components\TrustFunc.AllowedPublicKeys.inc
  47. if not exist "%targetfile%" goto failed
  48. powershell.exe -NoProfile -Command "$filePath = '%targetfile%'; $replacementFilePath = '%publickeyfile%'; $startMarker = 'AllowedPublicKey2Text :='; $endMarker = ';'; try { $content = Get-Content -Raw -Path $filePath; $replacementText = Get-Content -Raw -Path $replacementFilePath; $replacementText = $replacementText -replace \"`r`n\", \"' + #13#10 +`r`n'\"; $replacementText = \"'\" + $replacementText + \"'\"; $replacementText = $replacementText -replace \" \+`r`n''\", \"\"; [string] $pattern = '(?s)' + [regex]::Escape($startMarker) + '.*?' + [regex]::Escape($endMarker); if ($content -match $pattern) { $replacement = $startMarker + \"`r`n\" + $replacementText + $endMarker; $newContent = $content -replace $pattern, $replacement; $utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($false); [System.IO.File]::WriteAllText($filePath, $newContent, $utf8NoBomEncoding); Write-Host \"Embedded public key in $filePath.\"; } else { Write-Host \"Pattern not found in $filePath.\"; exit 1; } } catch { Write-Error (\"Error: $_.Exception.Message\"); exit 1; }"
  49. if errorlevel 1 goto failed
  50. echo Success!
  51. goto exit
  52. :signorverify
  53. Files\ISSigTool.exe %*
  54. if errorlevel 1 goto failed
  55. echo Success!
  56. goto exit
  57. :failed
  58. echo *** FAILED ***
  59. :failed2
  60. exit /b 1
  61. :exit