diff --git a/deploy/build.bat b/deploy/build.bat index 4b39bd1..2affac7 100644 --- a/deploy/build.bat +++ b/deploy/build.bat @@ -39,7 +39,7 @@ if exist "..\deploy\signature.build.txt" for /f "usebackq delims= eol=" %%A in ( if defined INTERNAL_SIGNATURE ( REM single quotes keep spaces inside the value intact for go's ldflags parser go build -ldflags "-X 'git.yeij.top/AskaEth/Scoreboard/server/internal/version.InternalSignature=%INTERNAL_SIGNATURE%'" -o ..\dist\scoreboard.exe . || exit /b 1 - findstr /m /c:"%INTERNAL_SIGNATURE%" ..\dist\scoreboard.exe >nul || echo [warn] signature NOT found in exe + node ..\deploy\verify-signature.mjs || exit /b 1 echo internal signature injected ) else ( go build -o ..\dist\scoreboard.exe . || exit /b 1 diff --git a/deploy/verify-signature.mjs b/deploy/verify-signature.mjs new file mode 100644 index 0000000..a5ad91f --- /dev/null +++ b/deploy/verify-signature.mjs @@ -0,0 +1,27 @@ +// 校验注入后的 exe 里确实含有署名。 +// +// 为什么不用 findstr:它在 chcp 65001 下匹配不了 UTF-8 中文(会静默误报 NOT found), +// 而 build.bat 又必须保持纯 ASCII。用 Node 读字节比对最稳。 +import { existsSync, readFileSync } from 'node:fs' +import { dirname, join } from 'node:path' + +const root = dirname(import.meta.dirname) +const sigFile = join(root, 'deploy', 'signature.build.txt') +const exe = join(root, 'dist', 'scoreboard.exe') + +if (!existsSync(sigFile)) process.exit(0) + +const sig = readFileSync(sigFile, 'utf8').trim() +if (sig === '') process.exit(0) + +if (!existsSync(exe)) { + console.error(' [warn] scoreboard.exe not found, skip signature check') + process.exit(0) +} + +if (!readFileSync(exe).includes(Buffer.from(sig, 'utf8'))) { + console.error(' [ERROR] internal signature NOT found in scoreboard.exe') + process.exit(1) +} + +console.log(' internal signature verified in exe')