Files
verify/shell/classic/shell6.cpp
T
admin 4b0c8faccb
Docker Build / Build and Push Docker Image (push) Successful in 5s
Docker Build / Deploy to Server (push) Successful in 2s
fix(shell): 验证窗不再强制置顶,无边框窗口补上标题栏拖动
用户反馈两点:云端加密出来的程序拖不动、而且一直压在最前面。

- 置顶:DuiLib 壳的 exstyle 带了 WS_EX_TOPMOST,classic 壳的
  CreateWindowExW 也带了。验证窗常驻最前会压住用户所有窗口,
  切出去回消息它还杵在最前,只有一个窗口时看着像卡死。
  两处都去掉,WS_EX_APPWINDOW / WS_EX_LAYERED 保留
  (任务栏还在、classic 的透明背景还要)。

- 拖不动:DuiLib 壳是 WS_POPUP 无边框窗口,而全文件里
  HTCAPTION / WM_NCHITTEST / WM_LBUTTONDOWN 一处都没有,
  系统没有标题栏可抓,自然拖不动。补 WM_NCHITTEST:
  顶部 44px(各皮肤 btnClose 的 height,8 套皮肤一致)返回
  HTCAPTION 交给系统原生拖动,关闭按钮矩形单独排除
  (否则点不到它)。必须放在 m_pm.MessageHandler 之前,
  DuiLib 先答 HTCLIENT 就没机会了。

  classic 壳本来就有完整的 NCHITTEST(标题栏 32px + 窗口外拖动),
  只缺不置顶,所以只去掉 WS_EX_TOPMOST。

实测(wine + xdotool):
  _NET_WM_STATE 为空                      → 不再置顶
  标题栏按下拖动,位移 +175/+160 与鼠标同步 → 能拖
  关闭按钮区按下拖动,位置纹丝不动          → 排除生效
  界面 4 tab / 卡密单框 / 卡密登录按钮完整  → 没改坏

注意:classic 的 assets/shell64.bin(332330)、shell32.bin(328922) 与
build-classic.sh 现编产物(76800/86528)对不上,不是同一版本,
来源待确认,本次未替换(DuiLib 的 8 套皮肤已全部更新)。
2026-11-29 10:13:34 +08:00

1057 lines
43 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// vfy shell v6 —— VS 2026 暗黑 / 3× 超采样抗锯齿 / QQ 式设备管理踢线
#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 SS 3
#define MAXDEV 6
static float g_S = 1.0f; // DPI 缩放
static float g_SSf = (float)SS; // 超采样倍数(字体探测时临时设为 1)
static inline float L(float v) { return v * g_S * g_SSf; }
static inline float L1(float v) { return v * g_S; }
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, C_ROW, C_ROW_H;
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, g_hRow, g_hKick, g_hBack;
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 int g_screen = 0; // 0=登录 1=设备管理
/* 设备列表 */
struct DevInfo { char id[48], name[96], last[40]; int cur; };
static DevInfo g_devs[MAXDEV];
static int g_devCount = 0, g_devLimit = 1;
static char g_kickPending[48] = {0};
static int g_autoKick = 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};
static const RECT LR_BACK = {20, 330, 190, 352};
/* 载荷(独立 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 int json_int(const char *src, const char *key, int defv) {
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
const char *p = strstr(src, pat);
if (!p) return defv;
p = strchr(p + strlen(pat), ':');
if (!p) return defv;
p++;
while (*p == ' ' || *p == '"') p++;
return atoi(p);
}
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));
json_str(g_cfg, "auto_pass", g_auto, sizeof(g_auto));
g_autoKick = json_int(g_cfg, "auto_kick", 0);
}
/* ---------- 文本(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, L(4000), L(px * 2), &lay))) {
DWRITE_TEXT_METRICS m;
if (SUCCEEDED(lay->GetMetrics(&m)) && m.width > 0.5f) w = m.width / (g_S * g_SSf) - 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 RECT rowRect(int i) { RECT r = {20, 100 + i * 56, 400, 100 + i * 56 + 52}; return r; }
static RECT kickRect(int i) { RECT r = {308, 100 + i * 56 + 13, 392, 100 + i * 56 + 39}; return r; }
/* ---------- 画面 ---------- */
static void paint_chrome(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));
{
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, C_TXT);
line(cx + 4.5f, cy - 4.5f, cx - 4.5f, cy + 4.5f, 1.0f, C_TXT);
float mx = (LR_MIN.left + LR_MIN.right) / 2.0f;
line(mx - 4.5f, cy, mx + 4.5f, cy, 1.0f, C_TXT);
}
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);
}
}
static void paint_footer(void) {
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);
if (g_screen == 0)
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);
else
textL(L"\x8D85\x51FA\x4E0A\x9650\x65F6\x8BF7\x4E0B\x7EBF\x4E00\x53F0\x8BBE\x5907\xFF0C\x5426\x5219\x65E0\x6CD5\x767B\x5F55",
20, 380, 380, 16, 10, D2D1::ColorF(0.55f, 0.55f, 0.58f, 1), 0, 0);
}
static void paint_login(void) {
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 (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 (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);
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);
}
static void paint_devices(void) {
textL(L"\x8BBE\x5907\x5DF2\x8FBE\x4E0A\x9650", 20, 46, 320, 26, 15, C_TXT, 1, 0);
{
wchar_t sub[160];
swprintf(sub, 160, L"\x6700\x591A %d \x53F0\x8BBE\x5907\x540C\x65F6\x5728\x7EBF\xFF0C\x8BF7\x4E0B\x7EBF\x4E00\x53F0", g_devLimit);
textL(sub, 20, 72, 380, 16, 11, C_TXT2, 0, 0);
}
for (int i = 0; i < g_devCount; i++) {
RECT r = rowRect(i);
float y = (float)r.top;
fillRound(20, y, 380, 52, 3, g_hRow == i ? C_ROW_H : C_ROW);
strokeRound(20, y, 380, 52, 3, 1.0f, C_INPUT_BD);
wchar_t nm[128] = {0};
MultiByteToWideChar(CP_UTF8, 0, g_devs[i].name, -1, nm, 128);
textL(nm, 34, y + 9, 260, 20, 11.5f, C_TXT, 0, 0);
wchar_t lt[80] = {0};
MultiByteToWideChar(CP_UTF8, 0, g_devs[i].last, -1, lt, 80);
textL(lt, 34, y + 28, 200, 16, 10, C_TXT2, 0, 0);
if (g_devs[i].cur) {
fillRound(320, y + 15, 72, 22, 2, D2D1::ColorF(0.0f, 0.471f, 0.831f, 0.18f));
textL(L"\x672C\x673A\x5728\x7EBF", 320, y + 15, 72, 22, 10, C_LINK, 0, 1);
} else {
int hov = (g_hKick == i);
fillRound(308, y + 13, 84, 26, 2, hov ? C_ACCENT_H : D2D1::ColorF(1, 1, 1, 0.06f));
strokeRound(308, y + 13, 84, 26, 2, 1.0f, hov ? C_ACCENT_H : C_INPUT_BD);
textL(L"\x4E0B\x7EBF", 308, y + 13, 84, 26, 10.5f, C_TXT, 0, 1);
}
}
textL(L"\x53D6\x6D88\xFF0C\x8FD4\x56DE\x767B\x5F55", 20, 330, 170, 22, 11,
g_hBack ? C_LINK : C_TXT2, 0, 0);
}
static void paint(void) {
paint_chrome();
if (g_screen == 0) paint_login();
else paint_devices();
paint_footer();
g_rt->SetTransform(D2D1::Matrix3x2F::Identity());
}
/* ---------- 超采样渲染 + 手写降采样 ---------- */
static HDC g_mem3 = NULL;
static HBITMAP g_dib3 = NULL, g_dib1 = NULL;
static HDC g_mem1 = NULL;
static void *g_bits3 = NULL, *g_bits1 = NULL;
static int g_curW = 0, g_curH = 0;
static void free_surfaces(void) {
if (g_dib3) { DeleteObject(g_dib3); g_dib3 = NULL; g_bits3 = NULL; }
if (g_dib1) { DeleteObject(g_dib1); g_dib1 = NULL; g_bits1 = NULL; }
if (g_mem3) { DeleteDC(g_mem3); g_mem3 = NULL; }
if (g_mem1) { DeleteDC(g_mem1); g_mem1 = NULL; }
g_curW = g_curH = 0;
}
static int ensure_surfaces(int w1, int h1, HDC screen) {
if (g_curW == w1 && g_curH == h1 && g_dib3 && g_dib1) return 1;
free_surfaces();
BITMAPINFO bi; ZeroMemory(&bi, sizeof(bi));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biWidth = w1 * SS;
bi.bmiHeader.biHeight = -(h1 * SS);
g_dib3 = CreateDIBSection(screen, &bi, DIB_RGB_COLORS, &g_bits3, NULL, 0);
bi.bmiHeader.biWidth = w1;
bi.bmiHeader.biHeight = -h1;
g_dib1 = CreateDIBSection(screen, &bi, DIB_RGB_COLORS, &g_bits1, NULL, 0);
if (!g_dib3 || !g_dib1) { free_surfaces(); return 0; }
g_mem3 = CreateCompatibleDC(screen);
g_mem1 = CreateCompatibleDC(screen);
SelectObject(g_mem3, g_dib3);
SelectObject(g_mem1, g_dib1);
g_curW = w1; g_curH = h1;
return 1;
}
static void render(void) {
if (!g_rt || !g_hwnd) return;
int w1 = (int)((CARD_W + PAD * 2) * g_S), h1 = (int)((CARD_H + PAD * 2) * g_S);
HDC screen = GetDC(NULL);
if (!ensure_surfaces(w1, h1, screen)) { ReleaseDC(NULL, screen); return; }
/* 1) 3× 面渲染 */
memset(g_bits3, 0, (size_t)w1 * h1 * SS * SS * 4);
RECT rc3 = {0, 0, w1 * SS, h1 * SS};
g_rt->BindDC(g_mem3, &rc3);
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));
g_SSf = (float)SS;
paint();
g_rt->EndDraw();
/* 2) 手写降采样(9 像素盒式平均,预乘 alpha 直接平均即可) */
unsigned char *s3 = (unsigned char *)g_bits3;
unsigned char *d1 = (unsigned char *)g_bits1;
for (int y = 0; y < h1; y++) {
for (int x = 0; x < w1; x++) {
int sr = 0, sg = 0, sb = 0, sa = 0;
for (int dy = 0; dy < SS; dy++) {
unsigned char *row = s3 + ((size_t)(y * SS + dy) * (w1 * SS) + x * SS) * 4;
for (int dx = 0; dx < SS; dx++) {
unsigned char *p = row + dx * 4;
sb += p[0]; sg += p[1]; sr += p[2]; sa += p[3];
}
}
unsigned char *o = d1 + ((size_t)y * w1 + x) * 4;
int n = SS * SS;
o[0] = (unsigned char)(sb / n); o[1] = (unsigned char)(sg / n);
o[2] = (unsigned char)(sr / n); o[3] = (unsigned char)(sa / n);
}
}
/* 3) 提交 */
RECT wr; GetWindowRect(g_hwnd, &wr);
POINT dst = {wr.left, wr.top}, src = {0, 0};
SIZE sz = {w1, h1};
BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
UpdateLayeredWindow(g_hwnd, screen, &dst, &sz, g_mem1, &src, 0, &bf, ULW_ALPHA);
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);
float save = g_SSf;
g_SSf = 1.0f;
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();
g_SSf = save;
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 ok");
}
/* ---------- 网络 ---------- */
static int api_call(const char *suffix, const char *body, char *resp, int cap) {
wchar_t wHost[256], wPath[512];
char full[600];
snprintf(full, sizeof(full), "%s", g_api);
char *p = strstr(full, "://");
if (!p) return 0;
// 判断 scheme:p 指向 "://" 的冒号,p[-1] 就是 http/https 的最后一个字母
bool https = (p > full && p[-1] == 's');
p += 3;
char *slash = strchr(p, '/');
char dir[400] = {0};
if (slash) {
snprintf(dir, sizeof(dir), "%s", slash); // 含前导 /
*slash = 0;
char *last = strrchr(dir, '/');
if (last) *last = 0;
}
char host[256];
snprintf(host, sizeof(host), "%s", p);
// 原来写死 80:https 的 api 会被当成明文 HTTP 发到 443,服务端直接回
// 400 "The plain HTTP request was sent to HTTPS port",登录恒失败。
unsigned short port = https ? 443 : 80;
char *colon = strrchr(host, ':');
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
char path[512];
snprintf(path, sizeof(path), "%s/%s", dir[0] ? dir : "", suffix);
MultiByteToWideChar(CP_UTF8, 0, host, -1, wHost, 256);
MultiByteToWideChar(CP_UTF8, 0, path, -1, wPath, 512);
resp[0] = 0;
HINTERNET hS = WinHttpOpen(L"vfy/6.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,
https ? WINHTTP_FLAG_SECURE : 0) : NULL;
int ok = 0;
if (hR) {
const wchar_t *hdr = L"Content-Type: application/json\r\n";
WinHttpSendRequest(hR, hdr, (DWORD)-1L, (LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
WinHttpReceiveResponse(hR, NULL);
DWORD cl = 0;
if (WinHttpReadData(hR, resp, cap - 1, &cl)) resp[cl < (DWORD)cap ? cl : (DWORD)cap - 1] = 0;
if (strstr(resp, "\"ok\":true")) ok = 1;
logf_("api %s -> %.240s", suffix, resp);
}
if (hR) WinHttpCloseHandle(hR);
if (hC) WinHttpCloseHandle(hC);
WinHttpCloseHandle(hS);
return ok;
}
static void parse_devices(const char *resp) {
g_devCount = 0;
int lim = json_int(resp, "limit", 0);
if (lim > 0) g_devLimit = lim;
const char *p = strstr(resp, "\"devices\":[");
if (!p) return;
p += 11;
while (*p && g_devCount < MAXDEV) {
const char *ob = strchr(p, '{');
if (!ob) break;
const char *oe = strchr(ob, '}');
if (!oe) break;
char blk[640];
int n = (int)(oe - ob) + 1;
if (n > 639) n = 639;
memcpy(blk, ob, n);
blk[n] = 0;
DevInfo &d = g_devs[g_devCount];
ZeroMemory(&d, sizeof(d));
json_str(blk, "id", d.id, sizeof(d.id));
json_str(blk, "name", d.name, sizeof(d.name));
json_str(blk, "last", d.last, sizeof(d.last));
d.cur = json_int(blk, "cur", 0);
if (d.id[0]) g_devCount++;
p = oe + 1;
}
logf_("devices parsed: %d limit=%d", g_devCount, g_devLimit);
}
/* ---------- 流程 ---------- */
typedef void (*PFN_OEP)(void);
static PFN_OEP g_oep = NULL;
static int launch_payload(void) {
unsigned char *plain = NULL; DWORD plainLen = 0;
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];
BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO info;
unsigned char *buf = NULL; ULONG got = 0; NTSTATUS st = 0;
int okd = 0;
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(g_payloadSize + 16);
st = BCryptDecrypt(hKey, (PUCHAR)g_payload, g_payloadSize, &info, NULL, 0, buf, g_payloadSize, &got, 0);
okd = (st == 0);
done:
if (hKey) BCryptDestroyKey(hKey);
if (hAlg) BCryptCloseAlgorithmProvider(hAlg, 0);
if (hHash) BCryptDestroyHash(hHash);
if (!okd) return 0;
plainLen = got;
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(buf); return 0; }
DWORD w = 0; WriteFile(h, buf, plainLen, &w, NULL); CloseHandle(h);
free(buf);
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;
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);
}
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);
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 DWORD WINAPI kick_thread(LPVOID) {
char user[128] = {0}, body[512] = {0}, resp[2048] = {0};
GetWindowTextA(g_hUser, user, sizeof(user));
snprintf(body, sizeof(body), "{\"user\":\"%s\",\"device\":\"%s\",\"kick\":\"%s\"}", user, g_device, g_kickPending);
api_call("kick", body, resp, sizeof(resp));
logf_("kicked %s", g_kickPending);
g_kickPending[0] = 0;
g_busy = 0;
do_login(); // 踢完自动重试登录
return 0;
}
static void do_kick(int idx) {
if (idx < 0 || idx >= g_devCount) return;
if (g_devs[idx].cur) return;
snprintf(g_kickPending, sizeof(g_kickPending), "%s", g_devs[idx].id);
if (InterlockedExchange(&g_busy, 1) != 0) return;
set_status(0, L"\x6B63\x5728\x4E0B\x7EBF\x8BE5\x8BBE\x5907");
CreateThread(NULL, 0, kick_thread, NULL, 0, NULL);
}
static DWORD WINAPI login_thread(LPVOID) {
char user[128] = {0}, pass[128] = {0}, msg[256] = {0}, body[512] = {0}, resp[2048] = {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");
snprintf(body, sizeof(body), "{\"user\":\"%s\",\"pass\":\"%s\",\"device\":\"%s\"}", user, pass, g_device);
int passed = api_call("login", body, resp, sizeof(resp));
if (!passed && g_offline[0] && strcmp(pass, g_offline) == 0 && !strstr(resp, "DEVICE_LIMIT")) {
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 (strstr(resp, "DEVICE_LIMIT")) {
parse_devices(resp);
g_screen = 1;
set_status(2, L"\x8BBE\x5907\x8DF3\x8FC7\x4E0A\x9650\xFF0C\x8BF7\x9009\x62E9\x4E00\x53F0\x4E0B\x7EBF");
if (g_autoKick) SetTimer(g_hwnd, 7, 700, NULL);
} else {
json_str(resp, "msg", msg, sizeof(msg));
if (msg[0]) set_status_u8(2, msg);
else set_status(2, L"\x9A8C\x8BC1\x5931\x8D25");
}
g_busy = 0;
InvalidateRect(g_hwnd, NULL, FALSE);
return 0;
}
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 int row_at(int x, int y) {
for (int i = 0; i < g_devCount; i++) {
RECT r = rowRect(i);
if (in_rect(r, x, y)) return i;
}
return -1;
}
static int kick_at(int x, int y) {
for (int i = 0; i < g_devCount; i++)
if (in_rect(kickRect(i), x, y) && !g_devs[i].cur) return i;
return -1;
}
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)L1(32), (int)L1(125), (int)L1(356), (int)L1(30), h, (HMENU)201, NULL, NULL);
g_hPass = CreateWindowExW(0, L"EDIT", L"", WS_CHILD | WS_VISIBLE | ES_PASSWORD | ES_AUTOHSCROLL,
(int)L1(32), (int)L1(187), (int)L1(324), (int)L1(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); }
if (w == 7) {
KillTimer(h, 7);
for (int i = 0; i < g_devCount; i++)
if (!g_devs[i].cur) { do_kick(i); break; }
}
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 = 0, nc = 0, nt = 0, ne = 0, nx = in_rect(LR_CLOSE, lx, ly), nm = in_rect(LR_MIN, lx, ly);
int nl = 0, nrow = -1, nkick = -1, nback = 0;
if (g_screen == 0) {
nb = in_rect(LR_BTN, lx, ly); nc = in_rect(LR_REM, lx, ly);
nt = in_rect(LR_TAG, lx, ly); ne = in_rect(LR_EYE, lx, ly);
nl = in_rect(LR_L1, lx, ly) ? 1 : (in_rect(LR_L2, lx, ly) ? 2 : (in_rect(LR_L3, lx, ly) ? 3 : 0));
} else {
nrow = row_at(lx, ly);
nkick = kick_at(lx, ly);
nback = in_rect(LR_BACK, lx, ly);
}
if (nb != g_hBtn || nc != g_hChk || nt != g_hTag || ne != g_hEye || nx != g_hClose || nm != g_hMin ||
nl != g_hLink || nrow != g_hRow || nkick != g_hKick || nback != g_hBack) {
g_hBtn = nb; g_hChk = nc; g_hTag = nt; g_hEye = ne; g_hClose = nx; g_hMin = nm; g_hLink = nl;
g_hRow = nrow; g_hKick = nkick; g_hBack = nback;
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 = g_hBack = 0;
g_hRow = g_hKick = -1;
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 (g_screen == 0) {
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;
}
} else {
if (kick_at(lx, ly) >= 0 || in_rect(LR_BACK, lx, ly) || in_rect(LR_CLOSE, lx, ly) || in_rect(LR_MIN, 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 (g_screen == 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; }
} else {
int k = kick_at(lx, ly);
if (k >= 0) { do_kick(k); return 0; }
if (in_rect(LR_BACK, lx, ly)) {
g_screen = 0;
set_status(0, L"\x5C31\x7EEA");
InvalidateRect(h, NULL, FALSE);
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);
}
static const wchar_t *CLS_NAME = L"VfyShellV6";
static void make_colors(void) {
C_CARD = D2D1::ColorF(0.118f, 0.118f, 0.118f, 1);
C_BAR = D2D1::ColorF(0.145f, 0.145f, 0.153f, 1);
C_BORDER = D2D1::ColorF(0.247f, 0.247f, 0.275f, 1);
C_INPUT = D2D1::ColorF(0.145f, 0.145f, 0.149f, 1);
C_INPUT_BD = D2D1::ColorF(0.247f, 0.247f, 0.275f, 1);
C_FOCUS = D2D1::ColorF(0.0f, 0.471f, 0.831f, 1);
C_TXT = D2D1::ColorF(0.902f, 0.902f, 0.902f, 1);
C_TXT2 = D2D1::ColorF(0.616f, 0.616f, 0.616f, 1);
C_ACCENT = D2D1::ColorF(0.055f, 0.388f, 0.612f, 1);
C_ACCENT_H = D2D1::ColorF(0.067f, 0.467f, 0.733f, 1);
C_ACCENT_P = D2D1::ColorF(0.039f, 0.306f, 0.478f, 1);
C_LINK = D2D1::ColorF(0.216f, 0.58f, 1.0f, 1);
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);
C_ROW = D2D1::ColorF(0.145f, 0.145f, 0.149f, 1);
C_ROW_H = D2D1::ColorF(0.18f, 0.18f, 0.19f, 1);
}
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)-L1(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);
// 不带 WS_EX_TOPMOST:验证窗常驻最前会压住用户所有窗口,像卡死。
HWND hwnd = CreateWindowExW(WS_EX_LAYERED | WS_EX_APPWINDOW, CLS_NAME, L"\x9A8C\x8BC1\x767B\x5F55",
WS_POPUP, 0, 0, w, h, NULL, NULL, wc.hInstance, NULL);
if (!hwnd) return -1;
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;
}
#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 6; }
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID) {
if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(h);
return TRUE;
}
#else
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);
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);
return shell_main(NULL);
}
#endif