issig.bat 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 (before compilation) or to sign files
  9. rem using it (after compilation)
  10. rem
  11. rem If the key is missing it will be generated
  12. setlocal
  13. cd /d %~dp0
  14. if exist compilesettings.bat goto compilesettingsfound
  15. :compilesettingserror
  16. echo compilesettings.bat is missing or incomplete. It needs to contain
  17. echo the following line, adjusted for your system:
  18. echo.
  19. echo set ISSIGTOOL_KEY_FILE=x:\path\MyKey.isprivatekey
  20. goto failed2
  21. :compilesettingsfound
  22. set ISSIGTOOL_KEY_FILE=
  23. call .\compilesettings.bat
  24. if "%ISSIGTOOL_KEY_FILE%"=="" goto compilesettingserror
  25. rem -------------------------------------------------------------------------
  26. cd Files
  27. if errorlevel 1 goto failed
  28. if not exist "%ISSIGTOOL_KEY_FILE%" (
  29. echo Missing key file
  30. ISSigTool.exe generate-private-key
  31. if errorlevel 1 goto failed
  32. if not exist "%ISSIGTOOL_KEY_FILE%" goto failed
  33. echo Generating key file done - do not share with others!
  34. )
  35. if "%1"=="embed" goto embed
  36. if "%1"=="sign" goto sign
  37. if not "%1"=="" goto failed
  38. :embed
  39. set targetfile=..\Components\TrustFunc.AllowedPublicKeys.inc
  40. if not exist "%targetfile%" goto failed
  41. set publickeyfile=_temp.ispublickey
  42. ISSigTool.exe export-public-key "%publickeyfile%"
  43. if errorlevel 1 goto failed
  44. if not exist "%publickeyfile%" goto failed
  45. 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 key.'; } else { Write-Host 'Markers not found.'; exit 1; } } catch { Write-Error ('Error: ' + $_.Exception.Message); exit 1; }"
  46. if errorlevel 1 goto failed
  47. del "%publickeyfile%"
  48. if errorlevel 1 goto failed
  49. cd ..
  50. if errorlevel 1 goto failed
  51. echo Success!
  52. goto exit
  53. :sign
  54. ISSigTool.exe sign ISCmplr.dll ISPP.dll
  55. if errorlevel 1 goto failed
  56. cd ..
  57. if errorlevel 1 goto failed
  58. echo Success!
  59. goto exit
  60. :failed
  61. echo *** FAILED ***
  62. cd ..
  63. :failed2
  64. exit /b 1
  65. :exit