-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathissig.bat
More file actions
76 lines (62 loc) · 3.05 KB
/
issig.bat
File metadata and controls
76 lines (62 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
@echo off
rem Inno Setup
rem Copyright (C) 1997-2025 Jordan Russell
rem Portions by Martijn Laan
rem For conditions of distribution and use, see LICENSE.TXT.
rem
rem Batch file to embed the user's public key from compilesettings.bat in
rem TrustFunc.AllowedPublicKeys.inc and to export it as def02.ispublickey
rem (before compilation) or to sign files using it (after compilation)
rem
rem Also used by build(-ce).bat to verify some precompiled files
rem
rem If the user's private key is missing it will be generated
setlocal
cd /d %~dp0
if exist compilesettings.bat goto compilesettingsfound
:compilesettingserror
echo compilesettings.bat is missing or incomplete. It needs to contain
echo the following line, adjusted for your system:
echo.
echo set ISSIGTOOL_KEY_FILE=x:\path\MyKey.isprivatekey
echo.
echo Keep the path outside of your source tree!
goto failed2
:compilesettingsfound
set ISSIGTOOL_KEY_FILE=
call .\compilesettings.bat
if "%ISSIGTOOL_KEY_FILE%"=="" goto compilesettingserror
rem -------------------------------------------------------------------------
if not exist "%ISSIGTOOL_KEY_FILE%" (
echo Missing key file
Files\ISSigTool.exe generate-private-key
if errorlevel 1 goto failed
if not exist "%ISSIGTOOL_KEY_FILE%" goto failed
echo Generating key file done - do not share with others!
)
if /I "%1"=="embed" goto embed
if /I "%1"=="sign" goto signorverify
if /I "%1"=="verify" goto signorverify
echo Defaulting to embed
if not "%1"=="" goto failed
:embed
set publickeyfile=def02.ispublickey
Files\ISSigTool.exe --allow-overwrite export-public-key "%publickeyfile%"
if errorlevel 1 goto failed
if not exist "%publickeyfile%" goto failed
set targetfile=Components\TrustFunc.AllowedPublicKeys.inc
if not exist "%targetfile%" goto failed
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; }"
if errorlevel 1 goto failed
echo Success!
goto exit
:signorverify
Files\ISSigTool.exe %*
if errorlevel 1 goto failed
echo Success!
goto exit
:failed
echo *** FAILED ***
:failed2
exit /b 1
:exit