fix(build): 署名自检改用 Node 字节比对(findstr 在 chcp 65001 下匹配不了 UTF-8 中文)

findstr 会误报 NOT found,而实测 exe 里署名是存在的。改成 verify-signature.mjs
读字节 includes 比对,缺失时让构建硬失败。
This commit is contained in:
AskaEth committed 2026-09-09 22:21:28 +08:00
1 parent e7948088df
commit 8039da384d
2 files changed
+28 -1

No files matched your search

+1 -1
View File
@@ -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
+27
View File
@@ -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')