merge feat/doglic:自签授权验签 + 双重加壳兼容 + 壳源码入库
This commit is contained in:
@@ -52,3 +52,6 @@ temp/
|
||||
|
||||
# Trae
|
||||
.trae/
|
||||
|
||||
# 壳源码的本地构建产物
|
||||
shell/**/out/
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
// 签发自签授权序列号(与 DogProtect tools/dogkeygen 等价,Go 版,便于服务端集成)
|
||||
//
|
||||
// 用法:
|
||||
// doglicgen -key <工程.dog|license.xml> -user "客户A" [-email a@b.c] [-exp 20271231]
|
||||
// [-max-build 20270101] [-running-time 90] [-hwid <base64>] [-user-data <hex>]
|
||||
// [-out serial.txt]
|
||||
// doglicgen -key <file> -verify <serial> # 用公钥验一遍并打印字段
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"verification-platform-backend/internal/doglic"
|
||||
)
|
||||
|
||||
func dateArg(s string) (time.Time, error) {
|
||||
if s == "" {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
return time.Parse("20060102", s)
|
||||
}
|
||||
|
||||
func main() {
|
||||
keyPath := flag.String("key", "", "工程/授权文件(含 <LicenseManager Modulus/PrivateExp>)")
|
||||
user := flag.String("user", "", "客户名")
|
||||
email := flag.String("email", "", "客户邮箱")
|
||||
exp := flag.String("exp", "", "到期日 YYYYMMDD")
|
||||
maxBuild := flag.String("max-build", "", "最高构建日 YYYYMMDD")
|
||||
runningTime := flag.Int("running-time", 0, "运行时长限制(分钟)")
|
||||
hwidB64 := flag.String("hwid", "", "绑机数据(base64)")
|
||||
userDataHex := flag.String("user-data", "", "用户数据(hex,首字节常作产品 ID)")
|
||||
serialVersion := flag.Int("serial-version", 1, "序列号版本 1 或 2")
|
||||
out := flag.String("out", "", "写入文件")
|
||||
verifySerial := flag.String("verify", "", "只验签并打印字段")
|
||||
flag.Parse()
|
||||
|
||||
if *keyPath == "" {
|
||||
fmt.Fprintln(os.Stderr, "缺少 -key")
|
||||
os.Exit(2)
|
||||
}
|
||||
keys, err := doglic.LoadKeysFromFile(*keyPath)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "读密钥失败:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if *verifySerial != "" {
|
||||
ok, fields, err := doglic.Verify(keys, *verifySerial)
|
||||
fmt.Printf("verify=%v err=%v\n", ok, err)
|
||||
for k, v := range fields {
|
||||
fmt.Printf(" %-14s %s\n", k, v)
|
||||
}
|
||||
if !ok {
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
expDate, err := dateArg(*exp)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "-exp 格式应为 YYYYMMDD")
|
||||
os.Exit(2)
|
||||
}
|
||||
mbDate, err := dateArg(*maxBuild)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "-max-build 格式应为 YYYYMMDD")
|
||||
os.Exit(2)
|
||||
}
|
||||
var hwid, userData []byte
|
||||
if *hwidB64 != "" {
|
||||
hwid, err = base64.StdEncoding.DecodeString(*hwidB64)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "-hwid base64 解析失败")
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
if *userDataHex != "" {
|
||||
userData, err = hex.DecodeString(*userDataHex)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "-user-data 应为 hex")
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
serial, err := doglic.Sign(keys, doglic.Request{
|
||||
UserName: *user,
|
||||
Email: *email,
|
||||
ExpDate: expDate,
|
||||
MaxBuildDate: mbDate,
|
||||
RunningTime: *runningTime,
|
||||
HWID: hwid,
|
||||
UserData: userData,
|
||||
SerialVersion: byte(*serialVersion),
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "签发失败:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ok, fields, verr := doglic.Verify(keys, serial)
|
||||
fmt.Printf("self-check: %v (%v)\n", ok, verr)
|
||||
for k, v := range fields {
|
||||
fmt.Printf(" %-14s %s\n", k, v)
|
||||
}
|
||||
|
||||
if *out != "" {
|
||||
if err := os.WriteFile(*out, []byte(serial), 0o600); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "写文件失败:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("已写入 %s(%d 字符)\n", *out, len(serial))
|
||||
}
|
||||
fmt.Println(serial)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// 临时工具:以 signed 模式(flags bit1,壳侧跳过整文件 CRC)注入验证壳
|
||||
// 用法: packsigned <src> <out> <cfg.json>
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"verification-platform-backend/internal/protect"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 4 {
|
||||
fmt.Fprintln(os.Stderr, "用法: packsigned <src> <out> <cfg.json>")
|
||||
os.Exit(2)
|
||||
}
|
||||
src, err := os.ReadFile(os.Args[1])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg, err := os.ReadFile(os.Args[3])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
arch, err := protect.DetectArch(src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
out, info, err := protect.PatchSigned(src, cfg, arch, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := os.WriteFile(os.Args[2], out, 0o644); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("产物 %s %d 字节 入口 0x%x→0x%x crcVfy=%08x crcFile=%08x\n",
|
||||
os.Args[2], info.OutSize, info.EntryOld, info.EntryNew, info.CrcVfy, info.CrcFile)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// 按主题打壳:packtest 固定用 classic 壳,这个工具多了 theme 参数,用来出各套验证界面
|
||||
// 用法: packthemed <src.exe> <out.exe> <cfg.json> <theme>
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"verification-platform-backend/internal/protect"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 5 {
|
||||
fmt.Fprintln(os.Stderr, "用法: packthemed <src.exe> <out.exe> <cfg.json> <theme>")
|
||||
os.Exit(2)
|
||||
}
|
||||
src, err := os.ReadFile(os.Args[1])
|
||||
must(err)
|
||||
cfg, err := os.ReadFile(os.Args[3])
|
||||
must(err)
|
||||
arch, err := protect.DetectArch(src)
|
||||
must(err)
|
||||
theme := protect.NormalizeTheme(os.Args[4])
|
||||
|
||||
out, info, err := protect.PatchSignedThemed(src, cfg, arch, false, theme)
|
||||
must(err)
|
||||
must(os.WriteFile(os.Args[2], out, 0o644))
|
||||
|
||||
fmt.Printf("%-10s 架构=%s 产物=%s %d 字节 .vfy size=%d\n",
|
||||
theme, arch, filepath.Base(os.Args[2]), info.OutSize, info.SecSize)
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
// vfyfix — 修正 .vfy 壳头里的两个 CRC(crcV / crcFile)
|
||||
//
|
||||
// 场景:先用 verify 的加壳链路打壳(signed=false,壳会校验整文件 CRC),再用别的工具
|
||||
// (如 DogProtect)二次加壳。后者重写了 PE,壳一校验就退出。本工具在最后一步重算:
|
||||
//
|
||||
// .vfy 节内偏移 36 处:crcV(4 字节) = CRC32IEEE(节内 [0,36) + [44,size))
|
||||
// .vfy 节内偏移 40 处:crcFile(4 字节)= CRC32IEEE(整文件,跳过这两个字段共 8 字节)
|
||||
//
|
||||
// 与 backend/internal/protect/protect.go 的算法逐字节一致(crcOff=36、crcSkip=crc32.IEEE)。
|
||||
//
|
||||
// 用法:
|
||||
//
|
||||
// vfyfix <file.exe> # 修正并写回
|
||||
// vfyfix <file.exe> -dry-run # 只打印新旧值
|
||||
//
|
||||
// 注意:外层加壳时别开压缩(DogProtect 项目的 Options 里不要 cpPack=0x100),
|
||||
// 否则 .vfy 节在文件里不是明文,壳运行时看到的内容与磁盘不一致,这里的重算就失去意义。
|
||||
package main
|
||||
|
||||
import (
|
||||
"debug/pe"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
secName = ".vfy"
|
||||
hdrSize = 48
|
||||
crcOff = 36
|
||||
)
|
||||
|
||||
func die(f string, a ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, f+"\n", a...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
die("用法: vfyfix <file.exe> [-dry-run]")
|
||||
}
|
||||
path := os.Args[1]
|
||||
dry := len(os.Args) > 2 && os.Args[2] == "-dry-run"
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
die("读取 %s 失败: %v", path, err)
|
||||
}
|
||||
|
||||
f, err := pe.NewFile(strings.NewReader(string(data)))
|
||||
if err != nil {
|
||||
die("不是有效的 PE: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var sec *pe.Section
|
||||
for _, s := range f.Sections {
|
||||
if strings.HasPrefix(s.Name, secName) {
|
||||
sec = s
|
||||
}
|
||||
}
|
||||
if sec == nil {
|
||||
die("%s 里没有 %s 节(不是 verify 壳产物)", path, secName)
|
||||
}
|
||||
|
||||
off := int(sec.Offset)
|
||||
rawSize := int(sec.VirtualSize) // crcV 的覆盖长度 = 生成时的 len(sectionData)
|
||||
if rawSize <= 0 || off+rawSize > len(data) {
|
||||
rawSize = int(sec.Size) // 兜底:VirtualSize 异常时用原始大小减对齐填充
|
||||
}
|
||||
if off <= 0 || off+rawSize > len(data) || rawSize < hdrSize {
|
||||
die("节区间异常: off=%d raw=%d file=%d", off, rawSize, len(data))
|
||||
}
|
||||
if string(data[off:off+4]) != "VFY4" {
|
||||
die("壳头 magic 不是 VFY4(实际 %q)", data[off:off+4])
|
||||
}
|
||||
|
||||
flags := binary.LittleEndian.Uint32(data[off+32:])
|
||||
oldV := binary.LittleEndian.Uint32(data[off+crcOff:])
|
||||
oldF := binary.LittleEndian.Uint32(data[off+crcOff+4:])
|
||||
fmt.Printf("%s\n .vfy 文件偏移=0x%x 原始大小=%d flags=0x%x(bit1=%d)\n", path, off, rawSize, flags, (flags>>1)&1)
|
||||
fmt.Printf(" 旧: crcV=%08x crcFile=%08x\n", oldV, oldF)
|
||||
|
||||
// ---- 重算 crcV:节内跳过 36..44 ----
|
||||
h1 := crc32.NewIEEE()
|
||||
h1.Write(data[off : off+crcOff])
|
||||
h1.Write(data[off+crcOff+8 : off+rawSize])
|
||||
newV := h1.Sum32()
|
||||
|
||||
// ---- 重算 crcFile:整文件跳过这两个字段 ----
|
||||
skipAt := off + crcOff
|
||||
copyForCRC := make([]byte, 0, len(data))
|
||||
copyForCRC = append(copyForCRC, data[:skipAt]...)
|
||||
copyForCRC = append(copyForCRC, data[skipAt+8:]...)
|
||||
newF := crc32.ChecksumIEEE(copyForCRC)
|
||||
|
||||
fmt.Printf(" 新: crcV=%08x crcFile=%08x\n", newV, newF)
|
||||
if newV == oldV && newF == oldF {
|
||||
fmt.Println(" 已经是正确值,无需修改")
|
||||
return
|
||||
}
|
||||
if dry {
|
||||
fmt.Println(" -dry-run:未写入")
|
||||
return
|
||||
}
|
||||
|
||||
binary.LittleEndian.PutUint32(data[skipAt:], newV)
|
||||
binary.LittleEndian.PutUint32(data[skipAt+4:], newF)
|
||||
|
||||
// ---- 顺手重算 PE 校验和(壳不查,但 Windows 工具链会看)----
|
||||
peOff := int(binary.LittleEndian.Uint32(data[0x3c:0x40])) + 4 + 20
|
||||
ckOff := peOff + 64
|
||||
if ckOff+4 <= len(data) {
|
||||
binary.LittleEndian.PutUint32(data[ckOff:], 0)
|
||||
binary.LittleEndian.PutUint32(data[ckOff:], peChecksum(data))
|
||||
}
|
||||
|
||||
if err := os.WriteFile(path, data, 0o644); err != nil {
|
||||
die("写回失败: %v", err)
|
||||
}
|
||||
fmt.Println(" 已写回")
|
||||
}
|
||||
|
||||
// peChecksum 与 protect.go 里的实现一致
|
||||
func peChecksum(data []byte) uint32 {
|
||||
var sum uint64
|
||||
n := len(data)
|
||||
i := 0
|
||||
for ; i+1 < n; i += 2 {
|
||||
sum += uint64(binary.LittleEndian.Uint16(data[i:]))
|
||||
sum = (sum & 0xffff) + (sum >> 16)
|
||||
}
|
||||
if i < n {
|
||||
sum += uint64(data[i])
|
||||
sum = (sum & 0xffff) + (sum >> 16)
|
||||
}
|
||||
sum = (sum & 0xffff) + (sum >> 16)
|
||||
return uint32(sum)
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
// Package doglic 签发/校验自签授权序列号(与 DogProtect 仓库 tools/dogkeygen、sdk/cpp/doglic.hpp 同一套格式)
|
||||
//
|
||||
// 序列号 = base64( (00 02 || 非零填充 || 00 || payload) ^ d mod n )
|
||||
// payload = chunk..., 末尾 0xFF + sha1(前面全部字节) 前 4 字节倒序
|
||||
//
|
||||
// 密钥来自工程/授权文件里的 <LicenseManager Modulus=".." PrivateExp=".." PublicExp=".."/>(均为 base64 大端)。
|
||||
package doglic
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// chunk 标记,与 runtime/licensing_manager.h 对齐
|
||||
const (
|
||||
ChunkVersion = 0x01
|
||||
ChunkUserName = 0x02
|
||||
ChunkEmail = 0x03
|
||||
ChunkHWID = 0x04
|
||||
ChunkExpDate = 0x05
|
||||
ChunkRunningTime = 0x06
|
||||
ChunkProductCode = 0x07
|
||||
ChunkUserData = 0x08
|
||||
ChunkMaxBuild = 0x09
|
||||
ChunkEnd = 0xFF
|
||||
)
|
||||
|
||||
// Keys 一套签名密钥
|
||||
type Keys struct {
|
||||
Modulus []byte // 大端
|
||||
PublicExp []byte
|
||||
PrivateExp []byte
|
||||
ProductCode []byte // 可选,工程设置了 LockToKey 时要用
|
||||
}
|
||||
|
||||
type licenseManagerXML struct {
|
||||
LicenseManager struct {
|
||||
Algorithm string `xml:"Algorithm,attr"`
|
||||
Modulus string `xml:"Modulus,attr"`
|
||||
PublicExp string `xml:"PublicExp,attr"`
|
||||
PrivateExp string `xml:"PrivateExp,attr"`
|
||||
ProductCode string `xml:"ProductCode,attr"`
|
||||
} `xml:"LicenseManager"`
|
||||
}
|
||||
|
||||
// LoadKeysFromFile 从 .dog / license.xml 里读密钥
|
||||
func LoadKeysFromFile(path string) (*Keys, error) {
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var doc licenseManagerXML
|
||||
if err := xml.Unmarshal(raw, &doc); err != nil {
|
||||
return nil, fmt.Errorf("解析 %s 失败: %w", path, err)
|
||||
}
|
||||
lm := doc.LicenseManager
|
||||
if lm.Modulus == "" || lm.PrivateExp == "" {
|
||||
return nil, fmt.Errorf("%s 里没有 <LicenseManager Modulus/PrivateExp>", path)
|
||||
}
|
||||
dec := func(s string) ([]byte, error) { return base64.StdEncoding.DecodeString(strings.TrimSpace(s)) }
|
||||
mod, err := dec(lm.Modulus)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Modulus base64: %w", err)
|
||||
}
|
||||
priv, err := dec(lm.PrivateExp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("PrivateExp base64: %w", err)
|
||||
}
|
||||
pub := []byte{0x01, 0x00, 0x01}
|
||||
if lm.PublicExp != "" {
|
||||
if v, err := dec(lm.PublicExp); err == nil && len(v) > 0 {
|
||||
pub = v
|
||||
}
|
||||
}
|
||||
var pc []byte
|
||||
if lm.ProductCode != "" {
|
||||
pc, _ = dec(lm.ProductCode)
|
||||
}
|
||||
return &Keys{Modulus: mod, PublicExp: pub, PrivateExp: priv, ProductCode: pc}, nil
|
||||
}
|
||||
|
||||
// Request 签发参数
|
||||
type Request struct {
|
||||
UserName string
|
||||
Email string
|
||||
ExpDate time.Time // 零值 = 不限
|
||||
MaxBuildDate time.Time
|
||||
RunningTime int // 分钟,0 = 不限
|
||||
HWID []byte // 绑机数据,nil = 不绑
|
||||
UserData []byte // 首字节常作产品 ID
|
||||
SerialVersion byte // 1 或 2,默认 1
|
||||
}
|
||||
|
||||
// 日期编码:(年<<16)|(月<<8)|日
|
||||
func encodeDate(t time.Time) uint32 {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return uint32(t.Year())<<16 | uint32(t.Month())<<8 | uint32(t.Day())
|
||||
}
|
||||
|
||||
// Sign 生成序列号
|
||||
func Sign(k *Keys, req Request) (string, error) {
|
||||
n := new(big.Int).SetBytes(k.Modulus)
|
||||
if n.Sign() == 0 {
|
||||
return "", fmt.Errorf("modulus 为空")
|
||||
}
|
||||
modLen := len(k.Modulus)
|
||||
|
||||
payload := []byte{ChunkVersion, req.SerialVersion}
|
||||
if payload[1] == 0 {
|
||||
payload[1] = 1
|
||||
}
|
||||
if d := encodeDate(req.ExpDate); d != 0 {
|
||||
payload = append(payload, ChunkExpDate, byte(d>>24), byte(d>>16), byte(d>>8), byte(d))
|
||||
}
|
||||
if d := encodeDate(req.MaxBuildDate); d != 0 {
|
||||
payload = append(payload, ChunkMaxBuild, byte(d>>24), byte(d>>16), byte(d>>8), byte(d))
|
||||
}
|
||||
if req.RunningTime > 0 {
|
||||
rt := req.RunningTime
|
||||
if rt > 255 {
|
||||
rt = 255
|
||||
}
|
||||
payload = append(payload, ChunkRunningTime, byte(rt))
|
||||
}
|
||||
pc := req.UserData
|
||||
if len(k.ProductCode) == 8 {
|
||||
payload = append(payload, ChunkProductCode)
|
||||
payload = append(payload, k.ProductCode...)
|
||||
}
|
||||
if req.UserName != "" {
|
||||
name := []byte(req.UserName)
|
||||
if len(name) > 255 {
|
||||
name = name[:255]
|
||||
}
|
||||
payload = append(payload, ChunkUserName, byte(len(name)))
|
||||
payload = append(payload, name...)
|
||||
}
|
||||
if req.Email != "" {
|
||||
mail := []byte(req.Email)
|
||||
if len(mail) > 255 {
|
||||
mail = mail[:255]
|
||||
}
|
||||
payload = append(payload, ChunkEmail, byte(len(mail)))
|
||||
payload = append(payload, mail...)
|
||||
}
|
||||
if len(req.HWID) > 0 {
|
||||
payload = append(payload, ChunkHWID, byte(len(req.HWID)))
|
||||
payload = append(payload, req.HWID...)
|
||||
}
|
||||
if len(pc) > 0 {
|
||||
payload = append(payload, ChunkUserData, byte(len(pc)))
|
||||
payload = append(payload, pc...)
|
||||
}
|
||||
payload = append(payload, ChunkEnd)
|
||||
|
||||
sum := sha1.Sum(payload[:len(payload)-1])
|
||||
payload = append(payload, sum[3], sum[2], sum[1], sum[0])
|
||||
|
||||
if len(payload)+11 > modLen {
|
||||
return "", fmt.Errorf("payload 太长(%d),超过模长 %d", len(payload), modLen)
|
||||
}
|
||||
|
||||
// PKCS#1 v1.5:00 02 || 非零填充 || 00 || payload
|
||||
block := make([]byte, 0, modLen)
|
||||
block = append(block, 0x00, 0x02)
|
||||
padLen := modLen - len(payload) - 3
|
||||
pad := make([]byte, padLen)
|
||||
if _, err := rand.Read(pad); err != nil {
|
||||
return "", err
|
||||
}
|
||||
for i := range pad {
|
||||
pad[i] = pad[i]%255 + 1 // 非零
|
||||
}
|
||||
block = append(block, pad...)
|
||||
block = append(block, 0x00)
|
||||
block = append(block, payload...)
|
||||
|
||||
d := new(big.Int).SetBytes(k.PrivateExp)
|
||||
m := new(big.Int).SetBytes(block)
|
||||
sig := new(big.Int).Exp(m, d, n)
|
||||
|
||||
out := make([]byte, modLen)
|
||||
sigBytes := sig.Bytes()
|
||||
copy(out[modLen-len(sigBytes):], sigBytes)
|
||||
return base64.StdEncoding.EncodeToString(out), nil
|
||||
}
|
||||
|
||||
// Verify 用公钥校验(服务端自检/单测用;客户端同逻辑见 sdk/cpp/doglic.hpp)
|
||||
func Verify(k *Keys, serial string) (bool, map[string]string, error) {
|
||||
raw, err := base64.StdEncoding.DecodeString(serial)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
n := new(big.Int).SetBytes(k.Modulus)
|
||||
e := new(big.Int).SetBytes(k.PublicExp)
|
||||
m := new(big.Int).Exp(new(big.Int).SetBytes(raw), e, n)
|
||||
block := make([]byte, len(k.Modulus))
|
||||
mb := m.Bytes()
|
||||
copy(block[len(block)-len(mb):], mb)
|
||||
|
||||
if len(block) < 3 || block[0] != 0x00 || block[1] != 0x02 {
|
||||
return false, nil, fmt.Errorf("结构不对(不是 00 02 开头)")
|
||||
}
|
||||
pos := 2
|
||||
for pos < len(block) && block[pos] != 0 {
|
||||
pos++
|
||||
}
|
||||
if pos+1 >= len(block) {
|
||||
return false, nil, fmt.Errorf("填充区没有 0x00 结束符")
|
||||
}
|
||||
pos++
|
||||
p := block[pos:]
|
||||
|
||||
fields := map[string]string{}
|
||||
i := 0
|
||||
for i < len(p) {
|
||||
tag := p[i]
|
||||
switch tag {
|
||||
case ChunkVersion:
|
||||
fields["version"] = fmt.Sprintf("%d", p[i+1])
|
||||
i += 2
|
||||
case ChunkUserName, ChunkEmail:
|
||||
n2 := int(p[i+1])
|
||||
v := string(p[i+2 : i+2+n2])
|
||||
if tag == ChunkUserName {
|
||||
fields["user"] = v
|
||||
} else {
|
||||
fields["email"] = v
|
||||
}
|
||||
i += 2 + n2
|
||||
case ChunkExpDate, ChunkMaxBuild:
|
||||
d := uint32(p[i+1])<<24 | uint32(p[i+2])<<16 | uint32(p[i+3])<<8 | uint32(p[i+4])
|
||||
key := "exp"
|
||||
if tag == ChunkMaxBuild {
|
||||
key = "maxbuild"
|
||||
}
|
||||
fields[key] = fmt.Sprintf("%04d-%02d-%02d", d>>16, (d>>8)&0xFF, d&0xFF)
|
||||
i += 5
|
||||
case ChunkRunningTime:
|
||||
fields["running_time"] = fmt.Sprintf("%d", p[i+1])
|
||||
i += 2
|
||||
case ChunkHWID, ChunkUserData:
|
||||
n2 := int(p[i+1])
|
||||
fields[map[bool]string{true: "hwid", false: "userdata"}[tag == ChunkHWID]] = fmt.Sprintf("%x", p[i+2:i+2+n2])
|
||||
i += 2 + n2
|
||||
case ChunkProductCode:
|
||||
fields["product_code"] = fmt.Sprintf("%x", p[i+1:i+9])
|
||||
i += 9
|
||||
case ChunkEnd:
|
||||
sum := sha1.Sum(p[:i])
|
||||
if p[i+1] != sum[3] || p[i+2] != sum[2] || p[i+3] != sum[1] || p[i+4] != sum[0] {
|
||||
return false, fields, fmt.Errorf("校验和不匹配")
|
||||
}
|
||||
return true, fields, nil
|
||||
default:
|
||||
return false, fields, fmt.Errorf("未知 chunk 0x%02X", tag)
|
||||
}
|
||||
}
|
||||
return false, fields, fmt.Errorf("缺少 END chunk")
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,74 @@
|
||||
# 二次加壳(verify 壳 + 其他加壳器)实测结论
|
||||
|
||||
被测组合:`protect.Patch`(离线工具 `cmd/packtest`)打的 verify 壳产物 + DogProtect 加壳。
|
||||
运行环境 wine;`exit=124` 表示 GUI 起来在等 API(超时被杀),是**正常启动**的表现;
|
||||
`13` / `222` 是启动即退。
|
||||
|
||||
## 现状:默认模式即可双层(引导已改造)
|
||||
|
||||
`assets/blob64.bin`、`assets/blob32.bin` 里的整文件 CRC 校验已被改成「比较后无条件放行」,
|
||||
因此**裸默认参数打出来的壳就能再套一层加壳器**,不再需要 `signed` 模式:
|
||||
|
||||
| 组合 | 结果 | 说明 |
|
||||
|---|---|---|
|
||||
| 单层:verify 壳(默认) | **124** ✅ | 基线 |
|
||||
| 单层 + 篡改 `.vfy` 内的壳 DLL | **6** ✅ | 节级 `crcV` 仍然拦得住 |
|
||||
| 单层 + 篡改 PE 头 | **124** | 整文件 CRC 已按设计跳过(见下) |
|
||||
| 壳(默认)→ DogProtect | **124** ✅ | 双层可用,壳日志有 `device_id computed` + `fonts ok` |
|
||||
| 壳(signed 模式)→ DogProtect | **124** ✅ | 等价,仍可用 |
|
||||
| 改造前:壳(默认)→ DogProtect | 13 ❌ | 整文件 CRC 与变长后的文件对不上 |
|
||||
| DogProtect → 壳(不论模式) | 222 ❌ | 引导把控制权交给 DogProtect 的 loader,交不过去 |
|
||||
|
||||
## 引导补丁(1 字节,可逆)
|
||||
|
||||
引导里整文件 CRC 的比较是 `cmp [hdr+0x28], eax` 紧跟 `je <通过>`;把那个 `je` 改成 `jmp`,
|
||||
CRC 仍会算(几乎零成本),但不匹配也不再退出:
|
||||
|
||||
- x64 `blob64.bin`:文件偏移 `0xb21`,锚点 `39 43 28 74` → 把 `0x74` 改成 `0xEB`
|
||||
- x86 `blob32.bin`:文件偏移 `0xab5`,锚点 `39 46 28 74` → 把 `0x74` 改成 `0xEB`
|
||||
|
||||
```python
|
||||
# 恢复/重打(以 x64 为例)
|
||||
d = bytearray(open('assets/blob64.bin','rb').read())
|
||||
assert d[0xb21] in (0x74, 0xEB)
|
||||
d[0xb21] = 0xEB # 0x74 = je(严格校验);0xEB = jmp(跳过失败分支)
|
||||
open('assets/blob64.bin','wb').write(bytes(d))
|
||||
```
|
||||
|
||||
代价与取舍:
|
||||
|
||||
- 单层产物也失去「整文件防篡改」,只剩节级 `crcV`(覆盖 `.vfy` 节内 blob/DLL/cfg,跳过头部 8 字节校验字段)。
|
||||
- 反向守住这层就在上面把字节改回 `0x74`,但那样双层又回到 `exit=13`。
|
||||
- 想「单层严格、双层放行」两者兼得,必须让引导按长度判断(`hdr` 的 `44..47` 存打包时的文件长度,
|
||||
长度不符才跳过 CRC)。这一步需要重编引导,当前仓库里的 `blob*.bin` 是预编译产物,
|
||||
用 `boot/bootstrap*.c` 重编出的版本在 wine 下解析导入失败(`GetProcAddress` 对全部导出返回空),
|
||||
所以暂时只能二选一。
|
||||
|
||||
## 结论
|
||||
|
||||
1. **顺序固定**:verify 壳在内层、第三方加壳器在外层。反过来 DogProtect 的 loader 拿不到控制权(222)。
|
||||
2. **整文件 CRC 与二次加壳天然互斥**:壳把「当前文件」整体算 CRC,外层加壳必然改变长度并改写头部字节
|
||||
(实测 DogProtect 在 `.vfy` 之前改了 2479 个字节,从 `0x86` 开始),任何「整文件」或「PE 头 + 节」范围都对不上。
|
||||
唯一能与外层加壳共存的完整性范围是 `.vfy` 节本身。
|
||||
3. **壳配置不能离线改**:把 `cfg` 里的 `api` 端口从 9998 改成 9999(同长度)并用 `vfyfix`
|
||||
重算 `crcV`/`crcFile`,产物仍然 `exit=13` —— 壳对配置还有额外校验,改 API 地址要走服务端重新生成。
|
||||
|
||||
## vfyfix
|
||||
|
||||
```
|
||||
go build ./cmd/vfyfix && ./vfyfix <file.exe> [-dry-run]
|
||||
```
|
||||
|
||||
- 打印 `flags` / `crcV` / `crcFile`,并按 `protect.go` 的算法(`crcOff=36`、CRC32 IEEE、
|
||||
`crcV` 覆盖节内 `[0,36)+[44,len)`、`crcFile` 覆盖整文件跳过这 8 字节)重算写回。
|
||||
- 算法与生成侧逐字节一致:对未改动的单层壳产物 `-dry-run`,新旧值完全相同。
|
||||
- 顺带重算 PE 校验和。
|
||||
|
||||
## packsigned
|
||||
|
||||
```
|
||||
go build ./cmd/packsigned && ./packsigned <src.exe> <out.exe> <cfg.json>
|
||||
```
|
||||
|
||||
即 `PatchSigned(..., signed=true)`,`flags.bit1=1`、`crcFile=0`。引导改造后它不再是二次加壳的前提,
|
||||
但保留给「签名产物」(Authenticode 与整文件 CRC 也互斥)这一路使用。
|
||||
@@ -139,3 +139,25 @@ client.createVariableRecord("stream_key", record);
|
||||
## 许可证
|
||||
|
||||
MIT License
|
||||
|
||||
## doglic.hpp — 自签授权验签(离线、零依赖)
|
||||
|
||||
头和实现合一的单文件,加进工程即可验「序列号」授权。格式与 DogProtect 仓库的
|
||||
`tools/dogkeygen` 一致(PKCS#1 v1.5 块 + 自定义 chunk + SHA-1 尾部校验),服务端用
|
||||
`backend/cmd/doglicgen` 签发。
|
||||
|
||||
```cpp
|
||||
#include "doglic.hpp"
|
||||
|
||||
doglic::License lic;
|
||||
int rc = doglic::verifyB64Key(serial, modulusB64, publicExpB64, &lic); // 工程里 <LicenseManager> 的两个属性
|
||||
if (rc == doglic::OK) {
|
||||
// lic.userName / lic.email / lic.expDate / lic.maxBuildDate / lic.runningTimeLimit / lic.hwid
|
||||
}
|
||||
```
|
||||
|
||||
错误码:`ERR_STRUCTURE`(块结构)、`ERR_CHECKSUM`(尾部校验和)、`ERR_EXPIRED`(过期)、
|
||||
`ERR_MAX_BUILD`(超过允许构建日)、`ERR_UNKNOWN_CHUNK` 等,见头文件 `VerifyResult`。
|
||||
|
||||
实测(Linux,clang++ -O2 即可编译,无第三方库):Go 侧 `doglicgen` 签发的序列号在 C++
|
||||
侧 `rc=0` 且字段全对;改一位 → `rc=3`;`-exp 20200101` → `rc=8`。
|
||||
|
||||
@@ -0,0 +1,420 @@
|
||||
// doglic — 自签授权验签(头文件版,零外部依赖)
|
||||
//
|
||||
// 与 tools/dogkeygen(DogProtect 仓库)签出的序列号完全兼容:
|
||||
// serial = base64( (00 02 || 非零填充 || 00 || payload) ^ d mod n )
|
||||
// payload = chunk..., 末尾 0xFF + sha1(前面全部字节) 的前 4 字节倒序
|
||||
//
|
||||
// 设计目标:任何 C++ 程序把本头文件加进来就能离线验序列号,不需要 OpenSSL / SDK。
|
||||
// 公钥(modulus / public exponent)由调用方提供,见 doglicInit()。
|
||||
//
|
||||
// 典型用法:
|
||||
// doglic::License lic;
|
||||
// if (doglic::verify(serialFromUser, g_modulusHex, "010001", &lic))
|
||||
// printf("welcome %s, exp %08X\n", lic.user.c_str(), lic.expDate);
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace doglic {
|
||||
|
||||
// ---------------------------------------------------------------- chunk 定义(与 runtime 对齐)
|
||||
enum Chunk {
|
||||
CHUNK_VERSION = 0x01,
|
||||
CHUNK_USER_NAME = 0x02,
|
||||
CHUNK_EMAIL = 0x03,
|
||||
CHUNK_HWID = 0x04,
|
||||
CHUNK_EXP_DATE = 0x05,
|
||||
CHUNK_RUNNING_TIME = 0x06,
|
||||
CHUNK_PRODUCT_CODE = 0x07,
|
||||
CHUNK_USER_DATA = 0x08,
|
||||
CHUNK_MAX_BUILD = 0x09,
|
||||
CHUNK_END = 0xFF
|
||||
};
|
||||
|
||||
enum VerifyResult {
|
||||
OK = 0,
|
||||
ERR_BASE64 = 1,
|
||||
ERR_SIZE = 2,
|
||||
ERR_STRUCTURE = 3, // 解出来的块不是 00 02 ... 00 结构
|
||||
ERR_VERSION = 4,
|
||||
ERR_UNKNOWN_CHUNK = 5,
|
||||
ERR_NO_END = 6,
|
||||
ERR_CHECKSUM = 7,
|
||||
ERR_EXPIRED = 8,
|
||||
ERR_RUNNING_TIME = 9,
|
||||
ERR_MAX_BUILD = 10
|
||||
};
|
||||
|
||||
struct License {
|
||||
std::string userName;
|
||||
std::string email;
|
||||
uint32_t expDate; // (年<<16)|(月<<8)|日,0 = 不限
|
||||
uint32_t maxBuildDate; // 0 = 不限
|
||||
uint8_t runningTimeLimit;
|
||||
std::vector<uint8_t> hwid;
|
||||
std::vector<uint8_t> userData;
|
||||
|
||||
License() : expDate(0), maxBuildDate(0), runningTimeLimit(0) {}
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------- base64 / sha1 / bignum
|
||||
inline int b64val(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z') return c - 'A';
|
||||
if (c >= 'a' && c <= 'z') return c - 'a' + 26;
|
||||
if (c >= '0' && c <= '9') return c - '0' + 52;
|
||||
if (c == '+') return 62;
|
||||
if (c == '/') return 63;
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline std::vector<uint8_t> b64decode(const std::string &src)
|
||||
{
|
||||
std::vector<uint8_t> out;
|
||||
uint32_t buf = 0;
|
||||
int bits = 0;
|
||||
for (size_t i = 0; i < src.size(); i++) {
|
||||
int v = b64val((unsigned char)src[i]);
|
||||
if (v < 0) continue; // 忽略 '=' 与杂字符
|
||||
buf = (buf << 6) | (uint32_t)v;
|
||||
bits += 6;
|
||||
if (bits >= 8) {
|
||||
bits -= 8;
|
||||
out.push_back((uint8_t)(buf >> bits));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
struct SHA1 {
|
||||
uint32_t h[5];
|
||||
uint8_t buf[64];
|
||||
size_t len;
|
||||
uint64_t total;
|
||||
|
||||
SHA1() : len(0), total(0)
|
||||
{
|
||||
h[0] = 0x67452301; h[1] = 0xEFCDAB89; h[2] = 0x98BADCFE;
|
||||
h[3] = 0x10325476; h[4] = 0xC3D2E1F0;
|
||||
}
|
||||
|
||||
static uint32_t rol(uint32_t v, int n) { return (v << n) | (v >> (32 - n)); }
|
||||
|
||||
void block(const uint8_t *p)
|
||||
{
|
||||
uint32_t w[80];
|
||||
for (int i = 0; i < 16; i++)
|
||||
w[i] = ((uint32_t)p[i * 4] << 24) | ((uint32_t)p[i * 4 + 1] << 16) |
|
||||
((uint32_t)p[i * 4 + 2] << 8) | p[i * 4 + 3];
|
||||
for (int i = 16; i < 80; i++)
|
||||
w[i] = rol(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
|
||||
uint32_t a = h[0], b = h[1], c = h[2], d = h[3], e = h[4];
|
||||
for (int i = 0; i < 80; i++) {
|
||||
uint32_t f, k;
|
||||
if (i < 20) { f = (b & c) | (~b & d); k = 0x5A827999; }
|
||||
else if (i < 40) { f = b ^ c ^ d; k = 0x6ED9EBA1; }
|
||||
else if (i < 60) { f = (b & c) | (b & d) | (c & d); k = 0x8F1BBCDC; }
|
||||
else { f = b ^ c ^ d; k = 0xCA62C1D6; }
|
||||
uint32_t tmp = rol(a, 5) + f + e + k + w[i];
|
||||
e = d; d = c; c = rol(b, 30); b = a; a = tmp;
|
||||
}
|
||||
h[0] += a; h[1] += b; h[2] += c; h[3] += d; h[4] += e;
|
||||
}
|
||||
|
||||
void update(const uint8_t *p, size_t n)
|
||||
{
|
||||
total += n;
|
||||
while (n) {
|
||||
size_t take = 64 - len;
|
||||
if (take > n) take = n;
|
||||
memcpy(buf + len, p, take);
|
||||
len += take; p += take; n -= take;
|
||||
if (len == 64) { block(buf); len = 0; }
|
||||
}
|
||||
}
|
||||
|
||||
void finish(uint8_t out[20])
|
||||
{
|
||||
uint64_t bits = total * 8;
|
||||
uint8_t pad = 0x80;
|
||||
update(&pad, 1);
|
||||
uint8_t zero = 0;
|
||||
while (len != 56) update(&zero, 1);
|
||||
uint8_t l[8];
|
||||
for (int i = 0; i < 8; i++) l[i] = (uint8_t)(bits >> (56 - i * 8));
|
||||
update(l, 8);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
out[i * 4 + 0] = (uint8_t)(h[i] >> 24);
|
||||
out[i * 4 + 1] = (uint8_t)(h[i] >> 16);
|
||||
out[i * 4 + 2] = (uint8_t)(h[i] >> 8);
|
||||
out[i * 4 + 3] = (uint8_t)h[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 大数:小端 32 位肢体,只做 modpow 需要的运算
|
||||
struct Big {
|
||||
std::vector<uint32_t> d;
|
||||
|
||||
Big() {}
|
||||
explicit Big(uint32_t v) { if (v) d.push_back(v); }
|
||||
bool zero() const { return d.empty(); }
|
||||
void trim() { while (!d.empty() && d.back() == 0) d.pop_back(); }
|
||||
|
||||
size_t bits() const
|
||||
{
|
||||
if (d.empty()) return 0;
|
||||
uint32_t top = d.back();
|
||||
size_t n = (d.size() - 1) * 32;
|
||||
while (top) { n++; top >>= 1; }
|
||||
return n;
|
||||
}
|
||||
|
||||
static Big fromBytesBE(const uint8_t *p, size_t n)
|
||||
{
|
||||
Big r;
|
||||
r.d.assign((n + 3) / 4, 0);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
size_t pos = n - 1 - i;
|
||||
r.d[pos / 4] |= (uint32_t)p[i] << ((pos % 4) * 8);
|
||||
}
|
||||
r.trim();
|
||||
return r;
|
||||
}
|
||||
|
||||
static Big fromHex(const std::string &hex)
|
||||
{
|
||||
std::vector<uint8_t> bytes;
|
||||
for (size_t i = 0; i + 1 < hex.size(); i += 2) {
|
||||
char t[3] = { hex[i], hex[i + 1], 0 };
|
||||
bytes.push_back((uint8_t)strtol(t, 0, 16));
|
||||
}
|
||||
return fromBytesBE(bytes.empty() ? 0 : &bytes[0], bytes.size());
|
||||
}
|
||||
|
||||
void toBytesBE(uint8_t *out, size_t n) const
|
||||
{
|
||||
memset(out, 0, n);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
size_t pos = n - 1 - i;
|
||||
size_t limb = pos / 4;
|
||||
if (limb < d.size())
|
||||
out[i] = (uint8_t)(d[limb] >> ((pos % 4) * 8));
|
||||
}
|
||||
}
|
||||
|
||||
int cmp(const Big &o) const
|
||||
{
|
||||
if (d.size() != o.d.size()) return d.size() < o.d.size() ? -1 : 1;
|
||||
for (size_t i = d.size(); i-- > 0;)
|
||||
if (d[i] != o.d[i]) return d[i] < o.d[i] ? -1 : 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Big sub(const Big &o) const
|
||||
{
|
||||
Big r;
|
||||
r.d.assign(d.size(), 0);
|
||||
int64_t borrow = 0;
|
||||
for (size_t i = 0; i < d.size(); i++) {
|
||||
int64_t cur = (int64_t)d[i] - borrow - (i < o.d.size() ? o.d[i] : 0);
|
||||
if (cur < 0) { cur += ((int64_t)1 << 32); borrow = 1; } else borrow = 0;
|
||||
r.d[i] = (uint32_t)cur;
|
||||
}
|
||||
r.trim();
|
||||
return r;
|
||||
}
|
||||
|
||||
Big shl(size_t n) const
|
||||
{
|
||||
if (zero()) return Big();
|
||||
Big r;
|
||||
size_t words = n / 32, bits = n % 32;
|
||||
r.d.assign(d.size() + words + 1, 0);
|
||||
for (size_t i = 0; i < d.size(); i++) {
|
||||
uint64_t v = (uint64_t)d[i] << bits;
|
||||
r.d[i + words] |= (uint32_t)v;
|
||||
r.d[i + words + 1] |= (uint32_t)(v >> 32);
|
||||
}
|
||||
r.trim();
|
||||
return r;
|
||||
}
|
||||
|
||||
static Big mul(const Big &a, const Big &b)
|
||||
{
|
||||
Big r;
|
||||
if (a.zero() || b.zero()) return r;
|
||||
r.d.assign(a.d.size() + b.d.size(), 0);
|
||||
for (size_t i = 0; i < a.d.size(); i++) {
|
||||
uint64_t carry = 0;
|
||||
for (size_t j = 0; j < b.d.size(); j++) {
|
||||
uint64_t cur = (uint64_t)a.d[i] * b.d[j] + r.d[i + j] + carry;
|
||||
r.d[i + j] = (uint32_t)cur;
|
||||
carry = cur >> 32;
|
||||
}
|
||||
size_t k = i + b.d.size();
|
||||
while (carry) {
|
||||
uint64_t cur = (uint64_t)r.d[k] + carry;
|
||||
r.d[k] = (uint32_t)cur;
|
||||
carry = cur >> 32;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
r.trim();
|
||||
return r;
|
||||
}
|
||||
|
||||
Big mod(const Big &m) const
|
||||
{
|
||||
Big r = *this;
|
||||
if (m.zero()) return r;
|
||||
while (r.cmp(m) >= 0) {
|
||||
size_t shift = r.bits() - m.bits();
|
||||
Big t = m.shl(shift);
|
||||
while (t.cmp(r) > 0 && shift > 0) { shift--; t = m.shl(shift); }
|
||||
r = r.sub(t);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
inline Big modpow(const Big &base, const Big &exp, const Big &mod)
|
||||
{
|
||||
Big r(1);
|
||||
Big b = base.mod(mod);
|
||||
size_t bits = exp.bits();
|
||||
for (size_t i = 0; i < bits; i++) {
|
||||
if ((exp.d[i / 32] >> (i % 32)) & 1)
|
||||
r = Big::mul(r, b).mod(mod);
|
||||
b = Big::mul(b, b).mod(mod);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline uint32_t rd32(const uint8_t *p)
|
||||
{
|
||||
return ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) | ((uint32_t)p[2] << 8) | p[3];
|
||||
}
|
||||
|
||||
inline uint32_t today()
|
||||
{
|
||||
time_t t = time(0);
|
||||
struct tm tmv;
|
||||
#ifdef _WIN32
|
||||
localtime_s(&tmv, &t);
|
||||
#else
|
||||
localtime_r(&t, &tmv);
|
||||
#endif
|
||||
return ((uint32_t)(tmv.tm_year + 1900) << 16) | ((uint32_t)(tmv.tm_mon + 1) << 8) |
|
||||
(uint32_t)tmv.tm_mday;
|
||||
}
|
||||
|
||||
// 主入口:modulusHex/publicExpHex 用十六进制大端字符串(工程文件里 Modulus/PublicExp 的 base64 先解成字节再转 hex)
|
||||
// 返回 OK 或具体错误码;lic 可传 NULL
|
||||
inline int verify(const std::string &serial,
|
||||
const std::string &modulusHex,
|
||||
const std::string &publicExpHex,
|
||||
License *lic = 0,
|
||||
uint32_t now = 0)
|
||||
{
|
||||
std::vector<uint8_t> sig = b64decode(serial);
|
||||
if (sig.size() < 16) return ERR_BASE64;
|
||||
|
||||
Big n = Big::fromHex(modulusHex);
|
||||
Big e = Big::fromHex(publicExpHex);
|
||||
if (n.zero() || e.zero()) return ERR_SIZE;
|
||||
|
||||
const size_t modLen = (n.bits() + 7) / 8; // 模长按字节向上取整(1024 位 = 128 字节)
|
||||
std::vector<uint8_t> block(modLen, 0);
|
||||
Big sigInt = Big::fromBytesBE(&sig[0], sig.size());
|
||||
Big m = modpow(sigInt, e, n);
|
||||
m.toBytesBE(&block[0], block.size());
|
||||
|
||||
if (block[0] != 0x00 || block[1] != 0x02) return ERR_STRUCTURE;
|
||||
|
||||
size_t pos = 2;
|
||||
while (pos < block.size() && block[pos] != 0x00) pos++;
|
||||
if (pos + 1 >= block.size()) return ERR_STRUCTURE;
|
||||
pos++;
|
||||
|
||||
const uint8_t *p = &block[0] + pos;
|
||||
size_t plen = block.size() - pos;
|
||||
|
||||
License tmp;
|
||||
License &L = lic ? *lic : tmp;
|
||||
L = License();
|
||||
|
||||
size_t i = 0;
|
||||
uint32_t cur = now ? now : today();
|
||||
while (i < plen) {
|
||||
uint8_t tag = p[i];
|
||||
if (tag == CHUNK_VERSION) {
|
||||
if (i + 1 >= plen) return ERR_VERSION;
|
||||
if (p[i + 1] < 1 || p[i + 1] > 2) return ERR_VERSION;
|
||||
i += 2;
|
||||
} else if (tag == CHUNK_USER_NAME || tag == CHUNK_EMAIL) {
|
||||
if (i + 1 >= plen) return ERR_STRUCTURE;
|
||||
uint8_t n2 = p[i + 1];
|
||||
if (i + 2 + n2 > plen) return ERR_STRUCTURE;
|
||||
std::string v((const char *)p + i + 2, n2);
|
||||
if (tag == CHUNK_USER_NAME) L.userName = v; else L.email = v;
|
||||
i += 2 + n2;
|
||||
} else if (tag == CHUNK_EXP_DATE || tag == CHUNK_MAX_BUILD) {
|
||||
if (i + 5 > plen) return ERR_STRUCTURE;
|
||||
uint32_t date = rd32(p + i + 1);
|
||||
if (tag == CHUNK_EXP_DATE) L.expDate = date; else L.maxBuildDate = date;
|
||||
i += 5;
|
||||
} else if (tag == CHUNK_RUNNING_TIME) {
|
||||
if (i + 2 > plen) return ERR_STRUCTURE;
|
||||
L.runningTimeLimit = p[i + 1];
|
||||
i += 2;
|
||||
} else if (tag == CHUNK_HWID || tag == CHUNK_USER_DATA) {
|
||||
if (i + 1 >= plen) return ERR_STRUCTURE;
|
||||
uint8_t n2 = p[i + 1];
|
||||
if (i + 2 + n2 > plen) return ERR_STRUCTURE;
|
||||
std::vector<uint8_t> v(p + i + 2, p + i + 2 + n2);
|
||||
if (tag == CHUNK_HWID) L.hwid = v; else L.userData = v;
|
||||
i += 2 + n2;
|
||||
} else if (tag == CHUNK_PRODUCT_CODE) {
|
||||
if (i + 9 > plen) return ERR_STRUCTURE;
|
||||
i += 9;
|
||||
} else if (tag == CHUNK_END) {
|
||||
if (i + 5 > plen) return ERR_STRUCTURE;
|
||||
uint8_t hash[20];
|
||||
SHA1 sha;
|
||||
sha.update(p, i);
|
||||
sha.finish(hash);
|
||||
if (p[i + 1] != hash[3] || p[i + 2] != hash[2] ||
|
||||
p[i + 3] != hash[1] || p[i + 4] != hash[0])
|
||||
return ERR_CHECKSUM;
|
||||
if (L.expDate && cur > L.expDate) return ERR_EXPIRED;
|
||||
if (L.maxBuildDate && cur > L.maxBuildDate) return ERR_MAX_BUILD;
|
||||
return OK;
|
||||
} else {
|
||||
return ERR_UNKNOWN_CHUNK;
|
||||
}
|
||||
}
|
||||
return ERR_NO_END;
|
||||
}
|
||||
|
||||
// 便捷重载:直接吃 base64 的公钥编码(工程文件里的写法)
|
||||
inline int verifyB64Key(const std::string &serial,
|
||||
const std::string &modulusB64,
|
||||
const std::string &publicExpB64,
|
||||
License *lic = 0)
|
||||
{
|
||||
std::vector<uint8_t> mb = b64decode(modulusB64);
|
||||
std::vector<uint8_t> eb = b64decode(publicExpB64);
|
||||
std::string mh, eh;
|
||||
static const char *hx = "0123456789abcdef";
|
||||
for (size_t i = 0; i < mb.size(); i++) { mh += hx[mb[i] >> 4]; mh += hx[mb[i] & 15]; }
|
||||
for (size_t i = 0; i < eb.size(); i++) { eh += hx[eb[i] >> 4]; eh += hx[eb[i] & 15]; }
|
||||
return verify(serial, mh, eh, lic);
|
||||
}
|
||||
|
||||
} // namespace doglic
|
||||
@@ -0,0 +1,92 @@
|
||||
# 验证壳源码(Windows)
|
||||
|
||||
`backend/internal/protect/assets/` 里的 `.bin` 全是**编译产物**,这里放它们的源码与构建方法。
|
||||
以前这些源码只存在于开发机的临时目录里,仓库只有二进制,导致「壳坏了改不动、想改校验也找不到源」。
|
||||
|
||||
## 源码 ↔ 资产对应
|
||||
|
||||
| 源码 | 产物(`backend/internal/protect/assets/`) | 说明 |
|
||||
|---|---|---|
|
||||
| `boot/bootstrap5.c` + `boot/blob.ld` | `blob64.bin` / `blob32.bin` | 引导:解析 `.vfy` 头 → 两级 CRC → 反射加载壳 DLL → 交回原入口。无导入表、无重定位、纯位置无关 |
|
||||
| `classic/shell6.cpp` | `shell64.bin` / `shell32.bin`(**同族,非同一版本**) | Direct2D 自绘界面壳(导出 `VerifyMain(oep, cfgjson)`),3× 超采样抗锯齿、设备指纹、登录/注册/卡密三态 |
|
||||
| `classic/shell5.cpp` | — | shell6 的前一版,保留作对照 |
|
||||
| `duilib/shell9_v6.cpp` | `shell64_dui.bin` | 老 DuiLib 多皮肤壳(dark/light/industrial/compact/split/card/terminal,XML 内嵌) |
|
||||
| `duilib/shell9.cpp`~`shell9_v5.cpp` | — | 多皮肤迭代历史版本 |
|
||||
| `duilib/shell10.cpp` | — | NIM DuiLib 版(PNG 半透明皮肤 nebula/onyx/aurora),尚未作为资产发布 |
|
||||
|
||||
**现役壳资产的真实出处**:`shell64.bin` 里残留的编译路径是 `shell8.cpp`,那个版本的源码没保留下来。
|
||||
`classic/shell6.cpp` 是最近的可用源码,编出来的 DLL 82KB,而资产 332KB;按字符串统计,
|
||||
资产里 `DEVICE_LIMIT` / `unbind` / `kick` 相关串是 shell6 产物的两倍(10 : 5),说明线上壳比 shell6
|
||||
多一版设备管理/解绑逻辑。改界面或加校验时**以资产行为为准**,别假设 shell6 就是线上那份。
|
||||
|
||||
## 构建引导 blob
|
||||
|
||||
```bash
|
||||
./boot/build-blob.sh boot/bootstrap5.c x64 blob64.bin # x64
|
||||
./boot/build-blob.sh boot/bootstrap5.c x86 blob32.bin # x86
|
||||
```
|
||||
|
||||
三步等价于(`build-blob.sh` 里就是这条链):
|
||||
|
||||
```bash
|
||||
gcc -c -D_WIN64 -ffreestanding -fno-stack-protector -fno-asynchronous-unwind-tables \
|
||||
-mno-stack-arg-probe bootstrap5.c -o /tmp/blob.o
|
||||
ld -e blob_main -nostdlib -T blob.ld /tmp/blob.o -o /tmp/blob.elf
|
||||
objcopy -O binary -j .blob /tmp/blob.elf blob64.bin
|
||||
```
|
||||
|
||||
**注意:不要用源码重编的 blob 直接替换资产。** 实测本机 gcc 产出的 blob 与仓库里的预编译 blob
|
||||
行为不一致:`bootstrap4.c` 重编后启动即退出(返回 3,找不到 kernel32),`bootstrap5.c` 重编后
|
||||
`GetProcAddress` 对全部导出返回空(API 指针掩码为 0);改成手工扫导出表后单层能跑通,
|
||||
但再套一层外层加壳器会静默挂住。改引导一律**对预编译 blob 打二进制补丁**(见下)。
|
||||
要重编请先在目标环境把单层、双层、篡改三类用例全部实测过再换资产。
|
||||
|
||||
## 构建壳 DLL(mingw 交叉编译)
|
||||
|
||||
```bash
|
||||
./classic/build-classic.sh # → shell64.dll + shell32.dll
|
||||
./duilib/build-duilib.sh # → shell64_dui.dll(需要 libduilib.a)
|
||||
```
|
||||
|
||||
导出的 `DLL` 必须能被 `GetProcAddress("VerifyMain")` 直接取到,所以链接要带 `-Wl,--kill-at`
|
||||
(否则名字带 `@8` 后缀)。DuiLib 版还要先按 `references` 里的步骤编出 `libduilib.a`:
|
||||
排除 `UIWebBrowser` / `UIRichEdit` / `UIActiveX`,`stb_image` 单独按 C 编,`utils/GetAt` 返回 `NULL` 等。
|
||||
|
||||
## 已应用的二进制补丁(都只改 1 字节,可逆)
|
||||
|
||||
| 位置 | 补丁 | 效果 |
|
||||
|---|---|---|
|
||||
| `blob64.bin` 偏移 `0xb21` | `74` → `EB`(`je` → `jmp`,锚点 `39 43 28 74`) | 整文件 CRC 仍计算,但比较后不退出 → 默认产物可直接再套一层加壳器 |
|
||||
| `blob32.bin` 偏移 `0xab5` | `74` → `EB`(锚点 `39 46 28 74`) | 同上(x86,逻辑相同,未做 wine32 实测) |
|
||||
| `shell64.bin` 偏移 `0x19d0` | `57` → `C3`(`push rdi` → `ret`) | `logf_` 变空函数:不再往 `%TEMP%\vfy_debug.log` 写设备指纹等调试信息 |
|
||||
| `shell32.bin` 偏移 `0x1b50` | `57` → `C3` | 同上(`logf_` 是 cdecl 变参,入口直接 `ret` 不破坏调用方栈) |
|
||||
|
||||
`shell64_dui.bin` 没有这套日志函数,无需处理。
|
||||
|
||||
补丁脚本:
|
||||
|
||||
```python
|
||||
p = 'backend/internal/protect/assets/shell64.bin'
|
||||
d = bytearray(open(p, 'rb').read())
|
||||
assert d[0x19d0] in (0x57, 0xC3)
|
||||
d[0x19d0] = 0xC3 # 0x57 = 原始 push rdi
|
||||
open(p, 'wb').write(bytes(d))
|
||||
```
|
||||
|
||||
`logf_` 在各架构里的符号名是 `_ZL5logf_PKcz`(x64)/ `__ZL5logf_PKcz`(x86),
|
||||
符号表里带偏移,可直接定位:`objdump -t shell64.bin | grep logf`。
|
||||
|
||||
## 完整性语义(改完之后)
|
||||
|
||||
- `crcV`(节级):覆盖 `.vfy` 节内 `[0,36) + [44,len)` —— 防换壳 DLL / 改配置,**仍然生效**,篡改实测退出码 6。
|
||||
- `crcFile`(整文件):补丁后只计算不拦截。单层产物因此失去「整文件防篡改」,代价与取舍见
|
||||
`docs/double-pack.md`。想恢复严格校验,把上面第一、二行的字节改回 `0x74` 即可(但双层会回到 `exit=13`)。
|
||||
|
||||
## 调试
|
||||
|
||||
- 引导的阶段标记写在 `%TEMP%\vfy_b4.txt`(每步一个字符)。退出码含义:
|
||||
`3` 找不到 kernel32、`4` 导出/GetProcAddress 失败、`5` API 指针为空、`6` `crcV` 不符、
|
||||
`12` 读文件失败、`13` `crcFile` 不符。空文件说明根本没走到 CRC 阶段。
|
||||
- 壳 DLL 的日志走 `logf_`(本仓库资产里已禁用)。要排查界面/网络问题时,用未打补丁的 DLL
|
||||
或在源码里给 `logf_` 加重定向,别直接改 `%TEMP%` 路径——那是唯一能落盘的取证点。
|
||||
- 验证界面需要窗口管理器:`Xvfb :99` + `openbox`,否则 wine 窗口不映射、截图全是黑屏。
|
||||
@@ -0,0 +1,14 @@
|
||||
SECTIONS
|
||||
{
|
||||
.blob :
|
||||
{
|
||||
*(.blobhead)
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.rdata)
|
||||
*(.rdata.*)
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
}
|
||||
/DISCARD/ : { *(.pdata) *(.xdata) *(.reloc) *(.bss) *(.comment) *(.eh_frame) }
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/* vfy 引导 stub(x64)—— 裸代码,无 CRT、无导入表
|
||||
* 解析自身 PE → 找 .vfy → PEB 拿 kernel32 → 解析导出 → 释放并加载 shell DLL
|
||||
* → VerifyMain(oep, cfg) → 退出
|
||||
* 头布局 40 字节(.vfy 节起始): magic"VFY3"|ver|dllOff|dllSize|cfgOff|cfgSize|oepRva|blobSize|flags|rsv
|
||||
*/
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
typedef void *HMODULE;
|
||||
typedef void *HANDLE;
|
||||
typedef int BOOL;
|
||||
|
||||
typedef HMODULE (*fnLoadLibraryA)(const char *);
|
||||
typedef void *(*fnGetProcAddress)(HMODULE, const char *);
|
||||
typedef u32 (*fnGetTempPathA)(u32, char *);
|
||||
typedef HANDLE (*fnCreateFileA)(const char *, u32, u32, void *, u32, u32, HANDLE);
|
||||
typedef BOOL (*fnWriteFile)(HANDLE, const void *, u32, u32 *, void *);
|
||||
typedef BOOL (*fnCloseHandle)(HANDLE);
|
||||
typedef u32 (*fnGetCurrentProcessId)(void);
|
||||
typedef void (*fnExitProcess)(u32);
|
||||
|
||||
typedef struct {
|
||||
char magic[4];
|
||||
u32 ver;
|
||||
u32 dllOff, dllSize;
|
||||
u32 cfgOff, cfgSize;
|
||||
u32 oepRva;
|
||||
u32 blobSize;
|
||||
u32 flags;
|
||||
u32 reserved;
|
||||
} VFYHDR;
|
||||
|
||||
/* UTF-16 模块名 vs ASCII 常量比较(不区分大小写) */
|
||||
static int uname_eq(const u16 *w, const char *a, int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
u16 c = w[i];
|
||||
if (c >= 'A' && c <= 'Z') c = (u16)(c + 32);
|
||||
if (c != (u8)a[i]) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
__attribute__((section(".blobhead"), used)) int blob_main(void) {
|
||||
u64 peb = 0;
|
||||
__asm__ volatile("movq %%gs:0x60, %0" : "=r"(peb));
|
||||
if (!peb) return 1;
|
||||
u64 imageBase = *(u64 *)(peb + 0x10);
|
||||
if (!imageBase) return 1;
|
||||
|
||||
u8 *img = (u8 *)imageBase;
|
||||
u32 lfanew = *(u32 *)(img + 0x3C);
|
||||
u8 *nt = img + lfanew;
|
||||
u16 numSec = *(u16 *)(nt + 6);
|
||||
u16 optSize = *(u16 *)(nt + 20);
|
||||
u8 *sec = nt + 24 + optSize;
|
||||
VFYHDR *hdr = 0;
|
||||
for (u16 i = 0; i < numSec; i++) {
|
||||
u8 *s = sec + i * 40;
|
||||
if (s[0] == '.' && s[1] == 'v' && s[2] == 'f' && s[3] == 'y') {
|
||||
hdr = (VFYHDR *)(img + *(u32 *)(s + 12));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hdr) return 2;
|
||||
if (!(hdr->magic[0] == 'V' && hdr->magic[1] == 'F' && hdr->magic[2] == 'Y' && hdr->magic[3] == '3')) return 2;
|
||||
|
||||
u8 *secBase = (u8 *)hdr;
|
||||
u8 *dllBytes = secBase + hdr->dllOff;
|
||||
const char *cfg = (const char *)(secBase + hdr->cfgOff);
|
||||
|
||||
/* kernel32 from PEB->Ldr->InMemoryOrderModuleList */
|
||||
u64 ldr = *(u64 *)(peb + 0x18);
|
||||
u64 head = ldr + 0x20; /* InMemoryOrderModuleList */
|
||||
u64 cur = *(u64 *)(head);
|
||||
u64 kern = 0;
|
||||
for (int guard = 0; guard < 64 && cur && cur != head; guard++) {
|
||||
u8 *entry = (u8 *)(cur - 0x10);
|
||||
u64 dllBase = *(u64 *)(entry + 0x30);
|
||||
u16 nameLen = *(u16 *)(entry + 0x58);
|
||||
u64 nameBuf = *(u64 *)(entry + 0x60);
|
||||
if (nameLen == 24 && nameBuf && uname_eq((const u16 *)nameBuf, "kernel32.dll", 12)) {
|
||||
kern = dllBase;
|
||||
break;
|
||||
}
|
||||
cur = *(u64 *)(cur);
|
||||
}
|
||||
if (!kern) return 3;
|
||||
|
||||
/* kernel32 export table */
|
||||
u8 *kb = (u8 *)kern;
|
||||
u32 kl = *(u32 *)(kb + 0x3C);
|
||||
u8 *knt = kb + kl;
|
||||
u32 expRVA = *(u32 *)(knt + 24 + 112);
|
||||
if (!expRVA) return 4;
|
||||
u8 *exp = kb + expRVA;
|
||||
u32 numNames = *(u32 *)(exp + 24);
|
||||
u32 *names = (u32 *)(kb + *(u32 *)(exp + 32));
|
||||
u16 *ords = (u16 *)(kb + *(u32 *)(exp + 36));
|
||||
u32 *funcs = (u32 *)(kb + *(u32 *)(exp + 28));
|
||||
|
||||
fnGetProcAddress pGPA = 0;
|
||||
fnLoadLibraryA pLLA = 0;
|
||||
static const char nGPA[] = "GetProcAddress";
|
||||
static const char nLLA[] = "LoadLibraryA";
|
||||
for (u32 i = 0; i < numNames; i++) {
|
||||
const char *nm = (const char *)(kb + names[i]);
|
||||
int ok1 = 1, ok2 = 1;
|
||||
for (int k = 0; k < 14; k++) {
|
||||
if (nm[k] != nGPA[k]) { ok1 = 0; break; }
|
||||
if (!nGPA[k]) break;
|
||||
}
|
||||
for (int k = 0; k < 12; k++) {
|
||||
if (nm[k] != nLLA[k]) { ok2 = 0; break; }
|
||||
if (!nLLA[k]) break;
|
||||
}
|
||||
if (ok1) pGPA = (fnGetProcAddress)(kb + funcs[ords[i]]);
|
||||
if (ok2) pLLA = (fnLoadLibraryA)(kb + funcs[ords[i]]);
|
||||
if (pGPA && pLLA) break;
|
||||
}
|
||||
if (!pGPA || !pLLA) return 4;
|
||||
|
||||
static const char nTemp[] = "GetTempPathA";
|
||||
static const char nCreate[] = "CreateFileA";
|
||||
static const char nWrite[] = "WriteFile";
|
||||
static const char nClose[] = "CloseHandle";
|
||||
static const char nPid[] = "GetCurrentProcessId";
|
||||
static const char nExit[] = "ExitProcess";
|
||||
fnGetTempPathA pTemp = (fnGetTempPathA)pGPA((HMODULE)kern, nTemp);
|
||||
fnCreateFileA pCreate = (fnCreateFileA)pGPA((HMODULE)kern, nCreate);
|
||||
fnWriteFile pWrite = (fnWriteFile)pGPA((HMODULE)kern, nWrite);
|
||||
fnCloseHandle pClose = (fnCloseHandle)pGPA((HMODULE)kern, nClose);
|
||||
fnGetCurrentProcessId pPid = (fnGetCurrentProcessId)pGPA((HMODULE)kern, nPid);
|
||||
fnExitProcess pExit = (fnExitProcess)pGPA((HMODULE)kern, nExit);
|
||||
if (!pTemp || !pCreate || !pWrite || !pClose || !pPid || !pExit) return 5;
|
||||
|
||||
/* 阶段打点:写到 %TEMP%\vfy_boot.txt(覆盖) */
|
||||
char tdir[260];
|
||||
u32 tl = pTemp(260, tdir);
|
||||
char dbg[300];
|
||||
int dp = 0;
|
||||
if (tl && tl < 250) {
|
||||
for (u32 i = 0; i < tl; i++) dbg[dp++] = tdir[i];
|
||||
static const char dn[] = "vfy_boot.txt";
|
||||
for (int i = 0; dn[i]; i++) dbg[dp++] = dn[i];
|
||||
dbg[dp] = 0;
|
||||
} else dp = 0;
|
||||
|
||||
/* 释放 DLL */
|
||||
char path[300];
|
||||
int p = 0;
|
||||
for (u32 i = 0; i < tl; i++) path[p++] = tdir[i];
|
||||
static const char pre[] = "vfycore_";
|
||||
for (int i = 0; pre[i]; i++) path[p++] = pre[i];
|
||||
u32 pid = pPid();
|
||||
char digits[12];
|
||||
int dn2 = 0;
|
||||
if (!pid) digits[dn2++] = '0';
|
||||
while (pid && dn2 < 11) { digits[dn2++] = (char)('0' + pid % 10); pid /= 10; }
|
||||
for (int i = dn2 - 1; i >= 0; i--) path[p++] = digits[i];
|
||||
static const char ext[] = ".dll";
|
||||
for (int i = 0; ext[i]; i++) path[p++] = ext[i];
|
||||
path[p] = 0;
|
||||
|
||||
HANDLE hf = pCreate(path, 0x40000000u, 0, 0, 2, 0x80, 0);
|
||||
if (hf == (HANDLE)-1 || !hf) return 7;
|
||||
u32 wrote = 0;
|
||||
if (!pWrite(hf, dllBytes, hdr->dllSize, &wrote, 0) || wrote != hdr->dllSize) {
|
||||
pClose(hf);
|
||||
return 7;
|
||||
}
|
||||
pClose(hf);
|
||||
|
||||
/* 加载并调用 */
|
||||
HMODULE mod = pLLA(path);
|
||||
static const char nMain[] = "VerifyMain";
|
||||
typedef int (*PFN)(void *, const char *);
|
||||
PFN fn = 0;
|
||||
if (mod) fn = (PFN)pGPA(mod, nMain);
|
||||
|
||||
if (dp) {
|
||||
HANDLE hd = pCreate(dbg, 0x40000000u, 0, 0, 2, 0x80, 0);
|
||||
if (hd && hd != (HANDLE)-1) {
|
||||
char line[8];
|
||||
line[0] = mod ? 'M' : 'm';
|
||||
line[1] = fn ? 'F' : 'f';
|
||||
line[2] = '\n';
|
||||
u32 w2 = 0;
|
||||
pWrite(hd, line, 3, &w2, 0);
|
||||
pClose(hd);
|
||||
}
|
||||
}
|
||||
if (!mod) return 8;
|
||||
if (!fn) return 9;
|
||||
|
||||
void *oep = (void *)(imageBase + hdr->oepRva);
|
||||
int rc = fn(oep, cfg);
|
||||
if (rc != 0) {
|
||||
if (hdr->flags & 1) ((void (*)(void))oep)();
|
||||
pExit(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
/* vfy 引导 stub(x64)v2 —— 反射式加载:壳 DLL 从 .vfy 节直接映射进内存,不落盘
|
||||
*
|
||||
* 流程:解析自身 PE → 找 .vfy → 校验 CRC32 → 手动映射内嵌 DLL(头/节/重定位/导入)
|
||||
* → 调 DllMain(ATTACH) → 找导出 VerifyMain → 调用(oep, cfg) → 退出
|
||||
*
|
||||
* 头布局 40 字节(.vfy 节起始):
|
||||
* 0..3 magic "VFY3" | 4..7 ver
|
||||
* 8..11 dllOff | 12..15 dllSize
|
||||
* 16..19 cfgOff | 20..23 cfgSize
|
||||
* 24..27 oepRva | 28..31 blobSize
|
||||
* 32..35 flags | 36..39 dllCrc32
|
||||
*/
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
typedef void *HMODULE;
|
||||
typedef void *HANDLE;
|
||||
typedef int BOOL;
|
||||
|
||||
typedef HMODULE (*fnLoadLibraryA)(const char *);
|
||||
typedef void *(*fnGetProcAddress)(HMODULE, const char *);
|
||||
typedef void *(*fnVirtualAlloc)(void *, u64, u32, u32);
|
||||
typedef BOOL (*fnVirtualProtect)(void *, u64, u32, u32 *);
|
||||
typedef void (*fnExitProcess)(u32);
|
||||
|
||||
typedef struct {
|
||||
char magic[4];
|
||||
u32 ver;
|
||||
u32 dllOff, dllSize;
|
||||
u32 cfgOff, cfgSize;
|
||||
u32 oepRva;
|
||||
u32 blobSize;
|
||||
u32 flags;
|
||||
u32 dllCrc32;
|
||||
} VFYHDR;
|
||||
|
||||
|
||||
/* ---------- 小工具 ---------- */
|
||||
static int mem_eq(const u8 *a, const char *b) {
|
||||
for (int i = 0; b[i]; i++) if (a[i] != (u8)b[i]) return 0;
|
||||
return 1;
|
||||
}
|
||||
static void mem_cpy(u8 *d, const u8 *s, u64 n) {
|
||||
for (u64 i = 0; i < n; i++) d[i] = s[i];
|
||||
}
|
||||
static void mem_zero(u8 *d, u64 n) {
|
||||
for (u64 i = 0; i < n; i++) d[i] = 0;
|
||||
}
|
||||
static u32 crc32_of(const u8 *p, u32 n) {
|
||||
u32 c = 0xFFFFFFFFu;
|
||||
for (u32 i = 0; i < n; i++) {
|
||||
c ^= p[i];
|
||||
for (int k = 0; k < 8; k++) c = (c & 1) ? (0xEDB88320u ^ (c >> 1)) : (c >> 1);
|
||||
}
|
||||
return c ^ 0xFFFFFFFFu;
|
||||
}
|
||||
|
||||
__attribute__((section(".blobhead"), used)) int blob_main(void) {
|
||||
u64 peb = 0;
|
||||
__asm__ volatile("movq %%gs:0x60, %0" : "=r"(peb));
|
||||
if (!peb) return 1;
|
||||
u64 imageBase = *(u64 *)(peb + 0x10);
|
||||
if (!imageBase) return 1;
|
||||
|
||||
/* 自身 PE → .vfy */
|
||||
u8 *img = (u8 *)imageBase;
|
||||
u32 lfanew = *(u32 *)(img + 0x3C);
|
||||
u8 *nt = img + lfanew;
|
||||
u16 numSec = *(u16 *)(nt + 6);
|
||||
u16 optSize = *(u16 *)(nt + 20);
|
||||
u8 *sec = nt + 24 + optSize;
|
||||
VFYHDR *hdr = 0;
|
||||
for (u16 i = 0; i < numSec; i++) {
|
||||
u8 *s = sec + i * 40;
|
||||
if (s[0] == '.' && s[1] == 'v' && s[2] == 'f' && s[3] == 'y') {
|
||||
hdr = (VFYHDR *)(img + *(u32 *)(s + 12));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hdr) return 2;
|
||||
if (!(hdr->magic[0] == 'V' && hdr->magic[1] == 'F' && hdr->magic[2] == 'Y' && hdr->magic[3] == '3')) return 2;
|
||||
|
||||
u8 *secBase = (u8 *)hdr;
|
||||
u8 *dllSrc = secBase + hdr->dllOff;
|
||||
const char *cfg = (const char *)(secBase + hdr->cfgOff);
|
||||
|
||||
/* kernel32 */
|
||||
u64 ldr = *(u64 *)(peb + 0x18);
|
||||
u64 head = ldr + 0x20;
|
||||
u64 cur = *(u64 *)(head);
|
||||
u64 kern = 0;
|
||||
for (int guard = 0; guard < 64 && cur && cur != head; guard++) {
|
||||
u8 *entry = (u8 *)(cur - 0x10);
|
||||
u64 dllBase = *(u64 *)(entry + 0x30);
|
||||
u16 nameLen = *(u16 *)(entry + 0x58);
|
||||
u64 nameBuf = *(u64 *)(entry + 0x60);
|
||||
if (nameLen == 24 && nameBuf) {
|
||||
const u16 *w = (const u16 *)nameBuf;
|
||||
int ok = 1;
|
||||
for (int k = 0; k < 12; k++) {
|
||||
u16 c = w[k];
|
||||
if (c >= 'A' && c <= 'Z') c = (u16)(c + 32);
|
||||
if (c != (u16)"kernel32.dll"[k]) { ok = 0; break; }
|
||||
}
|
||||
if (ok) { kern = dllBase; break; }
|
||||
}
|
||||
cur = *(u64 *)(cur);
|
||||
}
|
||||
if (!kern) return 3;
|
||||
|
||||
u8 *kb = (u8 *)kern;
|
||||
u32 kl = *(u32 *)(kb + 0x3C);
|
||||
u8 *knt = kb + kl;
|
||||
u32 expRVA = *(u32 *)(knt + 24 + 112);
|
||||
if (!expRVA) return 4;
|
||||
u8 *exp = kb + expRVA;
|
||||
u32 numNames = *(u32 *)(exp + 24);
|
||||
u32 *names = (u32 *)(kb + *(u32 *)(exp + 32));
|
||||
u16 *ords = (u16 *)(kb + *(u32 *)(exp + 36));
|
||||
u32 *funcs = (u32 *)(kb + *(u32 *)(exp + 28));
|
||||
|
||||
fnGetProcAddress pGPA = 0;
|
||||
fnLoadLibraryA pLLA = 0;
|
||||
for (u32 i = 0; i < numNames; i++) {
|
||||
const u8 *nm = kb + names[i];
|
||||
if (mem_eq(nm, "GetProcAddress")) pGPA = (fnGetProcAddress)(kb + funcs[ords[i]]);
|
||||
if (mem_eq(nm, "LoadLibraryA")) pLLA = (fnLoadLibraryA)(kb + funcs[ords[i]]);
|
||||
if (pGPA && pLLA) break;
|
||||
}
|
||||
if (!pGPA || !pLLA) return 4;
|
||||
|
||||
fnVirtualAlloc pAlloc = (fnVirtualAlloc)pGPA((HMODULE)kern, "VirtualAlloc");
|
||||
fnVirtualProtect pProt = (fnVirtualProtect)pGPA((HMODULE)kern, "VirtualProtect");
|
||||
fnExitProcess pExit = (fnExitProcess)pGPA((HMODULE)kern, "ExitProcess");
|
||||
if (!pAlloc || !pExit) return 5;
|
||||
|
||||
/* 完整性:.vfy 里内嵌 DLL 的 CRC32 */
|
||||
if (hdr->dllCrc32) {
|
||||
u32 got = crc32_of(dllSrc, hdr->dllSize);
|
||||
if (got != hdr->dllCrc32) return 6;
|
||||
}
|
||||
|
||||
/* ---- 手动映射 DLL ---- */
|
||||
u8 *src = dllSrc;
|
||||
u32 dl = *(u32 *)(src + 0x3C);
|
||||
u8 *dnt = src + dl;
|
||||
u16 dsecs = *(u16 *)(dnt + 6);
|
||||
u16 doptSize = *(u16 *)(dnt + 20);
|
||||
u8 *dopt = dnt + 24;
|
||||
u64 prefBase = *(u64 *)(dopt + 24);
|
||||
u32 sizeOfImage = *(u32 *)(dopt + 56);
|
||||
u32 sizeOfHeaders = *(u32 *)(dopt + 60);
|
||||
u32 entryRVA = *(u32 *)(dopt + 16);
|
||||
u32 importRVA = *(u32 *)(dopt + 112 + 8);
|
||||
u32 relocRVA = *(u32 *)(dopt + 112 + 40);
|
||||
u32 relocSize = *(u32 *)(dopt + 112 + 44);
|
||||
u8 *dsec = dopt + doptSize;
|
||||
|
||||
u8 *base = (u8 *)pAlloc((void *)0, sizeOfImage, 0x3000 /*COMMIT|RESERVE*/, 0x40 /*RWX*/);
|
||||
if (!base) return 7;
|
||||
|
||||
/* 头 + 节 */
|
||||
mem_cpy(base, src, sizeOfHeaders);
|
||||
for (u16 i = 0; i < dsecs; i++) {
|
||||
u8 *s = dsec + i * 40;
|
||||
u32 va = *(u32 *)(s + 12);
|
||||
u32 rawSize = *(u32 *)(s + 16);
|
||||
u32 rawPtr = *(u32 *)(s + 20);
|
||||
if (rawSize && rawPtr) mem_cpy(base + va, src + rawPtr, rawSize);
|
||||
}
|
||||
|
||||
/* 重定位 */
|
||||
if (relocRVA && relocSize && (u64)base != prefBase) {
|
||||
u64 delta = (u64)base - prefBase;
|
||||
u8 *r = base + relocRVA;
|
||||
u8 *rend = r + relocSize;
|
||||
while (r + 8 <= rend) {
|
||||
u32 pageRVA = *(u32 *)r;
|
||||
u32 blockSize = *(u32 *)(r + 4);
|
||||
if (!blockSize) break;
|
||||
u16 *ent = (u16 *)(r + 8);
|
||||
int cnt = (int)(blockSize - 8) / 2;
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
u16 e = ent[i];
|
||||
u16 type = (u16)(e >> 12);
|
||||
u16 off = (u16)(e & 0x0FFF);
|
||||
if (type == 10) { /* DIR64 */
|
||||
u64 *p = (u64 *)(base + pageRVA + off);
|
||||
*p += delta;
|
||||
} else if (type == 0) {
|
||||
/* pad */
|
||||
}
|
||||
}
|
||||
r += blockSize;
|
||||
}
|
||||
}
|
||||
|
||||
/* 导入 */
|
||||
if (importRVA) {
|
||||
u8 *desc = base + importRVA;
|
||||
for (;;) {
|
||||
u32 oft = *(u32 *)desc;
|
||||
u32 nameRVA = *(u32 *)(desc + 12);
|
||||
u32 ft = *(u32 *)(desc + 16);
|
||||
if (!nameRVA && !ft && !oft) break;
|
||||
const char *dllName = (const char *)(base + nameRVA);
|
||||
HMODULE hm = pLLA(dllName);
|
||||
if (!hm) return 8;
|
||||
u64 *thunk = (u64 *)(base + (oft ? oft : ft));
|
||||
u64 *iat = (u64 *)(base + ft);
|
||||
for (int k = 0; thunk[k]; k++) {
|
||||
u64 t = thunk[k];
|
||||
if (t & 0x8000000000000000ull) {
|
||||
iat[k] = (u64)pGPA(hm, (const char *)(t & 0xFFFF));
|
||||
} else {
|
||||
const char *fnName = (const char *)(base + (u32)t + 2); /* 跳过 Hint */
|
||||
iat[k] = (u64)pGPA(hm, fnName);
|
||||
}
|
||||
if (!iat[k]) return 9;
|
||||
}
|
||||
desc += 20;
|
||||
}
|
||||
}
|
||||
|
||||
/* DllMain(DLL_PROCESS_ATTACH) */
|
||||
typedef BOOL (*fnDllMain)(HMODULE, u32, void *);
|
||||
if (entryRVA) {
|
||||
fnDllMain dm = (fnDllMain)(base + entryRVA);
|
||||
dm((HMODULE)base, 1, 0);
|
||||
}
|
||||
|
||||
/* 导出 VerifyMain(在映射镜像里查导出表) */
|
||||
u32 dexpRVA = *(u32 *)(dopt + 112);
|
||||
if (!dexpRVA) return 10;
|
||||
u8 *dexp = base + dexpRVA;
|
||||
u32 dnumNames = *(u32 *)(dexp + 24);
|
||||
u32 *dnames = (u32 *)(base + *(u32 *)(dexp + 32));
|
||||
u16 *dords = (u16 *)(base + *(u32 *)(dexp + 36));
|
||||
u32 *dfuncs = (u32 *)(base + *(u32 *)(dexp + 28));
|
||||
u32 vmRVA = 0;
|
||||
for (u32 i = 0; i < dnumNames; i++) {
|
||||
const u8 *nm = base + dnames[i];
|
||||
if (mem_eq(nm, "VerifyMain")) { vmRVA = dfuncs[dords[i]]; break; }
|
||||
}
|
||||
if (!vmRVA) return 11;
|
||||
|
||||
typedef int (*PFN)(void *, const char *);
|
||||
PFN fn = (PFN)(base + vmRVA);
|
||||
void *oep = (void *)(imageBase + hdr->oepRva);
|
||||
int rc = fn(oep, cfg);
|
||||
if (rc != 0) {
|
||||
if (hdr->flags & 1) ((void (*)(void))oep)();
|
||||
pExit(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
/* vfy 引导 stub v4 —— x64 / x86 通用,反射加载内嵌 DLL,全程零落盘
|
||||
*
|
||||
* 头布局 48 字节(.vfy 节起始):
|
||||
* 0..3 magic "VFY4" 4..7 ver
|
||||
* 8..11 dllOff 12..15 dllSize
|
||||
* 16..19 cfgOff 20..23 cfgSize
|
||||
* 24..27 oepRva 28..31 blobSize
|
||||
* 32..35 flags 36..39 crcVfy (.vfy 内容,跳过 36..44)
|
||||
* 40..43 crcFile 44..47 reserved
|
||||
*/
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
#if defined(_WIN64)
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned long long uptr;
|
||||
#else
|
||||
typedef unsigned int uptr;
|
||||
#endif
|
||||
typedef void *HMODULE;
|
||||
typedef void *HANDLE;
|
||||
typedef int BOOL;
|
||||
|
||||
/* x86 上 Win32 API 是 __stdcall,指针类型必须带上,否则栈被吃偏 */
|
||||
#if defined(_WIN64)
|
||||
#define API
|
||||
#else
|
||||
#define API __stdcall
|
||||
#endif
|
||||
|
||||
typedef HMODULE(API *fnLoadLibraryA)(const char *);
|
||||
typedef void *(API *fnGetProcAddress)(HMODULE, const char *);
|
||||
typedef void *(API *fnVirtualAlloc)(void *, uptr, u32, u32);
|
||||
typedef BOOL(API *fnVirtualFree)(void *, uptr, u32);
|
||||
typedef void(API *fnExitProcess)(u32);
|
||||
typedef u32(API *fnGetModuleFileNameA)(HMODULE, char *, u32);
|
||||
typedef HANDLE(API *fnCreateFileA)(const char *, u32, u32, void *, u32, u32, HANDLE);
|
||||
typedef BOOL(API *fnReadFile)(HANDLE, void *, u32, u32 *, void *);
|
||||
typedef u32(API *fnGetFileSize)(HANDLE, u32 *);
|
||||
typedef BOOL(API *fnCloseHandle)(HANDLE);
|
||||
typedef u32(API *fnGetTempPathA)(u32, char *);
|
||||
typedef BOOL(API *fnWriteFile)(HANDLE, const void *, u32, u32 *, void *);
|
||||
|
||||
typedef struct {
|
||||
char magic[4];
|
||||
u32 ver;
|
||||
u32 dllOff, dllSize;
|
||||
u32 cfgOff, cfgSize;
|
||||
u32 oepRva;
|
||||
u32 blobSize;
|
||||
u32 flags;
|
||||
u32 crcVfy;
|
||||
u32 crcFile;
|
||||
u32 reserved;
|
||||
} VFYHDR;
|
||||
|
||||
#define HDRSZ 48
|
||||
#define CRCOFF 36 /* 跳过 8 字节的校验字段 */
|
||||
|
||||
static uptr rd(const u8 *p) {
|
||||
#if defined(_WIN64)
|
||||
return *(const u64 *)p;
|
||||
#else
|
||||
return *(const u32 *)p;
|
||||
#endif
|
||||
}
|
||||
static int mem_eq(const u8 *a, const char *b) {
|
||||
for (int i = 0; b[i]; i++) if (a[i] != (u8)b[i]) return 0;
|
||||
return 1;
|
||||
}
|
||||
static void mem_cpy(u8 *d, const u8 *s, uptr n) {
|
||||
for (uptr i = 0; i < n; i++) d[i] = s[i];
|
||||
}
|
||||
static u32 crc_feed(u32 c, const u8 *p, u32 n) {
|
||||
for (u32 i = 0; i < n; i++) {
|
||||
c ^= p[i];
|
||||
for (int k = 0; k < 8; k++) c = (c & 1) ? (0xEDB88320u ^ (c >> 1)) : (c >> 1);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
__attribute__((section(".blobhead"), used)) int blob_main(void) {
|
||||
uptr peb = 0;
|
||||
#if defined(_WIN64)
|
||||
__asm__ volatile("movq %%gs:0x60, %0" : "=r"(peb));
|
||||
#else
|
||||
__asm__ volatile("movl %%fs:0x30, %0" : "=r"(peb));
|
||||
#endif
|
||||
if (!peb) return 1;
|
||||
#if defined(_WIN64)
|
||||
uptr imageBase = rd((const u8 *)peb + 0x10);
|
||||
#else
|
||||
uptr imageBase = rd((const u8 *)peb + 0x08);
|
||||
#endif
|
||||
if (!imageBase) return 1;
|
||||
|
||||
u8 *img = (u8 *)imageBase;
|
||||
u32 lfanew = *(u32 *)(img + 0x3C);
|
||||
u8 *nt = img + lfanew;
|
||||
u16 numSec = *(u16 *)(nt + 6);
|
||||
u16 optSize = *(u16 *)(nt + 20);
|
||||
u8 *sec = nt + 24 + optSize;
|
||||
VFYHDR *hdr = 0;
|
||||
u8 *secHdr = 0;
|
||||
for (u16 i = 0; i < numSec; i++) {
|
||||
u8 *s = sec + i * 40;
|
||||
if (s[0] == '.' && s[1] == 'v' && s[2] == 'f' && s[3] == 'y') {
|
||||
secHdr = s;
|
||||
hdr = (VFYHDR *)(img + *(u32 *)(s + 12));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hdr) return 2;
|
||||
if (!(hdr->magic[0] == 'V' && hdr->magic[1] == 'F' && hdr->magic[2] == 'Y' && hdr->magic[3] == '4')) return 2;
|
||||
|
||||
u8 *secBase = (u8 *)hdr;
|
||||
u32 secVSize = *(u32 *)(secHdr + 8);
|
||||
u32 secRawPtr = *(u32 *)(secHdr + 20);
|
||||
u8 *dllSrc = secBase + hdr->dllOff;
|
||||
const char *cfg = (const char *)(secBase + hdr->cfgOff);
|
||||
|
||||
/* ---- kernel32 ---- */
|
||||
uptr ldr = 0;
|
||||
#if defined(_WIN64)
|
||||
ldr = rd((const u8 *)peb + 0x18);
|
||||
#else
|
||||
ldr = rd((const u8 *)peb + 0x0C);
|
||||
#endif
|
||||
#if defined(_WIN64)
|
||||
uptr head = ldr + 0x20, entryOff = 0x10, dllBaseOff = 0x30, nameLenOff = 0x58, nameBufOff = 0x60;
|
||||
#else
|
||||
uptr head = ldr + 0x14, entryOff = 0x08, dllBaseOff = 0x18, nameLenOff = 0x2C, nameBufOff = 0x30;
|
||||
#endif
|
||||
uptr cur = rd((const u8 *)head);
|
||||
uptr kern = 0;
|
||||
for (int guard = 0; guard < 64 && cur && cur != head; guard++) {
|
||||
u8 *entry = (u8 *)(cur - entryOff);
|
||||
uptr dllBase = rd(entry + dllBaseOff);
|
||||
u16 nameLen = *(u16 *)(entry + nameLenOff);
|
||||
uptr nameBuf = rd(entry + nameBufOff);
|
||||
if (nameLen == 24 && nameBuf) {
|
||||
const u16 *w = (const u16 *)nameBuf;
|
||||
int ok = 1;
|
||||
for (int k = 0; k < 12; k++) {
|
||||
u16 c = w[k];
|
||||
if (c >= 'A' && c <= 'Z') c = (u16)(c + 32);
|
||||
if (c != (u16)"kernel32.dll"[k]) { ok = 0; break; }
|
||||
}
|
||||
if (ok) { kern = dllBase; break; }
|
||||
}
|
||||
cur = rd((const u8 *)cur);
|
||||
}
|
||||
if (!kern) return 3;
|
||||
|
||||
u8 *kb = (u8 *)kern;
|
||||
u32 kl = *(u32 *)(kb + 0x3C);
|
||||
u8 *knt = kb + kl;
|
||||
u32 ddOff = 112;
|
||||
#if !defined(_WIN64)
|
||||
ddOff = 96;
|
||||
#endif
|
||||
u32 expRVA = *(u32 *)(knt + 24 + ddOff);
|
||||
if (!expRVA) return 4;
|
||||
u8 *exp = kb + expRVA;
|
||||
u32 numNames = *(u32 *)(exp + 24);
|
||||
u32 *names = (u32 *)(kb + *(u32 *)(exp + 32));
|
||||
u16 *ords = (u16 *)(kb + *(u32 *)(exp + 36));
|
||||
u32 *funcs = (u32 *)(kb + *(u32 *)(exp + 28));
|
||||
|
||||
fnGetProcAddress pGPA = 0;
|
||||
fnLoadLibraryA pLLA = 0;
|
||||
for (u32 i = 0; i < numNames; i++) {
|
||||
const u8 *nm = kb + names[i];
|
||||
if (mem_eq(nm, "GetProcAddress")) pGPA = (fnGetProcAddress)(kb + funcs[ords[i]]);
|
||||
if (mem_eq(nm, "LoadLibraryA")) pLLA = (fnLoadLibraryA)(kb + funcs[ords[i]]);
|
||||
if (pGPA && pLLA) break;
|
||||
}
|
||||
if (!pGPA || !pLLA) return 4;
|
||||
|
||||
fnVirtualAlloc pAlloc = (fnVirtualAlloc)pGPA((HMODULE)kern, "VirtualAlloc");
|
||||
fnExitProcess pExit = (fnExitProcess)pGPA((HMODULE)kern, "ExitProcess");
|
||||
fnGetModuleFileNameA pModName = (fnGetModuleFileNameA)pGPA((HMODULE)kern, "GetModuleFileNameA");
|
||||
fnCreateFileA pCreate = (fnCreateFileA)pGPA((HMODULE)kern, "CreateFileA");
|
||||
fnReadFile pRead = (fnReadFile)pGPA((HMODULE)kern, "ReadFile");
|
||||
fnGetFileSize pSize = (fnGetFileSize)pGPA((HMODULE)kern, "GetFileSize");
|
||||
fnCloseHandle pClose = (fnCloseHandle)pGPA((HMODULE)kern, "CloseHandle");
|
||||
fnGetTempPathA pTemp = (fnGetTempPathA)pGPA((HMODULE)kern, "GetTempPathA");
|
||||
fnWriteFile pWrite = (fnWriteFile)pGPA((HMODULE)kern, "WriteFile");
|
||||
if (!pAlloc || !pExit || !pModName || !pCreate || !pRead || !pSize || !pClose) return 5;
|
||||
#define LOG(ch) do { \
|
||||
if (pTemp && pCreate && pWrite && pClose) { \
|
||||
char lp[300]; u32 tl_ = pTemp(300, lp); \
|
||||
if (tl_ && tl_ < 280) { \
|
||||
const char *nm_ = "vfy_b4.txt"; \
|
||||
int i_ = 0; while (nm_[i_]) { lp[tl_ + i_] = nm_[i_]; i_++; } \
|
||||
lp[tl_ + i_] = 0; \
|
||||
HANDLE h_ = pCreate(lp, 0x40000000u, 0, 0, 2, 0x80, 0); \
|
||||
if (h_ && h_ != (HANDLE)-1) { char cc_ = (char)(ch); u32 w_ = 0; pWrite(h_, &cc_, 1, &w_, 0); pClose(h_); } \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* ---- 完整性 1:.vfy 内容(跳过 36..44)---- */
|
||||
if (hdr->crcVfy) {
|
||||
u32 c = 0xFFFFFFFFu;
|
||||
c = crc_feed(c, secBase, CRCOFF);
|
||||
c = crc_feed(c, secBase + CRCOFF + 8, secVSize - CRCOFF - 8);
|
||||
c ^= 0xFFFFFFFFu;
|
||||
if (c != hdr->crcVfy) { LOG('1'); return 6; }
|
||||
LOG('2');
|
||||
}
|
||||
|
||||
/* ---- 完整性 2:整个文件(跳过同一段 8 字节)---- */
|
||||
if (hdr->crcFile) {
|
||||
char path[512];
|
||||
u32 n = pModName(0, path, 512);
|
||||
if (!n) return 12;
|
||||
HANDLE hf = pCreate(path, 0x80000000u, 1, 0, 3, 0x80, 0);
|
||||
if (hf == (HANDLE)-1 || !hf) return 12;
|
||||
u32 fsize = pSize(hf, 0);
|
||||
u8 *buf = (u8 *)pAlloc(0, fsize, 0x3000, 0x04);
|
||||
if (!buf) { pClose(hf); return 12; }
|
||||
u32 got = 0;
|
||||
if (!pRead(hf, buf, fsize, &got, 0) || got != fsize) { pClose(hf); return 12; }
|
||||
pClose(hf);
|
||||
u32 skipAt = secRawPtr + CRCOFF;
|
||||
u32 c = 0xFFFFFFFFu;
|
||||
if (skipAt > fsize) return 12;
|
||||
c = crc_feed(c, buf, skipAt);
|
||||
c = crc_feed(c, buf + skipAt + 8, fsize - skipAt - 8);
|
||||
c ^= 0xFFFFFFFFu;
|
||||
if (c != hdr->crcFile) { LOG('3'); return 13; }
|
||||
LOG('4');
|
||||
}
|
||||
|
||||
/* ---- 反射加载 DLL ---- */
|
||||
u8 *src = dllSrc;
|
||||
u32 dl = *(u32 *)(src + 0x3C);
|
||||
u8 *dnt = src + dl;
|
||||
u16 dsecs = *(u16 *)(dnt + 6);
|
||||
u16 doptSize = *(u16 *)(dnt + 20);
|
||||
u8 *dopt = dnt + 24;
|
||||
uptr prefBase = 0;
|
||||
u32 sizeOfImage = 0, sizeOfHeaders = 0, entryRVA = 0, importRVA = 0, relocRVA = 0, relocSize = 0;
|
||||
#if defined(_WIN64)
|
||||
prefBase = *(u64 *)(dopt + 24);
|
||||
sizeOfImage = *(u32 *)(dopt + 56);
|
||||
sizeOfHeaders = *(u32 *)(dopt + 60);
|
||||
entryRVA = *(u32 *)(dopt + 16);
|
||||
importRVA = *(u32 *)(dopt + 112 + 8);
|
||||
relocRVA = *(u32 *)(dopt + 112 + 40);
|
||||
relocSize = *(u32 *)(dopt + 112 + 44);
|
||||
#else
|
||||
prefBase = *(u32 *)(dopt + 28);
|
||||
sizeOfImage = *(u32 *)(dopt + 56);
|
||||
sizeOfHeaders = *(u32 *)(dopt + 60);
|
||||
entryRVA = *(u32 *)(dopt + 16);
|
||||
importRVA = *(u32 *)(dopt + 96 + 8);
|
||||
relocRVA = *(u32 *)(dopt + 96 + 40);
|
||||
relocSize = *(u32 *)(dopt + 96 + 44);
|
||||
#endif
|
||||
u8 *dsec = dopt + doptSize;
|
||||
|
||||
LOG('5');
|
||||
u8 *base = (u8 *)pAlloc(0, sizeOfImage, 0x3000, 0x40);
|
||||
if (!base) { LOG('6'); return 7; }
|
||||
LOG('7');
|
||||
mem_cpy(base, src, sizeOfHeaders);
|
||||
for (u16 i = 0; i < dsecs; i++) {
|
||||
u8 *s = dsec + i * 40;
|
||||
u32 va = *(u32 *)(s + 12);
|
||||
u32 rawSize = *(u32 *)(s + 16);
|
||||
u32 rawPtr = *(u32 *)(s + 20);
|
||||
if (rawSize && rawPtr) mem_cpy(base + va, src + rawPtr, rawSize);
|
||||
}
|
||||
|
||||
LOG('8');
|
||||
if (relocRVA && relocSize && (uptr)base != prefBase) {
|
||||
uptr delta = (uptr)base - prefBase;
|
||||
u8 *r = base + relocRVA;
|
||||
u8 *rend = r + relocSize;
|
||||
while (r + 8 <= rend) {
|
||||
u32 pageRVA = *(u32 *)r;
|
||||
u32 blockSize = *(u32 *)(r + 4);
|
||||
if (!blockSize) break;
|
||||
u16 *ent = (u16 *)(r + 8);
|
||||
int cnt = (int)(blockSize - 8) / 2;
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
u16 e = ent[i];
|
||||
u16 type = (u16)(e >> 12);
|
||||
u16 off = (u16)(e & 0x0FFF);
|
||||
#if defined(_WIN64)
|
||||
if (type == 10) {
|
||||
u64 *p = (u64 *)(base + pageRVA + off);
|
||||
*p += delta;
|
||||
}
|
||||
#else
|
||||
if (type == 3) {
|
||||
u32 *p = (u32 *)(base + pageRVA + off);
|
||||
*p += (u32)delta;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
r += blockSize;
|
||||
}
|
||||
}
|
||||
|
||||
LOG('9');
|
||||
if (importRVA) {
|
||||
u8 *desc = base + importRVA;
|
||||
for (;;) {
|
||||
u32 oft = *(u32 *)desc;
|
||||
u32 nameRVA = *(u32 *)(desc + 12);
|
||||
u32 ft = *(u32 *)(desc + 16);
|
||||
if (!nameRVA && !ft && !oft) break;
|
||||
const char *dllName = (const char *)(base + nameRVA);
|
||||
HMODULE hm = pLLA(dllName);
|
||||
if (!hm) { LOG('A'); return 8; }
|
||||
u8 *thunk = base + (oft ? oft : ft);
|
||||
u8 *iat = base + ft;
|
||||
for (u32 k = 0;; k++) {
|
||||
uptr t = rd(thunk + k * (u32)sizeof(uptr));
|
||||
if (!t) break;
|
||||
void *fn = 0;
|
||||
if (t & ((uptr)1 << (sizeof(uptr) * 8 - 1))) {
|
||||
fn = pGPA(hm, (const char *)(t & 0xFFFF));
|
||||
} else {
|
||||
fn = pGPA(hm, (const char *)(base + (u32)t + 2));
|
||||
}
|
||||
if (!fn) { LOG('B'); return 9; }
|
||||
*(uptr *)(iat + k * sizeof(uptr)) = (uptr)fn;
|
||||
}
|
||||
desc += 20;
|
||||
}
|
||||
}
|
||||
|
||||
LOG('C');
|
||||
typedef BOOL(API *fnDllMain)(HMODULE, u32, void *);
|
||||
if (entryRVA) {
|
||||
fnDllMain dm = (fnDllMain)(base + entryRVA);
|
||||
dm((HMODULE)base, 1, 0);
|
||||
}
|
||||
|
||||
u32 dexpRVA = 0;
|
||||
#if defined(_WIN64)
|
||||
dexpRVA = *(u32 *)(dopt + 112);
|
||||
#else
|
||||
dexpRVA = *(u32 *)(dopt + 96);
|
||||
#endif
|
||||
LOG('D');
|
||||
if (!dexpRVA) return 10;
|
||||
u8 *dexp = base + dexpRVA;
|
||||
u32 dnumNames = *(u32 *)(dexp + 24);
|
||||
u32 *dnames = (u32 *)(base + *(u32 *)(dexp + 32));
|
||||
u16 *dords = (u16 *)(base + *(u32 *)(dexp + 36));
|
||||
u32 *dfuncs = (u32 *)(base + *(u32 *)(dexp + 28));
|
||||
u32 vmRVA = 0;
|
||||
for (u32 i = 0; i < dnumNames; i++) {
|
||||
const u8 *nm = base + dnames[i];
|
||||
if (mem_eq(nm, "VerifyMain")) { vmRVA = dfuncs[dords[i]]; break; }
|
||||
}
|
||||
if (!vmRVA) { LOG('E'); return 11; }
|
||||
LOG('F');
|
||||
|
||||
typedef int (*PFN)(void *, const char *);
|
||||
PFN fn = (PFN)(base + vmRVA);
|
||||
void *oep = (void *)((u8 *)imageBase + hdr->oepRva);
|
||||
int rc = fn(oep, cfg);
|
||||
if (rc != 0) {
|
||||
if (hdr->flags & 1) ((void (*)(void))oep)();
|
||||
pExit(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
/* vfy 引导 stub v5 —— x64/x86 通用;**不含任何字符串字面量**(全用立即数打包),
|
||||
* 因此 x86 下也是位置无关的:32 位没有 RIP 相对寻址,字面量会变成绝对地址而错位。
|
||||
*
|
||||
* 头布局 48 字节(.vfy 节起始):
|
||||
* 0..3 magic "VFY4" | 4..7 ver | 8..11 dllOff | 12..15 dllSize
|
||||
* 16..19 cfgOff | 20..23 cfgSize | 24..27 oepRva | 28..31 blobSize
|
||||
* 32..35 flags | 36..39 crcVfy | 40..43 crcFile | 44..47 reserved
|
||||
*/
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
#if defined(_WIN64)
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned long long uptr;
|
||||
#else
|
||||
typedef unsigned int uptr;
|
||||
#endif
|
||||
typedef void *HMODULE;
|
||||
typedef void *HANDLE;
|
||||
typedef int BOOL;
|
||||
|
||||
#if defined(_WIN64)
|
||||
#define API
|
||||
#else
|
||||
#define API __stdcall
|
||||
#endif
|
||||
|
||||
typedef HMODULE(API *fnLoadLibraryA)(const char *);
|
||||
typedef void *(API *fnGetProcAddress)(HMODULE, const char *);
|
||||
typedef void *(API *fnVirtualAlloc)(void *, uptr, u32, u32);
|
||||
typedef void(API *fnExitProcess)(u32);
|
||||
typedef u32(API *fnGetModuleFileNameA)(HMODULE, char *, u32);
|
||||
typedef HANDLE(API *fnCreateFileA)(const char *, u32, u32, void *, u32, u32, HANDLE);
|
||||
typedef BOOL(API *fnReadFile)(HANDLE, void *, u32, u32 *, void *);
|
||||
typedef u32(API *fnGetFileSize)(HANDLE, u32 *);
|
||||
typedef BOOL(API *fnCloseHandle)(HANDLE);
|
||||
typedef u32(API *fnGetTempPathA)(u32, char *);
|
||||
typedef BOOL(API *fnWriteFile)(HANDLE, const void *, u32, u32 *, void *);
|
||||
|
||||
typedef struct {
|
||||
char magic[4];
|
||||
u32 ver;
|
||||
u32 dllOff, dllSize;
|
||||
u32 cfgOff, cfgSize;
|
||||
u32 oepRva;
|
||||
u32 blobSize;
|
||||
u32 flags;
|
||||
u32 crcVfy;
|
||||
u32 crcFile;
|
||||
u32 reserved;
|
||||
} VFYHDR;
|
||||
|
||||
#define CRCOFF 36
|
||||
|
||||
/* ---------- 位置无关的字符串工具(不用 .rdata) ---------- */
|
||||
static void putw(u32 *w, u32 w0, u32 w1, u32 w2, u32 w3, u32 w4, u32 w5) {
|
||||
w[0] = w0; w[1] = w1; w[2] = w2; w[3] = w3; w[4] = w4; w[5] = w5;
|
||||
}
|
||||
static void mk(char *d, u32 w0, u32 w1, u32 w2, u32 w3, u32 w4, u32 w5, int n) {
|
||||
u32 w[6]; putw(w, w0, w1, w2, w3, w4, w5);
|
||||
for (int i = 0; i < n; i++) d[i] = (char)((w[i >> 2] >> ((i & 3) * 8)) & 0xFF);
|
||||
d[n] = 0;
|
||||
}
|
||||
static int eq_s(const u8 *a, u32 w0, u32 w1, u32 w2, u32 w3, u32 w4, u32 w5, int n) {
|
||||
u32 w[6]; putw(w, w0, w1, w2, w3, w4, w5);
|
||||
for (int i = 0; i < n; i++)
|
||||
if (a[i] != (u8)((w[i >> 2] >> ((i & 3) * 8)) & 0xFF)) return 0;
|
||||
return 1;
|
||||
}
|
||||
static int eq_u16ci(const u16 *a, u32 w0, u32 w1, u32 w2, u32 w3, u32 w4, u32 w5, int n) {
|
||||
u32 w[6]; putw(w, w0, w1, w2, w3, w4, w5);
|
||||
for (int i = 0; i < n; i++) {
|
||||
u16 c = a[i];
|
||||
if (c >= 'A' && c <= 'Z') c = (u16)(c + 32);
|
||||
if (c != (u16)((w[i >> 2] >> ((i & 3) * 8)) & 0xFF)) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
static void *api(void *kern, fnGetProcAddress gpa, u32 w0, u32 w1, u32 w2, u32 w3, u32 w4, u32 w5, int n) {
|
||||
char nm[32];
|
||||
mk(nm, w0, w1, w2, w3, w4, w5, n);
|
||||
return gpa((HMODULE)kern, nm);
|
||||
}
|
||||
static uptr rd(const u8 *p) {
|
||||
#if defined(_WIN64)
|
||||
return *(const u64 *)p;
|
||||
#else
|
||||
return *(const u32 *)p;
|
||||
#endif
|
||||
}
|
||||
static void mem_cpy(u8 *d, const u8 *s, uptr n) {
|
||||
for (uptr i = 0; i < n; i++) d[i] = s[i];
|
||||
}
|
||||
static u32 crc_feed(u32 c, const u8 *p, u32 n) {
|
||||
for (u32 i = 0; i < n; i++) {
|
||||
c ^= p[i];
|
||||
for (int k = 0; k < 8; k++) c = (c & 1) ? (0xEDB88320u ^ (c >> 1)) : (c >> 1);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
__attribute__((section(".blobhead"), used)) int blob_main(void) {
|
||||
uptr peb = 0;
|
||||
#if defined(_WIN64)
|
||||
__asm__ volatile("movq %%gs:0x60, %0" : "=r"(peb));
|
||||
#else
|
||||
__asm__ volatile("movl %%fs:0x30, %0" : "=r"(peb));
|
||||
#endif
|
||||
if (!peb) return 1;
|
||||
#if defined(_WIN64)
|
||||
uptr imageBase = rd((const u8 *)peb + 0x10);
|
||||
#else
|
||||
uptr imageBase = rd((const u8 *)peb + 0x08);
|
||||
#endif
|
||||
if (!imageBase) return 1;
|
||||
|
||||
u8 *img = (u8 *)imageBase;
|
||||
u32 lfanew = *(u32 *)(img + 0x3C);
|
||||
u8 *nt = img + lfanew;
|
||||
u16 numSec = *(u16 *)(nt + 6);
|
||||
u16 optSize = *(u16 *)(nt + 20);
|
||||
u8 *sec = nt + 24 + optSize;
|
||||
VFYHDR *hdr = 0;
|
||||
u8 *secHdr = 0;
|
||||
for (u16 i = 0; i < numSec; i++) {
|
||||
u8 *s = sec + i * 40;
|
||||
if (s[0] == '.' && s[1] == 'v' && s[2] == 'f' && s[3] == 'y') {
|
||||
secHdr = s;
|
||||
hdr = (VFYHDR *)(img + *(u32 *)(s + 12));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hdr) return 2;
|
||||
if (!(hdr->magic[0] == 'V' && hdr->magic[1] == 'F' && hdr->magic[2] == 'Y' && hdr->magic[3] == '4')) return 2;
|
||||
|
||||
u8 *secBase = (u8 *)hdr;
|
||||
u32 secVSize = *(u32 *)(secHdr + 8);
|
||||
u32 secRawPtr = *(u32 *)(secHdr + 20);
|
||||
u8 *dllSrc = secBase + hdr->dllOff;
|
||||
const char *cfg = (const char *)(secBase + hdr->cfgOff);
|
||||
|
||||
/* kernel32 */
|
||||
uptr ldr = 0;
|
||||
#if defined(_WIN64)
|
||||
ldr = rd((const u8 *)peb + 0x18);
|
||||
uptr head = ldr + 0x20, entryOff = 0x10, dllBaseOff = 0x30, nameLenOff = 0x58, nameBufOff = 0x60;
|
||||
#else
|
||||
ldr = rd((const u8 *)peb + 0x0C);
|
||||
uptr head = ldr + 0x14, entryOff = 0x08, dllBaseOff = 0x18, nameLenOff = 0x2C, nameBufOff = 0x30;
|
||||
#endif
|
||||
uptr cur = rd((const u8 *)head);
|
||||
uptr kern = 0;
|
||||
for (int guard = 0; guard < 64 && cur && cur != head; guard++) {
|
||||
u8 *entry = (u8 *)(cur - entryOff);
|
||||
uptr dllBase = rd(entry + dllBaseOff);
|
||||
u16 nameLen = *(u16 *)(entry + nameLenOff);
|
||||
uptr nameBuf = rd(entry + nameBufOff);
|
||||
if (nameLen == 24 && nameBuf &&
|
||||
eq_u16ci((const u16 *)nameBuf, 0x6E72656B, 0x32336C65, 0x6C6C642E, 0, 0, 0, 12)) {
|
||||
kern = dllBase;
|
||||
break;
|
||||
}
|
||||
cur = rd((const u8 *)cur);
|
||||
}
|
||||
if (!kern) return 3;
|
||||
|
||||
u8 *kb = (u8 *)kern;
|
||||
u32 kl = *(u32 *)(kb + 0x3C);
|
||||
u8 *knt = kb + kl;
|
||||
#if defined(_WIN64)
|
||||
u32 ddOff = 112;
|
||||
#else
|
||||
u32 ddOff = 96;
|
||||
#endif
|
||||
u32 expRVA = *(u32 *)(knt + 24 + ddOff);
|
||||
if (!expRVA) return 4;
|
||||
u8 *exp = kb + expRVA;
|
||||
u32 numNames = *(u32 *)(exp + 24);
|
||||
u32 *names = (u32 *)(kb + *(u32 *)(exp + 32));
|
||||
u16 *ords = (u16 *)(kb + *(u32 *)(exp + 36));
|
||||
u32 *funcs = (u32 *)(kb + *(u32 *)(exp + 28));
|
||||
|
||||
fnGetProcAddress pGPA = 0;
|
||||
fnLoadLibraryA pLLA = 0;
|
||||
for (u32 i = 0; i < numNames; i++) {
|
||||
const u8 *nm = kb + names[i];
|
||||
if (eq_s(nm, 0x50746547, 0x41636F72, 0x65726464, 0x00007373, 0, 0, 14))
|
||||
pGPA = (fnGetProcAddress)(kb + funcs[ords[i]]);
|
||||
if (eq_s(nm, 0x64616F4C, 0x7262694C, 0x41797261, 0x00000000, 0, 0, 12))
|
||||
pLLA = (fnLoadLibraryA)(kb + funcs[ords[i]]);
|
||||
if (pGPA && pLLA) break;
|
||||
}
|
||||
if (!pGPA || !pLLA) return 4;
|
||||
|
||||
fnVirtualAlloc pAlloc = (fnVirtualAlloc)api((void *)kern, pGPA, 0x74726956, 0x416C6175, 0x636F6C6C, 0, 0, 0, 12);
|
||||
fnExitProcess pExit = (fnExitProcess)api((void *)kern, pGPA, 0x74697845, 0x636F7250, 0x00737365, 0, 0, 0, 11);
|
||||
fnGetModuleFileNameA pModName = (fnGetModuleFileNameA)api((void *)kern, pGPA, 0x4D746547, 0x6C75646F, 0x6C694665, 0x6D614E65, 0x00004165, 0, 18);
|
||||
fnCreateFileA pCreate = (fnCreateFileA)api((void *)kern, pGPA, 0x61657243, 0x69466574, 0x0041656C, 0, 0, 0, 11);
|
||||
fnReadFile pRead = (fnReadFile)api((void *)kern, pGPA, 0x64616552, 0x656C6946, 0, 0, 0, 0, 8);
|
||||
fnGetFileSize pSize = (fnGetFileSize)api((void *)kern, pGPA, 0x46746547, 0x53656C69, 0x00657A69, 0, 0, 0, 11);
|
||||
fnCloseHandle pClose = (fnCloseHandle)api((void *)kern, pGPA, 0x736F6C43, 0x6E614865, 0x00656C64, 0, 0, 0, 11);
|
||||
fnGetTempPathA pTemp = (fnGetTempPathA)api((void *)kern, pGPA, 0x54746547, 0x50706D65, 0x41687461, 0, 0, 0, 12);
|
||||
fnWriteFile pWrite = (fnWriteFile)api((void *)kern, pGPA, 0x74697257, 0x6C694665, 0x00000065, 0, 0, 0, 9);
|
||||
if (!pAlloc || !pExit || !pModName || !pCreate || !pRead || !pSize || !pClose) return 5;
|
||||
|
||||
#define LOG(ch) do { \
|
||||
if (pTemp && pCreate && pWrite && pClose) { \
|
||||
char lp[300]; \
|
||||
u32 tl_ = pTemp(300, lp); \
|
||||
if (tl_ && tl_ < 280) { \
|
||||
char fn_[16]; \
|
||||
mk(fn_, 0x5F796676, 0x742E3462, 0x00007478, 0, 0, 0, 10); \
|
||||
int i_ = 0; \
|
||||
while (fn_[i_]) { lp[tl_ + i_] = fn_[i_]; i_++; } \
|
||||
lp[tl_ + i_] = 0; \
|
||||
HANDLE h_ = pCreate(lp, 0x40000000u, 0, 0, 2, 0x80, 0); \
|
||||
if (h_ && h_ != (HANDLE)-1) { char cc_ = (char)(ch); u32 w_ = 0; pWrite(h_, &cc_, 1, &w_, 0); pClose(h_); } \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* 完整性 1:.vfy 内容 */
|
||||
if (hdr->crcVfy) {
|
||||
u32 c = 0xFFFFFFFFu;
|
||||
c = crc_feed(c, secBase, CRCOFF);
|
||||
c = crc_feed(c, secBase + CRCOFF + 8, secVSize - CRCOFF - 8);
|
||||
c ^= 0xFFFFFFFFu;
|
||||
if (c != hdr->crcVfy) { LOG('1'); return 6; }
|
||||
LOG('2');
|
||||
}
|
||||
|
||||
/* 完整性 2:整个文件 */
|
||||
if (hdr->crcFile) {
|
||||
char path[512];
|
||||
u32 n = pModName(0, path, 512);
|
||||
if (!n) return 12;
|
||||
HANDLE hf = pCreate(path, 0x80000000u, 1, 0, 3, 0x80, 0);
|
||||
if (hf == (HANDLE)-1 || !hf) return 12;
|
||||
u32 fsize = pSize(hf, 0);
|
||||
u8 *buf = (u8 *)pAlloc(0, fsize, 0x3000, 0x04);
|
||||
if (!buf) { pClose(hf); return 12; }
|
||||
u32 got = 0;
|
||||
if (!pRead(hf, buf, fsize, &got, 0) || got != fsize) { pClose(hf); return 12; }
|
||||
pClose(hf);
|
||||
u32 skipAt = secRawPtr + CRCOFF;
|
||||
if (skipAt > fsize) return 12;
|
||||
u32 c = 0xFFFFFFFFu;
|
||||
c = crc_feed(c, buf, skipAt);
|
||||
c = crc_feed(c, buf + skipAt + 8, fsize - skipAt - 8);
|
||||
c ^= 0xFFFFFFFFu;
|
||||
if (c != hdr->crcFile) { LOG('3'); return 13; }
|
||||
LOG('4');
|
||||
}
|
||||
|
||||
/* 反射加载 */
|
||||
u8 *src = dllSrc;
|
||||
u32 dl = *(u32 *)(src + 0x3C);
|
||||
u8 *dnt = src + dl;
|
||||
u16 dsecs = *(u16 *)(dnt + 6);
|
||||
u16 doptSize = *(u16 *)(dnt + 20);
|
||||
u8 *dopt = dnt + 24;
|
||||
uptr prefBase = 0;
|
||||
u32 sizeOfImage = 0, sizeOfHeaders = 0, entryRVA = 0, importRVA = 0, relocRVA = 0, relocSize = 0;
|
||||
#if defined(_WIN64)
|
||||
prefBase = *(u64 *)(dopt + 24);
|
||||
sizeOfImage = *(u32 *)(dopt + 56);
|
||||
sizeOfHeaders = *(u32 *)(dopt + 60);
|
||||
entryRVA = *(u32 *)(dopt + 16);
|
||||
importRVA = *(u32 *)(dopt + 112 + 8);
|
||||
relocRVA = *(u32 *)(dopt + 112 + 40);
|
||||
relocSize = *(u32 *)(dopt + 112 + 44);
|
||||
#else
|
||||
prefBase = *(u32 *)(dopt + 28);
|
||||
sizeOfImage = *(u32 *)(dopt + 56);
|
||||
sizeOfHeaders = *(u32 *)(dopt + 60);
|
||||
entryRVA = *(u32 *)(dopt + 16);
|
||||
importRVA = *(u32 *)(dopt + 96 + 8);
|
||||
relocRVA = *(u32 *)(dopt + 96 + 40);
|
||||
relocSize = *(u32 *)(dopt + 96 + 44);
|
||||
#endif
|
||||
u8 *dsec = dopt + doptSize;
|
||||
|
||||
LOG('5');
|
||||
u8 *base = (u8 *)pAlloc(0, sizeOfImage, 0x3000, 0x40);
|
||||
if (!base) { LOG('6'); return 7; }
|
||||
LOG('7');
|
||||
mem_cpy(base, src, sizeOfHeaders);
|
||||
for (u16 i = 0; i < dsecs; i++) {
|
||||
u8 *s = dsec + i * 40;
|
||||
u32 va = *(u32 *)(s + 12);
|
||||
u32 rawSize = *(u32 *)(s + 16);
|
||||
u32 rawPtr = *(u32 *)(s + 20);
|
||||
if (rawSize && rawPtr) mem_cpy(base + va, src + rawPtr, rawSize);
|
||||
}
|
||||
|
||||
LOG('8');
|
||||
if (relocRVA && relocSize && (uptr)base != prefBase) {
|
||||
uptr delta = (uptr)base - prefBase;
|
||||
u8 *r = base + relocRVA;
|
||||
u8 *rend = r + relocSize;
|
||||
while (r + 8 <= rend) {
|
||||
u32 pageRVA = *(u32 *)r;
|
||||
u32 blockSize = *(u32 *)(r + 4);
|
||||
if (!blockSize) break;
|
||||
u16 *ent = (u16 *)(r + 8);
|
||||
int cnt = (int)(blockSize - 8) / 2;
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
u16 e = ent[i];
|
||||
u16 type = (u16)(e >> 12);
|
||||
u16 off = (u16)(e & 0x0FFF);
|
||||
#if defined(_WIN64)
|
||||
if (type == 10) { u64 *p = (u64 *)(base + pageRVA + off); *p += delta; }
|
||||
#else
|
||||
if (type == 3) { u32 *p = (u32 *)(base + pageRVA + off); *p += (u32)delta; }
|
||||
#endif
|
||||
}
|
||||
r += blockSize;
|
||||
}
|
||||
}
|
||||
|
||||
LOG('9');
|
||||
if (importRVA) {
|
||||
u8 *desc = base + importRVA;
|
||||
for (;;) {
|
||||
u32 oft = *(u32 *)desc;
|
||||
u32 nameRVA = *(u32 *)(desc + 12);
|
||||
u32 ft = *(u32 *)(desc + 16);
|
||||
if (!nameRVA && !ft && !oft) break;
|
||||
const char *dllName = (const char *)(base + nameRVA);
|
||||
HMODULE hm = pLLA(dllName);
|
||||
if (!hm) { LOG('A'); return 8; }
|
||||
u8 *thunk = base + (oft ? oft : ft);
|
||||
u8 *iat = base + ft;
|
||||
for (u32 k = 0;; k++) {
|
||||
uptr t = rd(thunk + k * (u32)sizeof(uptr));
|
||||
if (!t) break;
|
||||
void *fn = 0;
|
||||
if (t & ((uptr)1 << (sizeof(uptr) * 8 - 1)))
|
||||
fn = pGPA(hm, (const char *)(t & 0xFFFF));
|
||||
else
|
||||
fn = pGPA(hm, (const char *)(base + (u32)t + 2));
|
||||
if (!fn) { LOG('B'); return 9; }
|
||||
*(uptr *)(iat + k * sizeof(uptr)) = (uptr)fn;
|
||||
}
|
||||
desc += 20;
|
||||
}
|
||||
}
|
||||
|
||||
LOG('C');
|
||||
typedef BOOL(API *fnDllMain)(HMODULE, u32, void *);
|
||||
if (entryRVA) {
|
||||
fnDllMain dm = (fnDllMain)(base + entryRVA);
|
||||
dm((HMODULE)base, 1, 0);
|
||||
}
|
||||
|
||||
LOG('D');
|
||||
u32 dexpRVA = 0;
|
||||
#if defined(_WIN64)
|
||||
dexpRVA = *(u32 *)(dopt + 112);
|
||||
#else
|
||||
dexpRVA = *(u32 *)(dopt + 96);
|
||||
#endif
|
||||
if (!dexpRVA) return 10;
|
||||
u8 *dexp = base + dexpRVA;
|
||||
u32 dnumNames = *(u32 *)(dexp + 24);
|
||||
u32 *dnames = (u32 *)(base + *(u32 *)(dexp + 32));
|
||||
u16 *dords = (u16 *)(base + *(u32 *)(dexp + 36));
|
||||
u32 *dfuncs = (u32 *)(base + *(u32 *)(dexp + 28));
|
||||
u32 vmRVA = 0;
|
||||
for (u32 i = 0; i < dnumNames; i++) {
|
||||
const u8 *nm = base + dnames[i];
|
||||
if (eq_s(nm, 0x69726556, 0x614D7966, 0x00006E69, 0, 0, 0, 10)) { vmRVA = dfuncs[dords[i]]; break; }
|
||||
}
|
||||
if (!vmRVA) { LOG('E'); return 11; }
|
||||
LOG('F');
|
||||
|
||||
typedef int (*PFN)(void *, const char *);
|
||||
PFN fn = (PFN)(base + vmRVA);
|
||||
void *oep = (void *)((u8 *)imageBase + hdr->oepRva);
|
||||
int rc = fn(oep, cfg);
|
||||
if (rc != 0) {
|
||||
if (hdr->flags & 1) ((void (*)(void))oep)();
|
||||
pExit(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
# 从源码重建引导 blob
|
||||
# 用法: ./build-blob.sh <bootstrap.c> [x64|x86] [输出文件]
|
||||
# 例: ./build-blob.sh bootstrap5.c x64 blob64.bin
|
||||
# 详见 ../README.md「构建引导 blob」——重编产物与仓库里的预编译 blob 行为不一致,替换前务必实测。
|
||||
set -euo pipefail
|
||||
|
||||
SRC=${1:?用法: $0 <bootstrap.c> [x64|x86] [out.bin]}
|
||||
ARCH=${2:-x64}
|
||||
OUT=${3:-blob64.bin}
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
DEFS=""
|
||||
if [ "$ARCH" = "x64" ]; then DEFS="-D_WIN64"; fi
|
||||
|
||||
TMP=$(mktemp -d)
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
gcc -c $DEFS -ffreestanding -fno-stack-protector -fno-asynchronous-unwind-tables \
|
||||
-mno-stack-arg-probe "$SRC" -o "$TMP/blob.o"
|
||||
|
||||
# 别用 ld --oformat=binary(会报 cannot perform PE operations on non PE output file),
|
||||
# 走链接脚本把 .text/.rdata/.data 合成单节再 objcopy 提取
|
||||
ld -e blob_main -nostdlib -T "$DIR/blob.ld" "$TMP/blob.o" -o "$TMP/blob.elf" 2>/dev/null
|
||||
|
||||
objcopy -O binary -j .blob "$TMP/blob.elf" "$OUT"
|
||||
|
||||
echo "生成 $OUT($(stat -c%s "$OUT") 字节,arch=$ARCH)"
|
||||
echo "注意:本机 gcc 重编的 blob 与 assets/ 里的预编译 blob 行为不同(详见 ../README.md),"
|
||||
echo " 替换资产前先把「单层 / 双层 / 篡改 .vfy & PE 头」四类用例实测一遍。"
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# 交叉编译 Direct2D 界面壳 → shell64.dll / shell32.dll
|
||||
# 用法: ./build-classic.sh [源码] (默认 shell6.cpp)
|
||||
# 依赖: x86_64-w64-mingw32-g++ / i686-w64-mingw32-g++
|
||||
# 注意: 必须带 -Wl,--kill-at,否则导出名带 @N 后缀,GetProcAddress("VerifyMain") 取不到
|
||||
set -euo pipefail
|
||||
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
SRC=${1:-$DIR/shell6.cpp}
|
||||
OUTDIR=${2:-$DIR/out}
|
||||
mkdir -p "$OUTDIR"
|
||||
|
||||
COMMON=(-std=c++17 -O2 -shared -s -DUNICODE -D_UNICODE -D_WIN32_WINNT=0x0601 -D_WIN32_LEAN_AND_MEAN)
|
||||
# 导入表按实测产物取:ADVAPI32/bcrypt/d2d1/DWrite/GDI32/KERNEL32/msvcrt/ole32/USER32/WINHTTP
|
||||
LIBS=(-static -ladvapi32 -lbcrypt -ld2d1 -ldwrite -lgdi32 -lole32 -luser32 -lwinhttp -Wl,--kill-at)
|
||||
|
||||
x86_64-w64-mingw32-g++ "${COMMON[@]}" -o "$OUTDIR/shell64.dll" "$SRC" "${LIBS[@]}"
|
||||
echo "生成 $OUTDIR/shell64.dll($(stat -c%s "$OUTDIR/shell64.dll") 字节)"
|
||||
|
||||
if command -v i686-w64-mingw32-g++ >/dev/null 2>&1; then
|
||||
i686-w64-mingw32-g++ "${COMMON[@]}" -o "$OUTDIR/shell32.dll" "$SRC" "${LIBS[@]}"
|
||||
echo "生成 $OUTDIR/shell32.dll($(stat -c%s "$OUTDIR/shell32.dll") 字节)"
|
||||
else
|
||||
echo "跳过 x86:未安装 i686-w64-mingw32-g++"
|
||||
fi
|
||||
|
||||
echo "产物是 DLL,加壳器会把它嵌进 .vfy 节;要更新资产请替换 assets/shell64.bin 并重新打壳验证。"
|
||||
echo "logf_ 的落盘日志补丁见 ../README.md(改完源码重编会自动带上/不带日志,先确认要哪种)。"
|
||||
@@ -0,0 +1,832 @@
|
||||
// vfy shell —— VS 2026 暗黑风(Direct2D + DirectWrite)
|
||||
// 两种形态:独立 exe(内嵌加密载荷)/ 注入用 DLL(导出 VerifyMain,验证后跳原入口 OEP)
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <d2d1.h>
|
||||
#include <d2d1helper.h>
|
||||
#include <dwrite.h>
|
||||
#include <winhttp.h>
|
||||
#include <bcrypt.h>
|
||||
#include <shellapi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#define CARD_W 420.0f
|
||||
#define CARD_H 404.0f
|
||||
#define PAD 20.0f
|
||||
#define D2D_VER 1
|
||||
|
||||
static float g_S = 1.0f;
|
||||
static inline float L(float v) { return v * g_S; }
|
||||
|
||||
/* VS 2026 dark */
|
||||
static D2D1_COLOR_F C_CARD, C_BAR, C_BORDER, C_INPUT, C_INPUT_BD, C_FOCUS, C_TXT, C_TXT2,
|
||||
C_ACCENT, C_ACCENT_H, C_ACCENT_P, C_LINK, C_RED, C_GREEN, C_WHITE, C_TAG;
|
||||
|
||||
static ID2D1Factory *g_d2d = NULL;
|
||||
static IDWriteFactory *g_dw = NULL;
|
||||
static ID2D1DCRenderTarget *g_rt = NULL;
|
||||
static const wchar_t *g_famCJK = L"Microsoft YaHei UI";
|
||||
static const wchar_t *g_famLat = L"Segoe UI";
|
||||
|
||||
static HWND g_hwnd, g_hUser, g_hPass;
|
||||
static HFONT g_fontEdit = NULL;
|
||||
static HBRUSH g_brInput = NULL;
|
||||
static int g_focus = 0;
|
||||
static int g_hBtn, g_hChk, g_hTag, g_hEye, g_hClose, g_hMin, g_hLink;
|
||||
static int g_pressBtn, g_checked, g_showPass;
|
||||
static volatile LONG g_busy = 0;
|
||||
static int g_statusKind = 0;
|
||||
static wchar_t g_status[256] = L"\x5C31\x7EEA";
|
||||
static int g_tick = 0;
|
||||
static int g_done = 0;
|
||||
|
||||
static const RECT LR_CLOSE = {420 - 44, 0, 420, 32};
|
||||
static const RECT LR_MIN = {420 - 88, 0, 420 - 44, 32};
|
||||
static const RECT LR_USER = {20, 124, 400, 156};
|
||||
static const RECT LR_PASS = {20, 186, 400, 218};
|
||||
static const RECT LR_EYE = {368, 190, 392, 214};
|
||||
static const RECT LR_CHK = {20, 233, 34, 247};
|
||||
static const RECT LR_REM = {20, 228, 150, 252};
|
||||
static const RECT LR_TAG = {244, 228, 400, 252};
|
||||
static const RECT LR_BTN = {20, 264, 400, 298};
|
||||
static const RECT LR_L1 = {20, 316, 116, 338};
|
||||
static const RECT LR_L2 = {128, 316, 224, 338};
|
||||
static const RECT LR_L3 = {236, 316, 332, 338};
|
||||
|
||||
/* ---------- 载荷(仅 exe 形态使用) ---------- */
|
||||
static unsigned char *g_file = NULL;
|
||||
static DWORD g_fileSize = 0;
|
||||
static const unsigned char *g_payload = NULL;
|
||||
static DWORD g_payloadSize = 0;
|
||||
static unsigned char g_nonce[12], g_tag[16];
|
||||
static char g_cfg[4096], g_api[512];
|
||||
static char g_name[128] = "\xE6\xBC\x94\xE7\xA4\xBA\xE7\xA8\x8B\xE5\xBA\x8F";
|
||||
static char g_device[64] = "A1B2-3C4D";
|
||||
static char g_auto[128], g_offline[64];
|
||||
static const char TAIL_MAGIC[8] = {'V', 'F', 'Y', 'D', '1', 0, 0, 0};
|
||||
|
||||
static void logf_(const char *fmt, ...) {
|
||||
char tmp[MAX_PATH] = {0}; GetTempPathA(MAX_PATH, tmp);
|
||||
char path[MAX_PATH]; snprintf(path, sizeof(path), "%svfy_debug.log", tmp);
|
||||
FILE *f = fopen(path, "a");
|
||||
if (!f) return;
|
||||
va_list ap; va_start(ap, fmt); vfprintf(f, fmt, ap); va_end(ap);
|
||||
fputc('\n', f); fclose(f);
|
||||
}
|
||||
|
||||
static int json_str(const char *src, const char *key, char *out, int cap) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return 0;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return 0;
|
||||
p = strchr(p, '"');
|
||||
if (!p) return 0;
|
||||
p++;
|
||||
int i = 0;
|
||||
while (*p && *p != '"' && i < cap - 1) out[i++] = *p++;
|
||||
out[i] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void load_cfg(const char *json) {
|
||||
snprintf(g_cfg, sizeof(g_cfg), "%s", json ? json : "");
|
||||
json_str(g_cfg, "api", g_api, sizeof(g_api));
|
||||
json_str(g_cfg, "name", g_name, sizeof(g_name));
|
||||
json_str(g_cfg, "device", g_device, sizeof(g_device));
|
||||
json_str(g_cfg, "offline_pass", g_offline, sizeof(g_offline));
|
||||
}
|
||||
|
||||
/* ---------- 文本:CJK/拉丁分段 ---------- */
|
||||
static int is_cjk(wchar_t c) {
|
||||
return (c >= 0x2E80 && c <= 0x9FFF) || (c >= 0xF900 && c <= 0xFAFF) ||
|
||||
(c >= 0xFF00 && c <= 0xFF65) || (c >= 0x3000 && c <= 0x303F);
|
||||
}
|
||||
|
||||
static void draw_run(const wchar_t *s, int n, const wchar_t *fam, float x, float y, float h,
|
||||
float px, D2D1_COLOR_F c, int bold) {
|
||||
IDWriteTextFormat *f = NULL;
|
||||
if (FAILED(g_dw->CreateTextFormat(fam, NULL, bold ? DWRITE_FONT_WEIGHT_SEMI_BOLD : DWRITE_FONT_WEIGHT_NORMAL,
|
||||
DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, L(px), L"zh-cn", &f)))
|
||||
return;
|
||||
f->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
|
||||
f->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
|
||||
f->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
|
||||
wchar_t sub[512];
|
||||
int k = n > 511 ? 511 : n;
|
||||
for (int i = 0; i < k; i++) sub[i] = (s[i] == 0x20) ? (wchar_t)0x00A0 : s[i];
|
||||
sub[k] = 0;
|
||||
IDWriteTextLayout *lay = NULL;
|
||||
if (FAILED(g_dw->CreateTextLayout(sub, (UINT32)k, f, 4000.0f, L(h), &lay))) { f->Release(); return; }
|
||||
ID2D1SolidColorBrush *b = NULL;
|
||||
if (SUCCEEDED(g_rt->CreateSolidColorBrush(c, &b))) {
|
||||
g_rt->DrawTextLayout(D2D1::Point2F(L(x), L(y)), lay, b, D2D1_DRAW_TEXT_OPTIONS_NONE);
|
||||
b->Release();
|
||||
}
|
||||
lay->Release();
|
||||
f->Release();
|
||||
}
|
||||
|
||||
static float run_width(const wchar_t *s, int n, const wchar_t *fam, float px, int bold) {
|
||||
IDWriteTextFormat *f = NULL;
|
||||
if (FAILED(g_dw->CreateTextFormat(fam, NULL, bold ? DWRITE_FONT_WEIGHT_SEMI_BOLD : DWRITE_FONT_WEIGHT_NORMAL,
|
||||
DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, L(px), L"zh-cn", &f)))
|
||||
return 0;
|
||||
f->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
|
||||
IDWriteTextLayout *lay = NULL;
|
||||
float w = 0;
|
||||
if (SUCCEEDED(g_dw->CreateTextLayout(s, (UINT32)n, f, 4000.0f, L(px * 2), &lay))) {
|
||||
DWRITE_TEXT_METRICS m;
|
||||
if (SUCCEEDED(lay->GetMetrics(&m)) && m.width > 0.5f) w = m.width / g_S - 0.6f;
|
||||
lay->Release();
|
||||
}
|
||||
if (w <= 0.5f)
|
||||
for (int i = 0; i < n; i++)
|
||||
w += is_cjk(s[i]) ? px : (s[i] == 0x20 ? px * 0.28f : px * 0.56f);
|
||||
f->Release();
|
||||
return w;
|
||||
}
|
||||
|
||||
static void textL(const wchar_t *s, float x, float y, float w, float h, float px,
|
||||
D2D1_COLOR_F c, int bold, int align) {
|
||||
int len = (int)wcslen(s);
|
||||
if (!len) return;
|
||||
int starts[64], lens[64], fams[64], cnt = 0, i = 0;
|
||||
while (i < len && cnt < 64) {
|
||||
int cjk = is_cjk(s[i]);
|
||||
int j = i;
|
||||
while (j < len && is_cjk(s[j]) == cjk) j++;
|
||||
starts[cnt] = i; lens[cnt] = j - i; fams[cnt] = cjk; cnt++;
|
||||
i = j;
|
||||
}
|
||||
float total = 0;
|
||||
for (int k = 0; k < cnt; k++) total += run_width(s + starts[k], lens[k], fams[k] ? g_famCJK : g_famLat, px, bold);
|
||||
float ox = x;
|
||||
if (align == 1) ox = x + (w - total) * 0.5f;
|
||||
else if (align == 2) ox = x + w - total;
|
||||
for (int k = 0; k < cnt; k++) {
|
||||
const wchar_t *fam = fams[k] ? g_famCJK : g_famLat;
|
||||
draw_run(s + starts[k], lens[k], fam, ox, y, h, px, c, bold);
|
||||
ox += run_width(s + starts[k], lens[k], fam, px, bold);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 形状 ---------- */
|
||||
static void fillRound(float x, float y, float w, float h, float r, D2D1_COLOR_F c) {
|
||||
ID2D1SolidColorBrush *b = NULL;
|
||||
if (FAILED(g_rt->CreateSolidColorBrush(c, &b))) return;
|
||||
g_rt->FillRoundedRectangle(D2D1::RoundedRect(D2D1::RectF(L(x), L(y), L(x + w), L(y + h)), L(r), L(r)), b);
|
||||
b->Release();
|
||||
}
|
||||
|
||||
static void strokeRound(float x, float y, float w, float h, float r, float wd, D2D1_COLOR_F c) {
|
||||
ID2D1SolidColorBrush *b = NULL;
|
||||
if (FAILED(g_rt->CreateSolidColorBrush(c, &b))) return;
|
||||
g_rt->DrawRoundedRectangle(D2D1::RoundedRect(D2D1::RectF(L(x), L(y), L(x + w), L(y + h)), L(r), L(r)), b, L(wd));
|
||||
b->Release();
|
||||
}
|
||||
|
||||
static void fillRect(float x, float y, float w, float h, D2D1_COLOR_F c) {
|
||||
ID2D1SolidColorBrush *b = NULL;
|
||||
if (FAILED(g_rt->CreateSolidColorBrush(c, &b))) return;
|
||||
g_rt->FillRectangle(D2D1::RectF(L(x), L(y), L(x + w), L(y + h)), b);
|
||||
b->Release();
|
||||
}
|
||||
|
||||
static void line(float x1, float y1, float x2, float y2, float wd, D2D1_COLOR_F c) {
|
||||
ID2D1SolidColorBrush *b = NULL;
|
||||
if (FAILED(g_rt->CreateSolidColorBrush(c, &b))) return;
|
||||
g_rt->DrawLine(D2D1::Point2F(L(x1), L(y1)), D2D1::Point2F(L(x2), L(y2)), b, L(wd));
|
||||
b->Release();
|
||||
}
|
||||
|
||||
static D2D1_COLOR_F status_color(void) {
|
||||
return g_statusKind == 1 ? C_GREEN : (g_statusKind == 2 ? C_RED : C_TXT2);
|
||||
}
|
||||
|
||||
/* ---------- 画面 ---------- */
|
||||
static void paint(void) {
|
||||
for (int i = 14; i >= 1; i--)
|
||||
fillRound(PAD - i, PAD - i + 2 + i / 8.0f, CARD_W + i * 2, CARD_H + i * 2, 6 + i,
|
||||
D2D1::ColorF(0, 0, 0, 0.02f + (15 - i) * 0.006f));
|
||||
fillRound(PAD, PAD, CARD_W, CARD_H, 6, C_CARD);
|
||||
strokeRound(PAD, PAD, CARD_W, CARD_H, 6, 1.0f, C_BORDER);
|
||||
|
||||
g_rt->SetTransform(D2D1::Matrix3x2F::Translation(L(PAD), L(PAD)));
|
||||
|
||||
/* 标题栏 */
|
||||
fillRound(0, 0, CARD_W, 32 + 6, 6, C_BAR);
|
||||
fillRect(0, 32, CARD_W, 6, C_CARD);
|
||||
fillRect(0, 31.6f, CARD_W, 0.6f, C_BORDER);
|
||||
|
||||
if (g_hClose) fillRect(LR_CLOSE.left, 0, 44, 32, D2D1::ColorF(0.91f, 0.07f, 0.14f, 1));
|
||||
else if (g_hMin) fillRect(LR_MIN.left, 0, 44, 32, D2D1::ColorF(1, 1, 1, 0.07f));
|
||||
{
|
||||
D2D1_COLOR_F ic = C_TXT;
|
||||
float cx = (LR_CLOSE.left + LR_CLOSE.right) / 2.0f, cy = 16;
|
||||
line(cx - 4.5f, cy - 4.5f, cx + 4.5f, cy + 4.5f, 1.0f, ic);
|
||||
line(cx + 4.5f, cy - 4.5f, cx - 4.5f, cy + 4.5f, 1.0f, ic);
|
||||
float mx = (LR_MIN.left + LR_MIN.right) / 2.0f;
|
||||
line(mx - 4.5f, cy, mx + 4.5f, cy, 1.0f, ic);
|
||||
}
|
||||
fillRound(12, 8, 16, 16, 3, C_ACCENT);
|
||||
{
|
||||
wchar_t t[256] = {0};
|
||||
MultiByteToWideChar(CP_UTF8, 0, g_name, -1, t, 256);
|
||||
textL(t, 36, 0, 260, 32, 12, C_TXT, 0, 0);
|
||||
}
|
||||
|
||||
/* 标题区 */
|
||||
textL(L"\x767B\x5F55\x4EE5\x7EE7\x7EED", 20, 46, 300, 26, 15, C_TXT, 1, 0);
|
||||
textL(L"\x8BF7\x4F7F\x7528\x8D26\x53F7\x6216\x5361\x5BC6\x767B\x5F55", 20, 72, 320, 16, 11, C_TXT2, 0, 0);
|
||||
|
||||
/* 账号 */
|
||||
textL(L"\x8D26\x53F7", 20, 102, 100, 16, 11, C_TXT2, 0, 0);
|
||||
fillRound(20, 124, 380, 32, 3, C_INPUT);
|
||||
strokeRound(20, 124, 380, 32, 3, 1.0f, g_focus == 1 ? C_FOCUS : C_INPUT_BD);
|
||||
if (g_focus == 1) strokeRound(21.5f, 125.5f, 377, 29, 2.4f, 1.0f, C_FOCUS);
|
||||
if (GetWindowTextLengthW(g_hUser) == 0 && g_focus != 1)
|
||||
textL(L"\x8BF7\x8F93\x5165\x8D26\x53F7", 32, 124, 340, 32, 12, D2D1::ColorF(0.52f, 0.52f, 0.55f, 1), 0, 0);
|
||||
|
||||
/* 密码 */
|
||||
textL(L"\x5BC6\x7801", 20, 164, 100, 16, 11, C_TXT2, 0, 0);
|
||||
fillRound(20, 186, 380, 32, 3, C_INPUT);
|
||||
strokeRound(20, 186, 380, 32, 3, 1.0f, g_focus == 2 ? C_FOCUS : C_INPUT_BD);
|
||||
if (g_focus == 2) strokeRound(21.5f, 187.5f, 377, 29, 2.4f, 1.0f, C_FOCUS);
|
||||
if (GetWindowTextLengthW(g_hPass) == 0 && g_focus != 2)
|
||||
textL(L"\x8BF7\x8F93\x5165\x5BC6\x7801", 32, 186, 320, 32, 12, D2D1::ColorF(0.52f, 0.52f, 0.55f, 1), 0, 0);
|
||||
{
|
||||
D2D1_COLOR_F ec = g_hEye ? C_FOCUS : D2D1::ColorF(0.6f, 0.6f, 0.63f, 1);
|
||||
ID2D1SolidColorBrush *b = NULL;
|
||||
if (SUCCEEDED(g_rt->CreateSolidColorBrush(ec, &b))) {
|
||||
g_rt->DrawEllipse(D2D1::Ellipse(D2D1::Point2F(L(376), L(202)), L(8.5f), L(5.5f)), b, L(1.0f));
|
||||
if (g_showPass) line(368, 210, 384, 194, 1.0f, ec);
|
||||
else {
|
||||
ID2D1SolidColorBrush *pb = NULL;
|
||||
if (SUCCEEDED(g_rt->CreateSolidColorBrush(ec, &pb))) {
|
||||
g_rt->FillEllipse(D2D1::Ellipse(D2D1::Point2F(L(376), L(202)), L(2.4f), L(2.4f)), pb);
|
||||
pb->Release();
|
||||
}
|
||||
}
|
||||
b->Release();
|
||||
}
|
||||
}
|
||||
|
||||
/* 记住账号 */
|
||||
fillRound(20, 233, 14, 14, 2, g_checked ? C_FOCUS : C_INPUT);
|
||||
strokeRound(20, 233, 14, 14, 2, 1.0f, g_checked ? C_FOCUS : (g_hChk ? C_TXT2 : C_INPUT_BD));
|
||||
if (g_checked) {
|
||||
line(23.2f, 240.2f, 25.6f, 242.8f, 1.4f, C_WHITE);
|
||||
line(25.6f, 242.8f, 31.0f, 236.8f, 1.4f, C_WHITE);
|
||||
}
|
||||
textL(L"\x8BB0\x4F4F\x8D26\x53F7", 40, 233, 100, 14, 11, C_TXT2, 0, 0);
|
||||
|
||||
/* 设备码(VS 标签样式:小圆角 + 细边) */
|
||||
fillRound(244, 228, 156, 24, 2, C_TAG);
|
||||
strokeRound(244, 228, 156, 24, 2, 1.0f, C_INPUT_BD);
|
||||
{
|
||||
wchar_t tg[160], dev[64] = {0};
|
||||
MultiByteToWideChar(CP_UTF8, 0, g_device, -1, dev, 64);
|
||||
swprintf(tg, 160, L"\x8BBE\x5907 %ls", dev);
|
||||
textL(tg, 244, 228, 156, 24, 10.5f, C_TXT2, 0, 1);
|
||||
}
|
||||
|
||||
/* 主按钮 */
|
||||
if (g_busy) {
|
||||
fillRound(20, 264, 380, 34, 3, D2D1::ColorF(0.22f, 0.22f, 0.24f, 1));
|
||||
wchar_t d[16] = L"\x9A8C\x8BC1\x4E2D";
|
||||
int k = g_tick % 4;
|
||||
for (int i = 0; i < k; i++) d[3 + i] = L'.';
|
||||
d[3 + k] = 0;
|
||||
textL(d, 20, 264, 380, 34, 12.5f, D2D1::ColorF(0.62f, 0.62f, 0.65f, 1), 0, 1);
|
||||
} else {
|
||||
fillRound(20, 264, 380, 34, 3, g_pressBtn ? C_ACCENT_P : (g_hBtn ? C_ACCENT_H : C_ACCENT));
|
||||
textL(L"\x767B\x5F55", 20, 264, 380, 34, 12.5f, C_WHITE, 0, 1);
|
||||
}
|
||||
|
||||
/* 链接 */
|
||||
textL(L"\x6CE8\x518C\x8D26\x53F7", 20, 316, 96, 22, 11, g_hLink == 1 ? C_LINK : C_TXT2, 0, 0);
|
||||
textL(L"\x5361\x5BC6\x5145\x503C", 128, 316, 96, 22, 11, g_hLink == 2 ? C_LINK : C_TXT2, 0, 0);
|
||||
textL(L"\x5FD8\x8BB0\x5BC6\x7801", 236, 316, 96, 22, 11, g_hLink == 3 ? C_LINK : C_TXT2, 0, 0);
|
||||
|
||||
/* 状态 + 页脚 */
|
||||
fillRound(20, 356, 5, 5, 2.5f, status_color());
|
||||
textL(g_status, 32, 348, 340, 20, 11, status_color(), 0, 0);
|
||||
line(20, 374, 400, 374, 0.6f, C_BORDER);
|
||||
textL(L"v1.0.0 \xB7 \x53EF\x4FE1\x8BBE\x5907\x7ED1\x5B9A \xB7 \x5F02\x5E38\x767B\x5F55\x81EA\x52A8\x9501\x5B9A",
|
||||
20, 380, 380, 16, 10, D2D1::ColorF(0.55f, 0.55f, 0.58f, 1), 0, 0);
|
||||
|
||||
g_rt->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
}
|
||||
|
||||
/* ---------- 离屏渲染 + 提交 ---------- */
|
||||
static void render(void) {
|
||||
if (!g_rt || !g_hwnd) return;
|
||||
int w = (int)((CARD_W + PAD * 2) * g_S), h = (int)((CARD_H + PAD * 2) * g_S);
|
||||
HDC screen = GetDC(NULL);
|
||||
HDC mem = CreateCompatibleDC(screen);
|
||||
BITMAPINFO bi; ZeroMemory(&bi, sizeof(bi));
|
||||
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bi.bmiHeader.biWidth = w;
|
||||
bi.bmiHeader.biHeight = -h;
|
||||
bi.bmiHeader.biPlanes = 1;
|
||||
bi.bmiHeader.biBitCount = 32;
|
||||
bi.bmiHeader.biCompression = BI_RGB;
|
||||
void *bits = NULL;
|
||||
HBITMAP dib = CreateDIBSection(screen, &bi, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
if (!dib) { DeleteDC(mem); ReleaseDC(NULL, screen); return; }
|
||||
HGDIOBJ old = SelectObject(mem, dib);
|
||||
memset(bits, 0, (size_t)w * h * 4);
|
||||
RECT rc = {0, 0, w, h};
|
||||
g_rt->BindDC(mem, &rc);
|
||||
g_rt->SetDpi(96.0f, 96.0f);
|
||||
g_rt->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
||||
g_rt->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
|
||||
g_rt->BeginDraw();
|
||||
g_rt->Clear(D2D1::ColorF(0, 0, 0, 0));
|
||||
paint();
|
||||
HRESULT hr = g_rt->EndDraw();
|
||||
if (FAILED(hr)) logf_("EndDraw hr=0x%lx", (unsigned long)hr);
|
||||
RECT wr; GetWindowRect(g_hwnd, &wr);
|
||||
POINT dst = {wr.left, wr.top}, src = {0, 0};
|
||||
SIZE sz = {w, h};
|
||||
BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
|
||||
UpdateLayeredWindow(g_hwnd, screen, &dst, &sz, mem, &src, 0, &bf, ULW_ALPHA);
|
||||
SelectObject(mem, old);
|
||||
DeleteObject(dib);
|
||||
DeleteDC(mem);
|
||||
ReleaseDC(NULL, screen);
|
||||
}
|
||||
|
||||
/* ---------- 字体自检 ---------- */
|
||||
static int font_cov(const wchar_t *fam, const wchar_t *sample) {
|
||||
const int W = 200, H = 40;
|
||||
HDC screen = GetDC(NULL);
|
||||
HDC mem = CreateCompatibleDC(screen);
|
||||
BITMAPINFO bi; ZeroMemory(&bi, sizeof(bi));
|
||||
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
bi.bmiHeader.biWidth = W; bi.bmiHeader.biHeight = -H;
|
||||
bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; bi.bmiHeader.biCompression = BI_RGB;
|
||||
void *bits = NULL;
|
||||
HBITMAP dib = CreateDIBSection(screen, &bi, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
if (!dib) { DeleteDC(mem); ReleaseDC(NULL, screen); return 0; }
|
||||
HGDIOBJ old = SelectObject(mem, dib);
|
||||
memset(bits, 0, W * H * 4);
|
||||
RECT rc = {0, 0, W, H};
|
||||
g_rt->BindDC(mem, &rc);
|
||||
g_rt->SetDpi(96.0f, 96.0f);
|
||||
g_rt->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
|
||||
g_rt->BeginDraw();
|
||||
g_rt->Clear(D2D1::ColorF(0, 0, 0, 0));
|
||||
draw_run(sample, (int)wcslen(sample), fam, 4, 2, 30, 15, D2D1::ColorF(1, 1, 1, 1), 0);
|
||||
g_rt->EndDraw();
|
||||
int n = 0;
|
||||
unsigned char *p = (unsigned char *)bits;
|
||||
for (int i = 0; i < W * H; i++) if (p[i * 4 + 3] > 16) n++;
|
||||
SelectObject(mem, old);
|
||||
DeleteObject(dib);
|
||||
DeleteDC(mem);
|
||||
ReleaseDC(NULL, screen);
|
||||
return n;
|
||||
}
|
||||
|
||||
static void detect_fonts(void) {
|
||||
const wchar_t *cjk[] = {L"Microsoft YaHei UI", L"Microsoft YaHei", L"WenQuanYi Micro Hei", L"Noto Sans CJK SC", L"DejaVu Sans"};
|
||||
const wchar_t *lat[] = {L"Segoe UI", L"Microsoft YaHei UI", L"DejaVu Sans", L"Arial", L"Tahoma"};
|
||||
int best = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int c = font_cov(cjk[i], L"\x8BBE\x5907\x8D26\x53F7");
|
||||
if (c > best) { best = c; g_famCJK = cjk[i]; }
|
||||
}
|
||||
best = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int c = font_cov(lat[i], L"A1B2-3C4D v1.0.0");
|
||||
if (c > best) { best = c; g_famLat = lat[i]; }
|
||||
}
|
||||
logf_("fonts: cjk/ lat ok");
|
||||
}
|
||||
|
||||
/* ---------- 鉴权 + 载荷 ---------- */
|
||||
static int aes_decrypt(const unsigned char *in, DWORD inLen, unsigned char **out, DWORD *outLen) {
|
||||
static const char secret[] = "vfy-demo-secret-2026";
|
||||
BCRYPT_ALG_HANDLE hAlg = NULL; BCRYPT_HASH_HANDLE hHash = NULL; BCRYPT_KEY_HANDLE hKey = NULL;
|
||||
unsigned char key[32]; int ok = 0;
|
||||
unsigned char *buf = NULL; ULONG got = 0; NTSTATUS st = 0;
|
||||
BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO info;
|
||||
if (BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_SHA256_ALGORITHM, NULL, 0) != 0) return 0;
|
||||
if (BCryptCreateHash(hAlg, &hHash, NULL, 0, NULL, 0, 0) != 0) goto done;
|
||||
BCryptHashData(hHash, (PUCHAR)secret, (ULONG)strlen(secret), 0);
|
||||
BCryptFinishHash(hHash, key, 32, 0);
|
||||
BCryptCloseAlgorithmProvider(hAlg, 0); hAlg = NULL;
|
||||
if (BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_AES_ALGORITHM, NULL, 0) != 0) goto done;
|
||||
if (BCryptSetProperty(hAlg, BCRYPT_CHAINING_MODE, (PUCHAR)BCRYPT_CHAIN_MODE_GCM, sizeof(BCRYPT_CHAIN_MODE_GCM), 0) != 0) goto done;
|
||||
if (BCryptGenerateSymmetricKey(hAlg, &hKey, NULL, 0, key, 32, 0) != 0) goto done;
|
||||
BCRYPT_INIT_AUTH_MODE_INFO(info);
|
||||
info.pbNonce = g_nonce; info.cbNonce = 12; info.pbTag = g_tag; info.cbTag = 16;
|
||||
buf = (unsigned char *)malloc(inLen + 16);
|
||||
st = BCryptDecrypt(hKey, (PUCHAR)in, inLen, &info, NULL, 0, buf, inLen, &got, 0);
|
||||
logf_("bcrypt st=0x%lx len=%lu", (unsigned long)st, (unsigned long)got);
|
||||
if (st != 0) { free(buf); goto done; }
|
||||
*out = buf; *outLen = got; ok = 1;
|
||||
done:
|
||||
if (hKey) BCryptDestroyKey(hKey);
|
||||
if (hAlg) BCryptCloseAlgorithmProvider(hAlg, 0);
|
||||
if (hHash) BCryptDestroyHash(hHash);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int http_login(const char *user, const char *pass, char *msg, int cap) {
|
||||
wchar_t wHost[256], wPath[512];
|
||||
char host[256] = {0}, path[512] = {0};
|
||||
snprintf(path, sizeof(path), "%s", g_api);
|
||||
char *p = strstr(path, "://");
|
||||
if (!p) return 0;
|
||||
p += 3;
|
||||
char *slash = strchr(p, '/');
|
||||
if (slash) { *slash = 0; snprintf(path, sizeof(path), "%s", slash + 1); }
|
||||
snprintf(host, sizeof(host), "%s", p);
|
||||
unsigned short port = 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
MultiByteToWideChar(CP_UTF8, 0, host, -1, wHost, 256);
|
||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, wPath, 512);
|
||||
char body[512];
|
||||
snprintf(body, sizeof(body), "{\"user\":\"%s\",\"pass\":\"%s\",\"device\":\"%s\"}", user, pass, g_device);
|
||||
int ok = 0;
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/5.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) return 0;
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost, port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath, NULL, NULL, NULL, 0) : NULL;
|
||||
if (hR) {
|
||||
const wchar_t *hdr = L"Content-Type: application/json\r\n";
|
||||
WinHttpSendRequest(hR, hdr, (DWORD)-1L, body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[1024] = {0};
|
||||
DWORD cl = 0;
|
||||
if (WinHttpReadData(hR, resp, sizeof(resp) - 1, &cl)) resp[cl < sizeof(resp) ? cl : sizeof(resp) - 1] = 0;
|
||||
logf_("http resp=%.300s", resp);
|
||||
if (strstr(resp, "\"ok\":true")) ok = 1;
|
||||
json_str(resp, "msg", msg, cap);
|
||||
if (!ok && !msg[0]) snprintf(msg, cap, "\xE9\xAA\x8C\xE8\xAF\x81\xE5\xA4\xB1\xE8\xB4\xA5");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* exe 形态:解密内嵌载荷并启动 */
|
||||
static int launch_payload(void) {
|
||||
unsigned char *plain = NULL; DWORD plainLen = 0;
|
||||
if (!aes_decrypt(g_payload, g_payloadSize, &plain, &plainLen)) return 0;
|
||||
wchar_t tmp[MAX_PATH]; GetTempPathW(MAX_PATH, tmp);
|
||||
wchar_t dir[MAX_PATH], out[MAX_PATH];
|
||||
swprintf(dir, MAX_PATH, L"%lsvfy_demo_%lu", tmp, (unsigned long)GetCurrentProcessId());
|
||||
CreateDirectoryW(dir, NULL);
|
||||
swprintf(out, MAX_PATH, L"%ls\\app.exe", dir);
|
||||
HANDLE h = CreateFileW(out, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
|
||||
if (h == INVALID_HANDLE_VALUE) { free(plain); return 0; }
|
||||
DWORD w = 0; WriteFile(h, plain, plainLen, &w, NULL); CloseHandle(h);
|
||||
free(plain);
|
||||
STARTUPINFOW si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si);
|
||||
PROCESS_INFORMATION pi;
|
||||
if (!CreateProcessW(out, NULL, NULL, NULL, FALSE, 0, NULL, dir, &si, &pi)) return 0;
|
||||
logf_("child pid=%lu", (unsigned long)pi.dwProcessId);
|
||||
CloseHandle(pi.hThread); CloseHandle(pi.hProcess);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void set_status(int kind, const wchar_t *s) {
|
||||
g_statusKind = kind;
|
||||
wcsncpy(g_status, s, 255); g_status[255] = 0;
|
||||
InvalidateRect(g_hwnd, NULL, FALSE);
|
||||
}
|
||||
|
||||
static void set_status_u8(int kind, const char *u8) {
|
||||
wchar_t w[256] = {0};
|
||||
MultiByteToWideChar(CP_UTF8, 0, u8, -1, w, 256);
|
||||
set_status(kind, w);
|
||||
}
|
||||
|
||||
/* 验证通过后的动作 */
|
||||
typedef void (*PFN_OEP)(void);
|
||||
static PFN_OEP g_oep = NULL;
|
||||
|
||||
static void on_success(void) {
|
||||
if (g_oep) {
|
||||
logf_("calling original entry %p", (void *)g_oep);
|
||||
g_oep(); /* 原程序自己的入口,正常会自己退出 */
|
||||
ExitProcess(0);
|
||||
}
|
||||
if (launch_payload()) ExitProcess(0);
|
||||
set_status(2, L"\x542F\x52A8\x5931\x8D25");
|
||||
}
|
||||
|
||||
static DWORD WINAPI login_thread(LPVOID) {
|
||||
char user[128] = {0}, pass[128] = {0}, msg[256] = {0};
|
||||
GetWindowTextA(g_hUser, user, sizeof(user));
|
||||
GetWindowTextA(g_hPass, pass, sizeof(pass));
|
||||
if (!user[0]) { set_status(2, L"\x8BF7\x8F93\x5165\x8D26\x53F7"); g_busy = 0; return 0; }
|
||||
set_status_u8(0, "\xE9\xAA\x8C\xE8\xAF\x81\xE4\xB8\xAD");
|
||||
int passed = http_login(user, pass, msg, sizeof(msg));
|
||||
if (!passed && g_offline[0] && strcmp(pass, g_offline) == 0) { logf_("offline mode"); passed = 1; }
|
||||
if (passed) {
|
||||
set_status_u8(1, "\xE9\xAA\x8C\xE8\xAF\x81\xE9\x80\x9A\xE8\xBF\x87");
|
||||
Sleep(180);
|
||||
g_done = 1;
|
||||
on_success();
|
||||
return 0;
|
||||
}
|
||||
if (msg[0]) set_status_u8(2, msg);
|
||||
else set_status(2, L"\x9A8C\x8BC1\x5931\x8D25");
|
||||
g_busy = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void do_login(void) {
|
||||
if (InterlockedExchange(&g_busy, 1) != 0) return;
|
||||
InvalidateRect(g_hwnd, NULL, FALSE);
|
||||
CreateThread(NULL, 0, login_thread, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
static int in_rect(const RECT &r, int x, int y) { return x >= r.left && x < r.right && y >= r.top && y < r.bottom; }
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
|
||||
switch (m) {
|
||||
case WM_CREATE:
|
||||
g_hwnd = h;
|
||||
g_hUser = CreateWindowExW(0, L"EDIT", L"", WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL,
|
||||
(int)L(32), (int)L(125), (int)L(356), (int)L(30), h, (HMENU)201, NULL, NULL);
|
||||
g_hPass = CreateWindowExW(0, L"EDIT", L"", WS_CHILD | WS_VISIBLE | ES_PASSWORD | ES_AUTOHSCROLL,
|
||||
(int)L(32), (int)L(187), (int)L(324), (int)L(30), h, (HMENU)202, NULL, NULL);
|
||||
SendMessage(g_hUser, WM_SETFONT, (WPARAM)g_fontEdit, TRUE);
|
||||
SendMessage(g_hPass, WM_SETFONT, (WPARAM)g_fontEdit, TRUE);
|
||||
if (g_auto[0]) {
|
||||
SetWindowTextA(g_hUser, "demo");
|
||||
SetWindowTextA(g_hPass, g_auto);
|
||||
SetTimer(h, 1, 500, NULL);
|
||||
}
|
||||
SetTimer(h, 2, 200, NULL);
|
||||
return 0;
|
||||
case WM_TIMER:
|
||||
if (w == 1) { KillTimer(h, 1); do_login(); }
|
||||
if (w == 2) { g_tick++; if (g_busy) InvalidateRect(h, NULL, FALSE); }
|
||||
return 0;
|
||||
case WM_CTLCOLOREDIT: {
|
||||
HDC dc = (HDC)w;
|
||||
SetTextColor(dc, RGB(230, 230, 230));
|
||||
SetBkColor(dc, RGB(37, 37, 38));
|
||||
return (LRESULT)g_brInput;
|
||||
}
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
case WM_PAINT: {
|
||||
PAINTSTRUCT ps; BeginPaint(h, &ps);
|
||||
render();
|
||||
EndPaint(h, &ps);
|
||||
return 0;
|
||||
}
|
||||
case WM_NCHITTEST: {
|
||||
POINT pt = {GET_X_LPARAM(l), GET_Y_LPARAM(l)};
|
||||
ScreenToClient(h, &pt);
|
||||
int lx = (int)(pt.x / g_S) - (int)PAD, ly = (int)(pt.y / g_S) - (int)PAD;
|
||||
if (lx >= 0 && lx < (int)CARD_W && ly >= 0 && ly < 32 &&
|
||||
!in_rect(LR_CLOSE, lx, ly) && !in_rect(LR_MIN, lx, ly))
|
||||
return HTCAPTION;
|
||||
if (!(lx >= 0 && lx < (int)CARD_W && ly >= 0 && ly < (int)CARD_H))
|
||||
return HTCAPTION;
|
||||
break;
|
||||
}
|
||||
case WM_MOUSEMOVE: {
|
||||
int lx = (int)(GET_X_LPARAM(l) / g_S) - (int)PAD, ly = (int)(GET_Y_LPARAM(l) / g_S) - (int)PAD;
|
||||
int nb = in_rect(LR_BTN, lx, ly), nc = in_rect(LR_REM, lx, ly), nt = in_rect(LR_TAG, lx, ly);
|
||||
int ne = in_rect(LR_EYE, lx, ly), nx = in_rect(LR_CLOSE, lx, ly), nm = in_rect(LR_MIN, lx, ly);
|
||||
int nl = in_rect(LR_L1, lx, ly) ? 1 : (in_rect(LR_L2, lx, ly) ? 2 : (in_rect(LR_L3, lx, ly) ? 3 : 0));
|
||||
if (nb != g_hBtn || nc != g_hChk || nt != g_hTag || ne != g_hEye || nx != g_hClose || nm != g_hMin || nl != g_hLink) {
|
||||
g_hBtn = nb; g_hChk = nc; g_hTag = nt; g_hEye = ne; g_hClose = nx; g_hMin = nm; g_hLink = nl;
|
||||
InvalidateRect(h, NULL, FALSE);
|
||||
}
|
||||
TRACKMOUSEEVENT tme = {sizeof(tme), TME_LEAVE, h, 0};
|
||||
TrackMouseEvent(&tme);
|
||||
return 0;
|
||||
}
|
||||
case WM_MOUSELEAVE:
|
||||
g_hBtn = g_hChk = g_hTag = g_hEye = g_hClose = g_hMin = g_hLink = 0;
|
||||
InvalidateRect(h, NULL, FALSE);
|
||||
return 0;
|
||||
case WM_SETCURSOR: {
|
||||
POINT pt; GetCursorPos(&pt); ScreenToClient(h, &pt);
|
||||
int lx = (int)(pt.x / g_S) - (int)PAD, ly = (int)(pt.y / g_S) - (int)PAD;
|
||||
if (in_rect(LR_BTN, lx, ly) || in_rect(LR_REM, lx, ly) || in_rect(LR_TAG, lx, ly) ||
|
||||
in_rect(LR_EYE, lx, ly) || in_rect(LR_CLOSE, lx, ly) || in_rect(LR_MIN, lx, ly) ||
|
||||
in_rect(LR_L1, lx, ly) || in_rect(LR_L2, lx, ly) || in_rect(LR_L3, lx, ly)) {
|
||||
SetCursor(LoadCursor(NULL, IDC_HAND));
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_LBUTTONDOWN: {
|
||||
int lx = (int)(GET_X_LPARAM(l) / g_S) - (int)PAD, ly = (int)(GET_Y_LPARAM(l) / g_S) - (int)PAD;
|
||||
if (in_rect(LR_CLOSE, lx, ly)) { DestroyWindow(h); return 0; }
|
||||
if (in_rect(LR_MIN, lx, ly)) { ShowWindow(h, SW_MINIMIZE); return 0; }
|
||||
if (in_rect(LR_BTN, lx, ly)) { g_pressBtn = 1; InvalidateRect(h, NULL, FALSE); return 0; }
|
||||
if (in_rect(LR_REM, lx, ly)) { g_checked = !g_checked; InvalidateRect(h, NULL, FALSE); return 0; }
|
||||
if (in_rect(LR_EYE, lx, ly)) {
|
||||
g_showPass = !g_showPass;
|
||||
SendMessage(g_hPass, EM_SETPASSWORDCHAR, g_showPass ? 0 : 0x25CF, 0);
|
||||
InvalidateRect(h, NULL, FALSE);
|
||||
return 0;
|
||||
}
|
||||
if (in_rect(LR_TAG, lx, ly)) {
|
||||
if (OpenClipboard(h)) {
|
||||
EmptyClipboard();
|
||||
int n = MultiByteToWideChar(CP_UTF8, 0, g_device, -1, NULL, 0);
|
||||
HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, n * 2);
|
||||
if (hg) {
|
||||
wchar_t *d = (wchar_t *)GlobalLock(hg);
|
||||
MultiByteToWideChar(CP_UTF8, 0, g_device, -1, d, n);
|
||||
GlobalUnlock(hg);
|
||||
SetClipboardData(CF_UNICODETEXT, hg);
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
set_status(1, L"\x8BBE\x5907\x7801\x5DF2\x590D\x5236");
|
||||
return 0;
|
||||
}
|
||||
if (in_rect(LR_L1, lx, ly)) { set_status(0, L"\x6CE8\x518C\xFF1A\x6253\x5F00\x5B98\x7F51"); return 0; }
|
||||
if (in_rect(LR_L2, lx, ly)) { set_status(0, L"\x5361\x5BC6\x5145\x503C\xFF1A\x5F39\x51FA\x5145\x503C\x7A97"); return 0; }
|
||||
if (in_rect(LR_L3, lx, ly)) { set_status(0, L"\x5FD8\x8BB0\x5BC6\x7801\xFF1A\x8BF7\x8054\x7CFB\x5BA2\x670D"); return 0; }
|
||||
break;
|
||||
}
|
||||
case WM_LBUTTONUP: {
|
||||
int lx = (int)(GET_X_LPARAM(l) / g_S) - (int)PAD, ly = (int)(GET_Y_LPARAM(l) / g_S) - (int)PAD;
|
||||
if (g_pressBtn) {
|
||||
g_pressBtn = 0;
|
||||
InvalidateRect(h, NULL, FALSE);
|
||||
if (in_rect(LR_BTN, lx, ly)) do_login();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_COMMAND:
|
||||
if (HIWORD(w) == EN_SETFOCUS) { g_focus = (LOWORD(w) == 201) ? 1 : 2; InvalidateRect(h, NULL, FALSE); }
|
||||
else if (HIWORD(w) == EN_KILLFOCUS) { g_focus = 0; InvalidateRect(h, NULL, FALSE); }
|
||||
else if (HIWORD(w) == EN_CHANGE) InvalidateRect(h, NULL, FALSE);
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(h);
|
||||
return 0;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProcW(h, m, w, l);
|
||||
}
|
||||
|
||||
/* ---------- 启动壳(DLL 与 exe 共用) ---------- */
|
||||
static const wchar_t *CLS_NAME = L"VfyShellV5";
|
||||
|
||||
static void make_colors(void) {
|
||||
C_CARD = D2D1::ColorF(0.118f, 0.118f, 0.118f, 1); /* #1E1E1E */
|
||||
C_BAR = D2D1::ColorF(0.145f, 0.145f, 0.153f, 1); /* #252527 */
|
||||
C_BORDER = D2D1::ColorF(0.247f, 0.247f, 0.275f, 1); /* #3F3F46 */
|
||||
C_INPUT = D2D1::ColorF(0.145f, 0.145f, 0.149f, 1); /* #252526 */
|
||||
C_INPUT_BD = D2D1::ColorF(0.247f, 0.247f, 0.275f, 1);
|
||||
C_FOCUS = D2D1::ColorF(0.0f, 0.471f, 0.831f, 1); /* #0078D4 */
|
||||
C_TXT = D2D1::ColorF(0.902f, 0.902f, 0.902f, 1); /* #E6E6E6 */
|
||||
C_TXT2 = D2D1::ColorF(0.616f, 0.616f, 0.616f, 1); /* #9D9D9D */
|
||||
C_ACCENT = D2D1::ColorF(0.055f, 0.388f, 0.612f, 1); /* #0E639C */
|
||||
C_ACCENT_H = D2D1::ColorF(0.067f, 0.467f, 0.733f, 1); /* #1177BB */
|
||||
C_ACCENT_P = D2D1::ColorF(0.039f, 0.306f, 0.478f, 1); /* #0A4E7A */
|
||||
C_LINK = D2D1::ColorF(0.216f, 0.58f, 1.0f, 1); /* #3794FF */
|
||||
C_RED = D2D1::ColorF(0.96f, 0.35f, 0.35f, 1);
|
||||
C_GREEN = D2D1::ColorF(0.35f, 0.78f, 0.45f, 1);
|
||||
C_WHITE = D2D1::ColorF(1, 1, 1, 1);
|
||||
C_TAG = D2D1::ColorF(1, 1, 1, 0.05f);
|
||||
}
|
||||
|
||||
static int shell_main(PFN_OEP oep) {
|
||||
g_oep = oep;
|
||||
typedef BOOL(WINAPI * PFN_SetCtx)(HANDLE);
|
||||
PFN_SetCtx setCtx = (PFN_SetCtx)GetProcAddress(GetModuleHandleW(L"user32.dll"), "SetProcessDpiAwarenessContext");
|
||||
if (setCtx) setCtx((HANDLE)-4);
|
||||
HDC sdc = GetDC(NULL);
|
||||
g_S = GetDeviceCaps(sdc, LOGPIXELSX) / 96.0f;
|
||||
ReleaseDC(NULL, sdc);
|
||||
if (g_S < 1.0f) g_S = 1.0f;
|
||||
|
||||
make_colors();
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
||||
if (FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &g_d2d))) return -1;
|
||||
if (FAILED(DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), (IUnknown **)&g_dw))) return -1;
|
||||
|
||||
g_fontEdit = CreateFontW((int)-L(13), 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, 0, 0, CLEARTYPE_QUALITY, 0, L"Microsoft YaHei UI");
|
||||
g_brInput = CreateSolidBrush(RGB(37, 37, 38));
|
||||
|
||||
WNDCLASSEXW wc; ZeroMemory(&wc, sizeof(wc));
|
||||
wc.cbSize = sizeof(wc);
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = GetModuleHandleW(NULL);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.lpszClassName = CLS_NAME;
|
||||
wc.hbrBackground = NULL;
|
||||
RegisterClassExW(&wc);
|
||||
|
||||
int w = (int)((CARD_W + PAD * 2) * g_S), h = (int)((CARD_H + PAD * 2) * g_S);
|
||||
HWND hwnd = CreateWindowExW(WS_EX_LAYERED | WS_EX_APPWINDOW | WS_EX_TOPMOST, CLS_NAME, L"\x9A8C\x8BC1\x767B\x5F55",
|
||||
WS_POPUP, 0, 0, w, h, NULL, NULL, wc.hInstance, NULL);
|
||||
if (!hwnd) return -1;
|
||||
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, w, h, SWP_NOMOVE | SWP_NOACTIVATE);
|
||||
|
||||
D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
|
||||
D2D1_RENDER_TARGET_TYPE_DEFAULT,
|
||||
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED),
|
||||
0, 0, D2D1_RENDER_TARGET_USAGE_NONE, D2D1_FEATURE_LEVEL_DEFAULT);
|
||||
if (FAILED(g_d2d->CreateDCRenderTarget(&props, &g_rt))) return -1;
|
||||
|
||||
detect_fonts();
|
||||
|
||||
RECT wa; SystemParametersInfoW(SPI_GETWORKAREA, 0, &wa, 0);
|
||||
int sx = wa.left + ((wa.right - wa.left) - w) / 2;
|
||||
int sy = wa.top + ((wa.bottom - wa.top) - h) / 2;
|
||||
SetWindowPos(hwnd, HWND_TOPMOST, sx, sy, w, h, SWP_NOACTIVATE);
|
||||
render();
|
||||
ShowWindow(hwnd, SW_SHOW);
|
||||
SetForegroundWindow(hwnd);
|
||||
|
||||
MSG msg;
|
||||
while (GetMessageW(&msg, NULL, 0, 0)) {
|
||||
if (msg.message == WM_KEYDOWN && msg.wParam == VK_RETURN) { do_login(); continue; }
|
||||
if (msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) { ShowWindow(hwnd, SW_MINIMIZE); continue; }
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
return g_done ? 0 : -2;
|
||||
}
|
||||
|
||||
/* ================= 导出(DLL 形态) ================= */
|
||||
#ifdef SHELL_DLL
|
||||
extern "C" __declspec(dllexport) int VerifyMain(void *oep, const char *cfgjson) {
|
||||
load_cfg(cfgjson);
|
||||
return shell_main((PFN_OEP)oep);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int VerifyShellVersion(void) { return 5; }
|
||||
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID) {
|
||||
if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(h);
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
/* ================= 独立 exe 形态 ================= */
|
||||
static int read_self(void) {
|
||||
wchar_t path[MAX_PATH]; DWORD n = GetModuleFileNameW(NULL, path, MAX_PATH);
|
||||
if (!n) return 0;
|
||||
HANDLE h = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (h == INVALID_HANDLE_VALUE) return 0;
|
||||
LARGE_INTEGER sz; GetFileSizeEx(h, &sz);
|
||||
g_fileSize = (DWORD)sz.QuadPart;
|
||||
g_file = (unsigned char *)malloc(g_fileSize);
|
||||
DWORD got = 0;
|
||||
BOOL ok = ReadFile(h, g_file, g_fileSize, &got, NULL);
|
||||
CloseHandle(h);
|
||||
return ok && got == g_fileSize;
|
||||
}
|
||||
|
||||
static unsigned int le32(const unsigned char *p) {
|
||||
return (unsigned int)p[0] | ((unsigned int)p[1] << 8) | ((unsigned int)p[2] << 16) | ((unsigned int)p[3] << 24);
|
||||
}
|
||||
|
||||
static int parse_tail(void) {
|
||||
if (g_fileSize < 64) return 0;
|
||||
const unsigned char *t = g_file + g_fileSize - 64;
|
||||
if (memcmp(t, TAIL_MAGIC, 8) != 0) return 0;
|
||||
unsigned int poff = le32(t + 8), psize = le32(t + 12), coff = le32(t + 16), csize = le32(t + 20);
|
||||
memcpy(g_nonce, t + 24, 12);
|
||||
memcpy(g_tag, t + 36, 16);
|
||||
if (poff + psize > g_fileSize) return 0;
|
||||
g_payload = g_file + poff; g_payloadSize = psize;
|
||||
DWORD cs = csize < sizeof(g_cfg) - 1 ? csize : sizeof(g_cfg) - 1;
|
||||
if (coff + cs > g_fileSize) return 0;
|
||||
char buf[4096] = {0};
|
||||
memcpy(buf, g_file + coff, cs);
|
||||
buf[cs] = 0;
|
||||
load_cfg(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int) {
|
||||
if (!read_self() || !parse_tail()) {
|
||||
MessageBoxW(NULL, L"\x7A0B\x5E8F\x5DF2\x635F\x574F", L"\x9519\x8BEF", MB_ICONERROR);
|
||||
return 1;
|
||||
}
|
||||
int argc = 0;
|
||||
LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||
for (int i = 1; i + 1 < argc; i++)
|
||||
if (!wcscmp(argv[i], L"--auto"))
|
||||
WideCharToMultiByte(CP_UTF8, 0, argv[i + 1], -1, g_auto, sizeof(g_auto), NULL, NULL);
|
||||
int r = shell_main(NULL);
|
||||
return r == 0 ? 0 : 1;
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# 交叉编译 DuiLib 多皮肤壳 → shell64_dui.dll
|
||||
# 用法: DUILIB_DIR=/tmp/duilib ./build-duilib.sh [源码] (默认 shell9_v6.cpp)
|
||||
#
|
||||
# 前置:先编 libduilib.a(老 DuiLib,mingw)。必须做的改动:
|
||||
# - 排除 UIWebBrowser(ExDisp.h 不存在)/ UIRichEdit(goto 跨初始化)/ UIActiveX(CActiveXUI 未定义)
|
||||
# - UIlib.h 里注释掉这三个控件的 include,UIDlgBuilder.cpp 删对应 new CXxxUI 分支
|
||||
# - stb_image.c 单独按 C 编(header-only,否则 stbi_load_from_memory 未定义)
|
||||
# - UICombo::GetClassStyle 不要自递归;UIOption 的 goto Label_ForeImage 就地展开
|
||||
# - Utils::GetAt 返回 NULL;UIManager 取不到 HFONT 时返回 NULL
|
||||
# - 链接入口是 WinMain 时不要加 -municode(否则链接器找 wWinMain)
|
||||
set -euo pipefail
|
||||
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
SRC=${1:-$DIR/shell9_v6.cpp}
|
||||
DUILIB_DIR=${DUILIB_DIR:-/tmp/duilib}
|
||||
OUTDIR=${2:-$DIR/out}
|
||||
LIBDUILIB=${LIBDUILIB:-$DUILIB_DIR/libduilib.a}
|
||||
|
||||
[ -f "$LIBDUILIB" ] || { echo "缺少 $LIBDUILIB:先按上面注释里的步骤编 libduilib.a,或用 LIBDUILIB=... 指定"; exit 1; }
|
||||
mkdir -p "$OUTDIR"
|
||||
|
||||
# 导入表按实测产物取:ADVAPI32/bcrypt/COMCTL32/GDI32/gdiplus/KERNEL32/msvcrt/ole32/SHELL32/USER32/WINHTTP
|
||||
x86_64-w64-mingw32-g++ -std=c++17 -O2 -shared -s \
|
||||
-DUNICODE -D_UNICODE -D_WIN32_WINNT=0x0601 -D_WIN32_LEAN_AND_MEAN \
|
||||
-I"$DUILIB_DIR" -I"$DUILIB_DIR/DuiLib" -include "$DUILIB_DIR/shim/compat.h" -fpermissive -w \
|
||||
-o "$OUTDIR/shell64_dui.dll" "$SRC" "$LIBDUILIB" \
|
||||
-static -lcomctl32 -lgdiplus -lole32 -loleaut32 -luuid -lshlwapi -limm32 -lwinmm -lversion \
|
||||
-lgdi32 -luser32 -lwinhttp -ladvapi32 -lbcrypt -Wl,--kill-at
|
||||
|
||||
echo "生成 $OUTDIR/shell64_dui.dll($(stat -c%s "$OUTDIR/shell64_dui.dll") 字节)"
|
||||
echo "皮肤用 XML 字符串内嵌,theme 从壳 cfg 读;加壳任务侧用 shell_theme 选择,非法值请在校验层挡掉。"
|
||||
@@ -0,0 +1,403 @@
|
||||
// shell10.cpp —— NIM DuiLib 版 Windows 验证壳(多皮肤,含透明 PNG 皮肤)
|
||||
//
|
||||
// 对外接口与老壳完全一致:
|
||||
// int VerifyMain(void *oep, const char *cfgjson);
|
||||
// int VerifyShellVersion(void); // 10
|
||||
//
|
||||
// 皮肤分两类:
|
||||
// XML 皮肤(dark / light / industrial)—— 纯属性绘制,零图片
|
||||
// PNG 皮肤(nebula / onyx / aurora)—— 半透明玻璃卡片 + 发光 + 星尘,整窗按像素 alpha
|
||||
// 所有皮肤资源在启动时释放到 %TEMP%\vfytheme\<theme>\,进程结束自动清理。
|
||||
#include <windows.h>
|
||||
#include <winhttp.h>
|
||||
#include <shlobj.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "UIlib.h"
|
||||
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
|
||||
using namespace ui;
|
||||
|
||||
/* ============================== cfg ============================== */
|
||||
static char g_cfg[4096];
|
||||
static char g_api[512];
|
||||
static char g_name[128] = "\xE6\xBC\x94\xE7\xA4\xBA\xE7\xA8\x8B\xE5\xBA\x8F"; // 演示程序
|
||||
static char g_theme[32] = "dark";
|
||||
static char g_device[64] = "";
|
||||
static int g_deviceAuto = 1;
|
||||
|
||||
static int json_str(const char *src, const char *key, char *out, int cap) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return 0;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return 0;
|
||||
while (*p && *p != '"') p++;
|
||||
if (!*p) return 0;
|
||||
p++;
|
||||
int i = 0;
|
||||
while (*p && *p != '"' && i < cap - 1) out[i++] = *p++;
|
||||
out[i] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int json_int(const char *src, const char *key, int def) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return def;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return def;
|
||||
return atoi(p + 1);
|
||||
}
|
||||
|
||||
static void make_device_id(char *out, int cap); // 定义在后面
|
||||
|
||||
static void load_cfg(const char *json) {
|
||||
snprintf(g_cfg, sizeof(g_cfg), "%s", json ? json : "");
|
||||
json_str(g_cfg, "api", g_api, sizeof(g_api));
|
||||
json_str(g_cfg, "name", g_name, sizeof(g_name));
|
||||
g_deviceAuto = json_int(g_cfg, "device_auto", 1);
|
||||
if (!json_str(g_cfg, "device", g_device, sizeof(g_device)) || !g_device[0]) {
|
||||
if (g_deviceAuto) make_device_id(g_device, sizeof(g_device));
|
||||
else snprintf(g_device, sizeof(g_device), "%s", "UNKNOWN-DEVICE");
|
||||
}
|
||||
if (!json_str(g_cfg, "theme", g_theme, sizeof(g_theme))) snprintf(g_theme, sizeof(g_theme), "dark");
|
||||
}
|
||||
|
||||
|
||||
static void LOGF(const char *fmt, ...) {
|
||||
FILE *f = fopen("C:\\vfy10.log", "a");
|
||||
if (!f) return;
|
||||
va_list ap; va_start(ap, fmt); vfprintf(f, fmt, ap); va_end(ap);
|
||||
fputc('\n', f); fclose(f);
|
||||
}
|
||||
|
||||
/* ============================ 工具 ============================ */
|
||||
static std::wstring U8(const char *s) {
|
||||
if (!s) return L"";
|
||||
int n = ::MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
|
||||
std::wstring w(n > 0 ? n - 1 : 0, L'\0');
|
||||
if (n > 1) ::MultiByteToWideChar(CP_UTF8, 0, s, -1, &w[0], n);
|
||||
return w;
|
||||
}
|
||||
|
||||
static std::string W2U8(const std::wstring &w) {
|
||||
if (w.empty()) return std::string();
|
||||
int n = ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, NULL, 0, NULL, NULL);
|
||||
std::string s(n > 0 ? n - 1 : 0, '\0');
|
||||
if (n > 1) ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, &s[0], n, NULL, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
// MachineGuid + 系统盘卷序列号 → 稳定机器码
|
||||
static void make_device_id(char *out, int cap) {
|
||||
wchar_t guid[128] = {0};
|
||||
HKEY hk = NULL;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
|
||||
0, KEY_READ | KEY_WOW64_64KEY, &hk) == ERROR_SUCCESS) {
|
||||
DWORD sz = sizeof(guid) - sizeof(wchar_t), type = 0;
|
||||
RegQueryValueExW(hk, L"MachineGuid", NULL, &type, (LPBYTE)guid, &sz);
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
DWORD serial = 0;
|
||||
GetVolumeInformationW(L"C:\\", NULL, 0, &serial, NULL, NULL, NULL, 0);
|
||||
unsigned int h1 = 2166136261u, h2 = 3735928559u;
|
||||
for (const wchar_t *p = guid; *p; p++) {
|
||||
h1 = (h1 ^ (unsigned int)(*p & 0xFF)) * 16777619u;
|
||||
h2 = (h2 ^ (unsigned int)(*p >> 8)) * 16777619u;
|
||||
}
|
||||
h1 = (h1 ^ serial) * 16777619u;
|
||||
h2 = (h2 ^ (serial >> 16)) * 16777619u;
|
||||
snprintf(out, cap, "%04X-%04X-%04X", h1 & 0xFFFF, (h1 >> 16) & 0xFFFF, h2 & 0xFFFF);
|
||||
}
|
||||
|
||||
/* ======================= 皮肤资源(内嵌) ======================= */
|
||||
// 每个皮肤 = global.xml + <theme>.xml + 可选 PNG。启动时写到临时目录。
|
||||
#include "skins_data.h" // 由 gen_skins.py 生成:SkinFile / kSkins[] / kThemeList
|
||||
|
||||
static std::wstring g_skinRoot;
|
||||
|
||||
static bool EnsureDir(const std::wstring &p) {
|
||||
return ::CreateDirectoryW(p.c_str(), NULL) != 0 || ::GetLastError() == ERROR_ALREADY_EXISTS;
|
||||
}
|
||||
|
||||
// 递归建目录:%TEMP%\vfytheme\<theme> 这类多层路径要一层层来
|
||||
static void MakeDirs(const std::wstring &path) {
|
||||
std::wstring cur;
|
||||
for (size_t i = 0; i < path.size(); i++) {
|
||||
cur += path[i];
|
||||
if (path[i] == L'\\' && cur.size() > 3) EnsureDir(cur);
|
||||
}
|
||||
EnsureDir(path);
|
||||
}
|
||||
|
||||
static void WriteFileBytes(const std::wstring &path, const void *data, unsigned int size) {
|
||||
HANDLE h = ::CreateFileW(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (h == INVALID_HANDLE_VALUE) return;
|
||||
DWORD wrote = 0;
|
||||
::WriteFile(h, data, size, &wrote, NULL);
|
||||
::CloseHandle(h);
|
||||
}
|
||||
|
||||
// 把某套皮肤的 XML/PNG 释放到临时目录 vfytheme/<theme>/
|
||||
static bool StageSkin(const char *theme) {
|
||||
wchar_t tmp[MAX_PATH] = {0};
|
||||
DWORD n = ::GetTempPathW(MAX_PATH, tmp);
|
||||
std::wstring base;
|
||||
if (n == 0 || tmp[0] == 0) {
|
||||
// 没有 TEMP:退到 exe 所在目录
|
||||
wchar_t exe[MAX_PATH] = {0};
|
||||
::GetModuleFileNameW(NULL, exe, MAX_PATH);
|
||||
base.assign(exe);
|
||||
size_t pos = base.find_last_of(L"\\");
|
||||
base = (pos != std::wstring::npos) ? base.substr(0, pos + 1) : std::wstring(L".\\");
|
||||
} else {
|
||||
base.assign(tmp); // 已经带尾部反斜杠
|
||||
}
|
||||
g_skinRoot = base + L"vfytheme";
|
||||
MakeDirs(g_skinRoot);
|
||||
|
||||
std::wstring dir = g_skinRoot + L"\\" + U8(theme);
|
||||
MakeDirs(dir);
|
||||
|
||||
bool any = false;
|
||||
for (int i = 0; kSkins[i].name != NULL; i++) {
|
||||
std::wstring fn = U8(kSkins[i].name);
|
||||
// 只释放本皮肤 + 公共 global.xml
|
||||
std::string nm = kSkins[i].name;
|
||||
if (nm != "global.xml" && nm.compare(0, strlen(theme), theme) != 0) continue;
|
||||
WriteFileBytes(dir + L"\\" + fn, kSkins[i].data, kSkins[i].size);
|
||||
any = true;
|
||||
}
|
||||
return any;
|
||||
}
|
||||
|
||||
static void CleanupSkins() {
|
||||
if (g_skinRoot.empty()) return;
|
||||
// %TEMP% 每次启动会重置同名文件,这里只删文件不删目录,留一点余量
|
||||
std::wstring pat = g_skinRoot + L"\\*";
|
||||
WIN32_FIND_DATAW fd;
|
||||
HANDLE h = ::FindFirstFileW(pat.c_str(), &fd);
|
||||
if (h != INVALID_HANDLE_VALUE) {
|
||||
do {
|
||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
std::wstring sub = g_skinRoot + L"\\" + fd.cFileName + L"\\*";
|
||||
WIN32_FIND_DATAW fd2; HANDLE h2 = ::FindFirstFileW(sub.c_str(), &fd2);
|
||||
if (h2 != INVALID_HANDLE_VALUE) {
|
||||
do {
|
||||
::DeleteFileW((g_skinRoot + L"\\" + fd.cFileName + L"\\" + fd2.cFileName).c_str());
|
||||
} while (::FindNextFileW(h2, &fd2));
|
||||
::FindClose(h2);
|
||||
}
|
||||
::RemoveDirectoryW((g_skinRoot + L"\\" + fd.cFileName).c_str());
|
||||
}
|
||||
} while (::FindNextFileW(h, &fd));
|
||||
::FindClose(h);
|
||||
}
|
||||
::RemoveDirectoryW(g_skinRoot.c_str());
|
||||
}
|
||||
|
||||
/* ============================ 登录 ============================ */
|
||||
static int api_login(const char *code, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
if (!g_api[0]) { snprintf(msg, cap, "cfg 里没有 api 地址"); return 0; }
|
||||
|
||||
char scheme[16] = "http://";
|
||||
const char *rest = g_api;
|
||||
if (!strncmp(g_api, "https://", 8)) { snprintf(scheme, sizeof(scheme), "https://"); rest = g_api + 8; }
|
||||
else if (!strncmp(g_api, "http://", 7)) rest = g_api + 7;
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) {
|
||||
int hl = (int)(slash - rest);
|
||||
if (hl > 255) hl = 255;
|
||||
memcpy(host, rest, hl);
|
||||
snprintf(path, sizeof(path), "%s", slash);
|
||||
} else {
|
||||
snprintf(host, sizeof(host), "%s", rest);
|
||||
}
|
||||
unsigned short port = (scheme[4] == 's') ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char body[1024];
|
||||
snprintf(body, sizeof(body), "{\"code\":\"%s\",\"device\":\"%s\"}", code, g_device);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/10.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[2048] = {0};
|
||||
DWORD cl = 0;
|
||||
WinHttpReadData(hR, resp, sizeof(resp) - 1, &cl);
|
||||
resp[cl < sizeof(resp) ? cl : sizeof(resp) - 1] = 0;
|
||||
if (strstr(resp, "\"ok\":true") || strstr(resp, "\"code\":200")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap)) {
|
||||
if (ok) snprintf(msg, cap, "验证成功");
|
||||
else if (strstr(resp, "DEVICE_LIMIT")) snprintf(msg, cap, "设备数量已达上限");
|
||||
else snprintf(msg, cap, "卡密无效或已过期");
|
||||
}
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* ============================ 窗口 ============================ */
|
||||
typedef void (*PFN_OEP)(void);
|
||||
static PFN_OEP g_oep = NULL;
|
||||
static int g_logged_in = 0;
|
||||
|
||||
class VerifyWnd : public WindowImplBase {
|
||||
public:
|
||||
explicit VerifyWnd(const std::string &theme) : theme_(theme) {}
|
||||
|
||||
std::wstring GetSkinFolder() override { return U8(theme_.c_str()); }
|
||||
std::wstring GetSkinFile() override { return U8((theme_ + ".xml").c_str()); }
|
||||
std::wstring GetWindowClassName() const override { return L"VfyNimWnd"; }
|
||||
|
||||
// WindowImplBase::OnCreate 会用 GetStyle() 覆盖创建时的样式(默认是有边框的主窗口),
|
||||
// 验证窗必须是无边框弹窗,否则系统标题栏会盖在皮肤上。
|
||||
LONG GetStyle() override { return WS_POPUP | WS_CLIPCHILDREN; }
|
||||
|
||||
void InitWindow() override {
|
||||
if (Label *p = dynamic_cast<Label *>(FindControl(L"lblApp")))
|
||||
p->SetText(U8(g_name));
|
||||
if (Label *p = dynamic_cast<Label *>(FindControl(L"lblTip"))) {
|
||||
std::wstring t = L"设备指纹:";
|
||||
t += U8(g_device);
|
||||
p->SetText(t);
|
||||
}
|
||||
if (Button *b = dynamic_cast<Button *>(FindControl(L"btnLogin")))
|
||||
b->AttachClick([this](EventArgs *) { DoLogin(); return true; });
|
||||
if (Button *b = dynamic_cast<Button *>(FindControl(L"btnClose")))
|
||||
b->AttachClick([this](EventArgs *) { ::PostQuitMessage(0); return true; });
|
||||
if (Button *b = dynamic_cast<Button *>(FindControl(L"btnQuit")))
|
||||
b->AttachClick([this](EventArgs *) { ::PostQuitMessage(0); return true; });
|
||||
if (RichEdit *e = dynamic_cast<RichEdit *>(FindControl(L"editCard")))
|
||||
e->SetFocus();
|
||||
}
|
||||
|
||||
void DoLogin() {
|
||||
RichEdit *edit = dynamic_cast<RichEdit *>(FindControl(L"editCard"));
|
||||
Label *tip = dynamic_cast<Label *>(FindControl(L"lblTip"));
|
||||
Button *btn = dynamic_cast<Button *>(FindControl(L"btnLogin"));
|
||||
if (!edit || !tip) return;
|
||||
std::wstring code = edit->GetText();
|
||||
if (code.empty()) { tip->SetText(L"请输入卡密"); return; }
|
||||
if (btn) btn->SetText(L"验证中…");
|
||||
tip->SetText(L"正在连接验证服务器…");
|
||||
|
||||
char msg[512] = {0};
|
||||
std::string codeU8 = W2U8(code);
|
||||
int ok = api_login(codeU8.c_str(), msg, sizeof(msg));
|
||||
if (ok) {
|
||||
g_logged_in = 1;
|
||||
tip->SetText(L"验证成功,正在启动程序…");
|
||||
::SetTimer(m_hWnd, 1, 700, NULL);
|
||||
} else {
|
||||
tip->SetText(U8(msg));
|
||||
if (btn) btn->SetText(L"登 录");
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override {
|
||||
if (uMsg == WM_TIMER && wParam == 1) {
|
||||
::KillTimer(m_hWnd, 1);
|
||||
::ShowWindow(m_hWnd, SW_HIDE);
|
||||
if (g_oep) g_oep();
|
||||
::PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
return WindowImplBase::HandleMessage(uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string theme_;
|
||||
};
|
||||
|
||||
static int RunShell(void *oep) {
|
||||
LOGF("RunShell enter theme=%s", g_theme);
|
||||
g_oep = (PFN_OEP)oep;
|
||||
|
||||
std::string theme = g_theme;
|
||||
bool png = (theme == "nebula" || theme == "onyx" || theme == "aurora");
|
||||
if (!StageSkin(theme.c_str())) {
|
||||
::MessageBoxW(NULL, L"皮肤资源释放失败", L"验证", MB_ICONERROR);
|
||||
return 6;
|
||||
}
|
||||
|
||||
LOGF("skins staged at %ls", g_skinRoot.c_str());
|
||||
GlobalManager::Startup(g_skinRoot + L"\\", CreateControlCallback(), false, L"", L"");
|
||||
LOGF("GlobalManager started");
|
||||
|
||||
int w = 470, h = 330;
|
||||
if (theme == "industrial") { w = 520; h = 350; }
|
||||
if (png) { w = 520; h = 356; }
|
||||
|
||||
VerifyWnd *pwnd = new VerifyWnd(theme);
|
||||
LOGF("window obj created");
|
||||
// isLayeredWindow=true:整窗按像素 alpha,PNG 皮肤的圆角/发光才不会被裁成方块
|
||||
HWND hwnd = pwnd->Create(NULL, L"软件授权验证",
|
||||
WS_POPUP | WS_CLIPCHILDREN,
|
||||
WS_EX_TOPMOST | WS_EX_APPWINDOW,
|
||||
png, UiRect(0, 0, w, h));
|
||||
LOGF("Create returned %p", (void*)hwnd);
|
||||
if (hwnd == NULL) {
|
||||
::MessageBoxW(NULL, L"窗口创建失败", L"验证", MB_ICONERROR);
|
||||
GlobalManager::Shutdown();
|
||||
CleanupSkins();
|
||||
delete pwnd;
|
||||
return 6;
|
||||
}
|
||||
pwnd->CenterWindow();
|
||||
pwnd->ShowWindow(true, true);
|
||||
|
||||
MSG msg;
|
||||
while (::GetMessage(&msg, NULL, 0, 0)) {
|
||||
if (!pwnd->TranslateAccelerator(&msg)) {
|
||||
::TranslateMessage(&msg);
|
||||
::DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
GlobalManager::Shutdown();
|
||||
CleanupSkins();
|
||||
return g_logged_in ? 0 : 6;
|
||||
}
|
||||
|
||||
/* ============================ 导出 ============================ */
|
||||
#ifdef SHELL_EXE
|
||||
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
|
||||
const char *cfg = (lpCmdLine && lpCmdLine[0]) ? lpCmdLine : getenv("VFY_CFG");
|
||||
if (!cfg || !cfg[0]) cfg = "{\"theme\":\"nebula\"}";
|
||||
load_cfg(cfg);
|
||||
return RunShell(NULL);
|
||||
}
|
||||
#else
|
||||
extern "C" __declspec(dllexport) int VerifyMain(void *oep, const char *cfgjson) {
|
||||
load_cfg(cfgjson);
|
||||
return RunShell(oep);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int VerifyShellVersion(void) { return 10; }
|
||||
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID) {
|
||||
if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(h);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,521 @@
|
||||
// shell9.cpp —— DuiLib 版 Windows 验证壳(多皮肤)
|
||||
//
|
||||
// 与原 Direct2D 壳(shell6)对外接口一致:
|
||||
// extern "C" __declspec(dllexport) int VerifyMain(void *oep, const char *cfgjson);
|
||||
// extern "C" __declspec(dllexport) int VerifyShellVersion(void); // 9
|
||||
//
|
||||
// 皮肤由 cfg 里的 "theme" 决定:dark / light / industrial,三套 XML 内嵌在 DLL 里。
|
||||
// 用 -DSHELL_EXE 编译时变成独立 exe(用于在 Wine 里截图验收界面)。
|
||||
#include <windows.h>
|
||||
#include <winhttp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "UIlib.h"
|
||||
#include "Utils/WinImplBase.h"
|
||||
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
|
||||
using namespace DuiLib;
|
||||
|
||||
/* ------------------------------ cfg ------------------------------ */
|
||||
static char g_cfg[4096];
|
||||
static char g_api[512];
|
||||
static char g_name[128] = "\xE6\xBC\x94\xE7\xA4\xBA\xE7\xA8\x8B\xE5\xBA\x8F"; // 演示程序
|
||||
static char g_theme[32] = "dark";
|
||||
static char g_device[64] = "";
|
||||
static int g_deviceAuto = 1;
|
||||
|
||||
static int json_str(const char *src, const char *key, char *out, int cap) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return 0;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return 0;
|
||||
while (*p && *p != '"') p++;
|
||||
if (!*p) return 0;
|
||||
p++;
|
||||
int i = 0;
|
||||
while (*p && *p != '"' && i < cap - 1) out[i++] = *p++;
|
||||
out[i] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void make_device_id(char *out, int cap); // 定义在后面
|
||||
|
||||
static int json_int(const char *src, const char *key, int def) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return def;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return def;
|
||||
return atoi(p + 1);
|
||||
}
|
||||
|
||||
static void load_cfg(const char *json) {
|
||||
snprintf(g_cfg, sizeof(g_cfg), "%s", json ? json : "");
|
||||
json_str(g_cfg, "api", g_api, sizeof(g_api));
|
||||
json_str(g_cfg, "name", g_name, sizeof(g_name));
|
||||
g_deviceAuto = json_int(g_cfg, "device_auto", 0);
|
||||
if (!json_str(g_cfg, "device", g_device, sizeof(g_device)) || !g_device[0]) {
|
||||
if (g_deviceAuto) make_device_id(g_device, sizeof(g_device));
|
||||
else snprintf(g_device, sizeof(g_device), "%s", "UNKNOWN-DEVICE");
|
||||
}
|
||||
if (!json_str(g_cfg, "theme", g_theme, sizeof(g_theme))) snprintf(g_theme, sizeof(g_theme), "dark");
|
||||
}
|
||||
|
||||
/* ------------------------------ 工具 ------------------------------ */
|
||||
static std::wstring U8(const char *s) {
|
||||
if (!s) return L"";
|
||||
int n = ::MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
|
||||
std::wstring w(n > 0 ? n - 1 : 0, L'\0');
|
||||
if (n > 1) ::MultiByteToWideChar(CP_UTF8, 0, s, -1, &w[0], n);
|
||||
return w;
|
||||
}
|
||||
|
||||
static std::string W2U8(const std::wstring &w) {
|
||||
if (w.empty()) return std::string();
|
||||
int n = ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, NULL, 0, NULL, NULL);
|
||||
std::string s(n > 0 ? n - 1 : 0, '\0');
|
||||
if (n > 1) ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, &s[0], n, NULL, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------- 设备指纹 --------------------------- */
|
||||
// 固定占位指纹会让所有机器算同一台设备,设备上限就形同虚设,
|
||||
// 所以按「MachineGuid + 系统盘卷序列号」算一个稳定的机器码:
|
||||
// 重装系统才会变,改机器名/换网卡都不会变。
|
||||
static void make_device_id(char *out, int cap) {
|
||||
wchar_t guid[128] = {0};
|
||||
HKEY hk = NULL;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
|
||||
0, KEY_READ | KEY_WOW64_64KEY, &hk) == ERROR_SUCCESS) {
|
||||
DWORD sz = sizeof(guid) - sizeof(wchar_t), type = 0;
|
||||
RegQueryValueExW(hk, L"MachineGuid", NULL, &type, (LPBYTE)guid, &sz);
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
DWORD serial = 0;
|
||||
GetVolumeInformationW(L"C:\\", NULL, 0, &serial, NULL, NULL, NULL, 0);
|
||||
|
||||
// FNV-1a 32 位,跑两遍(不同种子)凑出 12 位十六进制
|
||||
unsigned int h1 = 2166136261u, h2 = 3735928559u;
|
||||
for (const wchar_t *p = guid; *p; p++) {
|
||||
h1 = (h1 ^ (unsigned int)(*p & 0xFF)) * 16777619u;
|
||||
h2 = (h2 ^ (unsigned int)(*p >> 8)) * 16777619u;
|
||||
}
|
||||
h1 = (h1 ^ serial) * 16777619u;
|
||||
h2 = (h2 ^ (serial >> 16)) * 16777619u;
|
||||
snprintf(out, cap, "%04X-%04X-%04X", h1 & 0xFFFF, (h1 >> 16) & 0xFFFF, h2 & 0xFFFF);
|
||||
}
|
||||
|
||||
/* --------------------------- 多套皮肤 ---------------------------
|
||||
* 设计原则:每套在「结构」上就不一样,不是换色。
|
||||
* dark 竖排紧凑 / 顶部条
|
||||
* light 浅色办公 / 顶部条
|
||||
* industrial 横向卡密行 + 双按钮(设备授权风)
|
||||
* compact 极简单行横幅:左信息右操作
|
||||
* split 左右分栏:左品牌竖区 + 右表单
|
||||
* card 宽扁卡片:顶部大色条 + 双列内容
|
||||
* terminal 终端风:等宽感、提示符、绿色强调
|
||||
*/
|
||||
|
||||
// 1) 竖排紧凑 · 深色
|
||||
static const char *kSkinDark =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"470,330\" caption=\"0,0,-1,40\" mininfo=\"470,330\" bkcolor=\"#FF1B1B1B\">"
|
||||
" <VerticalLayout bkcolor=\"#FF1B1B1B\" bordercolor=\"#FF3A3A3A\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"40\" bkcolor=\"#FF252526\">"
|
||||
" <Label text=\"软件授权验证\" textcolor=\"#FFE8E8E8\" font=\"1\" inset=\"16,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"40\" textcolor=\"#FFCCCCCC\" bkcolor=\"#FF252526\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"26,20,26,16\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FF7FB8E0\" height=\"26\" font=\"1\" />"
|
||||
" <Label text=\"请输入卡密激活本机\" textcolor=\"#FF9A9A9A\" height=\"22\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <Edit name=\"editCard\" height=\"38\" bkcolor=\"#FF2D2D30\" textcolor=\"#FFFFFFFF\" bordercolor=\"#FF3F3F46\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout height=\"14\" />"
|
||||
" <Button name=\"btnLogin\" text=\"登 录\" height=\"40\" bkcolor=\"#FF0E639C\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" <HorizontalLayout height=\"12\" />"
|
||||
" <Label name=\"lblTip\" text=\"设备指纹:\" textcolor=\"#FF8A8A8A\" height=\"20\" />"
|
||||
" </VerticalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 2) 浅色办公
|
||||
static const char *kSkinLight =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"470,330\" caption=\"0,0,-1,40\" mininfo=\"470,330\" bkcolor=\"#FFF7F7F7\">"
|
||||
" <VerticalLayout bkcolor=\"#FFF7F7F7\" bordercolor=\"#FFD8D8D8\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"40\" bkcolor=\"#FFFFFFFF\">"
|
||||
" <Label text=\"软件授权验证\" textcolor=\"#FF1F1F1F\" font=\"1\" inset=\"16,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"40\" textcolor=\"#FF666666\" bkcolor=\"#FFFFFFFF\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"26,20,26,16\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FF0067B8\" height=\"26\" font=\"1\" />"
|
||||
" <Label text=\"请输入卡密激活本机\" textcolor=\"#FF666666\" height=\"22\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <Edit name=\"editCard\" height=\"38\" bkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F1F1F\" bordercolor=\"#FFC8C8C8\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout height=\"14\" />"
|
||||
" <Button name=\"btnLogin\" text=\"登录\" height=\"40\" bkcolor=\"#FF0078D4\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" <HorizontalLayout height=\"12\" />"
|
||||
" <Label name=\"lblTip\" text=\"设备指纹:\" textcolor=\"#FF8A8A8A\" height=\"20\" />"
|
||||
" </VerticalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 3) 工业蓝 · 设备授权(横向卡密行 + 双按钮)
|
||||
static const char *kSkinIndustrial =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"530,340\" caption=\"0,0,-1,44\" mininfo=\"530,340\" bkcolor=\"#FF0A1622\">"
|
||||
" <VerticalLayout bkcolor=\"#FF0A1622\" bordercolor=\"#FF1F4E79\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"44\" bkcolor=\"#FF113250\">"
|
||||
" <Label text=\"DEVICE AUTHORIZATION\" textcolor=\"#FF7FD1FF\" font=\"1\" inset=\"16,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"44\" textcolor=\"#FFBEE3FF\" bkcolor=\"#FF113250\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"28,18,28,16\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FF6FA8C8\" height=\"26\" font=\"1\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <HorizontalLayout height=\"42\" bkcolor=\"#FF0E2438\">"
|
||||
" <Label text=\"卡密\" textcolor=\"#FF8FC4E6\" width=\"64\" inset=\"12,0,0,0\" />"
|
||||
" <Edit name=\"editCard\" textcolor=\"#FFFFFFFF\" bkcolor=\"#FF0E2438\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"14\" />"
|
||||
" <HorizontalLayout height=\"44\">"
|
||||
" <Button name=\"btnLogin\" text=\"激活本机\" bkcolor=\"#FF1F6FB2\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" <HorizontalLayout width=\"12\" />"
|
||||
" <Button name=\"btnQuit\" text=\"退出\" bkcolor=\"#FF22384F\" textcolor=\"#FFBEE3FF\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <Label name=\"lblTip\" text=\"设备指纹:\" textcolor=\"#FF5F89A6\" height=\"22\" />"
|
||||
" </VerticalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 4) 极简单行横幅:左信息 / 右操作,高度只有 132
|
||||
static const char *kSkinCompact =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"640,132\" caption=\"0,0,-1,32\" mininfo=\"640,132\" bkcolor=\"#FF101418\">"
|
||||
" <VerticalLayout bkcolor=\"#FF101418\" bordercolor=\"#FF2A3440\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"32\" bkcolor=\"#FF161C22\">"
|
||||
" <Label text=\"授权验证\" textcolor=\"#FF9FB3C8\" inset=\"14,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"34\" textcolor=\"#FFB0C4D8\" bkcolor=\"#FF161C22\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout inset=\"14,10,14,10\">"
|
||||
" <VerticalLayout width=\"210\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FFE6EEF6\" height=\"26\" font=\"1\" />"
|
||||
" <Label name=\"lblTip\" text=\"设备指纹:\" textcolor=\"#FF6B7C8C\" height=\"20\" />"
|
||||
" </VerticalLayout>"
|
||||
" <HorizontalLayout>"
|
||||
" <Edit name=\"editCard\" height=\"40\" bkcolor=\"#FF1B232B\" textcolor=\"#FFFFFFFF\" bordercolor=\"#FF32404E\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout width=\"10\" />"
|
||||
" <Button name=\"btnLogin\" text=\"激活\" width=\"96\" height=\"40\" bkcolor=\"#FF2E9E6B\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" </HorizontalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 5) 左右分栏:左品牌竖区 + 右表单
|
||||
static const char *kSkinSplit =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"580,320\" caption=\"0,0,0,0\" mininfo=\"580,320\" bkcolor=\"#FF14171C\">"
|
||||
" <HorizontalLayout bkcolor=\"#FF14171C\" bordercolor=\"#FF2B3038\" bordersize=\"1\">"
|
||||
" <VerticalLayout width=\"168\" bkcolor=\"#FF1E2833\">"
|
||||
" <Label text=\"VFY\" textcolor=\"#FF4CC2FF\" font=\"1\" height=\"52\" inset=\"22,16,0,0\" />"
|
||||
" <Label text=\"软件授权\" textcolor=\"#FFB8C6D4\" height=\"24\" inset=\"22,0,0,0\" />"
|
||||
" <Label text=\"Software License\" textcolor=\"#FF61707E\" height=\"20\" inset=\"22,0,0,0\" />"
|
||||
" <VerticalLayout />"
|
||||
" <Label text=\"v9 · DuiLib\" textcolor=\"#FF44515E\" height=\"22\" inset=\"22,0,0,14\" />"
|
||||
" </VerticalLayout>"
|
||||
" <VerticalLayout bkcolor=\"#FF14171C\">"
|
||||
" <HorizontalLayout height=\"34\">"
|
||||
" <Label text=\"\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"34\" textcolor=\"#FF97A6B5\" bkcolor=\"#FF14171C\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"26,4,26,18\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FFEAF2FA\" height=\"28\" font=\"1\" />"
|
||||
" <Label text=\"卡密\" textcolor=\"#FF8794A3\" height=\"20\" />"
|
||||
" <Edit name=\"editCard\" height=\"40\" bkcolor=\"#FF1B2027\" textcolor=\"#FFFFFFFF\" bordercolor=\"#FF313944\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout height=\"12\" />"
|
||||
" <Button name=\"btnLogin\" text=\"激活授权\" height=\"40\" bkcolor=\"#FF2C7BE5\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" <Label name=\"lblTip\" text=\"设备指纹:\" textcolor=\"#FF6B7A88\" height=\"20\" />"
|
||||
" </VerticalLayout>"
|
||||
" </VerticalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 6) 宽扁卡片:顶部大色条 + 双列内容
|
||||
static const char *kSkinCard =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"620,290\" caption=\"0,0,-1,74\" mininfo=\"620,290\" bkcolor=\"#FFF4F6F9\">"
|
||||
" <VerticalLayout bkcolor=\"#FFF4F6F9\" bordercolor=\"#FFD5DBE4\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"74\" bkcolor=\"#FF4A3AFF\">"
|
||||
" <VerticalLayout>"
|
||||
" <Label text=\"激活你的授权\" textcolor=\"#FFFFFFFF\" font=\"1\" height=\"34\" inset=\"24,14,0,0\" />"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FFD8D4FF\" height=\"20\" inset=\"24,0,0,0\" />"
|
||||
" </VerticalLayout>"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"44\" textcolor=\"#FFEDEBFF\" bkcolor=\"#FF4A3AFF\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout inset=\"24,20,24,18\">"
|
||||
" <VerticalLayout width=\"250\">"
|
||||
" <Label text=\"为什么需要激活\" textcolor=\"#FF2A2F3A\" height=\"24\" font=\"1\" />"
|
||||
" <Label text=\"授权绑定本机设备,一个卡密可在\" textcolor=\"#FF6B7280\" height=\"20\" />"
|
||||
" <Label text=\"允许的设备数量内使用。\" textcolor=\"#FF6B7280\" height=\"20\" />"
|
||||
" <VerticalLayout />"
|
||||
" <Label name=\"lblTip\" text=\"设备指纹:\" textcolor=\"#FF9AA3AF\" height=\"20\" />"
|
||||
" </VerticalLayout>"
|
||||
" <VerticalLayout width=\"24\" />"
|
||||
" <VerticalLayout>"
|
||||
" <Label text=\"卡密\" textcolor=\"#FF6B7280\" height=\"20\" />"
|
||||
" <Edit name=\"editCard\" height=\"42\" bkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F2430\" bordercolor=\"#FFC9D1DC\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout height=\"14\" />"
|
||||
" <Button name=\"btnLogin\" text=\"立即激活\" height=\"42\" bkcolor=\"#FF4A3AFF\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" </VerticalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 7) 终端风:提示符 + 绿色强调
|
||||
static const char *kSkinTerminal =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"560,300\" caption=\"0,0,-1,34\" mininfo=\"560,300\" bkcolor=\"#FF0C0F0D\">"
|
||||
" <VerticalLayout bkcolor=\"#FF0C0F0D\" bordercolor=\"#FF2C3A2E\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"34\" bkcolor=\"#FF10150F\">"
|
||||
" <Label text=\"vfy@local:~$\" textcolor=\"#FF54C97A\" inset=\"12,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"34\" textcolor=\"#FF7FB08C\" bkcolor=\"#FF10150F\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"16,12,16,14\">"
|
||||
" <Label name=\"lblApp\" text=\"# 演示程序\" textcolor=\"#FF7FE39B\" height=\"24\" />"
|
||||
" <Label text=\"# 输入卡密后回车\" textcolor=\"#FF4E7A5C\" height=\"22\" />"
|
||||
" <HorizontalLayout height=\"12\" />"
|
||||
" <HorizontalLayout height=\"40\" bordercolor=\"#FF2C3A2E\" bordersize=\"1\">"
|
||||
" <Label text=\">\" textcolor=\"#FF54C97A\" width=\"24\" inset=\"10,0,0,0\" />"
|
||||
" <Edit name=\"editCard\" textcolor=\"#FFD7F5DF\" bkcolor=\"#FF0C0F0D\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"12\" />"
|
||||
" <Label name=\"lblTip\" text=\"# 设备指纹:\" textcolor=\"#FF4E7A5C\" height=\"22\" />"
|
||||
" <VerticalLayout />"
|
||||
" <Button name=\"btnLogin\" text=\"[ 执行激活 ]\" height=\"38\" bkcolor=\"#FF16261A\" textcolor=\"#FF7FE39B\" bordercolor=\"#FF2C3A2E\" bordersize=\"1\" />"
|
||||
" </VerticalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
struct SkinDef { const char *name; const char *xml; int w, h; };
|
||||
static const SkinDef kSkins[] = {
|
||||
{ "dark", kSkinDark, 470, 330 },
|
||||
{ "light", kSkinLight, 470, 330 },
|
||||
{ "industrial", kSkinIndustrial, 530, 340 },
|
||||
{ "compact", kSkinCompact, 640, 132 },
|
||||
{ "split", kSkinSplit, 580, 320 },
|
||||
{ "card", kSkinCard, 620, 290 },
|
||||
{ "terminal", kSkinTerminal, 560, 300 },
|
||||
{ NULL, NULL, 0, 0 }
|
||||
};
|
||||
|
||||
static const SkinDef *skin_for(const char *theme) {
|
||||
for (int i = 0; kSkins[i].name; i++)
|
||||
if (!_stricmp(theme, kSkins[i].name)) return &kSkins[i];
|
||||
return &kSkins[0]; // 未知主题回落 dark
|
||||
}
|
||||
|
||||
/* ---------------------------- 登录请求 ---------------------------- */
|
||||
// 返回 1 成功;0 失败;把服务端给的 message 放进 msg
|
||||
static int api_login(const char *code, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
if (!g_api[0]) { snprintf(msg, cap, "cfg 里没有 api 地址"); return 0; }
|
||||
|
||||
char scheme[16] = "http://";
|
||||
const char *rest = g_api;
|
||||
if (!strncmp(g_api, "https://", 8)) { snprintf(scheme, sizeof(scheme), "https://"); rest = g_api + 8; }
|
||||
else if (!strncmp(g_api, "http://", 7)) { rest = g_api + 7; }
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) {
|
||||
int hl = (int)(slash - rest);
|
||||
if (hl > 255) hl = 255;
|
||||
memcpy(host, rest, hl);
|
||||
snprintf(path, sizeof(path), "%s", slash);
|
||||
} else {
|
||||
snprintf(host, sizeof(host), "%s", rest);
|
||||
}
|
||||
unsigned short port = (scheme[4] == 's') ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char body[1024];
|
||||
snprintf(body, sizeof(body), "{\"code\":\"%s\",\"device\":\"%s\"}", code, g_device);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[2048] = {0};
|
||||
DWORD cl = 0;
|
||||
WinHttpReadData(hR, resp, sizeof(resp) - 1, &cl);
|
||||
resp[cl < sizeof(resp) ? cl : sizeof(resp) - 1] = 0;
|
||||
if (strstr(resp, "\"ok\":true") || strstr(resp, "\"code\":200")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap)) {
|
||||
if (ok) snprintf(msg, cap, "验证成功");
|
||||
else if (strstr(resp, "DEVICE_LIMIT")) snprintf(msg, cap, "设备数量已达上限");
|
||||
else snprintf(msg, cap, "卡密无效或已过期");
|
||||
}
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* ---------------------------- 窗口 ---------------------------- */
|
||||
typedef void (*PFN_OEP)(void);
|
||||
static PFN_OEP g_oep = NULL;
|
||||
static int g_logged_in = 0;
|
||||
|
||||
class CVerifyWnd : public CWindowWnd, public INotifyUI {
|
||||
public:
|
||||
explicit CVerifyWnd(const char *skin) : m_skin(skin) {}
|
||||
|
||||
LPCTSTR GetWindowClassName() const override { return _T("VfyDuiWnd"); }
|
||||
UINT GetClassStyle() const override { return CS_DBLCLKS; }
|
||||
|
||||
void Notify(TNotifyUI &msg) override {
|
||||
if (msg.sType == _T("click")) {
|
||||
CControlUI *pSender = msg.pSender;
|
||||
LPCTSTR nm = pSender ? pSender->GetName().GetData() : NULL;
|
||||
if (nm && (_tcsicmp(nm, _T("btnClose")) == 0 || _tcsicmp(nm, _T("btnQuit")) == 0)) {
|
||||
::PostQuitMessage(0);
|
||||
return;
|
||||
}
|
||||
if (nm && _tcsicmp(nm, _T("btnLogin")) == 0) DoLogin();
|
||||
} else if (msg.sType == _T("return")) {
|
||||
DoLogin();
|
||||
}
|
||||
}
|
||||
|
||||
void DoLogin() {
|
||||
CEditUI *pEdit = static_cast<CEditUI *>(m_pm.FindControl(_T("editCard")));
|
||||
CLabelUI *pTip = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblTip")));
|
||||
CButtonUI *pBtn = static_cast<CButtonUI *>(m_pm.FindControl(_T("btnLogin")));
|
||||
if (!pEdit || !pTip) return;
|
||||
|
||||
std::wstring code = pEdit->GetText().GetData();
|
||||
if (code.empty()) {
|
||||
pTip->SetText(L"请输入卡密");
|
||||
return;
|
||||
}
|
||||
if (pBtn) { pBtn->SetText(L"验证中…"); pBtn->SetEnabled(false); }
|
||||
pTip->SetText(L"正在连接验证服务器…");
|
||||
|
||||
char msg[512] = {0};
|
||||
std::string codeU8 = W2U8(code);
|
||||
int ok = api_login(codeU8.c_str(), msg, sizeof(msg));
|
||||
|
||||
if (ok) {
|
||||
g_logged_in = 1;
|
||||
pTip->SetText(L"验证成功,正在启动程序…");
|
||||
::SetTimer(m_hWnd, 1, 700, NULL);
|
||||
} else {
|
||||
std::wstring w = U8(msg);
|
||||
pTip->SetText(w.c_str());
|
||||
if (pBtn) { pBtn->SetText(L"登 录"); pBtn->SetEnabled(true); }
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override {
|
||||
if (uMsg == WM_CREATE) {
|
||||
m_pm.Init(m_hWnd);
|
||||
CDialogBuilder builder;
|
||||
std::wstring xml = U8(m_skin);
|
||||
CControlUI *pRoot = builder.Create(xml.c_str(), (UINT)0, NULL, &m_pm);
|
||||
if (!pRoot) { ::MessageBoxW(m_hWnd, L"皮肤解析失败", L"验证", MB_ICONERROR); return 0; }
|
||||
m_pm.AttachDialog(pRoot);
|
||||
m_pm.AddNotifier(this);
|
||||
|
||||
if (CLabelUI *pApp = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblApp")))) {
|
||||
std::wstring wn = U8(g_name);
|
||||
if (FILE *lf = fopen("C:\\vfy9dbg.txt", "w")) {
|
||||
fprintf(lf, "cfg=%s\nname=%s\ntheme=%s\n", g_cfg, g_name, g_theme);
|
||||
for (size_t i = 0; i < wn.size(); i++) fprintf(lf, "%04X ", (unsigned)wn[i]);
|
||||
fprintf(lf, "\n");
|
||||
fclose(lf);
|
||||
}
|
||||
pApp->SetText(wn.c_str());
|
||||
}
|
||||
if (CLabelUI *pTip = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblTip")))) {
|
||||
std::wstring t = L"设备指纹:";
|
||||
t += U8(g_device);
|
||||
pTip->SetText(t.c_str());
|
||||
}
|
||||
if (CEditUI *pEdit = static_cast<CEditUI *>(m_pm.FindControl(_T("editCard"))))
|
||||
pEdit->SetFocus();
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_TIMER && wParam == 1) {
|
||||
::KillTimer(m_hWnd, 1);
|
||||
::ShowWindow(m_hWnd, SW_HIDE);
|
||||
if (g_oep) g_oep();
|
||||
::PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_DESTROY) { ::PostQuitMessage(0); return 0; }
|
||||
|
||||
LRESULT lr = 0;
|
||||
if (m_pm.MessageHandler(uMsg, wParam, lParam, lr)) return lr;
|
||||
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
CPaintManagerUI m_pm;
|
||||
const char *m_skin;
|
||||
};
|
||||
|
||||
static int RunShell(void *oep) {
|
||||
g_oep = (PFN_OEP)oep;
|
||||
const SkinDef *sk = skin_for(g_theme);
|
||||
|
||||
CPaintManagerUI::SetInstance(::GetModuleHandle(NULL));
|
||||
::CoInitialize(NULL);
|
||||
|
||||
CVerifyWnd wnd(sk->xml);
|
||||
UINT style = WS_POPUP | WS_CLIPCHILDREN;
|
||||
UINT exstyle = WS_EX_TOPMOST | WS_EX_APPWINDOW;
|
||||
|
||||
wnd.Create(NULL, L"软件授权验证", style, exstyle, 0, 0, sk->w, sk->h);
|
||||
wnd.CenterWindow();
|
||||
::ShowWindow(wnd, SW_SHOW);
|
||||
|
||||
CPaintManagerUI::MessageLoop();
|
||||
::CoUninitialize();
|
||||
return g_logged_in ? 0 : 6;
|
||||
}
|
||||
|
||||
/* ---------------------------- 对外接口 ---------------------------- */
|
||||
#ifdef SHELL_EXE
|
||||
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
|
||||
const char *cfg = (lpCmdLine && lpCmdLine[0]) ? lpCmdLine : getenv("VFY_CFG");
|
||||
if (!cfg || !cfg[0]) cfg = "{\"theme\":\"dark\",\"name\":\"演示程序\"}";
|
||||
load_cfg(cfg);
|
||||
return RunShell(NULL);
|
||||
}
|
||||
#else
|
||||
extern "C" __declspec(dllexport) int VerifyMain(void *oep, const char *cfgjson) {
|
||||
load_cfg(cfgjson);
|
||||
return RunShell(oep);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int VerifyShellVersion(void) { return 9; }
|
||||
extern "C" __declspec(dllexport) const char *VerifyShellThemes(void) { return "dark,light,industrial,compact,split,card,terminal"; }
|
||||
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID) {
|
||||
if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(h);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,696 @@
|
||||
// shell9.cpp —— DuiLib 版 Windows 验证壳(多套结构不同的皮肤)
|
||||
//
|
||||
// 与平台验证方式严格对齐(/api/v1/app/<appKey>/login):
|
||||
// POST {username, password, device_id, device_name, device_type, instance_id}
|
||||
// 即「账号(或卡密)+ 密码 + 设备绑定」,不是只填一个卡密框。
|
||||
//
|
||||
// 对外接口不变:
|
||||
// int VerifyMain(void *oep, const char *cfgjson);
|
||||
// int VerifyShellVersion(void); // 9
|
||||
// const char *VerifyShellThemes(void); // 主题清单
|
||||
#include <windows.h>
|
||||
#include <winhttp.h>
|
||||
#include <shlobj.h>
|
||||
#include <shellapi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include "UIlib.h"
|
||||
#include "Utils/WinImplBase.h"
|
||||
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
|
||||
using namespace DuiLib;
|
||||
|
||||
/* ============================== cfg ============================== */
|
||||
static char g_cfg[4096];
|
||||
static char g_api[512];
|
||||
static char g_name[128] = "\xE6\xBC\x94\xE7\xA4\xBA\xE7\xA8\x8B\xE5\xBA\x8F"; // 演示程序
|
||||
static char g_theme[32] = "dark";
|
||||
static char g_device[64] = "";
|
||||
static char g_instance[64] = "";
|
||||
static int g_deviceAuto = 1;
|
||||
|
||||
static int json_str(const char *src, const char *key, char *out, int cap) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return 0;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return 0;
|
||||
while (*p && *p != '"') p++;
|
||||
if (!*p) return 0;
|
||||
p++;
|
||||
int i = 0;
|
||||
while (*p && *p != '"' && i < cap - 1) out[i++] = *p++;
|
||||
out[i] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int json_int(const char *src, const char *key, int def) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return def;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return def;
|
||||
return atoi(p + 1);
|
||||
}
|
||||
|
||||
static void make_machine_id(char *out, int cap);
|
||||
static void load_cfg(const char *json);
|
||||
|
||||
/* ============================ 工具 ============================ */
|
||||
static std::wstring U8(const char *s) {
|
||||
if (!s) return L"";
|
||||
int n = ::MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
|
||||
std::wstring w(n > 0 ? n - 1 : 0, L'\0');
|
||||
if (n > 1) ::MultiByteToWideChar(CP_UTF8, 0, s, -1, &w[0], n);
|
||||
return w;
|
||||
}
|
||||
|
||||
static std::string W2U8(const std::wstring &w) {
|
||||
if (w.empty()) return std::string();
|
||||
int n = ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, NULL, 0, NULL, NULL);
|
||||
std::string s(n > 0 ? n - 1 : 0, '\0');
|
||||
if (n > 1) ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, &s[0], n, NULL, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
// MachineGuid + 系统盘卷序列号 → 稳定机器码(重装系统才变)
|
||||
static void make_machine_id(char *out, int cap) {
|
||||
wchar_t guid[128] = {0};
|
||||
HKEY hk = NULL;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
|
||||
0, KEY_READ | KEY_WOW64_64KEY, &hk) == ERROR_SUCCESS) {
|
||||
DWORD sz = sizeof(guid) - sizeof(wchar_t), type = 0;
|
||||
RegQueryValueExW(hk, L"MachineGuid", NULL, &type, (LPBYTE)guid, &sz);
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
DWORD serial = 0;
|
||||
GetVolumeInformationW(L"C:\\", NULL, 0, &serial, NULL, NULL, NULL, 0);
|
||||
unsigned int h1 = 2166136261u, h2 = 3735928559u;
|
||||
for (const wchar_t *p = guid; *p; p++) {
|
||||
h1 = (h1 ^ (unsigned int)(*p & 0xFF)) * 16777619u;
|
||||
h2 = (h2 ^ (unsigned int)(*p >> 8)) * 16777619u;
|
||||
}
|
||||
h1 = (h1 ^ serial) * 16777619u;
|
||||
h2 = (h2 ^ (serial >> 16)) * 16777619u;
|
||||
snprintf(out, cap, "%04X-%04X-%04X", h1 & 0xFFFF, (h1 >> 16) & 0xFFFF, h2 & 0xFFFF);
|
||||
}
|
||||
|
||||
static std::wstring AccountIniPath() {
|
||||
wchar_t app[MAX_PATH] = {0};
|
||||
::SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, app);
|
||||
std::wstring dir = std::wstring(app) + L"\\vfy";
|
||||
::CreateDirectoryW(dir.c_str(), NULL);
|
||||
return dir + L"\\account.ini";
|
||||
}
|
||||
|
||||
static void SaveAccount(const std::wstring &user, bool remember) {
|
||||
std::wstring p = AccountIniPath();
|
||||
::WritePrivateProfileStringW(L"login", L"remember", remember ? L"1" : L"0", p.c_str());
|
||||
if (remember) ::WritePrivateProfileStringW(L"login", L"user", user.c_str(), p.c_str());
|
||||
}
|
||||
|
||||
static std::wstring LoadAccount(bool &remember) {
|
||||
std::wstring p = AccountIniPath();
|
||||
wchar_t buf[256] = {0};
|
||||
::GetPrivateProfileStringW(L"login", L"remember", L"0", buf, 256, p.c_str());
|
||||
remember = (buf[0] == L'1');
|
||||
wchar_t user[256] = {0};
|
||||
::GetPrivateProfileStringW(L"login", L"user", L"", user, 256, p.c_str());
|
||||
return remember ? std::wstring(user) : std::wstring();
|
||||
}
|
||||
|
||||
/* --------------------------- 皮肤 ---------------------------
|
||||
* 7 套在「结构」上彼此不同,字段集统一按平台验证方式:
|
||||
* 账号(账号或卡密)/ 密码 / 记住账号 / 设备信息 / 登录 / 状态行 / 注册·卡密充值·忘记密码
|
||||
* 注意:老 DuiLib 的 Edit 是「真 EDIT 子窗口」,必须用 nativebkcolor 指定它自己的底色,
|
||||
* 否则聚焦时会出现刺眼的白条(这是它构造里写死 0xFFFFFFFF 导致的)。
|
||||
*/
|
||||
|
||||
// 1) 竖排标准 · 深色
|
||||
static const char *kSkinDark =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"440,404\" caption=\"0,0,-1,44\" mininfo=\"440,404\" bkcolor=\"#FF16161A\">"
|
||||
" <VerticalLayout bkcolor=\"#FF16161A\" bordercolor=\"#FF33333A\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"44\" bkcolor=\"#FF1F1F26\">"
|
||||
" <Label text=\"登录以继续\" textcolor=\"#FFEDEDF0\" font=\"1\" inset=\"20,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"44\" textcolor=\"#FF9A9AA5\" bkcolor=\"#FF1F1F26\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"24,18,24,16\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FF6FB6E8\" height=\"26\" font=\"1\" />"
|
||||
" <Label text=\"请使用账号或卡密登录\" textcolor=\"#FFB2B2BC\" height=\"20\" />"
|
||||
" <HorizontalLayout height=\"14\" />"
|
||||
" <Label text=\"账号\" textcolor=\"#FFB2B2BC\" height=\"18\" />"
|
||||
" <Edit name=\"editUser\" height=\"40\" bkcolor=\"#FF3C3C49\" nativebkcolor=\"#FF3C3C49\" textcolor=\"#FFF2F2F5\" bordercolor=\"#FF4E4E5C\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <Label text=\"密码\" textcolor=\"#FFB2B2BC\" height=\"18\" />"
|
||||
" <Edit name=\"editPass\" height=\"40\" bkcolor=\"#FF3C3C49\" nativebkcolor=\"#FF3C3C49\" textcolor=\"#FFF2F2F5\" bordercolor=\"#FF4E4E5C\" inset=\"10,0,0,0\" password=\"true\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <HorizontalLayout height=\"22\">"
|
||||
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FFB2B2BC\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FFB2B2BC\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"12\" />"
|
||||
" <Button name=\"btnLogin\" text=\"登 录\" height=\"44\" bkcolor=\"#FF146FB8\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFD98A8A\" height=\"26\" inset=\"0,6,0,0\" />"
|
||||
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF62626E\" height=\"18\" />"
|
||||
" <HorizontalLayout height=\"24\">"
|
||||
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 2) 竖排标准 · 浅色
|
||||
static const char *kSkinLight =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"440,404\" caption=\"0,0,-1,44\" mininfo=\"440,404\" bkcolor=\"#FFFBFBFD\">"
|
||||
" <VerticalLayout bkcolor=\"#FFFBFBFD\" bordercolor=\"#FFDCDCE2\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"44\" bkcolor=\"#FFFFFFFF\">"
|
||||
" <Label text=\"登录以继续\" textcolor=\"#FF1F1F24\" font=\"1\" inset=\"20,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"44\" textcolor=\"#FF6B6B74\" bkcolor=\"#FFFFFFFF\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"24,18,24,16\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FF1B6FD6\" height=\"26\" font=\"1\" />"
|
||||
" <Label text=\"请使用账号或卡密登录\" textcolor=\"#FF454C58\" height=\"20\" />"
|
||||
" <HorizontalLayout height=\"14\" />"
|
||||
" <Label text=\"账号\" textcolor=\"#FF454C58\" height=\"18\" />"
|
||||
" <Edit name=\"editUser\" height=\"40\" bkcolor=\"#FFFFFFFF\" nativebkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F1F24\" bordercolor=\"#FFC9C9D2\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <Label text=\"密码\" textcolor=\"#FF454C58\" height=\"18\" />"
|
||||
" <Edit name=\"editPass\" height=\"40\" bkcolor=\"#FFFFFFFF\" nativebkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F1F24\" bordercolor=\"#FFC9C9D2\" inset=\"10,0,0,0\" password=\"true\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <HorizontalLayout height=\"22\">"
|
||||
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF7A7A85\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF454C58\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"12\" />"
|
||||
" <Button name=\"btnLogin\" text=\"登录\" height=\"44\" bkcolor=\"#FF1568C8\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFC0392B\" height=\"30\" inset=\"0,8,0,0\" />"
|
||||
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF8A8F99\" height=\"18\" />"
|
||||
" <HorizontalLayout height=\"24\">"
|
||||
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 3) 左右分栏:左品牌竖栏 + 右表单
|
||||
static const char *kSkinSplit =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"620,400\" caption=\"0,0,0,0\" mininfo=\"620,400\" bkcolor=\"#FF14161B\">"
|
||||
" <HorizontalLayout bkcolor=\"#FF14161B\" bordercolor=\"#FF2A2E36\" bordersize=\"1\">"
|
||||
" <VerticalLayout width=\"196\" bkcolor=\"#FF1B2230\">"
|
||||
" <Label text=\"VFY\" textcolor=\"#FF4CC2FF\" font=\"1\" height=\"64\" inset=\"26,22,0,0\" />"
|
||||
" <Label text=\"软件授权\" textcolor=\"#FFC4CFDC\" height=\"26\" inset=\"26,0,0,0\" />"
|
||||
" <Label text=\"SOFTWARE LICENSE\" textcolor=\"#FF63707E\" height=\"20\" inset=\"26,0,0,0\" />"
|
||||
" <VerticalLayout />"
|
||||
" <Label text=\"设备绑定 · 异常登录自动锁定\" textcolor=\"#FF4C5A68\" height=\"40\" inset=\"26,0,0,26\" multiline=\"true\" />"
|
||||
" </VerticalLayout>"
|
||||
" <VerticalLayout>"
|
||||
" <HorizontalLayout height=\"40\">"
|
||||
" <Label text=\"\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"40\" textcolor=\"#FF8E9BAA\" bkcolor=\"#FF14161B\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"28,6,28,18\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FFF0F5FA\" height=\"28\" font=\"1\" />"
|
||||
" <Label text=\"请使用账号或卡密登录\" textcolor=\"#FF8794A3\" height=\"20\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <Edit name=\"editUser\" height=\"40\" bkcolor=\"#FF262B34\" nativebkcolor=\"#FF262B34\" textcolor=\"#FFF2F6FA\" bordercolor=\"#FF2E343D\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <Edit name=\"editPass\" height=\"40\" bkcolor=\"#FF262B34\" nativebkcolor=\"#FF262B34\" textcolor=\"#FFF2F6FA\" bordercolor=\"#FF2E343D\" inset=\"10,0,0,0\" password=\"true\" />"
|
||||
" <HorizontalLayout height=\"8\" />"
|
||||
" <HorizontalLayout height=\"22\">"
|
||||
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF8794A3\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF8794A3\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <Button name=\"btnLogin\" text=\"登录\" height=\"42\" bkcolor=\"#FF2C7BE5\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFE08585\" height=\"28\" inset=\"0,6,0,0\" />"
|
||||
" </VerticalLayout>"
|
||||
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF5E6B78\" height=\"18\" />"
|
||||
" <HorizontalLayout height=\"24\">"
|
||||
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 4) 宽扁卡片:顶部强调色条 + 双列(左说明 / 右表单)
|
||||
static const char *kSkinCard =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"680,392\" caption=\"0,0,-1,80\" mininfo=\"680,392\" bkcolor=\"#FFF5F6F9\">"
|
||||
" <VerticalLayout bkcolor=\"#FFF5F6F9\" bordercolor=\"#FFD7DBE3\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"80\" bkcolor=\"#FF3B2BD6\">"
|
||||
" <VerticalLayout inset=\"0,0,0,0\">"
|
||||
" <Label text=\"登录以继续\" textcolor=\"#FFFFFFFF\" font=\"1\" height=\"36\" inset=\"26,18,0,0\" />"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FFD9D4FF\" height=\"22\" inset=\"26,0,0,0\" />"
|
||||
" </VerticalLayout>"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"46\" textcolor=\"#FFEDEBFF\" bkcolor=\"#FF3B2BD6\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout inset=\"26,22,26,20\">"
|
||||
" <VerticalLayout width=\"264\">"
|
||||
" <Label text=\"账号安全\" textcolor=\"#FF2A2F3A\" height=\"24\" font=\"1\" />"
|
||||
" <Label text=\"登录后账号与本机设备绑定,\" textcolor=\"#FF4B5563\" height=\"20\" />"
|
||||
" <Label text=\"超出设备上限时请先下线一台。\" textcolor=\"#FF4B5563\" height=\"20\" />"
|
||||
" <VerticalLayout height=\"10\" />"
|
||||
" <VerticalLayout />"
|
||||
" </VerticalLayout>"
|
||||
" <VerticalLayout width=\"28\" />"
|
||||
" <VerticalLayout>"
|
||||
" <Label text=\"账号或卡密\" textcolor=\"#FF4B5563\" height=\"18\" />"
|
||||
" <Edit name=\"editUser\" height=\"40\" bkcolor=\"#FFFFFFFF\" nativebkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F2430\" bordercolor=\"#FFC9D1DC\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <Label text=\"密码\" textcolor=\"#FF4B5563\" height=\"18\" />"
|
||||
" <Edit name=\"editPass\" height=\"40\" bkcolor=\"#FFFFFFFF\" nativebkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F2430\" bordercolor=\"#FFC9D1DC\" inset=\"10,0,0,0\" password=\"true\" />"
|
||||
" <HorizontalLayout height=\"8\" />"
|
||||
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF4B5563\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF4B5563\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <Button name=\"btnLogin\" text=\"登录\" height=\"42\" bkcolor=\"#FF3B2BD6\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFC0392B\" height=\"26\" inset=\"0,6,0,0\" />"
|
||||
" </VerticalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF8A8F99\" height=\"18\" />"
|
||||
" <HorizontalLayout height=\"24\">"
|
||||
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF3B2BD6\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF3B2BD6\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF3B2BD6\" bkcolor=\"#00000000\" />"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 5) 工业蓝:标签 + 输入 横排两行,双按钮
|
||||
static const char *kSkinIndustrial =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"560,376\" caption=\"0,0,-1,46\" mininfo=\"560,376\" bkcolor=\"#FF0A1520\">"
|
||||
" <VerticalLayout bkcolor=\"#FF0A1520\" bordercolor=\"#FF1F4E79\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"46\" bkcolor=\"#FF10304C\">"
|
||||
" <Label text=\"AUTHORIZATION\" textcolor=\"#FF7FD1FF\" font=\"1\" inset=\"18,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"46\" textcolor=\"#FFBEE3FF\" bkcolor=\"#FF10304C\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"22,16,22,16\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FF8FC4E6\" height=\"26\" font=\"1\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <HorizontalLayout height=\"42\" bkcolor=\"#FF14304A\">"
|
||||
" <Label text=\"账号\" textcolor=\"#FF7FA8C4\" width=\"72\" inset=\"12,0,0,0\" />"
|
||||
" <Edit name=\"editUser\" bkcolor=\"#FF14304A\" nativebkcolor=\"#FF14304A\" textcolor=\"#FFEAF6FF\" inset=\"4,0,0,0\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"8\" />"
|
||||
" <HorizontalLayout height=\"42\" bkcolor=\"#FF14304A\">"
|
||||
" <Label text=\"密码\" textcolor=\"#FF7FA8C4\" width=\"72\" inset=\"12,0,0,0\" />"
|
||||
" <Edit name=\"editPass\" bkcolor=\"#FF14304A\" nativebkcolor=\"#FF14304A\" textcolor=\"#FFEAF6FF\" inset=\"4,0,0,0\" password=\"true\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"10\">"
|
||||
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF7FA8C4\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF7FA8C4\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"12\" />"
|
||||
" <HorizontalLayout height=\"44\">"
|
||||
" <Button name=\"btnLogin\" text=\"登录\" bkcolor=\"#FF1F6FB2\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" <HorizontalLayout width=\"12\" />"
|
||||
" <Button name=\"btnQuit\" text=\"退出\" width=\"120\" bkcolor=\"#FF1B3247\" textcolor=\"#FFBEE3FF\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFE0A0A0\" height=\"30\" inset=\"0,8,0,0\" />"
|
||||
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF5F89A6\" height=\"18\" />"
|
||||
" <HorizontalLayout height=\"24\">"
|
||||
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 6) 终端风
|
||||
static const char *kSkinTerminal =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"580,392\" caption=\"0,0,-1,38\" mininfo=\"580,392\" bkcolor=\"#FF16211A\">"
|
||||
" <VerticalLayout bkcolor=\"#FF16211A\" bordercolor=\"#FF2B3A2D\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"38\" bkcolor=\"#FF101710\">"
|
||||
" <Label text=\"vfy@local:~$\" textcolor=\"#FF54C97A\" inset=\"14,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"38\" textcolor=\"#FF7FB08C\" bkcolor=\"#FF101710\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout inset=\"16,12,16,14\">"
|
||||
" <Label name=\"lblApp\" text=\"# 演示程序\" textcolor=\"#FF7FE39B\" height=\"24\" />"
|
||||
" <Label text=\"# 用例:输入账号与密码后回车\" textcolor=\"#FF4E7A5C\" height=\"20\" />"
|
||||
" <HorizontalLayout height=\"10\" />"
|
||||
" <HorizontalLayout height=\"40\" bordercolor=\"#FF2B3A2D\" bordersize=\"1\">"
|
||||
" <Label text=\"账号\" textcolor=\"#FF54C97A\" width=\"62\" inset=\"12,0,0,0\" />"
|
||||
" <Edit name=\"editUser\" bkcolor=\"#FF16211A\" nativebkcolor=\"#FF16211A\" textcolor=\"#FFD7F5DF\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"8\" />"
|
||||
" <HorizontalLayout height=\"40\" bordercolor=\"#FF2B3A2D\" bordersize=\"1\">"
|
||||
" <Label text=\"密码\" textcolor=\"#FF54C97A\" width=\"62\" inset=\"12,0,0,0\" />"
|
||||
" <Edit name=\"editPass\" bkcolor=\"#FF16211A\" nativebkcolor=\"#FF16211A\" textcolor=\"#FFD7F5DF\" password=\"true\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"8\">"
|
||||
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF5E8A6C\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF5E8A6C\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
" <VerticalLayout />"
|
||||
" <Button name=\"btnLogin\" text=\"[ 执行登录 ]\" height=\"40\" bkcolor=\"#FF16261A\" textcolor=\"#FF7FE39B\" bordercolor=\"#FF2B3A2D\" bordersize=\"1\" />"
|
||||
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFD98A8A\" height=\"28\" inset=\"0,6,0,0\" />"
|
||||
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF4E7A5C\" height=\"18\" />"
|
||||
" <HorizontalLayout height=\"24\">"
|
||||
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
// 7) 极简单行:账号 + 密码 + 登录 一行排开
|
||||
static const char *kSkinCompact =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||
"<Window size=\"720,168\" caption=\"0,0,-1,36\" mininfo=\"720,168\" bkcolor=\"#FF11151A\">"
|
||||
" <VerticalLayout bkcolor=\"#FF11151A\" bordercolor=\"#FF2A3440\" bordersize=\"1\">"
|
||||
" <HorizontalLayout height=\"36\" bkcolor=\"#FF161C22\">"
|
||||
" <Label text=\"账号登录\" textcolor=\"#FFA8BCCE\" inset=\"16,0,0,0\" />"
|
||||
" <Button name=\"btnClose\" text=\"X\" width=\"38\" textcolor=\"#FFA8BCCE\" bkcolor=\"#FF161C22\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout inset=\"16,12,16,10\">"
|
||||
" <VerticalLayout width=\"186\">"
|
||||
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FFE9F1F8\" height=\"26\" font=\"1\" />"
|
||||
" </VerticalLayout>"
|
||||
" <VerticalLayout>"
|
||||
" <HorizontalLayout height=\"42\">"
|
||||
" <Edit name=\"editUser\" width=\"190\" bkcolor=\"#FF262E38\" nativebkcolor=\"#FF262E38\" textcolor=\"#FFFFFFFF\" bordercolor=\"#FF32404E\" inset=\"10,0,0,0\" />"
|
||||
" <HorizontalLayout width=\"10\" />"
|
||||
" <Edit name=\"editPass\" width=\"190\" bkcolor=\"#FF262E38\" nativebkcolor=\"#FF262E38\" textcolor=\"#FFFFFFFF\" bordercolor=\"#FF32404E\" inset=\"10,0,0,0\" password=\"true\" />"
|
||||
" <HorizontalLayout width=\"10\" />"
|
||||
" <Button name=\"btnLogin\" text=\"登录\" width=\"104\" height=\"42\" bkcolor=\"#FF2E9E6B\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||||
" </HorizontalLayout>"
|
||||
" <HorizontalLayout height=\"26\">"
|
||||
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF6B7C8C\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF6B7C8C\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||||
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFD98A8A\" />"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
" </HorizontalLayout>"
|
||||
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF6B7C8C\" height=\"18\" />"
|
||||
" <HorizontalLayout height=\"24\">"
|
||||
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||||
" </HorizontalLayout>"
|
||||
" </VerticalLayout>"
|
||||
"</Window>";
|
||||
|
||||
struct SkinDef { const char *name; const char *xml; int w, h; };
|
||||
static const SkinDef kSkins[] = {
|
||||
{ "dark", kSkinDark, 440, 404 },
|
||||
{ "light", kSkinLight, 440, 404 },
|
||||
{ "split", kSkinSplit, 620, 400 },
|
||||
{ "card", kSkinCard, 680, 392 },
|
||||
{ "industrial", kSkinIndustrial, 560, 376 },
|
||||
{ "terminal", kSkinTerminal, 580, 392 },
|
||||
{ "compact", kSkinCompact, 720, 168 },
|
||||
{ NULL, NULL, 0, 0 }
|
||||
};
|
||||
|
||||
static const SkinDef *skin_for(const char *theme) {
|
||||
for (int i = 0; kSkins[i].name; i++)
|
||||
if (!_stricmp(theme, kSkins[i].name)) return &kSkins[i];
|
||||
return &kSkins[0];
|
||||
}
|
||||
|
||||
/* ---------------------------- 接口请求 ---------------------------- */
|
||||
// 平台接口:POST /api/v1/app/<appKey>/login
|
||||
// {"username","password","device_id","device_name","device_type","instance_id"}
|
||||
static int api_login(const char *user, const char *pass, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
if (!g_api[0]) { snprintf(msg, cap, "配置缺少验证地址"); return 0; }
|
||||
|
||||
const char *rest = g_api;
|
||||
if (!strncmp(g_api, "https://", 8)) rest = g_api + 8;
|
||||
else if (!strncmp(g_api, "http://", 7)) rest = g_api + 7;
|
||||
bool https = (rest != g_api && g_api[4] == 's');
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) {
|
||||
int hl = (int)(slash - rest);
|
||||
if (hl > 255) hl = 255;
|
||||
memcpy(host, rest, hl);
|
||||
snprintf(path, sizeof(path), "%s", slash);
|
||||
} else {
|
||||
snprintf(host, sizeof(host), "%s", rest);
|
||||
}
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char cname[256] = {0}; DWORD cn = sizeof(cname);
|
||||
::GetComputerNameA(cname, &cn);
|
||||
|
||||
char body[2048];
|
||||
snprintf(body, sizeof(body),
|
||||
"{\"username\":\"%s\",\"password\":\"%s\",\"device_id\":\"%s\","
|
||||
"\"device_name\":\"%s\",\"device_type\":\"windows\",\"instance_id\":\"%s\"}",
|
||||
user, pass, g_device, cname, g_instance);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[4096] = {0};
|
||||
DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||||
total += cl;
|
||||
if (total >= sizeof(resp) - 1) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0]) {
|
||||
if (strstr(resp, "DEVICE_LIMIT")) snprintf(msg, cap, "设备数量已达上限,请先在平台下线一台设备");
|
||||
else if (strstr(resp, "IP_LIMIT")) snprintf(msg, cap, "IP 绑定已达上限,请解绑后再试");
|
||||
else if (ok) snprintf(msg, cap, "登录成功");
|
||||
else snprintf(msg, cap, "账号或密码错误");
|
||||
}
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* ---------------------------- 窗口 ---------------------------- */
|
||||
typedef void (*PFN_OEP)(void);
|
||||
static PFN_OEP g_oep = NULL;
|
||||
static int g_logged_in = 0;
|
||||
|
||||
// 从 cfg 的 api 里抽出站点根地址(去掉 /api/v1/... 部分)
|
||||
static std::wstring SiteRoot() {
|
||||
std::string a(g_api);
|
||||
size_t p = a.find("/api/");
|
||||
if (p != std::string::npos) a = a.substr(0, p);
|
||||
return U8(a.c_str());
|
||||
}
|
||||
static bool g_remember = false;
|
||||
|
||||
class CVerifyWnd : public CWindowWnd, public INotifyUI {
|
||||
public:
|
||||
explicit CVerifyWnd(const char *skin) : m_skin(skin) {}
|
||||
|
||||
LPCTSTR GetWindowClassName() const override { return _T("VfyDuiWnd"); }
|
||||
UINT GetClassStyle() const override { return CS_DBLCLKS; }
|
||||
|
||||
void Notify(TNotifyUI &msg) override {
|
||||
if (msg.sType == _T("click")) {
|
||||
CControlUI *p = msg.pSender;
|
||||
LPCTSTR nm = p ? p->GetName().GetData() : NULL;
|
||||
if (!nm) return;
|
||||
if (!_tcsicmp(nm, _T("btnClose")) || !_tcsicmp(nm, _T("btnQuit"))) { ::PostQuitMessage(0); return; }
|
||||
if (!_tcsicmp(nm, _T("btnLogin"))) { DoLogin(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnLinkReg")) || !_tcsicmp(nm, _T("btnLinkCard")) ||
|
||||
!_tcsicmp(nm, _T("btnLinkForgot"))) {
|
||||
std::wstring url = SiteRoot();
|
||||
// 平台只有 /login 与 /register 是公开页:注册直开,其余引导到登录页
|
||||
url += _tcsicmp(nm, _T("btnLinkReg")) == 0 ? L"/register" : L"/login";
|
||||
::ShellExecuteW(NULL, L"open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
return;
|
||||
}
|
||||
if (!_tcsicmp(nm, _T("btnRemember"))) {
|
||||
g_remember = !g_remember;
|
||||
UpdateRememberButton();
|
||||
return;
|
||||
}
|
||||
} else if (msg.sType == _T("return")) {
|
||||
DoLogin();
|
||||
} else if (msg.sType == _T("setfocus") || msg.sType == _T("killfocus")) {
|
||||
CControlUI *p = msg.pSender;
|
||||
if (!p) return;
|
||||
LPCTSTR nm = p->GetName().GetData();
|
||||
if (!nm || (_tcsicmp(nm, _T("editUser")) && _tcsicmp(nm, _T("editPass")))) return;
|
||||
bool focus = !_tcsicmp(msg.sType.GetData(), _T("setfocus"));
|
||||
if (CEditUI *e = static_cast<CEditUI *>(p)) {
|
||||
DWORD bg = e->GetBkColor();
|
||||
// 聚焦时把原生 EDIT 窗口底色提亮一档(纯 XML 画不出描边,用亮度做反馈)
|
||||
if (focus) {
|
||||
BYTE r = GetRValue(bg) + 10 > 255 ? 255 : GetRValue(bg) + 10;
|
||||
BYTE g = GetGValue(bg) + 10 > 255 ? 255 : GetGValue(bg) + 10;
|
||||
BYTE b = GetBValue(bg) + 14 > 255 ? 255 : GetBValue(bg) + 14;
|
||||
e->SetNativeEditBkColor(RGB(r, g, b));
|
||||
} else {
|
||||
e->SetNativeEditBkColor(bg);
|
||||
}
|
||||
e->Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 自绘勾选框:选中时方框填充主色(老 DuiLib 没有勾选图片资源,只能用色块表达)
|
||||
void UpdateRememberButton() {
|
||||
CLabelUI *box = static_cast<CLabelUI *>(m_pm.FindControl(_T("chkBox")));
|
||||
if (!box) return;
|
||||
box->SetBkColor(g_remember ? 0xFF2C7BE5 : 0x00000000);
|
||||
box->SetBorderColor(g_remember ? 0xFF2C7BE5 : 0xFF5A5A66);
|
||||
box->Invalidate();
|
||||
}
|
||||
|
||||
void DoLogin() {
|
||||
CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")));
|
||||
CEditUI *pPass = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")));
|
||||
CLabelUI *pTip = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblTip")));
|
||||
CButtonUI *pBtn = static_cast<CButtonUI *>(m_pm.FindControl(_T("btnLogin")));
|
||||
if (!pUser || !pPass || !pTip) return;
|
||||
|
||||
std::wstring user = pUser->GetText().GetData();
|
||||
std::wstring pass = pPass->GetText().GetData();
|
||||
if (user.empty()) { pTip->SetText(L"请输入账号或卡密"); return; }
|
||||
if (pass.empty()) { pTip->SetText(L"请输入密码"); return; }
|
||||
|
||||
SaveAccount(user, g_remember);
|
||||
|
||||
if (pBtn) { pBtn->SetText(L"验证中…"); pBtn->SetEnabled(false); }
|
||||
pTip->SetText(L"正在连接验证服务器…");
|
||||
|
||||
char msg[1024] = {0};
|
||||
int ok = api_login(W2U8(user).c_str(), W2U8(pass).c_str(), msg, sizeof(msg));
|
||||
if (ok) {
|
||||
g_logged_in = 1;
|
||||
pTip->SetText(L"验证成功,正在启动程序…");
|
||||
::SetTimer(m_hWnd, 1, 600, NULL);
|
||||
} else {
|
||||
pTip->SetText(U8(msg).c_str());
|
||||
if (pBtn) { pBtn->SetText(L"登 录"); pBtn->SetEnabled(true); }
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override {
|
||||
if (uMsg == WM_CREATE) {
|
||||
m_pm.Init(m_hWnd);
|
||||
CDialogBuilder builder;
|
||||
std::wstring xml = U8(m_skin);
|
||||
CControlUI *pRoot = builder.Create(xml.c_str(), (UINT)0, NULL, &m_pm);
|
||||
if (!pRoot) { ::MessageBoxW(m_hWnd, L"界面加载失败", L"验证", MB_ICONERROR); return 0; }
|
||||
m_pm.AttachDialog(pRoot);
|
||||
m_pm.AddNotifier(this);
|
||||
|
||||
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblApp"))))
|
||||
p->SetText(U8(g_name).c_str());
|
||||
|
||||
std::wstring devText = L"设备 ";
|
||||
devText += U8(g_device);
|
||||
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblDevice"))))
|
||||
p->SetText(devText.c_str());
|
||||
|
||||
bool remember = false;
|
||||
std::wstring saved = LoadAccount(remember);
|
||||
g_remember = remember;
|
||||
UpdateRememberButton();
|
||||
if (CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) {
|
||||
if (!saved.empty()) pUser->SetText(saved.c_str());
|
||||
pUser->SetFocus();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_TIMER && wParam == 1) {
|
||||
::KillTimer(m_hWnd, 1);
|
||||
::ShowWindow(m_hWnd, SW_HIDE);
|
||||
if (g_oep) g_oep();
|
||||
::PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_DESTROY) { ::PostQuitMessage(0); return 0; }
|
||||
|
||||
LRESULT lr = 0;
|
||||
if (m_pm.MessageHandler(uMsg, wParam, lParam, lr)) return lr;
|
||||
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
CPaintManagerUI m_pm;
|
||||
const char *m_skin;
|
||||
};
|
||||
|
||||
static int RunShell(void *oep) {
|
||||
g_oep = (PFN_OEP)oep;
|
||||
const SkinDef *sk = skin_for(g_theme);
|
||||
|
||||
CPaintManagerUI::SetInstance(::GetModuleHandle(NULL));
|
||||
::CoInitialize(NULL);
|
||||
|
||||
CVerifyWnd wnd(sk->xml);
|
||||
UINT style = WS_POPUP | WS_CLIPCHILDREN;
|
||||
UINT exstyle = WS_EX_TOPMOST | WS_EX_APPWINDOW;
|
||||
|
||||
wnd.Create(NULL, L"软件授权验证", style, exstyle, 0, 0, sk->w, sk->h);
|
||||
wnd.CenterWindow();
|
||||
::ShowWindow(wnd, SW_SHOW);
|
||||
|
||||
CPaintManagerUI::MessageLoop();
|
||||
::CoUninitialize();
|
||||
return g_logged_in ? 0 : 6;
|
||||
}
|
||||
|
||||
/* ---------------------------- 对外接口 ---------------------------- */
|
||||
static void load_cfg(const char *json) {
|
||||
snprintf(g_cfg, sizeof(g_cfg), "%s", json ? json : "");
|
||||
json_str(g_cfg, "api", g_api, sizeof(g_api));
|
||||
json_str(g_cfg, "name", g_name, sizeof(g_name));
|
||||
g_deviceAuto = json_int(g_cfg, "device_auto", 1);
|
||||
|
||||
char mid[64] = {0};
|
||||
make_machine_id(mid, sizeof(mid));
|
||||
snprintf(g_instance, sizeof(g_instance), "%s", mid);
|
||||
|
||||
if (!json_str(g_cfg, "device", g_device, sizeof(g_device)) || !g_device[0]) {
|
||||
if (g_deviceAuto) snprintf(g_device, sizeof(g_device), "%s", mid);
|
||||
else snprintf(g_device, sizeof(g_device), "%s", "UNKNOWN-DEVICE");
|
||||
}
|
||||
if (!json_str(g_cfg, "theme", g_theme, sizeof(g_theme))) snprintf(g_theme, sizeof(g_theme), "dark");
|
||||
}
|
||||
|
||||
#ifdef SHELL_EXE
|
||||
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
|
||||
const char *cfg = (lpCmdLine && lpCmdLine[0]) ? lpCmdLine : getenv("VFY_CFG");
|
||||
if (!cfg || !cfg[0]) cfg = "{\"theme\":\"dark\"}";
|
||||
load_cfg(cfg);
|
||||
return RunShell(NULL);
|
||||
}
|
||||
#else
|
||||
extern "C" __declspec(dllexport) int VerifyMain(void *oep, const char *cfgjson) {
|
||||
load_cfg(cfgjson);
|
||||
return RunShell(oep);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int VerifyShellVersion(void) { return 9; }
|
||||
extern "C" __declspec(dllexport) const char *VerifyShellThemes(void) {
|
||||
return "dark,light,split,card,industrial,terminal,compact";
|
||||
}
|
||||
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID) {
|
||||
if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(h);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,617 @@
|
||||
// shell9.cpp —— DuiLib 版 Windows 验证壳(多套结构不同的皮肤)
|
||||
//
|
||||
// 与平台验证方式严格对齐(/api/v1/app/<appKey>/login):
|
||||
// POST {username, password, device_id, device_name, device_type, instance_id}
|
||||
// 即「账号(或卡密)+ 密码 + 设备绑定」,不是只填一个卡密框。
|
||||
//
|
||||
// 对外接口不变:
|
||||
// int VerifyMain(void *oep, const char *cfgjson);
|
||||
// int VerifyShellVersion(void); // 9
|
||||
// const char *VerifyShellThemes(void); // 主题清单
|
||||
#include <windows.h>
|
||||
#include <winhttp.h>
|
||||
#include <shlobj.h>
|
||||
#include <shellapi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include "UIlib.h"
|
||||
#include "Utils/WinImplBase.h"
|
||||
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
|
||||
using namespace DuiLib;
|
||||
|
||||
/* ============================== cfg ============================== */
|
||||
static char g_cfg[4096];
|
||||
static char g_api[512];
|
||||
static char g_name[128] = "\xE6\xBC\x94\xE7\xA4\xBA\xE7\xA8\x8B\xE5\xBA\x8F"; // 演示程序
|
||||
static char g_theme[32] = "dark";
|
||||
static char g_device[64] = "";
|
||||
static char g_instance[64] = "";
|
||||
static int g_deviceAuto = 1;
|
||||
|
||||
static int json_str(const char *src, const char *key, char *out, int cap) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return 0;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return 0;
|
||||
while (*p && *p != '"') p++;
|
||||
if (!*p) return 0;
|
||||
p++;
|
||||
int i = 0;
|
||||
while (*p && *p != '"' && i < cap - 1) out[i++] = *p++;
|
||||
out[i] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int json_int(const char *src, const char *key, int def) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return def;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return def;
|
||||
return atoi(p + 1);
|
||||
}
|
||||
|
||||
static void make_machine_id(char *out, int cap);
|
||||
static void load_cfg(const char *json);
|
||||
|
||||
/* ============================ 工具 ============================ */
|
||||
static std::wstring U8(const char *s) {
|
||||
if (!s) return L"";
|
||||
int n = ::MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
|
||||
std::wstring w(n > 0 ? n - 1 : 0, L'\0');
|
||||
if (n > 1) ::MultiByteToWideChar(CP_UTF8, 0, s, -1, &w[0], n);
|
||||
return w;
|
||||
}
|
||||
|
||||
static std::string W2U8(const std::wstring &w) {
|
||||
if (w.empty()) return std::string();
|
||||
int n = ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, NULL, 0, NULL, NULL);
|
||||
std::string s(n > 0 ? n - 1 : 0, '\0');
|
||||
if (n > 1) ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, &s[0], n, NULL, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
// MachineGuid + 系统盘卷序列号 → 稳定机器码(重装系统才变)
|
||||
static void make_machine_id(char *out, int cap) {
|
||||
wchar_t guid[128] = {0};
|
||||
HKEY hk = NULL;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
|
||||
0, KEY_READ | KEY_WOW64_64KEY, &hk) == ERROR_SUCCESS) {
|
||||
DWORD sz = sizeof(guid) - sizeof(wchar_t), type = 0;
|
||||
RegQueryValueExW(hk, L"MachineGuid", NULL, &type, (LPBYTE)guid, &sz);
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
DWORD serial = 0;
|
||||
GetVolumeInformationW(L"C:\\", NULL, 0, &serial, NULL, NULL, NULL, 0);
|
||||
unsigned int h1 = 2166136261u, h2 = 3735928559u;
|
||||
for (const wchar_t *p = guid; *p; p++) {
|
||||
h1 = (h1 ^ (unsigned int)(*p & 0xFF)) * 16777619u;
|
||||
h2 = (h2 ^ (unsigned int)(*p >> 8)) * 16777619u;
|
||||
}
|
||||
h1 = (h1 ^ serial) * 16777619u;
|
||||
h2 = (h2 ^ (serial >> 16)) * 16777619u;
|
||||
snprintf(out, cap, "%04X-%04X-%04X", h1 & 0xFFFF, (h1 >> 16) & 0xFFFF, h2 & 0xFFFF);
|
||||
}
|
||||
|
||||
static std::wstring AccountIniPath() {
|
||||
wchar_t app[MAX_PATH] = {0};
|
||||
::SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, app);
|
||||
std::wstring dir = std::wstring(app) + L"\\vfy";
|
||||
::CreateDirectoryW(dir.c_str(), NULL);
|
||||
return dir + L"\\account.ini";
|
||||
}
|
||||
|
||||
static void SaveAccount(const std::wstring &user, bool remember) {
|
||||
std::wstring p = AccountIniPath();
|
||||
::WritePrivateProfileStringW(L"login", L"remember", remember ? L"1" : L"0", p.c_str());
|
||||
if (remember) ::WritePrivateProfileStringW(L"login", L"user", user.c_str(), p.c_str());
|
||||
}
|
||||
|
||||
static std::wstring LoadAccount(bool &remember) {
|
||||
std::wstring p = AccountIniPath();
|
||||
wchar_t buf[256] = {0};
|
||||
::GetPrivateProfileStringW(L"login", L"remember", L"0", buf, 256, p.c_str());
|
||||
remember = (buf[0] == L'1');
|
||||
wchar_t user[256] = {0};
|
||||
::GetPrivateProfileStringW(L"login", L"user", L"", user, 256, p.c_str());
|
||||
return remember ? std::wstring(user) : std::wstring();
|
||||
}
|
||||
|
||||
/* --------------------------- 皮肤 ---------------------------
|
||||
* 7 套在「结构」上彼此不同,字段集统一按平台验证方式:
|
||||
* 账号(账号或卡密)/ 密码 / 记住账号 / 设备信息 / 登录 / 状态行 / 注册·卡密充值·忘记密码
|
||||
* 注意:老 DuiLib 的 Edit 是「真 EDIT 子窗口」,必须用 nativebkcolor 指定它自己的底色,
|
||||
* 否则聚焦时会出现刺眼的白条(这是它构造里写死 0xFFFFFFFF 导致的)。
|
||||
*/
|
||||
|
||||
#include "skins_v3.h"
|
||||
|
||||
static const SkinDef *skin_for(const char *theme) {
|
||||
for (int i = 0; kSkins[i].name; i++)
|
||||
if (!strcmp(theme, kSkins[i].name)) return &kSkins[i];
|
||||
return &kSkins[0];
|
||||
}
|
||||
|
||||
/* ---------------------------- 接口请求 ---------------------------- */
|
||||
// 平台接口:POST /api/v1/app/<appKey>/login
|
||||
// {"username","password","device_id","device_name","device_type","instance_id"}
|
||||
static int api_login(const char *user, const char *pass, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
if (!g_api[0]) { snprintf(msg, cap, "配置缺少验证地址"); return 0; }
|
||||
|
||||
const char *rest = g_api;
|
||||
if (!strncmp(g_api, "https://", 8)) rest = g_api + 8;
|
||||
else if (!strncmp(g_api, "http://", 7)) rest = g_api + 7;
|
||||
bool https = (rest != g_api && g_api[4] == 's');
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) {
|
||||
int hl = (int)(slash - rest);
|
||||
if (hl > 255) hl = 255;
|
||||
memcpy(host, rest, hl);
|
||||
snprintf(path, sizeof(path), "%s", slash);
|
||||
} else {
|
||||
snprintf(host, sizeof(host), "%s", rest);
|
||||
}
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char cname[256] = {0}; DWORD cn = sizeof(cname);
|
||||
::GetComputerNameA(cname, &cn);
|
||||
|
||||
char body[2048];
|
||||
snprintf(body, sizeof(body),
|
||||
"{\"username\":\"%s\",\"password\":\"%s\",\"device_id\":\"%s\","
|
||||
"\"device_name\":\"%s\",\"device_type\":\"windows\",\"instance_id\":\"%s\"}",
|
||||
user, pass, g_device, cname, g_instance);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[4096] = {0};
|
||||
DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||||
total += cl;
|
||||
if (total >= sizeof(resp) - 1) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0]) {
|
||||
if (strstr(resp, "DEVICE_LIMIT")) snprintf(msg, cap, "设备数量已达上限,请先在平台下线一台设备");
|
||||
else if (strstr(resp, "IP_LIMIT")) snprintf(msg, cap, "IP 绑定已达上限,请解绑后再试");
|
||||
else if (ok) snprintf(msg, cap, "登录成功");
|
||||
else snprintf(msg, cap, "账号或密码错误");
|
||||
}
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// 注册:POST /api/v1/app/<appKey>/register
|
||||
static int api_register(const char *user, const char *email, const char *code,
|
||||
const char *pass, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
if (!g_api[0]) { snprintf(msg, cap, "配置缺少验证地址"); return 0; }
|
||||
|
||||
std::string reg = g_api;
|
||||
size_t pos = reg.rfind("/login");
|
||||
if (pos != std::string::npos) reg = reg.substr(0, pos) + "/register";
|
||||
|
||||
const char *rest = reg.c_str();
|
||||
bool https = false;
|
||||
if (!strncmp(rest, "https://", 8)) { rest += 8; https = true; }
|
||||
else if (!strncmp(rest, "http://", 7)) rest += 7;
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) { int hl = (int)(slash - rest); if (hl > 255) hl = 255; memcpy(host, rest, hl); snprintf(path, sizeof(path), "%s", slash); }
|
||||
else snprintf(host, sizeof(host), "%s", rest);
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char cname[256] = {0}; DWORD cn = sizeof(cname);
|
||||
::GetComputerNameA(cname, &cn);
|
||||
|
||||
char body[2048];
|
||||
snprintf(body, sizeof(body),
|
||||
"{\"username\":\"%s\",\"email\":\"%s\",\"email_code\":\"%s\",\"password\":\"%s\","
|
||||
"\"device_id\":\"%s\",\"device_name\":\"%s\",\"device_type\":\"windows\",\"instance_id\":\"%s\"}",
|
||||
user, email, code, pass, g_device, cname, g_instance);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[4096] = {0}; DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||||
total += cl; if (total >= sizeof(resp) - 1) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0])
|
||||
snprintf(msg, cap, ok ? "注册成功,正在登录…" : "注册失败,请检查邮箱验证码");
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// 发送邮箱验证码:POST /api/v1/app/<appKey>/send-email-code
|
||||
static int api_send_code(const char *email, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
std::string u = g_api;
|
||||
size_t pos = u.rfind("/login");
|
||||
if (pos != std::string::npos) u = u.substr(0, pos) + "/send-email-code";
|
||||
|
||||
const char *rest = u.c_str();
|
||||
bool https = false;
|
||||
if (!strncmp(rest, "https://", 8)) { rest += 8; https = true; }
|
||||
else if (!strncmp(rest, "http://", 7)) rest += 7;
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) { int hl = (int)(slash - rest); if (hl > 255) hl = 255; memcpy(host, rest, hl); snprintf(path, sizeof(path), "%s", slash); }
|
||||
else snprintf(host, sizeof(host), "%s", rest);
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char body[512];
|
||||
snprintf(body, sizeof(body), "{\"email\":\"%s\"}", email);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[2048] = {0}; DWORD cl = 0;
|
||||
WinHttpReadData(hR, resp, sizeof(resp) - 1, &cl);
|
||||
resp[cl < sizeof(resp) ? cl : sizeof(resp) - 1] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0])
|
||||
snprintf(msg, cap, ok ? "验证码已发送" : "发送失败");
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* ---------------------------- 窗口 ---------------------------- */
|
||||
typedef void (*PFN_OEP)(void);
|
||||
static PFN_OEP g_oep = NULL;
|
||||
static int g_logged_in = 0;
|
||||
|
||||
// 从 cfg 的 api 里抽出站点根地址(去掉 /api/v1/... 部分)
|
||||
static std::wstring SiteRoot() {
|
||||
std::string a(g_api);
|
||||
size_t p = a.find("/api/");
|
||||
if (p != std::string::npos) a = a.substr(0, p);
|
||||
return U8(a.c_str());
|
||||
}
|
||||
static bool g_remember = false;
|
||||
static int g_tab = 0; // 0=登录 1=注册
|
||||
|
||||
class CVerifyWnd : public CWindowWnd, public INotifyUI {
|
||||
public:
|
||||
explicit CVerifyWnd(const char *skin) : m_skin(skin) {}
|
||||
|
||||
LPCTSTR GetWindowClassName() const override { return _T("VfyDuiWnd"); }
|
||||
UINT GetClassStyle() const override { return CS_DBLCLKS; }
|
||||
|
||||
void Notify(TNotifyUI &msg) override {
|
||||
if (msg.sType == _T("click")) {
|
||||
CControlUI *p = msg.pSender;
|
||||
LPCTSTR nm = p ? p->GetName().GetData() : NULL;
|
||||
if (!nm) return;
|
||||
if (!_tcsicmp(nm, _T("btnClose")) || !_tcsicmp(nm, _T("btnQuit"))) { ::PostQuitMessage(0); return; }
|
||||
if (!_tcsicmp(nm, _T("btnLogin"))) { DoLogin(); return; }
|
||||
if (!_tcsicmp(nm, _T("tabLogin"))) { SwitchTab(0); return; }
|
||||
if (!_tcsicmp(nm, _T("tabRegister"))) { SwitchTab(1); return; }
|
||||
if (!_tcsicmp(nm, _T("btnRegister"))) { DoRegister(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnSendCode"))) { DoSendCode(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnLinkReg")) || !_tcsicmp(nm, _T("btnLinkCard")) ||
|
||||
!_tcsicmp(nm, _T("btnLinkForgot"))) {
|
||||
std::wstring url = SiteRoot();
|
||||
// 平台只有 /login 与 /register 是公开页:注册直开,其余引导到登录页
|
||||
url += _tcsicmp(nm, _T("btnLinkReg")) == 0 ? L"/register" : L"/login";
|
||||
::ShellExecuteW(NULL, L"open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
return;
|
||||
}
|
||||
if (!_tcsicmp(nm, _T("btnRemember"))) {
|
||||
g_remember = !g_remember;
|
||||
UpdateRememberButton();
|
||||
return;
|
||||
}
|
||||
} else if (msg.sType == _T("return")) {
|
||||
DoLogin();
|
||||
} else if (msg.sType == _T("setfocus") || msg.sType == _T("killfocus")) {
|
||||
CControlUI *p = msg.pSender;
|
||||
if (!p) return;
|
||||
LPCTSTR nm = p->GetName().GetData();
|
||||
if (!nm || (_tcsicmp(nm, _T("editUser")) && _tcsicmp(nm, _T("editPass")))) return;
|
||||
bool focus = !_tcsicmp(msg.sType.GetData(), _T("setfocus"));
|
||||
if (CEditUI *e = static_cast<CEditUI *>(p)) {
|
||||
DWORD bg = e->GetBkColor();
|
||||
// 聚焦时把原生 EDIT 窗口底色提亮一档(纯 XML 画不出描边,用亮度做反馈)
|
||||
if (focus) {
|
||||
BYTE r = GetRValue(bg) + 10 > 255 ? 255 : GetRValue(bg) + 10;
|
||||
BYTE g = GetGValue(bg) + 10 > 255 ? 255 : GetGValue(bg) + 10;
|
||||
BYTE b = GetBValue(bg) + 14 > 255 ? 255 : GetBValue(bg) + 14;
|
||||
e->SetNativeEditBkColor(RGB(r, g, b));
|
||||
} else {
|
||||
e->SetNativeEditBkColor(bg);
|
||||
}
|
||||
e->Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- 登录 / 注册 切换 ----------------
|
||||
void SwitchTab(int tab) {
|
||||
g_tab = tab;
|
||||
if (CControlUI *p = m_pm.FindControl(_T("panelLogin"))) p->SetVisible(tab == 0);
|
||||
if (CControlUI *p = m_pm.FindControl(_T("panelRegister"))) p->SetVisible(tab == 1);
|
||||
UpdateTabStyle();
|
||||
}
|
||||
|
||||
// 每套皮肤的 tab 表达方式不同:下划线 / 段按钮 / 纯文字 / 标题栏内
|
||||
void UpdateTabStyle() {
|
||||
CButtonUI *bL = static_cast<CButtonUI *>(m_pm.FindControl(_T("tabLogin")));
|
||||
CButtonUI *bR = static_cast<CButtonUI *>(m_pm.FindControl(_T("tabRegister")));
|
||||
if (!bL || !bR) return;
|
||||
bool login = (g_tab == 0);
|
||||
std::string th(g_theme);
|
||||
|
||||
if (th == "light") {
|
||||
bL->SetBkColor(login ? 0xFF1B6FD6 : 0xFFEDF0F5);
|
||||
bR->SetBkColor(login ? 0xFFEDF0F5 : 0xFF1B6FD6);
|
||||
bL->SetTextColor(login ? 0xFFFFFFFF : 0xFF5B6270);
|
||||
bR->SetTextColor(login ? 0xFF5B6270 : 0xFFFFFFFF);
|
||||
} else if (th == "industrial") {
|
||||
bL->SetBkColor(login ? 0xFF1A5A8C : 0x00000000);
|
||||
bR->SetBkColor(login ? 0x00000000 : 0xFF1A5A8C);
|
||||
bL->SetTextColor(login ? 0xFFFFFFFF : 0xFF9FC8E6);
|
||||
bR->SetTextColor(login ? 0xFF9FC8E6 : 0xFFFFFFFF);
|
||||
} else if (th == "compact") {
|
||||
bL->SetBkColor(login ? 0xFF2E9E6B : 0xFF1B232B);
|
||||
bR->SetBkColor(login ? 0xFF1B232B : 0xFF2E9E6B);
|
||||
bL->SetTextColor(login ? 0xFFFFFFFF : 0xFF9FB3C8);
|
||||
bR->SetTextColor(login ? 0xFF9FB3C8 : 0xFFFFFFFF);
|
||||
} else if (th == "card") {
|
||||
bL->SetBkColor(login ? 0xFFFFFFFF : 0xFFE8E6FF);
|
||||
bR->SetBkColor(login ? 0xFFE8E6FF : 0xFFFFFFFF);
|
||||
bL->SetTextColor(login ? 0xFF3B2BD6 : 0xFF5B56A8);
|
||||
bR->SetTextColor(login ? 0xFF5B56A8 : 0xFF3B2BD6);
|
||||
} else { // dark / split / terminal:只有文字颜色 + 下划线控件
|
||||
DWORD act = (th == "terminal") ? 0xFF7FE39B : (th == "split" ? 0xFF4CC2FF : 0xFF4EA3E8);
|
||||
DWORD idle = (th == "terminal") ? 0xFF4E7A5C : (th == "split" ? 0xFF7A8794 : 0xFF85858F);
|
||||
bL->SetTextColor(login ? act : idle);
|
||||
bR->SetTextColor(login ? idle : act);
|
||||
if (CControlUI *line = m_pm.FindControl(_T("tabRegLine")))
|
||||
line->SetBkColor(login ? 0x00000000 : act);
|
||||
}
|
||||
bL->Invalidate(); bR->Invalidate();
|
||||
}
|
||||
|
||||
void DoRegister() {
|
||||
CEditUI *u = static_cast<CEditUI *>(m_pm.FindControl(_T("regUser")));
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("regEmail")));
|
||||
CEditUI *c = static_cast<CEditUI *>(m_pm.FindControl(_T("regCode")));
|
||||
CEditUI *p1 = static_cast<CEditUI *>(m_pm.FindControl(_T("regPass")));
|
||||
CEditUI *p2 = static_cast<CEditUI *>(m_pm.FindControl(_T("regPass2")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("regTip")));
|
||||
if (!u || !e || !c || !p1 || !p2 || !tip) return;
|
||||
|
||||
std::wstring user = u->GetText().GetData(), email = e->GetText().GetData();
|
||||
std::wstring code = c->GetText().GetData(), pass = p1->GetText().GetData();
|
||||
std::wstring pass2 = p2->GetText().GetData();
|
||||
if (user.empty()) { tip->SetText(L"请输入用户名"); return; }
|
||||
if (email.empty()) { tip->SetText(L"请输入邮箱"); return; }
|
||||
if (code.empty()) { tip->SetText(L"请输入邮箱验证码"); return; }
|
||||
if (pass.size() < 6) { tip->SetText(L"密码至少 6 位"); return; }
|
||||
if (pass != pass2) { tip->SetText(L"两次输入的密码不一致"); return; }
|
||||
|
||||
tip->SetText(L"正在提交注册…");
|
||||
char msg[1024] = {0};
|
||||
int ok = api_register(W2U8(user).c_str(), W2U8(email).c_str(), W2U8(code).c_str(),
|
||||
W2U8(pass).c_str(), msg, sizeof(msg));
|
||||
if (!ok) { tip->SetText(U8(msg).c_str()); return; }
|
||||
|
||||
// 注册成功直接登录
|
||||
if (CEditUI *lu = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) lu->SetText(user.c_str());
|
||||
if (CEditUI *lp = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")))) lp->SetText(pass.c_str());
|
||||
SwitchTab(0);
|
||||
DoLogin();
|
||||
}
|
||||
|
||||
void DoSendCode() {
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("regEmail")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("regTip")));
|
||||
if (!e || !tip) return;
|
||||
std::wstring email = e->GetText().GetData();
|
||||
if (email.empty()) { tip->SetText(L"请先填邮箱"); return; }
|
||||
char msg[512] = {0};
|
||||
api_send_code(W2U8(email).c_str(), msg, sizeof(msg));
|
||||
tip->SetText(U8(msg).c_str());
|
||||
}
|
||||
|
||||
// 自绘勾选框:选中时方框填充主色(老 DuiLib 没有勾选图片资源,只能用色块表达)
|
||||
void UpdateRememberButton() {
|
||||
CLabelUI *box = static_cast<CLabelUI *>(m_pm.FindControl(_T("chkBox")));
|
||||
if (!box) return;
|
||||
box->SetBkColor(g_remember ? 0xFF2C7BE5 : 0x00000000);
|
||||
box->SetBorderColor(g_remember ? 0xFF2C7BE5 : 0xFF5A5A66);
|
||||
box->Invalidate();
|
||||
}
|
||||
|
||||
void DoLogin() {
|
||||
CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")));
|
||||
CEditUI *pPass = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")));
|
||||
CLabelUI *pTip = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblTip")));
|
||||
CButtonUI *pBtn = static_cast<CButtonUI *>(m_pm.FindControl(_T("btnLogin")));
|
||||
if (!pUser || !pPass || !pTip) return;
|
||||
|
||||
std::wstring user = pUser->GetText().GetData();
|
||||
std::wstring pass = pPass->GetText().GetData();
|
||||
if (user.empty()) { pTip->SetText(L"请输入账号或卡密"); return; }
|
||||
if (pass.empty()) { pTip->SetText(L"请输入密码"); return; }
|
||||
|
||||
SaveAccount(user, g_remember);
|
||||
|
||||
if (pBtn) { pBtn->SetText(L"验证中…"); pBtn->SetEnabled(false); }
|
||||
pTip->SetText(L"正在连接验证服务器…");
|
||||
|
||||
char msg[1024] = {0};
|
||||
int ok = api_login(W2U8(user).c_str(), W2U8(pass).c_str(), msg, sizeof(msg));
|
||||
if (ok) {
|
||||
g_logged_in = 1;
|
||||
pTip->SetText(L"验证成功,正在启动程序…");
|
||||
::SetTimer(m_hWnd, 1, 600, NULL);
|
||||
} else {
|
||||
pTip->SetText(U8(msg).c_str());
|
||||
if (pBtn) { pBtn->SetText(L"登 录"); pBtn->SetEnabled(true); }
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override {
|
||||
if (uMsg == WM_CREATE) {
|
||||
m_pm.Init(m_hWnd);
|
||||
CDialogBuilder builder;
|
||||
std::wstring xml = U8(m_skin);
|
||||
CControlUI *pRoot = builder.Create(xml.c_str(), (UINT)0, NULL, &m_pm);
|
||||
if (!pRoot) { ::MessageBoxW(m_hWnd, L"界面加载失败", L"验证", MB_ICONERROR); return 0; }
|
||||
m_pm.AttachDialog(pRoot);
|
||||
m_pm.AddNotifier(this);
|
||||
|
||||
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblApp"))))
|
||||
p->SetText(U8(g_name).c_str());
|
||||
|
||||
std::wstring devText = L"设备 ";
|
||||
devText += U8(g_device);
|
||||
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblDevice"))))
|
||||
p->SetText(devText.c_str());
|
||||
|
||||
bool remember = false;
|
||||
std::wstring saved = LoadAccount(remember);
|
||||
g_remember = remember;
|
||||
UpdateRememberButton();
|
||||
SwitchTab(0);
|
||||
if (CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) {
|
||||
if (!saved.empty()) pUser->SetText(saved.c_str());
|
||||
pUser->SetFocus();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_TIMER && wParam == 1) {
|
||||
::KillTimer(m_hWnd, 1);
|
||||
::ShowWindow(m_hWnd, SW_HIDE);
|
||||
if (g_oep) g_oep();
|
||||
::PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_DESTROY) { ::PostQuitMessage(0); return 0; }
|
||||
|
||||
LRESULT lr = 0;
|
||||
if (m_pm.MessageHandler(uMsg, wParam, lParam, lr)) return lr;
|
||||
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
CPaintManagerUI m_pm;
|
||||
const char *m_skin;
|
||||
};
|
||||
|
||||
static int RunShell(void *oep) {
|
||||
g_oep = (PFN_OEP)oep;
|
||||
const SkinDef *sk = skin_for(g_theme);
|
||||
|
||||
CPaintManagerUI::SetInstance(::GetModuleHandle(NULL));
|
||||
::CoInitialize(NULL);
|
||||
|
||||
CVerifyWnd wnd(sk->xml);
|
||||
UINT style = WS_POPUP | WS_CLIPCHILDREN;
|
||||
UINT exstyle = WS_EX_TOPMOST | WS_EX_APPWINDOW;
|
||||
|
||||
wnd.Create(NULL, L"软件授权验证", style, exstyle, 0, 0, sk->w, sk->h);
|
||||
wnd.CenterWindow();
|
||||
::ShowWindow(wnd, SW_SHOW);
|
||||
|
||||
CPaintManagerUI::MessageLoop();
|
||||
::CoUninitialize();
|
||||
return g_logged_in ? 0 : 6;
|
||||
}
|
||||
|
||||
/* ---------------------------- 对外接口 ---------------------------- */
|
||||
static void load_cfg(const char *json) {
|
||||
snprintf(g_cfg, sizeof(g_cfg), "%s", json ? json : "");
|
||||
json_str(g_cfg, "api", g_api, sizeof(g_api));
|
||||
json_str(g_cfg, "name", g_name, sizeof(g_name));
|
||||
g_deviceAuto = json_int(g_cfg, "device_auto", 1);
|
||||
|
||||
char mid[64] = {0};
|
||||
make_machine_id(mid, sizeof(mid));
|
||||
snprintf(g_instance, sizeof(g_instance), "%s", mid);
|
||||
|
||||
if (!json_str(g_cfg, "device", g_device, sizeof(g_device)) || !g_device[0]) {
|
||||
if (g_deviceAuto) snprintf(g_device, sizeof(g_device), "%s", mid);
|
||||
else snprintf(g_device, sizeof(g_device), "%s", "UNKNOWN-DEVICE");
|
||||
}
|
||||
if (!json_str(g_cfg, "theme", g_theme, sizeof(g_theme))) snprintf(g_theme, sizeof(g_theme), "dark");
|
||||
}
|
||||
|
||||
#ifdef SHELL_EXE
|
||||
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
|
||||
const char *cfg = (lpCmdLine && lpCmdLine[0]) ? lpCmdLine : getenv("VFY_CFG");
|
||||
if (!cfg || !cfg[0]) cfg = "{\"theme\":\"dark\"}";
|
||||
load_cfg(cfg);
|
||||
return RunShell(NULL);
|
||||
}
|
||||
#else
|
||||
extern "C" __declspec(dllexport) int VerifyMain(void *oep, const char *cfgjson) {
|
||||
load_cfg(cfgjson);
|
||||
return RunShell(oep);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int VerifyShellVersion(void) { return 9; }
|
||||
extern "C" __declspec(dllexport) const char *VerifyShellThemes(void) {
|
||||
return "dark,light,split,card,industrial,terminal,compact";
|
||||
}
|
||||
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID) {
|
||||
if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(h);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,771 @@
|
||||
// shell9.cpp —— DuiLib 版 Windows 验证壳(多套结构不同的皮肤)
|
||||
//
|
||||
// 与平台验证方式严格对齐(/api/v1/app/<appKey>/login):
|
||||
// POST {username, password, device_id, device_name, device_type, instance_id}
|
||||
// 即「账号(或卡密)+ 密码 + 设备绑定」,不是只填一个卡密框。
|
||||
//
|
||||
// 对外接口不变:
|
||||
// int VerifyMain(void *oep, const char *cfgjson);
|
||||
// int VerifyShellVersion(void); // 9
|
||||
// const char *VerifyShellThemes(void); // 主题清单
|
||||
#include <windows.h>
|
||||
#include <winhttp.h>
|
||||
#include <shlobj.h>
|
||||
#include <shellapi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include "UIlib.h"
|
||||
#include "Utils/WinImplBase.h"
|
||||
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
|
||||
using namespace DuiLib;
|
||||
|
||||
/* ============================== cfg ============================== */
|
||||
static char g_cfg[4096];
|
||||
static char g_api[512];
|
||||
static char g_name[128] = "\xE6\xBC\x94\xE7\xA4\xBA\xE7\xA8\x8B\xE5\xBA\x8F"; // 演示程序
|
||||
static char g_theme[32] = "dark";
|
||||
static char g_device[64] = "";
|
||||
static char g_instance[64] = "";
|
||||
static int g_deviceAuto = 1;
|
||||
|
||||
static int json_str(const char *src, const char *key, char *out, int cap) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return 0;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return 0;
|
||||
while (*p && *p != '"') p++;
|
||||
if (!*p) return 0;
|
||||
p++;
|
||||
int i = 0;
|
||||
while (*p && *p != '"' && i < cap - 1) out[i++] = *p++;
|
||||
out[i] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int json_int(const char *src, const char *key, int def) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return def;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return def;
|
||||
return atoi(p + 1);
|
||||
}
|
||||
|
||||
static void make_machine_id(char *out, int cap);
|
||||
static void load_cfg(const char *json);
|
||||
|
||||
/* ============================ 工具 ============================ */
|
||||
static std::wstring U8(const char *s) {
|
||||
if (!s) return L"";
|
||||
int n = ::MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
|
||||
std::wstring w(n > 0 ? n - 1 : 0, L'\0');
|
||||
if (n > 1) ::MultiByteToWideChar(CP_UTF8, 0, s, -1, &w[0], n);
|
||||
return w;
|
||||
}
|
||||
|
||||
static std::string W2U8(const std::wstring &w) {
|
||||
if (w.empty()) return std::string();
|
||||
int n = ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, NULL, 0, NULL, NULL);
|
||||
std::string s(n > 0 ? n - 1 : 0, '\0');
|
||||
if (n > 1) ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, &s[0], n, NULL, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
// MachineGuid + 系统盘卷序列号 → 稳定机器码(重装系统才变)
|
||||
static void make_machine_id(char *out, int cap) {
|
||||
wchar_t guid[128] = {0};
|
||||
HKEY hk = NULL;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
|
||||
0, KEY_READ | KEY_WOW64_64KEY, &hk) == ERROR_SUCCESS) {
|
||||
DWORD sz = sizeof(guid) - sizeof(wchar_t), type = 0;
|
||||
RegQueryValueExW(hk, L"MachineGuid", NULL, &type, (LPBYTE)guid, &sz);
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
DWORD serial = 0;
|
||||
GetVolumeInformationW(L"C:\\", NULL, 0, &serial, NULL, NULL, NULL, 0);
|
||||
unsigned int h1 = 2166136261u, h2 = 3735928559u;
|
||||
for (const wchar_t *p = guid; *p; p++) {
|
||||
h1 = (h1 ^ (unsigned int)(*p & 0xFF)) * 16777619u;
|
||||
h2 = (h2 ^ (unsigned int)(*p >> 8)) * 16777619u;
|
||||
}
|
||||
h1 = (h1 ^ serial) * 16777619u;
|
||||
h2 = (h2 ^ (serial >> 16)) * 16777619u;
|
||||
snprintf(out, cap, "%04X-%04X-%04X", h1 & 0xFFFF, (h1 >> 16) & 0xFFFF, h2 & 0xFFFF);
|
||||
}
|
||||
|
||||
static std::wstring AccountIniPath() {
|
||||
wchar_t app[MAX_PATH] = {0};
|
||||
::SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, app);
|
||||
std::wstring dir = std::wstring(app) + L"\\vfy";
|
||||
::CreateDirectoryW(dir.c_str(), NULL);
|
||||
return dir + L"\\account.ini";
|
||||
}
|
||||
|
||||
static void SaveAccount(const std::wstring &user, bool remember) {
|
||||
std::wstring p = AccountIniPath();
|
||||
::WritePrivateProfileStringW(L"login", L"remember", remember ? L"1" : L"0", p.c_str());
|
||||
if (remember) ::WritePrivateProfileStringW(L"login", L"user", user.c_str(), p.c_str());
|
||||
}
|
||||
|
||||
static std::wstring LoadAccount(bool &remember) {
|
||||
std::wstring p = AccountIniPath();
|
||||
wchar_t buf[256] = {0};
|
||||
::GetPrivateProfileStringW(L"login", L"remember", L"0", buf, 256, p.c_str());
|
||||
remember = (buf[0] == L'1');
|
||||
wchar_t user[256] = {0};
|
||||
::GetPrivateProfileStringW(L"login", L"user", L"", user, 256, p.c_str());
|
||||
return remember ? std::wstring(user) : std::wstring();
|
||||
}
|
||||
|
||||
/* --------------------------- 皮肤 ---------------------------
|
||||
* 7 套在「结构」上彼此不同,字段集统一按平台验证方式:
|
||||
* 账号(账号或卡密)/ 密码 / 记住账号 / 设备信息 / 登录 / 状态行 / 注册·卡密充值·忘记密码
|
||||
* 注意:老 DuiLib 的 Edit 是「真 EDIT 子窗口」,必须用 nativebkcolor 指定它自己的底色,
|
||||
* 否则聚焦时会出现刺眼的白条(这是它构造里写死 0xFFFFFFFF 导致的)。
|
||||
*/
|
||||
|
||||
#include "skins_v4.h"
|
||||
|
||||
static const SkinDef *skin_for(const char *theme) {
|
||||
for (int i = 0; kSkins[i].name; i++)
|
||||
if (!strcmp(theme, kSkins[i].name)) return &kSkins[i];
|
||||
return &kSkins[0];
|
||||
}
|
||||
|
||||
/* ---------------------------- 接口请求 ---------------------------- */
|
||||
// 平台接口:POST /api/v1/app/<appKey>/login
|
||||
// {"username","password","device_id","device_name","device_type","instance_id"}
|
||||
static int api_login(const char *user, const char *pass, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
if (!g_api[0]) { snprintf(msg, cap, "配置缺少验证地址"); return 0; }
|
||||
|
||||
const char *rest = g_api;
|
||||
if (!strncmp(g_api, "https://", 8)) rest = g_api + 8;
|
||||
else if (!strncmp(g_api, "http://", 7)) rest = g_api + 7;
|
||||
bool https = (rest != g_api && g_api[4] == 's');
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) {
|
||||
int hl = (int)(slash - rest);
|
||||
if (hl > 255) hl = 255;
|
||||
memcpy(host, rest, hl);
|
||||
snprintf(path, sizeof(path), "%s", slash);
|
||||
} else {
|
||||
snprintf(host, sizeof(host), "%s", rest);
|
||||
}
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char cname[256] = {0}; DWORD cn = sizeof(cname);
|
||||
::GetComputerNameA(cname, &cn);
|
||||
|
||||
char body[2048];
|
||||
snprintf(body, sizeof(body),
|
||||
"{\"username\":\"%s\",\"password\":\"%s\",\"device_id\":\"%s\","
|
||||
"\"device_name\":\"%s\",\"device_type\":\"windows\",\"instance_id\":\"%s\"}",
|
||||
user, pass, g_device, cname, g_instance);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[4096] = {0};
|
||||
DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||||
total += cl;
|
||||
if (total >= sizeof(resp) - 1) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0]) {
|
||||
if (strstr(resp, "DEVICE_LIMIT")) snprintf(msg, cap, "设备数量已达上限,请先在平台下线一台设备");
|
||||
else if (strstr(resp, "IP_LIMIT")) snprintf(msg, cap, "IP 绑定已达上限,请解绑后再试");
|
||||
else if (ok) snprintf(msg, cap, "登录成功");
|
||||
else snprintf(msg, cap, "账号或密码错误");
|
||||
}
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// 注册:POST /api/v1/app/<appKey>/register
|
||||
static int api_register(const char *user, const char *email, const char *code,
|
||||
const char *pass, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
if (!g_api[0]) { snprintf(msg, cap, "配置缺少验证地址"); return 0; }
|
||||
|
||||
std::string reg = g_api;
|
||||
size_t pos = reg.rfind("/login");
|
||||
if (pos != std::string::npos) reg = reg.substr(0, pos) + "/register";
|
||||
|
||||
const char *rest = reg.c_str();
|
||||
bool https = false;
|
||||
if (!strncmp(rest, "https://", 8)) { rest += 8; https = true; }
|
||||
else if (!strncmp(rest, "http://", 7)) rest += 7;
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) { int hl = (int)(slash - rest); if (hl > 255) hl = 255; memcpy(host, rest, hl); snprintf(path, sizeof(path), "%s", slash); }
|
||||
else snprintf(host, sizeof(host), "%s", rest);
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char cname[256] = {0}; DWORD cn = sizeof(cname);
|
||||
::GetComputerNameA(cname, &cn);
|
||||
|
||||
char body[2048];
|
||||
snprintf(body, sizeof(body),
|
||||
"{\"username\":\"%s\",\"email\":\"%s\",\"email_code\":\"%s\",\"password\":\"%s\","
|
||||
"\"device_id\":\"%s\",\"device_name\":\"%s\",\"device_type\":\"windows\",\"instance_id\":\"%s\"}",
|
||||
user, email, code, pass, g_device, cname, g_instance);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[4096] = {0}; DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||||
total += cl; if (total >= sizeof(resp) - 1) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0])
|
||||
snprintf(msg, cap, ok ? "注册成功,正在登录…" : "注册失败,请检查邮箱验证码");
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// 发送邮箱验证码:POST /api/v1/app/<appKey>/send-email-code
|
||||
static int api_send_code(const char *email, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
std::string u = g_api;
|
||||
size_t pos = u.rfind("/login");
|
||||
if (pos != std::string::npos) u = u.substr(0, pos) + "/send-email-code";
|
||||
|
||||
const char *rest = u.c_str();
|
||||
bool https = false;
|
||||
if (!strncmp(rest, "https://", 8)) { rest += 8; https = true; }
|
||||
else if (!strncmp(rest, "http://", 7)) rest += 7;
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) { int hl = (int)(slash - rest); if (hl > 255) hl = 255; memcpy(host, rest, hl); snprintf(path, sizeof(path), "%s", slash); }
|
||||
else snprintf(host, sizeof(host), "%s", rest);
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char body[512];
|
||||
snprintf(body, sizeof(body), "{\"email\":\"%s\"}", email);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[2048] = {0}; DWORD cl = 0;
|
||||
WinHttpReadData(hR, resp, sizeof(resp) - 1, &cl);
|
||||
resp[cl < sizeof(resp) ? cl : sizeof(resp) - 1] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0])
|
||||
snprintf(msg, cap, ok ? "验证码已发送" : "发送失败");
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
// 通用 POST:把 JSON 发到 api 的某个兄弟路径(/login → /recharge 之类)
|
||||
static int api_post_sibling(const char *sibling, const char *body, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
std::string u = g_api;
|
||||
size_t pos = u.rfind("/login");
|
||||
if (pos != std::string::npos) u = u.substr(0, pos) + sibling;
|
||||
|
||||
const char *rest = u.c_str();
|
||||
bool https = false;
|
||||
if (!strncmp(rest, "https://", 8)) { rest += 8; https = true; }
|
||||
else if (!strncmp(rest, "http://", 7)) rest += 7;
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) { int hl = (int)(slash - rest); if (hl > 255) hl = 255; memcpy(host, rest, hl); snprintf(path, sizeof(path), "%s", slash); }
|
||||
else snprintf(host, sizeof(host), "%s", rest);
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[4096] = {0}; DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||||
total += cl; if (total >= sizeof(resp) - 1) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0]) {
|
||||
if (ok) snprintf(msg, cap, "操作成功");
|
||||
else snprintf(msg, cap, "操作失败");
|
||||
}
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* ---------------------------- 窗口 ---------------------------- */
|
||||
typedef void (*PFN_OEP)(void);
|
||||
static PFN_OEP g_oep = NULL;
|
||||
static int g_logged_in = 0;
|
||||
|
||||
// 从 cfg 的 api 里抽出站点根地址(去掉 /api/v1/... 部分)
|
||||
static std::wstring SiteRoot() {
|
||||
std::string a(g_api);
|
||||
size_t p = a.find("/api/");
|
||||
if (p != std::string::npos) a = a.substr(0, p);
|
||||
return U8(a.c_str());
|
||||
}
|
||||
static bool g_remember = false;
|
||||
static int g_tab = 0; // 0=登录 1=注册
|
||||
|
||||
|
||||
// 面板内容高度 = 所有子控件固定高度之和(面板 height=auto,pos 不可靠)
|
||||
static int PanelContentHeight(CControlUI *panel) {
|
||||
CContainerUI *box = dynamic_cast<CContainerUI *>(panel);
|
||||
if (!box) return 0;
|
||||
int n = box->GetCount(), sum = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
CControlUI *c = box->GetItemAt(i);
|
||||
if (!c) continue;
|
||||
int h = c->GetFixedHeight();
|
||||
if (h <= 0) { RECT pr = c->GetPos(); h = pr.bottom - pr.top; }
|
||||
if (h > 0) sum += h;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
class CVerifyWnd : public CWindowWnd, public INotifyUI {
|
||||
public:
|
||||
explicit CVerifyWnd(const char *skin) : m_skin(skin) {}
|
||||
|
||||
LPCTSTR GetWindowClassName() const override { return _T("VfyDuiWnd"); }
|
||||
UINT GetClassStyle() const override { return CS_DBLCLKS; }
|
||||
|
||||
void Notify(TNotifyUI &msg) override {
|
||||
if (msg.sType == _T("click")) {
|
||||
CControlUI *p = msg.pSender;
|
||||
LPCTSTR nm = p ? p->GetName().GetData() : NULL;
|
||||
if (!nm) return;
|
||||
if (!_tcsicmp(nm, _T("btnClose")) || !_tcsicmp(nm, _T("btnQuit"))) { ::PostQuitMessage(0); return; }
|
||||
if (!_tcsicmp(nm, _T("btnLogin"))) { DoLogin(); return; }
|
||||
if (!_tcsicmp(nm, _T("tabLogin"))) { SwitchTab(0); return; }
|
||||
if (!_tcsicmp(nm, _T("tabRegister"))) { SwitchTab(1); return; }
|
||||
if (!_tcsicmp(nm, _T("tabCard"))) { SwitchTab(2); return; }
|
||||
if (!_tcsicmp(nm, _T("tabReset"))) { SwitchTab(3); return; }
|
||||
if (!_tcsicmp(nm, _T("btnRecharge"))) { DoRecharge(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnReset"))) { DoReset(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnSendCode2"))) { DoSendResetCode(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnRegister"))) { DoRegister(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnSendCode"))) { DoSendCode(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnLinkReg")) || !_tcsicmp(nm, _T("btnLinkCard")) ||
|
||||
!_tcsicmp(nm, _T("btnLinkForgot"))) {
|
||||
std::wstring url = SiteRoot();
|
||||
// 平台只有 /login 与 /register 是公开页:注册直开,其余引导到登录页
|
||||
url += _tcsicmp(nm, _T("btnLinkReg")) == 0 ? L"/register" : L"/login";
|
||||
::ShellExecuteW(NULL, L"open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
return;
|
||||
}
|
||||
if (!_tcsicmp(nm, _T("btnRemember"))) {
|
||||
g_remember = !g_remember;
|
||||
UpdateRememberButton();
|
||||
return;
|
||||
}
|
||||
} else if (msg.sType == _T("return")) {
|
||||
DoLogin();
|
||||
} else if (msg.sType == _T("setfocus") || msg.sType == _T("killfocus")) {
|
||||
CControlUI *p = msg.pSender;
|
||||
if (!p) return;
|
||||
LPCTSTR nm = p->GetName().GetData();
|
||||
if (!nm || (_tcsicmp(nm, _T("editUser")) && _tcsicmp(nm, _T("editPass")))) return;
|
||||
bool focus = !_tcsicmp(msg.sType.GetData(), _T("setfocus"));
|
||||
if (CEditUI *e = static_cast<CEditUI *>(p)) {
|
||||
DWORD bg = e->GetBkColor();
|
||||
// 聚焦时把原生 EDIT 窗口底色提亮一档(纯 XML 画不出描边,用亮度做反馈)
|
||||
if (focus) {
|
||||
BYTE r = GetRValue(bg) + 10 > 255 ? 255 : GetRValue(bg) + 10;
|
||||
BYTE g = GetGValue(bg) + 10 > 255 ? 255 : GetGValue(bg) + 10;
|
||||
BYTE b = GetBValue(bg) + 14 > 255 ? 255 : GetBValue(bg) + 14;
|
||||
e->SetNativeEditBkColor(RGB(r, g, b));
|
||||
} else {
|
||||
e->SetNativeEditBkColor(bg);
|
||||
}
|
||||
e->Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- 四个 tab:登录 / 注册 / 卡密充值 / 忘记密码 ----------------
|
||||
void SwitchTab(int tab) {
|
||||
int old = g_tab;
|
||||
g_tab = tab;
|
||||
const char *panels[4] = { "panelLogin", "panelRegister", "panelCard", "panelReset" };
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (CControlUI *p = m_pm.FindControl(U8(panels[i]).c_str()))
|
||||
p->SetVisible(i == tab);
|
||||
}
|
||||
UpdateTabStyle();
|
||||
ResizeForTab(tab, old);
|
||||
}
|
||||
|
||||
// 面板高度不同:切换后按新面板高度改窗口高度,避免大片空白或内容被切
|
||||
void ResizeForTab(int tab, int old) {
|
||||
if (m_chromeH <= 0) return;
|
||||
const char *panels[4] = { "panelLogin", "panelRegister", "panelCard", "panelReset" };
|
||||
CControlUI *p = m_pm.FindControl(U8(panels[tab]).c_str());
|
||||
if (!p) return;
|
||||
int h = p->GetFixedHeight(); // 面板现在都是固定高度,直接取
|
||||
if (h <= 0) h = PanelContentHeight(p);
|
||||
if (h <= 0) return;
|
||||
if (h <= 0) return;
|
||||
int newH = m_chromeH + h + 8;
|
||||
if (m_iMinH > 0 && newH < m_iMinH) newH = m_iMinH;
|
||||
::SetWindowPos(m_hWnd, NULL, 0, 0, m_iWidth, newH, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
}
|
||||
|
||||
// 每套皮肤的 tab 表达方式不同,这里按主题分别上色
|
||||
void UpdateTabStyle() {
|
||||
const char *names[4] = { "tabLogin", "tabRegister", "tabCard", "tabReset" };
|
||||
CButtonUI *btns[4] = { NULL, NULL, NULL, NULL };
|
||||
for (int i = 0; i < 4; i++)
|
||||
btns[i] = static_cast<CButtonUI *>(m_pm.FindControl(U8(names[i]).c_str()));
|
||||
if (!btns[0]) return;
|
||||
|
||||
std::string th(g_theme);
|
||||
DWORD actBg = 0, idleBg = 0, actFg = 0, idleFg = 0;
|
||||
bool bgMode = true;
|
||||
|
||||
if (th == "dark") { bgMode = false; actFg = 0xFF4EA3E8; idleFg = 0xFF85858F; }
|
||||
else if (th == "light") { actBg = 0xFF1B6FD6; idleBg = 0xFFEBEFF6; actFg = 0xFFFFFFFF; idleFg = 0xFF5B6270; }
|
||||
else if (th == "split") { bgMode = false; actFg = 0xFF4CC2FF; idleFg = 0xFF7A8794; }
|
||||
else if (th == "card") { actBg = 0xFFFFFFFF; idleBg = 0xFFE8E6FF; actFg = 0xFF3B2BD6; idleFg = 0xFF5B56A8; }
|
||||
else if (th == "industrial") { actBg = 0xFF1A5A8C; idleBg = 0x00000000; actFg = 0xFFFFFFFF; idleFg = 0xFF9FC8E6; }
|
||||
else if (th == "terminal") { bgMode = false; actFg = 0xFF7FE39B; idleFg = 0xFF4E7A5C; }
|
||||
else if (th == "compact") { actBg = 0xFF2E9E6B; idleBg = 0xFF161C22; actFg = 0xFFFFFFFF; idleFg = 0xFF9FB3C8; }
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!btns[i]) continue;
|
||||
bool on = (i == g_tab);
|
||||
if (bgMode) btns[i]->SetBkColor(on ? actBg : idleBg);
|
||||
btns[i]->SetTextColor(on ? actFg : idleFg);
|
||||
btns[i]->Invalidate();
|
||||
}
|
||||
// dark 皮肤用下划线指示条
|
||||
const char *lines[4] = { "lineLogin", "lineRegister", "lineCard", "lineReset" };
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (CControlUI *l = m_pm.FindControl(U8(lines[i]).c_str()))
|
||||
l->SetBkColor(i == g_tab ? 0xFF4EA3E8 : 0x00000000);
|
||||
}
|
||||
}
|
||||
|
||||
void DoRecharge() {
|
||||
CEditUI *u = static_cast<CEditUI *>(m_pm.FindControl(_T("cardUser")));
|
||||
CEditUI *k = static_cast<CEditUI *>(m_pm.FindControl(_T("cardKey")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("cardTip")));
|
||||
if (!u || !k || !tip) return;
|
||||
std::wstring user = u->GetText().GetData(), key = k->GetText().GetData();
|
||||
if (user.empty()) { tip->SetText(L"请输入用户名"); return; }
|
||||
if (key.empty()) { tip->SetText(L"请输入卡密"); return; }
|
||||
|
||||
char body[1024];
|
||||
snprintf(body, sizeof(body), "{\"username\":\"%s\",\"card_key\":\"%s\",\"device_id\":\"%s\"}",
|
||||
W2U8(user).c_str(), W2U8(key).c_str(), g_device);
|
||||
tip->SetText(L"正在提交充值…");
|
||||
char msg[1024] = {0};
|
||||
if (api_post_sibling("/recharge", body, msg, sizeof(msg))) {
|
||||
tip->SetText(U8(msg).c_str());
|
||||
if (CEditUI *lu = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) lu->SetText(user.c_str());
|
||||
} else {
|
||||
tip->SetText(U8(msg).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void DoReset() {
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("resetEmail")));
|
||||
CEditUI *c = static_cast<CEditUI *>(m_pm.FindControl(_T("resetCode")));
|
||||
CEditUI *p = static_cast<CEditUI *>(m_pm.FindControl(_T("resetPass")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("resetTip")));
|
||||
if (!e || !c || !p || !tip) return;
|
||||
std::wstring email = e->GetText().GetData(), code = c->GetText().GetData(), pass = p->GetText().GetData();
|
||||
if (email.empty()) { tip->SetText(L"请输入邮箱"); return; }
|
||||
if (code.empty()) { tip->SetText(L"请输入验证码"); return; }
|
||||
if (pass.size() < 6) { tip->SetText(L"新密码至少 6 位"); return; }
|
||||
|
||||
char body[1024];
|
||||
snprintf(body, sizeof(body), "{\"email\":\"%s\",\"code\":\"%s\",\"password\":\"%s\"}",
|
||||
W2U8(email).c_str(), W2U8(code).c_str(), W2U8(pass).c_str());
|
||||
tip->SetText(L"正在重置…");
|
||||
char msg[1024] = {0};
|
||||
int ok = api_post_sibling("/reset-password", body, msg, sizeof(msg));
|
||||
tip->SetText(U8(msg).c_str());
|
||||
if (ok) {
|
||||
if (CEditUI *lp = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")))) lp->SetText(pass.c_str());
|
||||
SwitchTab(0);
|
||||
}
|
||||
}
|
||||
|
||||
void DoSendResetCode() {
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("resetEmail")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("resetTip")));
|
||||
if (!e || !tip) return;
|
||||
std::wstring email = e->GetText().GetData();
|
||||
if (email.empty()) { tip->SetText(L"请先填邮箱"); return; }
|
||||
char msg[512] = {0};
|
||||
api_send_code(W2U8(email).c_str(), msg, sizeof(msg));
|
||||
tip->SetText(U8(msg).c_str());
|
||||
}
|
||||
|
||||
void DoRegister() {
|
||||
CEditUI *u = static_cast<CEditUI *>(m_pm.FindControl(_T("regUser")));
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("regEmail")));
|
||||
CEditUI *c = static_cast<CEditUI *>(m_pm.FindControl(_T("regCode")));
|
||||
CEditUI *p1 = static_cast<CEditUI *>(m_pm.FindControl(_T("regPass")));
|
||||
CEditUI *p2 = static_cast<CEditUI *>(m_pm.FindControl(_T("regPass2")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("regTip")));
|
||||
if (!u || !e || !c || !p1 || !p2 || !tip) return;
|
||||
|
||||
std::wstring user = u->GetText().GetData(), email = e->GetText().GetData();
|
||||
std::wstring code = c->GetText().GetData(), pass = p1->GetText().GetData();
|
||||
std::wstring pass2 = p2->GetText().GetData();
|
||||
if (user.empty()) { tip->SetText(L"请输入用户名"); return; }
|
||||
if (email.empty()) { tip->SetText(L"请输入邮箱"); return; }
|
||||
if (code.empty()) { tip->SetText(L"请输入邮箱验证码"); return; }
|
||||
if (pass.size() < 6) { tip->SetText(L"密码至少 6 位"); return; }
|
||||
if (pass != pass2) { tip->SetText(L"两次输入的密码不一致"); return; }
|
||||
|
||||
tip->SetText(L"正在提交注册…");
|
||||
char msg[1024] = {0};
|
||||
int ok = api_register(W2U8(user).c_str(), W2U8(email).c_str(), W2U8(code).c_str(),
|
||||
W2U8(pass).c_str(), msg, sizeof(msg));
|
||||
if (!ok) { tip->SetText(U8(msg).c_str()); return; }
|
||||
|
||||
// 注册成功直接登录
|
||||
if (CEditUI *lu = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) lu->SetText(user.c_str());
|
||||
if (CEditUI *lp = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")))) lp->SetText(pass.c_str());
|
||||
SwitchTab(0);
|
||||
DoLogin();
|
||||
}
|
||||
|
||||
void DoSendCode() {
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("regEmail")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("regTip")));
|
||||
if (!e || !tip) return;
|
||||
std::wstring email = e->GetText().GetData();
|
||||
if (email.empty()) { tip->SetText(L"请先填邮箱"); return; }
|
||||
char msg[512] = {0};
|
||||
api_send_code(W2U8(email).c_str(), msg, sizeof(msg));
|
||||
tip->SetText(U8(msg).c_str());
|
||||
}
|
||||
|
||||
// 自绘勾选框:选中时方框填充主色(老 DuiLib 没有勾选图片资源,只能用色块表达)
|
||||
void UpdateRememberButton() {
|
||||
CLabelUI *box = static_cast<CLabelUI *>(m_pm.FindControl(_T("chkBox")));
|
||||
if (!box) return;
|
||||
box->SetBkColor(g_remember ? 0xFF2C7BE5 : 0x00000000);
|
||||
box->SetBorderColor(g_remember ? 0xFF2C7BE5 : 0xFF5A5A66);
|
||||
box->Invalidate();
|
||||
}
|
||||
|
||||
void DoLogin() {
|
||||
CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")));
|
||||
CEditUI *pPass = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")));
|
||||
CLabelUI *pTip = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblTip")));
|
||||
CButtonUI *pBtn = static_cast<CButtonUI *>(m_pm.FindControl(_T("btnLogin")));
|
||||
if (!pUser || !pPass || !pTip) return;
|
||||
|
||||
std::wstring user = pUser->GetText().GetData();
|
||||
std::wstring pass = pPass->GetText().GetData();
|
||||
if (user.empty()) { pTip->SetText(L"请输入账号或卡密"); return; }
|
||||
if (pass.empty()) { pTip->SetText(L"请输入密码"); return; }
|
||||
|
||||
SaveAccount(user, g_remember);
|
||||
|
||||
if (pBtn) { pBtn->SetText(L"验证中…"); pBtn->SetEnabled(false); }
|
||||
pTip->SetText(L"正在连接验证服务器…");
|
||||
|
||||
char msg[1024] = {0};
|
||||
int ok = api_login(W2U8(user).c_str(), W2U8(pass).c_str(), msg, sizeof(msg));
|
||||
if (ok) {
|
||||
g_logged_in = 1;
|
||||
pTip->SetText(L"验证成功,正在启动程序…");
|
||||
::SetTimer(m_hWnd, 1, 600, NULL);
|
||||
} else {
|
||||
pTip->SetText(U8(msg).c_str());
|
||||
if (pBtn) { pBtn->SetText(L"登 录"); pBtn->SetEnabled(true); }
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override {
|
||||
if (uMsg == WM_CREATE) {
|
||||
m_pm.Init(m_hWnd);
|
||||
CDialogBuilder builder;
|
||||
std::wstring xml = U8(m_skin);
|
||||
CControlUI *pRoot = builder.Create(xml.c_str(), (UINT)0, NULL, &m_pm);
|
||||
if (!pRoot) { ::MessageBoxW(m_hWnd, L"界面加载失败", L"验证", MB_ICONERROR); return 0; }
|
||||
m_pm.AttachDialog(pRoot);
|
||||
m_pm.AddNotifier(this);
|
||||
|
||||
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblApp"))))
|
||||
p->SetText(U8(g_name).c_str());
|
||||
|
||||
std::wstring devText = L"设备 ";
|
||||
devText += U8(g_device);
|
||||
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblDevice"))))
|
||||
p->SetText(devText.c_str());
|
||||
|
||||
bool remember = false;
|
||||
std::wstring saved = LoadAccount(remember);
|
||||
g_remember = remember;
|
||||
UpdateRememberButton();
|
||||
|
||||
RECT rc = {0};
|
||||
::GetClientRect(m_hWnd, &rc);
|
||||
m_iWidth = rc.right - rc.left;
|
||||
CControlUI *lp = m_pm.FindControl(_T("panelLogin"));
|
||||
int loginH = lp ? lp->GetFixedHeight() : 0;
|
||||
if (loginH > 0) m_chromeH = (rc.bottom - rc.top) - loginH;
|
||||
SwitchTab(0);
|
||||
if (CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) {
|
||||
if (!saved.empty()) pUser->SetText(saved.c_str());
|
||||
pUser->SetFocus();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_TIMER && wParam == 1) {
|
||||
::KillTimer(m_hWnd, 1);
|
||||
::ShowWindow(m_hWnd, SW_HIDE);
|
||||
if (g_oep) g_oep();
|
||||
::PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_DESTROY) { ::PostQuitMessage(0); return 0; }
|
||||
|
||||
LRESULT lr = 0;
|
||||
if (m_pm.MessageHandler(uMsg, wParam, lParam, lr)) return lr;
|
||||
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
CPaintManagerUI m_pm;
|
||||
const char *m_skin;
|
||||
int m_chromeH = 0; // 除面板外的固定高度(标题栏 + tab 行 + 页脚)
|
||||
int m_iWidth = 0;
|
||||
int m_iMinH = 380;
|
||||
};
|
||||
|
||||
static int RunShell(void *oep) {
|
||||
g_oep = (PFN_OEP)oep;
|
||||
const SkinDef *sk = skin_for(g_theme);
|
||||
|
||||
CPaintManagerUI::SetInstance(::GetModuleHandle(NULL));
|
||||
::CoInitialize(NULL);
|
||||
|
||||
CVerifyWnd wnd(sk->xml);
|
||||
UINT style = WS_POPUP | WS_CLIPCHILDREN;
|
||||
UINT exstyle = WS_EX_TOPMOST | WS_EX_APPWINDOW;
|
||||
|
||||
wnd.Create(NULL, L"软件授权验证", style, exstyle, 0, 0, sk->w, sk->h);
|
||||
wnd.CenterWindow();
|
||||
::ShowWindow(wnd, SW_SHOW);
|
||||
|
||||
CPaintManagerUI::MessageLoop();
|
||||
::CoUninitialize();
|
||||
return g_logged_in ? 0 : 6;
|
||||
}
|
||||
|
||||
/* ---------------------------- 对外接口 ---------------------------- */
|
||||
static void load_cfg(const char *json) {
|
||||
snprintf(g_cfg, sizeof(g_cfg), "%s", json ? json : "");
|
||||
json_str(g_cfg, "api", g_api, sizeof(g_api));
|
||||
json_str(g_cfg, "name", g_name, sizeof(g_name));
|
||||
g_deviceAuto = json_int(g_cfg, "device_auto", 1);
|
||||
|
||||
char mid[64] = {0};
|
||||
make_machine_id(mid, sizeof(mid));
|
||||
snprintf(g_instance, sizeof(g_instance), "%s", mid);
|
||||
|
||||
if (!json_str(g_cfg, "device", g_device, sizeof(g_device)) || !g_device[0]) {
|
||||
if (g_deviceAuto) snprintf(g_device, sizeof(g_device), "%s", mid);
|
||||
else snprintf(g_device, sizeof(g_device), "%s", "UNKNOWN-DEVICE");
|
||||
}
|
||||
if (!json_str(g_cfg, "theme", g_theme, sizeof(g_theme))) snprintf(g_theme, sizeof(g_theme), "dark");
|
||||
}
|
||||
|
||||
#ifdef SHELL_EXE
|
||||
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
|
||||
const char *cfg = (lpCmdLine && lpCmdLine[0]) ? lpCmdLine : getenv("VFY_CFG");
|
||||
if (!cfg || !cfg[0]) cfg = "{\"theme\":\"dark\"}";
|
||||
load_cfg(cfg);
|
||||
return RunShell(NULL);
|
||||
}
|
||||
#else
|
||||
extern "C" __declspec(dllexport) int VerifyMain(void *oep, const char *cfgjson) {
|
||||
load_cfg(cfgjson);
|
||||
return RunShell(oep);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int VerifyShellVersion(void) { return 9; }
|
||||
extern "C" __declspec(dllexport) const char *VerifyShellThemes(void) {
|
||||
return "dark,light,split,card,industrial,terminal,compact";
|
||||
}
|
||||
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID) {
|
||||
if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(h);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,930 @@
|
||||
// shell9.cpp —— DuiLib 版 Windows 验证壳(多套结构不同的皮肤)
|
||||
//
|
||||
// 与平台验证方式严格对齐(/api/v1/app/<appKey>/login):
|
||||
// POST {username, password, device_id, device_name, device_type, instance_id}
|
||||
// 即「账号(或卡密)+ 密码 + 设备绑定」,不是只填一个卡密框。
|
||||
//
|
||||
// 对外接口不变:
|
||||
// int VerifyMain(void *oep, const char *cfgjson);
|
||||
// int VerifyShellVersion(void); // 9
|
||||
// const char *VerifyShellThemes(void); // 主题清单
|
||||
#include <windows.h>
|
||||
#include <winhttp.h>
|
||||
#include <shlobj.h>
|
||||
#include <shellapi.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include "UIlib.h"
|
||||
#include "Utils/WinImplBase.h"
|
||||
|
||||
#pragma comment(lib, "winhttp.lib")
|
||||
|
||||
using namespace DuiLib;
|
||||
|
||||
/* ============================== cfg ============================== */
|
||||
static char g_cfg[4096];
|
||||
static char g_api[512];
|
||||
static char g_name[128] = "\xE6\xBC\x94\xE7\xA4\xBA\xE7\xA8\x8B\xE5\xBA\x8F"; // 演示程序
|
||||
static char g_theme[32] = "dark";
|
||||
static char g_device[64] = "";
|
||||
static char g_instance[64] = "";
|
||||
static int g_deviceAuto = 1;
|
||||
|
||||
static int json_str(const char *src, const char *key, char *out, int cap) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return 0;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return 0;
|
||||
while (*p && *p != '"') p++;
|
||||
if (!*p) return 0;
|
||||
p++;
|
||||
int i = 0;
|
||||
while (*p && *p != '"' && i < cap - 1) out[i++] = *p++;
|
||||
out[i] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int json_bool(const char *src, const char *key, int def) {
|
||||
char pat[128];
|
||||
snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return def;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return def;
|
||||
p++;
|
||||
while (*p == ' ' || *p == '\t') p++;
|
||||
if (!strncmp(p, "true", 4)) return 1;
|
||||
if (!strncmp(p, "false", 5)) return 0;
|
||||
return atoi(p) ? 1 : 0;
|
||||
}
|
||||
|
||||
static int json_int(const char *src, const char *key, int def) {
|
||||
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||||
const char *p = strstr(src, pat);
|
||||
if (!p) return def;
|
||||
p = strchr(p + strlen(pat), ':');
|
||||
if (!p) return def;
|
||||
return atoi(p + 1);
|
||||
}
|
||||
|
||||
// 后台开关:从 /info 拉下来的界面配置
|
||||
static int g_allowRegister = 1, g_regVerify = 0, g_allowReset = 0;
|
||||
static int g_maxDevices = 1, g_trialDays = 0, g_enableTrial = 0;
|
||||
static char g_resetMethod[16] = "email", g_billing[16] = "free";
|
||||
static int g_infoLoaded = 0;
|
||||
|
||||
static void make_machine_id(char *out, int cap);
|
||||
static void load_cfg(const char *json);
|
||||
|
||||
/* ============================ 工具 ============================ */
|
||||
static std::wstring U8(const char *s) {
|
||||
if (!s) return L"";
|
||||
int n = ::MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
|
||||
std::wstring w(n > 0 ? n - 1 : 0, L'\0');
|
||||
if (n > 1) ::MultiByteToWideChar(CP_UTF8, 0, s, -1, &w[0], n);
|
||||
return w;
|
||||
}
|
||||
|
||||
static std::string W2U8(const std::wstring &w) {
|
||||
if (w.empty()) return std::string();
|
||||
int n = ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, NULL, 0, NULL, NULL);
|
||||
std::string s(n > 0 ? n - 1 : 0, '\0');
|
||||
if (n > 1) ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, &s[0], n, NULL, NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
// MachineGuid + 系统盘卷序列号 → 稳定机器码(重装系统才变)
|
||||
static void make_machine_id(char *out, int cap) {
|
||||
wchar_t guid[128] = {0};
|
||||
HKEY hk = NULL;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
|
||||
0, KEY_READ | KEY_WOW64_64KEY, &hk) == ERROR_SUCCESS) {
|
||||
DWORD sz = sizeof(guid) - sizeof(wchar_t), type = 0;
|
||||
RegQueryValueExW(hk, L"MachineGuid", NULL, &type, (LPBYTE)guid, &sz);
|
||||
RegCloseKey(hk);
|
||||
}
|
||||
DWORD serial = 0;
|
||||
GetVolumeInformationW(L"C:\\", NULL, 0, &serial, NULL, NULL, NULL, 0);
|
||||
unsigned int h1 = 2166136261u, h2 = 3735928559u;
|
||||
for (const wchar_t *p = guid; *p; p++) {
|
||||
h1 = (h1 ^ (unsigned int)(*p & 0xFF)) * 16777619u;
|
||||
h2 = (h2 ^ (unsigned int)(*p >> 8)) * 16777619u;
|
||||
}
|
||||
h1 = (h1 ^ serial) * 16777619u;
|
||||
h2 = (h2 ^ (serial >> 16)) * 16777619u;
|
||||
snprintf(out, cap, "%04X-%04X-%04X", h1 & 0xFFFF, (h1 >> 16) & 0xFFFF, h2 & 0xFFFF);
|
||||
}
|
||||
|
||||
static std::wstring AccountIniPath() {
|
||||
wchar_t app[MAX_PATH] = {0};
|
||||
::SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, app);
|
||||
std::wstring dir = std::wstring(app) + L"\\vfy";
|
||||
::CreateDirectoryW(dir.c_str(), NULL);
|
||||
return dir + L"\\account.ini";
|
||||
}
|
||||
|
||||
static void SaveAccount(const std::wstring &user, bool remember) {
|
||||
std::wstring p = AccountIniPath();
|
||||
::WritePrivateProfileStringW(L"login", L"remember", remember ? L"1" : L"0", p.c_str());
|
||||
if (remember) ::WritePrivateProfileStringW(L"login", L"user", user.c_str(), p.c_str());
|
||||
}
|
||||
|
||||
static std::wstring LoadAccount(bool &remember) {
|
||||
std::wstring p = AccountIniPath();
|
||||
wchar_t buf[256] = {0};
|
||||
::GetPrivateProfileStringW(L"login", L"remember", L"0", buf, 256, p.c_str());
|
||||
remember = (buf[0] == L'1');
|
||||
wchar_t user[256] = {0};
|
||||
::GetPrivateProfileStringW(L"login", L"user", L"", user, 256, p.c_str());
|
||||
return remember ? std::wstring(user) : std::wstring();
|
||||
}
|
||||
|
||||
/* --------------------------- 皮肤 ---------------------------
|
||||
* 7 套在「结构」上彼此不同,字段集统一按平台验证方式:
|
||||
* 账号(账号或卡密)/ 密码 / 记住账号 / 设备信息 / 登录 / 状态行 / 注册·卡密充值·忘记密码
|
||||
* 注意:老 DuiLib 的 Edit 是「真 EDIT 子窗口」,必须用 nativebkcolor 指定它自己的底色,
|
||||
* 否则聚焦时会出现刺眼的白条(这是它构造里写死 0xFFFFFFFF 导致的)。
|
||||
*/
|
||||
|
||||
#include "skins_v4.h"
|
||||
|
||||
static const SkinDef *skin_for(const char *theme) {
|
||||
for (int i = 0; kSkins[i].name; i++)
|
||||
if (!strcmp(theme, kSkins[i].name)) return &kSkins[i];
|
||||
return &kSkins[0];
|
||||
}
|
||||
|
||||
/* ---------------------------- 接口请求 ---------------------------- */
|
||||
// 平台接口:POST /api/v1/app/<appKey>/login
|
||||
// {"username","password","device_id","device_name","device_type","instance_id"}
|
||||
static int api_login(const char *user, const char *pass, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
if (!g_api[0]) { snprintf(msg, cap, "配置缺少验证地址"); return 0; }
|
||||
|
||||
const char *rest = g_api;
|
||||
if (!strncmp(g_api, "https://", 8)) rest = g_api + 8;
|
||||
else if (!strncmp(g_api, "http://", 7)) rest = g_api + 7;
|
||||
bool https = (rest != g_api && g_api[4] == 's');
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) {
|
||||
int hl = (int)(slash - rest);
|
||||
if (hl > 255) hl = 255;
|
||||
memcpy(host, rest, hl);
|
||||
snprintf(path, sizeof(path), "%s", slash);
|
||||
} else {
|
||||
snprintf(host, sizeof(host), "%s", rest);
|
||||
}
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char cname[256] = {0}; DWORD cn = sizeof(cname);
|
||||
::GetComputerNameA(cname, &cn);
|
||||
|
||||
char body[2048];
|
||||
snprintf(body, sizeof(body),
|
||||
"{\"username\":\"%s\",\"password\":\"%s\",\"device_id\":\"%s\","
|
||||
"\"device_name\":\"%s\",\"device_type\":\"windows\",\"instance_id\":\"%s\"}",
|
||||
user, pass, g_device, cname, g_instance);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[4096] = {0};
|
||||
DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||||
total += cl;
|
||||
if (total >= sizeof(resp) - 1) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0]) {
|
||||
if (strstr(resp, "DEVICE_LIMIT")) snprintf(msg, cap, "设备数量已达上限,请先在平台下线一台设备");
|
||||
else if (strstr(resp, "IP_LIMIT")) snprintf(msg, cap, "IP 绑定已达上限,请解绑后再试");
|
||||
else if (ok) snprintf(msg, cap, "登录成功");
|
||||
else snprintf(msg, cap, "账号或密码错误");
|
||||
}
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// 注册:POST /api/v1/app/<appKey>/register
|
||||
static int api_register(const char *user, const char *email, const char *code,
|
||||
const char *pass, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
if (!g_api[0]) { snprintf(msg, cap, "配置缺少验证地址"); return 0; }
|
||||
|
||||
std::string reg = g_api;
|
||||
size_t pos = reg.rfind("/login");
|
||||
if (pos != std::string::npos) reg = reg.substr(0, pos) + "/register";
|
||||
|
||||
const char *rest = reg.c_str();
|
||||
bool https = false;
|
||||
if (!strncmp(rest, "https://", 8)) { rest += 8; https = true; }
|
||||
else if (!strncmp(rest, "http://", 7)) rest += 7;
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) { int hl = (int)(slash - rest); if (hl > 255) hl = 255; memcpy(host, rest, hl); snprintf(path, sizeof(path), "%s", slash); }
|
||||
else snprintf(host, sizeof(host), "%s", rest);
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char cname[256] = {0}; DWORD cn = sizeof(cname);
|
||||
::GetComputerNameA(cname, &cn);
|
||||
|
||||
char body[2048];
|
||||
snprintf(body, sizeof(body),
|
||||
"{\"username\":\"%s\",\"email\":\"%s\",\"email_code\":\"%s\",\"password\":\"%s\","
|
||||
"\"device_id\":\"%s\",\"device_name\":\"%s\",\"device_type\":\"windows\",\"instance_id\":\"%s\"}",
|
||||
user, email, code, pass, g_device, cname, g_instance);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[4096] = {0}; DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||||
total += cl; if (total >= sizeof(resp) - 1) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0])
|
||||
snprintf(msg, cap, ok ? "注册成功,正在登录…" : "注册失败,请检查邮箱验证码");
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// 发送邮箱验证码:POST /api/v1/app/<appKey>/send-email-code
|
||||
static int api_send_code(const char *email, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
std::string u = g_api;
|
||||
size_t pos = u.rfind("/login");
|
||||
if (pos != std::string::npos) u = u.substr(0, pos) + "/send-email-code";
|
||||
|
||||
const char *rest = u.c_str();
|
||||
bool https = false;
|
||||
if (!strncmp(rest, "https://", 8)) { rest += 8; https = true; }
|
||||
else if (!strncmp(rest, "http://", 7)) rest += 7;
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) { int hl = (int)(slash - rest); if (hl > 255) hl = 255; memcpy(host, rest, hl); snprintf(path, sizeof(path), "%s", slash); }
|
||||
else snprintf(host, sizeof(host), "%s", rest);
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
char body[512];
|
||||
snprintf(body, sizeof(body), "{\"email\":\"%s\"}", email);
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[2048] = {0}; DWORD cl = 0;
|
||||
WinHttpReadData(hR, resp, sizeof(resp) - 1, &cl);
|
||||
resp[cl < sizeof(resp) ? cl : sizeof(resp) - 1] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0])
|
||||
snprintf(msg, cap, ok ? "验证码已发送" : "发送失败");
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
// 通用 POST:把 JSON 发到 api 的某个兄弟路径(/login → /recharge 之类)
|
||||
static int api_post_sibling(const char *sibling, const char *body, char *msg, int cap) {
|
||||
msg[0] = 0;
|
||||
std::string u = g_api;
|
||||
size_t pos = u.rfind("/login");
|
||||
if (pos != std::string::npos) u = u.substr(0, pos) + sibling;
|
||||
|
||||
const char *rest = u.c_str();
|
||||
bool https = false;
|
||||
if (!strncmp(rest, "https://", 8)) { rest += 8; https = true; }
|
||||
else if (!strncmp(rest, "http://", 7)) rest += 7;
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) { int hl = (int)(slash - rest); if (hl > 255) hl = 255; memcpy(host, rest, hl); snprintf(path, sizeof(path), "%s", slash); }
|
||||
else snprintf(host, sizeof(host), "%s", rest);
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||||
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
char resp[4096] = {0}; DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||||
total += cl; if (total >= sizeof(resp) - 1) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||||
if (!json_str(resp, "message", msg, cap) || !msg[0]) {
|
||||
if (ok) snprintf(msg, cap, "操作成功");
|
||||
else snprintf(msg, cap, "操作失败");
|
||||
}
|
||||
} else {
|
||||
snprintf(msg, cap, "无法连接验证服务器");
|
||||
}
|
||||
if (hR) WinHttpCloseHandle(hR);
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// GET 兄弟路径(只读,用于拉 /info 拿到界面开关)
|
||||
static int api_get_sibling(const char *sibling, char *resp, int cap) {
|
||||
resp[0] = 0; cap--;
|
||||
std::string u = g_api;
|
||||
size_t pos = u.rfind("/login");
|
||||
if (pos != std::string::npos) u = u.substr(0, pos) + sibling;
|
||||
|
||||
const char *rest = u.c_str();
|
||||
bool https = false;
|
||||
if (!strncmp(rest, "https://", 8)) { rest += 8; https = true; }
|
||||
else if (!strncmp(rest, "http://", 7)) rest += 7;
|
||||
|
||||
char host[256] = {0}, path[512] = "/";
|
||||
const char *slash = strchr(rest, '/');
|
||||
if (slash) { int hl = (int)(slash - rest); if (hl > 255) hl = 255; memcpy(host, rest, hl); snprintf(path, sizeof(path), "%s", slash); }
|
||||
else snprintf(host, sizeof(host), "%s", rest);
|
||||
unsigned short port = https ? 443 : 80;
|
||||
char *colon = strrchr(host, ':');
|
||||
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||||
|
||||
std::wstring wHost = U8(host), wPath = U8(path);
|
||||
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||||
if (!hS) return 0;
|
||||
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||||
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"GET", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||||
int ok = 0;
|
||||
if (hR) {
|
||||
WinHttpSendRequest(hR, WINHTTP_NO_ADDITIONAL_HEADERS, 0, NULL, 0, 0, 0);
|
||||
WinHttpReceiveResponse(hR, NULL);
|
||||
DWORD cl = 0, total = 0;
|
||||
while (WinHttpReadData(hR, resp + total, cap - total, &cl) && cl > 0) {
|
||||
total += cl;
|
||||
if ((int)total >= cap) break;
|
||||
}
|
||||
resp[total] = 0;
|
||||
ok = total > 0;
|
||||
WinHttpCloseHandle(hR);
|
||||
}
|
||||
if (hC) WinHttpCloseHandle(hC);
|
||||
WinHttpCloseHandle(hS);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* ---------------------------- 窗口 ---------------------------- */
|
||||
typedef void (*PFN_OEP)(void);
|
||||
static PFN_OEP g_oep = NULL;
|
||||
static int g_logged_in = 0;
|
||||
|
||||
// 从 cfg 的 api 里抽出站点根地址(去掉 /api/v1/... 部分)
|
||||
static std::wstring SiteRoot() {
|
||||
std::string a(g_api);
|
||||
size_t p = a.find("/api/");
|
||||
if (p != std::string::npos) a = a.substr(0, p);
|
||||
return U8(a.c_str());
|
||||
}
|
||||
static bool g_remember = false;
|
||||
static int g_codeLeft = 0; // 验证码倒计时(秒)
|
||||
static int g_tab = 0; // 0=登录 1=注册 2=充值 3=重置
|
||||
|
||||
|
||||
// 面板内容高度 = 所有子控件固定高度之和(面板 height=auto,pos 不可靠)
|
||||
static int PanelContentHeight(CControlUI *panel) {
|
||||
CContainerUI *box = dynamic_cast<CContainerUI *>(panel);
|
||||
if (!box) return 0;
|
||||
int n = box->GetCount(), sum = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
CControlUI *c = box->GetItemAt(i);
|
||||
if (!c) continue;
|
||||
int h = c->GetFixedHeight();
|
||||
if (h <= 0) { RECT pr = c->GetPos(); h = pr.bottom - pr.top; }
|
||||
if (h > 0) sum += h;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
class CVerifyWnd : public CWindowWnd, public INotifyUI {
|
||||
public:
|
||||
explicit CVerifyWnd(const char *skin) : m_skin(skin) {}
|
||||
|
||||
LPCTSTR GetWindowClassName() const override { return _T("VfyDuiWnd"); }
|
||||
UINT GetClassStyle() const override { return CS_DBLCLKS; }
|
||||
|
||||
void Notify(TNotifyUI &msg) override {
|
||||
if (msg.sType == _T("click")) {
|
||||
CControlUI *p = msg.pSender;
|
||||
LPCTSTR nm = p ? p->GetName().GetData() : NULL;
|
||||
if (!nm) return;
|
||||
if (!_tcsicmp(nm, _T("btnClose")) || !_tcsicmp(nm, _T("btnQuit"))) { ::PostQuitMessage(0); return; }
|
||||
if (!_tcsicmp(nm, _T("btnLogin"))) { DoLogin(); return; }
|
||||
if (!_tcsicmp(nm, _T("tabLogin"))) { SwitchTab(0); return; }
|
||||
if (!_tcsicmp(nm, _T("tabRegister"))) { SwitchTab(1); return; }
|
||||
if (!_tcsicmp(nm, _T("tabCard"))) { SwitchTab(2); return; }
|
||||
if (!_tcsicmp(nm, _T("tabReset"))) { SwitchTab(3); return; }
|
||||
if (!_tcsicmp(nm, _T("btnRecharge"))) { DoRecharge(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnReset"))) { DoReset(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnSendCode2"))) { DoSendResetCode(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnRegister"))) { DoRegister(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnSendCode"))) { DoSendCode(); return; }
|
||||
if (!_tcsicmp(nm, _T("btnLinkReg")) || !_tcsicmp(nm, _T("btnLinkCard")) ||
|
||||
!_tcsicmp(nm, _T("btnLinkForgot"))) {
|
||||
std::wstring url = SiteRoot();
|
||||
// 平台只有 /login 与 /register 是公开页:注册直开,其余引导到登录页
|
||||
url += _tcsicmp(nm, _T("btnLinkReg")) == 0 ? L"/register" : L"/login";
|
||||
::ShellExecuteW(NULL, L"open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
return;
|
||||
}
|
||||
if (!_tcsicmp(nm, _T("btnRemember"))) {
|
||||
g_remember = !g_remember;
|
||||
UpdateRememberButton();
|
||||
return;
|
||||
}
|
||||
} else if (msg.sType == _T("return")) {
|
||||
DoLogin();
|
||||
} else if (msg.sType == _T("setfocus") || msg.sType == _T("killfocus")) {
|
||||
CControlUI *p = msg.pSender;
|
||||
if (!p) return;
|
||||
LPCTSTR nm = p->GetName().GetData();
|
||||
if (!nm || (_tcsicmp(nm, _T("editUser")) && _tcsicmp(nm, _T("editPass")))) return;
|
||||
bool focus = !_tcsicmp(msg.sType.GetData(), _T("setfocus"));
|
||||
if (CEditUI *e = static_cast<CEditUI *>(p)) {
|
||||
DWORD bg = e->GetBkColor();
|
||||
// 聚焦时把原生 EDIT 窗口底色提亮一档(纯 XML 画不出描边,用亮度做反馈)
|
||||
if (focus) {
|
||||
BYTE r = GetRValue(bg) + 10 > 255 ? 255 : GetRValue(bg) + 10;
|
||||
BYTE g = GetGValue(bg) + 10 > 255 ? 255 : GetGValue(bg) + 10;
|
||||
BYTE b = GetBValue(bg) + 14 > 255 ? 255 : GetBValue(bg) + 14;
|
||||
e->SetNativeEditBkColor(RGB(r, g, b));
|
||||
} else {
|
||||
e->SetNativeEditBkColor(bg);
|
||||
}
|
||||
e->Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- 四个 tab:登录 / 注册 / 卡密充值 / 忘记密码 ----------------
|
||||
void SwitchTab(int tab) {
|
||||
int old = g_tab;
|
||||
g_tab = tab;
|
||||
const char *panels[4] = { "panelLogin", "panelRegister", "panelCard", "panelReset" };
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (CControlUI *p = m_pm.FindControl(U8(panels[i]).c_str()))
|
||||
p->SetVisible(i == tab);
|
||||
}
|
||||
UpdateTabStyle();
|
||||
ResizeForTab(tab, old);
|
||||
}
|
||||
|
||||
// 面板高度不同:切换后按新面板高度改窗口高度,避免大片空白或内容被切
|
||||
void ResizeForTab(int tab, int old) {
|
||||
if (m_chromeH <= 0) return;
|
||||
const char *panels[4] = { "panelLogin", "panelRegister", "panelCard", "panelReset" };
|
||||
CControlUI *p = m_pm.FindControl(U8(panels[tab]).c_str());
|
||||
if (!p) return;
|
||||
int h = p->GetFixedHeight(); // 面板现在都是固定高度,直接取
|
||||
if (h <= 0) h = PanelContentHeight(p);
|
||||
if (h <= 0) return;
|
||||
if (h <= 0) return;
|
||||
int newH = m_chromeH + h + 8;
|
||||
if (m_iMinH > 0 && newH < m_iMinH) newH = m_iMinH;
|
||||
::SetWindowPos(m_hWnd, NULL, 0, 0, m_iWidth, newH, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
}
|
||||
|
||||
// 每套皮肤的 tab 表达方式不同,这里按主题分别上色
|
||||
void UpdateTabStyle() {
|
||||
const char *names[4] = { "tabLogin", "tabRegister", "tabCard", "tabReset" };
|
||||
CButtonUI *btns[4] = { NULL, NULL, NULL, NULL };
|
||||
for (int i = 0; i < 4; i++)
|
||||
btns[i] = static_cast<CButtonUI *>(m_pm.FindControl(U8(names[i]).c_str()));
|
||||
if (!btns[0]) return;
|
||||
|
||||
std::string th(g_theme);
|
||||
DWORD actBg = 0, idleBg = 0, actFg = 0, idleFg = 0;
|
||||
bool bgMode = true;
|
||||
|
||||
if (th == "dark") { bgMode = false; actFg = 0xFF4EA3E8; idleFg = 0xFF85858F; }
|
||||
else if (th == "light") { actBg = 0xFF1B6FD6; idleBg = 0xFFEBEFF6; actFg = 0xFFFFFFFF; idleFg = 0xFF5B6270; }
|
||||
else if (th == "split") { bgMode = false; actFg = 0xFF4CC2FF; idleFg = 0xFF7A8794; }
|
||||
else if (th == "card") { actBg = 0xFFFFFFFF; idleBg = 0xFFE8E6FF; actFg = 0xFF3B2BD6; idleFg = 0xFF5B56A8; }
|
||||
else if (th == "industrial") { actBg = 0xFF1A5A8C; idleBg = 0x00000000; actFg = 0xFFFFFFFF; idleFg = 0xFF9FC8E6; }
|
||||
else if (th == "terminal") { bgMode = false; actFg = 0xFF7FE39B; idleFg = 0xFF4E7A5C; }
|
||||
else if (th == "compact") { actBg = 0xFF2E9E6B; idleBg = 0xFF161C22; actFg = 0xFFFFFFFF; idleFg = 0xFF9FB3C8; }
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!btns[i]) continue;
|
||||
bool on = (i == g_tab);
|
||||
if (bgMode) btns[i]->SetBkColor(on ? actBg : idleBg);
|
||||
btns[i]->SetTextColor(on ? actFg : idleFg);
|
||||
btns[i]->Invalidate();
|
||||
}
|
||||
// dark 皮肤用下划线指示条
|
||||
const char *lines[4] = { "lineLogin", "lineRegister", "lineCard", "lineReset" };
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (CControlUI *l = m_pm.FindControl(U8(lines[i]).c_str()))
|
||||
l->SetBkColor(i == g_tab ? 0xFF4EA3E8 : 0x00000000);
|
||||
}
|
||||
}
|
||||
|
||||
void DoRecharge() {
|
||||
CEditUI *u = static_cast<CEditUI *>(m_pm.FindControl(_T("cardUser")));
|
||||
CEditUI *k = static_cast<CEditUI *>(m_pm.FindControl(_T("cardKey")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("cardTip")));
|
||||
if (!u || !k || !tip) return;
|
||||
std::wstring user = u->GetText().GetData(), key = k->GetText().GetData();
|
||||
if (user.empty()) { tip->SetText(L"请输入用户名"); return; }
|
||||
if (key.empty()) { tip->SetText(L"请输入卡密"); return; }
|
||||
|
||||
char body[1024];
|
||||
snprintf(body, sizeof(body), "{\"username\":\"%s\",\"card_key\":\"%s\",\"device_id\":\"%s\"}",
|
||||
W2U8(user).c_str(), W2U8(key).c_str(), g_device);
|
||||
tip->SetText(L"正在提交充值…");
|
||||
char msg[1024] = {0};
|
||||
if (api_post_sibling("/recharge", body, msg, sizeof(msg))) {
|
||||
tip->SetText(U8(msg).c_str());
|
||||
if (CEditUI *lu = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) lu->SetText(user.c_str());
|
||||
} else {
|
||||
tip->SetText(U8(msg).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void DoReset() {
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("resetEmail")));
|
||||
CEditUI *c = static_cast<CEditUI *>(m_pm.FindControl(_T("resetCode")));
|
||||
CEditUI *p = static_cast<CEditUI *>(m_pm.FindControl(_T("resetPass")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("resetTip")));
|
||||
if (!e || !c || !p || !tip) return;
|
||||
std::wstring email = e->GetText().GetData(), code = c->GetText().GetData(), pass = p->GetText().GetData();
|
||||
if (email.empty()) { tip->SetText(L"请输入邮箱"); return; }
|
||||
if (code.empty()) { tip->SetText(L"请输入验证码"); return; }
|
||||
if (pass.size() < 6) { tip->SetText(L"新密码至少 6 位"); return; }
|
||||
|
||||
char body[1024];
|
||||
snprintf(body, sizeof(body), "{\"email\":\"%s\",\"code\":\"%s\",\"password\":\"%s\"}",
|
||||
W2U8(email).c_str(), W2U8(code).c_str(), W2U8(pass).c_str());
|
||||
tip->SetText(L"正在重置…");
|
||||
char msg[1024] = {0};
|
||||
int ok = api_post_sibling("/reset-password", body, msg, sizeof(msg));
|
||||
tip->SetText(U8(msg).c_str());
|
||||
if (ok) {
|
||||
if (CEditUI *lp = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")))) lp->SetText(pass.c_str());
|
||||
SwitchTab(0);
|
||||
}
|
||||
}
|
||||
|
||||
void DoSendResetCode() {
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("resetEmail")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("resetTip")));
|
||||
if (!e || !tip) return;
|
||||
std::wstring email = e->GetText().GetData();
|
||||
if (email.empty()) { tip->SetText(L"请先填邮箱"); return; }
|
||||
char msg[512] = {0};
|
||||
api_send_code(W2U8(email).c_str(), msg, sizeof(msg));
|
||||
tip->SetText(U8(msg).c_str());
|
||||
}
|
||||
|
||||
void DoRegister() {
|
||||
CEditUI *u = static_cast<CEditUI *>(m_pm.FindControl(_T("regUser")));
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("regEmail")));
|
||||
CEditUI *c = static_cast<CEditUI *>(m_pm.FindControl(_T("regCode")));
|
||||
CEditUI *p1 = static_cast<CEditUI *>(m_pm.FindControl(_T("regPass")));
|
||||
CEditUI *p2 = static_cast<CEditUI *>(m_pm.FindControl(_T("regPass2")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("regTip")));
|
||||
if (!u || !e || !c || !p1 || !p2 || !tip) return;
|
||||
|
||||
std::wstring user = u->GetText().GetData(), email = e->GetText().GetData();
|
||||
std::wstring code = c->GetText().GetData(), pass = p1->GetText().GetData();
|
||||
std::wstring pass2 = p2->GetText().GetData();
|
||||
if (user.empty()) { tip->SetText(L"请输入用户名"); return; }
|
||||
if (email.empty()) { tip->SetText(L"请输入邮箱"); return; }
|
||||
if (code.empty()) { tip->SetText(L"请输入邮箱验证码"); return; }
|
||||
if (pass.size() < 6) { tip->SetText(L"密码至少 6 位"); return; }
|
||||
if (pass != pass2) { tip->SetText(L"两次输入的密码不一致"); return; }
|
||||
|
||||
tip->SetText(L"正在提交注册…");
|
||||
char msg[1024] = {0};
|
||||
int ok = api_register(W2U8(user).c_str(), W2U8(email).c_str(), W2U8(code).c_str(),
|
||||
W2U8(pass).c_str(), msg, sizeof(msg));
|
||||
if (!ok) { tip->SetText(U8(msg).c_str()); return; }
|
||||
|
||||
// 注册成功直接登录
|
||||
if (CEditUI *lu = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) lu->SetText(user.c_str());
|
||||
if (CEditUI *lp = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")))) lp->SetText(pass.c_str());
|
||||
SwitchTab(0);
|
||||
DoLogin();
|
||||
}
|
||||
|
||||
// ---------------- 后台开关 → 界面 ----------------
|
||||
void FetchAppInfo() {
|
||||
char buf[8192] = {0};
|
||||
if (!api_get_sibling("/info", buf, sizeof(buf))) return;
|
||||
char v[256];
|
||||
if (json_str(buf, "name", v, sizeof(v)) && v[0])
|
||||
snprintf(g_name, sizeof(g_name), "%s", v);
|
||||
if (json_str(buf, "billing_type", v, sizeof(v)) && v[0])
|
||||
snprintf(g_billing, sizeof(g_billing), "%s", v);
|
||||
if (json_str(buf, "password_reset_method", v, sizeof(v)) && v[0])
|
||||
snprintf(g_resetMethod, sizeof(g_resetMethod), "%s", v);
|
||||
g_allowRegister = json_bool(buf, "allow_register", 1);
|
||||
g_regVerify = json_bool(buf, "enable_register_verify", 0);
|
||||
g_allowReset = json_bool(buf, "enable_password_reset", 0);
|
||||
g_enableTrial = json_bool(buf, "enable_trial", 0);
|
||||
g_maxDevices = json_int(buf, "max_devices", 1);
|
||||
g_trialDays = json_int(buf, "trial_days", 0);
|
||||
g_infoLoaded = 1;
|
||||
ApplyAppInfo();
|
||||
}
|
||||
|
||||
void ApplyAppInfo() {
|
||||
if (!g_infoLoaded) return;
|
||||
// 应用名以服务器为准
|
||||
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblApp"))))
|
||||
p->SetText(U8(g_name).c_str());
|
||||
|
||||
// 注册:后台关掉就整条 tab 拿掉
|
||||
if (!g_allowRegister) {
|
||||
HideByName("tabRegister"); HideByName("panelRegister");
|
||||
if (CEditUI *b = static_cast<CEditUI *>(m_pm.FindControl(_T("regTip")))) (void)b;
|
||||
if (CLabelUI *t = static_cast<CLabelUI *>(m_pm.FindControl(_T("regTip"))))
|
||||
{ t->SetTextColor(0xFF8A8F99); t->SetText(L"本应用未开放注册"); }
|
||||
} else if (!g_regVerify) {
|
||||
// 不需要邮箱验证:把「邮箱验证码」整行收起来,注册只要账号+密码
|
||||
HideByName("lblRegCode"); HideByName("regCode"); HideByName("btnSendCode");
|
||||
if (CLabelUI *t = static_cast<CLabelUI *>(m_pm.FindControl(_T("regTip"))))
|
||||
{ t->SetTextColor(0xFF8A8F99); t->SetText(L"本应用注册无需邮箱验证"); }
|
||||
}
|
||||
|
||||
// 忘记密码:后台没启用就是 0 个入口,别放个点了报错的按钮
|
||||
if (!g_allowReset) {
|
||||
HideByName("tabReset"); HideByName("panelReset");
|
||||
} else if (CLabelUI *t = static_cast<CLabelUI *>(m_pm.FindControl(_T("resetTip")))) {
|
||||
t->SetTextColor(0xFF8A8F99);
|
||||
t->SetText(strcmp(g_resetMethod, "email") ? L"验证码将发送到绑定手机" : L"验证码将发送到注册邮箱");
|
||||
}
|
||||
|
||||
// 免费/试用模式没有余额概念,卡密充值不出现
|
||||
if (!strcmp(g_billing, "free")) {
|
||||
HideByName("tabCard"); HideByName("panelCard");
|
||||
}
|
||||
|
||||
// 当前 tab 若已被隐藏,退回登录
|
||||
if (g_tab == 1 && (!g_allowRegister || 0)) SwitchTab(0);
|
||||
if (g_tab == 3 && !g_allowReset) SwitchTab(0);
|
||||
if (g_tab == 2 && !strcmp(g_billing, "free")) SwitchTab(0);
|
||||
}
|
||||
|
||||
void HideByName(const char *name) {
|
||||
if (CControlUI *c = m_pm.FindControl(U8(name).c_str())) c->SetVisible(false);
|
||||
}
|
||||
|
||||
// ---------------- 验证码倒计时 ----------------
|
||||
void StartCodeCountdown() {
|
||||
g_codeLeft = 60;
|
||||
::SetTimer(m_hWnd, 2, 1000, NULL);
|
||||
UpdateCodeButtons();
|
||||
}
|
||||
|
||||
void UpdateCodeButtons() {
|
||||
char label[32];
|
||||
if (g_codeLeft > 0) snprintf(label, sizeof(label), "%ds", g_codeLeft);
|
||||
const char *names[2] = { "btnSendCode", "btnSendCode2" };
|
||||
for (int i = 0; i < 2; i++) {
|
||||
CButtonUI *b = static_cast<CButtonUI *>(m_pm.FindControl(U8(names[i]).c_str()));
|
||||
if (!b) continue;
|
||||
b->SetText(g_codeLeft > 0 ? U8(label).c_str() : L"发送验证码");
|
||||
b->SetEnabled(g_codeLeft <= 0);
|
||||
}
|
||||
}
|
||||
|
||||
void DoSendCode() {
|
||||
CEditUI *e = static_cast<CEditUI *>(m_pm.FindControl(_T("regEmail")));
|
||||
CLabelUI *tip = static_cast<CLabelUI *>(m_pm.FindControl(_T("regTip")));
|
||||
if (!e || !tip) return;
|
||||
std::wstring email = e->GetText().GetData();
|
||||
if (email.empty()) { tip->SetText(L"请先填邮箱"); return; }
|
||||
char msg[512] = {0};
|
||||
if (api_send_code(W2U8(email).c_str(), msg, sizeof(msg))) StartCodeCountdown();
|
||||
tip->SetText(U8(msg).c_str());
|
||||
}
|
||||
|
||||
// 自绘勾选框:选中时方框填充主色(老 DuiLib 没有勾选图片资源,只能用色块表达)
|
||||
void UpdateRememberButton() {
|
||||
CLabelUI *box = static_cast<CLabelUI *>(m_pm.FindControl(_T("chkBox")));
|
||||
if (!box) return;
|
||||
box->SetBkColor(g_remember ? 0xFF2C7BE5 : 0x00000000);
|
||||
box->SetBorderColor(g_remember ? 0xFF2C7BE5 : 0xFF5A5A66);
|
||||
box->Invalidate();
|
||||
}
|
||||
|
||||
void DoLogin() {
|
||||
CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")));
|
||||
CEditUI *pPass = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")));
|
||||
CLabelUI *pTip = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblTip")));
|
||||
CButtonUI *pBtn = static_cast<CButtonUI *>(m_pm.FindControl(_T("btnLogin")));
|
||||
if (!pUser || !pPass || !pTip) return;
|
||||
|
||||
std::wstring user = pUser->GetText().GetData();
|
||||
std::wstring pass = pPass->GetText().GetData();
|
||||
if (user.empty()) { pTip->SetText(L"请输入账号或卡密"); return; }
|
||||
if (pass.empty()) { pTip->SetText(L"请输入密码"); return; }
|
||||
|
||||
SaveAccount(user, g_remember);
|
||||
|
||||
if (pBtn) { pBtn->SetText(L"验证中…"); pBtn->SetEnabled(false); }
|
||||
pTip->SetText(L"正在连接验证服务器…");
|
||||
|
||||
char msg[1024] = {0};
|
||||
int ok = api_login(W2U8(user).c_str(), W2U8(pass).c_str(), msg, sizeof(msg));
|
||||
if (ok) {
|
||||
g_logged_in = 1;
|
||||
pTip->SetText(L"验证成功,正在启动程序…");
|
||||
::SetTimer(m_hWnd, 1, 600, NULL);
|
||||
} else {
|
||||
std::wstring tipText = U8(msg);
|
||||
if (tipText.find(L"设备") != std::wstring::npos && tipText.find(L"上限") != std::wstring::npos) {
|
||||
wchar_t extra[128];
|
||||
swprintf(extra, 128, L"(本应用上限 %d 台,可在官网「我的设备」解绑后重试)", g_maxDevices);
|
||||
tipText += extra;
|
||||
}
|
||||
pTip->SetText(tipText.c_str());
|
||||
if (pBtn) { pBtn->SetText(L"登 录"); pBtn->SetEnabled(true); }
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override {
|
||||
if (uMsg == WM_CREATE) {
|
||||
m_pm.Init(m_hWnd);
|
||||
CDialogBuilder builder;
|
||||
std::wstring xml = U8(m_skin);
|
||||
CControlUI *pRoot = builder.Create(xml.c_str(), (UINT)0, NULL, &m_pm);
|
||||
if (!pRoot) { ::MessageBoxW(m_hWnd, L"界面加载失败", L"验证", MB_ICONERROR); return 0; }
|
||||
m_pm.AttachDialog(pRoot);
|
||||
m_pm.AddNotifier(this);
|
||||
|
||||
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblApp"))))
|
||||
p->SetText(U8(g_name).c_str());
|
||||
|
||||
std::wstring devText = L"设备 ";
|
||||
devText += U8(g_device);
|
||||
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblDevice"))))
|
||||
p->SetText(devText.c_str());
|
||||
|
||||
bool remember = false;
|
||||
std::wstring saved = LoadAccount(remember);
|
||||
g_remember = remember;
|
||||
UpdateRememberButton();
|
||||
|
||||
RECT rc = {0};
|
||||
::GetClientRect(m_hWnd, &rc);
|
||||
m_iWidth = rc.right - rc.left;
|
||||
CControlUI *lp = m_pm.FindControl(_T("panelLogin"));
|
||||
int loginH = lp ? lp->GetFixedHeight() : 0;
|
||||
if (loginH > 0) m_chromeH = (rc.bottom - rc.top) - loginH;
|
||||
SwitchTab(0);
|
||||
FetchAppInfo(); // 按后台设置裁剪界面(注册/重置/充值 tab、注册验证码)
|
||||
if (CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) {
|
||||
if (!saved.empty()) pUser->SetText(saved.c_str());
|
||||
pUser->SetFocus();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_TIMER && wParam == 2) {
|
||||
if (g_codeLeft > 0) g_codeLeft--;
|
||||
if (g_codeLeft <= 0) { g_codeLeft = 0; ::KillTimer(m_hWnd, 2); }
|
||||
UpdateCodeButtons();
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_TIMER && wParam == 1) {
|
||||
::KillTimer(m_hWnd, 1);
|
||||
::ShowWindow(m_hWnd, SW_HIDE);
|
||||
if (g_oep) g_oep();
|
||||
::PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
if (uMsg == WM_DESTROY) { ::PostQuitMessage(0); return 0; }
|
||||
|
||||
LRESULT lr = 0;
|
||||
if (m_pm.MessageHandler(uMsg, wParam, lParam, lr)) return lr;
|
||||
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
CPaintManagerUI m_pm;
|
||||
const char *m_skin;
|
||||
int m_chromeH = 0; // 除面板外的固定高度(标题栏 + tab 行 + 页脚)
|
||||
int m_iWidth = 0;
|
||||
int m_iMinH = 380;
|
||||
};
|
||||
|
||||
static int RunShell(void *oep) {
|
||||
g_oep = (PFN_OEP)oep;
|
||||
const SkinDef *sk = skin_for(g_theme);
|
||||
|
||||
CPaintManagerUI::SetInstance(::GetModuleHandle(NULL));
|
||||
::CoInitialize(NULL);
|
||||
|
||||
CVerifyWnd wnd(sk->xml);
|
||||
UINT style = WS_POPUP | WS_CLIPCHILDREN;
|
||||
UINT exstyle = WS_EX_TOPMOST | WS_EX_APPWINDOW;
|
||||
|
||||
wnd.Create(NULL, L"软件授权验证", style, exstyle, 0, 0, sk->w, sk->h);
|
||||
wnd.CenterWindow();
|
||||
::ShowWindow(wnd, SW_SHOW);
|
||||
|
||||
CPaintManagerUI::MessageLoop();
|
||||
::CoUninitialize();
|
||||
return g_logged_in ? 0 : 6;
|
||||
}
|
||||
|
||||
/* ---------------------------- 对外接口 ---------------------------- */
|
||||
static void load_cfg(const char *json) {
|
||||
snprintf(g_cfg, sizeof(g_cfg), "%s", json ? json : "");
|
||||
json_str(g_cfg, "api", g_api, sizeof(g_api));
|
||||
json_str(g_cfg, "name", g_name, sizeof(g_name));
|
||||
g_deviceAuto = json_int(g_cfg, "device_auto", 1);
|
||||
|
||||
char mid[64] = {0};
|
||||
make_machine_id(mid, sizeof(mid));
|
||||
snprintf(g_instance, sizeof(g_instance), "%s", mid);
|
||||
|
||||
if (!json_str(g_cfg, "device", g_device, sizeof(g_device)) || !g_device[0]) {
|
||||
if (g_deviceAuto) snprintf(g_device, sizeof(g_device), "%s", mid);
|
||||
else snprintf(g_device, sizeof(g_device), "%s", "UNKNOWN-DEVICE");
|
||||
}
|
||||
if (!json_str(g_cfg, "theme", g_theme, sizeof(g_theme))) snprintf(g_theme, sizeof(g_theme), "dark");
|
||||
}
|
||||
|
||||
#ifdef SHELL_EXE
|
||||
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
|
||||
const char *cfg = (lpCmdLine && lpCmdLine[0]) ? lpCmdLine : getenv("VFY_CFG");
|
||||
if (!cfg || !cfg[0]) cfg = "{\"theme\":\"dark\"}";
|
||||
load_cfg(cfg);
|
||||
return RunShell(NULL);
|
||||
}
|
||||
#else
|
||||
extern "C" __declspec(dllexport) int VerifyMain(void *oep, const char *cfgjson) {
|
||||
load_cfg(cfgjson);
|
||||
return RunShell(oep);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int VerifyShellVersion(void) { return 9; }
|
||||
extern "C" __declspec(dllexport) const char *VerifyShellThemes(void) {
|
||||
return "dark,light,split,card,industrial,terminal,compact";
|
||||
}
|
||||
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID) {
|
||||
if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(h);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user