From 8039da384dba2330f0ef638985da25a76d99ea5a Mon Sep 17 00:00:00 2001 From: AskaEth Date: Wed, 9 Sep 2026 22:21:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(build):=20=E7=BD=B2=E5=90=8D=E8=87=AA?= =?UTF-8?q?=E6=A3=80=E6=94=B9=E7=94=A8=20Node=20=E5=AD=97=E8=8A=82?= =?UTF-8?q?=E6=AF=94=E5=AF=B9=EF=BC=88findstr=20=E5=9C=A8=20chcp=2065001?= =?UTF-8?q?=20=E4=B8=8B=E5=8C=B9=E9=85=8D=E4=B8=8D=E4=BA=86=20UTF-8=20?= =?UTF-8?q?=E4=B8=AD=E6=96=87=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit findstr 会误报 NOT found,而实测 exe 里署名是存在的。改成 verify-signature.mjs 读字节 includes 比对,缺失时让构建硬失败。 --- deploy/build.bat | 2 +- deploy/verify-signature.mjs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 deploy/verify-signature.mjs 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')