// 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 #include #include #include #include #include #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 = "" "" " " " " "