issig.bat 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 /I "%1"=="embed" goto embed
  38. if /I "%1"=="sign" goto signorverify
  39. if /I "%1"=="verify" goto signorverify
  40. echo Defaulting to embed
  41. if not "%1"=="" goto failed
  42. :embed
  43. set publickeyfile=def02.ispublickey
  44. Files\ISSigTool.exe --allow-overwrite export-public-key "%publickeyfile%"
  45. if errorlevel 1 goto failed
  46. if not exist "%publickeyfile%" goto failed
  47. set targetfile=Components\TrustFunc.AllowedPublicKeys.inc
  48. if not exist "%targetfile%" goto failed
  49. 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; }"
  50. if errorlevel 1 goto failed
  51. echo Success!
  52. goto exit
  53. :signorverify
  54. Files\ISSigTool.exe %*
  55. if errorlevel 1 goto failed
  56. echo Success!
  57. goto exit
  58. :failed
  59. echo *** FAILED ***
  60. :failed2
  61. exit /b 1
  62. :exit