522 lines
23 KiB
C++
522 lines
23 KiB
C++
// 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
|