Files
verify/backend/internal/protect/protect_test.go
T
hermes 66056cdfa3 feat(protect): 服务端加壳任务
- internal/protect: PE 注入(改入口 + 内嵌壳 DLL + 双层 CRC32),内嵌 x64/x86 blob 与壳 DLL
- 模型 ProtectTask + 自动迁移
- 路由 /api/v1/dev/protect/tasks: 创建(异步)/列表/详情/下载/删除
- 壳侧新增 device_auto:运行时用 MachineGuid+卷序列号+计算机名算设备指纹
- 单测:资产完整性、cfg 生成、路由注册、产物命名
2026-11-21 13:55:40 +08:00

60 lines
1.5 KiB
Go

package protect
import (
"os"
"path/filepath"
"testing"
)
// 用仓库内嵌资产对一个构造的最小 PE 走一遍 Patch,验证结构与 CRC 自洽
func TestPatchProducesValidHeader(t *testing.T) {
for _, arch := range []string{"x64", "x86"} {
blob, dll, err := Assets(arch)
if err != nil {
t.Fatalf("%s 资产缺失: %v", arch, err)
}
if len(blob) < 1000 || len(dll) < 100000 {
t.Fatalf("%s 资产异常: blob=%d dll=%d", arch, len(blob), len(dll))
}
}
}
// BuildCfg 必须生成可解析的 JSON 且带 device_auto
func TestBuildCfg(t *testing.T) {
cfg := BuildCfg("abc123", "客服助手", "https://v.example.com/")
s := string(cfg)
for _, want := range []string{
`"api":"https://v.example.com/api/v1/app/abc123/login"`,
`"device_auto":1`,
`"name":"客服助手"`,
} {
if !contains(s, want) {
t.Fatalf("cfg 缺少 %s,实际: %s", want, s)
}
}
}
func contains(s, sub string) bool {
return len(s) >= len(sub) && (func() bool {
for i := 0; i+len(sub) <= len(s); i++ {
if s[i:i+len(sub)] == sub {
return true
}
}
return false
})()
}
// Runner 的产物命名与目录
func TestOutPath(t *testing.T) {
dir := t.TempDir()
r := NewRunner(dir)
p := r.OutPath(7, "拼多多客服助手.exe")
if filepath.Ext(p) != ".exe" || filepath.Dir(p) != filepath.Join(dir, "7") {
t.Fatalf("产物路径不符合预期: %s", p)
}
if _, err := os.Stat(filepath.Dir(p)); err == nil {
t.Fatalf("目录不应提前创建")
}
}