From ddb381d7f98098a05d87d256cf6e47249426cb26 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Wed, 25 Nov 2026 06:05:20 +0800 Subject: [PATCH] fix(native): handle local HTTPS and allow shared log reads Use the loopback service certificate for the offline HTTPS path. Retain original host names for host-based routing and allow the network log to be read while the client is running. --- .../accept-local-tls-certificate/locate.json | 11 ++++++ .../accept-local-tls-certificate/patch.json | 39 +++++++++++++++++++ native/wto-net/src/hook_config.c | 3 +- packages/build/src/network/address-rewrite.ts | 11 +++--- packages/build/src/network/login-overrides.ts | 19 ++++----- 5 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 exe-patches/online/accept-local-tls-certificate/locate.json create mode 100644 exe-patches/online/accept-local-tls-certificate/patch.json diff --git a/exe-patches/online/accept-local-tls-certificate/locate.json b/exe-patches/online/accept-local-tls-certificate/locate.json new file mode 100644 index 0000000..6b51017 --- /dev/null +++ b/exe-patches/online/accept-local-tls-certificate/locate.json @@ -0,0 +1,11 @@ +{ + "method": "signature", + "section": ".text", + + "how": [ + "libcurl 的 Curl_clone_primary_ssl_config(从入口到读取 cert_blob 判空跳转,共 176 字节)。跳转位移已通配(authoring.py 生成)。", + "在 2.61.0.37 原版 aces.exe 上唯一命中 0x56463c0;要改的指令在 +0x52(0x5646412)。" + ], + + "pattern": "56 57 53 48 83 ec 20 48 89 d6 48 89 cf 8b 82 98 00 00 00 83 c8 20 89 82 98 00 00 00 0f b6 89 95 00 00 00 88 8a 95 00 00 00 8b 8f 90 00 00 00 89 8a 90 00 00 00 8b 8f 98 00 00 00 83 e1 01 83 e0 fe 09 c8 89 82 98 00 00 00 8b 8f 98 00 00 00 83 e1 02 83 e0 fd 09 c8 89 82 98 00 00 00 8b 8f 98 00 00 00 83 e1 04 83 e0 fb 09 c8 89 82 98 00 00 00 8b 8f 98 00 00 00 83 e1 08 83 e0 f7 09 c8 89 82 98 00 00 00 8b 8f 98 00 00 00 83 e1 10 83 e0 ef 09 c8 89 82 98 00 00 00 0f b6 87 94 00 00 00 88 82 94 00 00 00 48 8b 5f 68 48 85 db 74 ??" +} diff --git a/exe-patches/online/accept-local-tls-certificate/patch.json b/exe-patches/online/accept-local-tls-certificate/patch.json new file mode 100644 index 0000000..a63f746 --- /dev/null +++ b/exe-patches/online/accept-local-tls-certificate/patch.json @@ -0,0 +1,39 @@ +{ + "id": "online/accept-local-tls-certificate", + "title": "让客户端的 HTTPS 连接接受本地服务的自签证书", + + "program_behaviour": { + "stock": "libcurl 建立新连接时用 Curl_clone_primary_ssl_config 把请求侧的 SSL 配置复制到连接侧(+0x98 的第 0 位 verifypeer、第 1 位 verifyhost 默认都是 1)。对于没有读取 enableSslCertCheck 开关的 HTTPS 请求(如脚本的 dagor.http、yuplay2 的购买与兑换码、事件上报),连接被 wto_ws.dll 改道到本地服务后,因本地服务使用自签证书而报 CURLE_PEER_FAILED_VERIFICATION(60)断开。", + "patched": "复制 SSL 配置到连接侧时,把 verifypeer 和 verifyhost 两位一并清零,所有经 wto_ws.dll 改道到本地服务的 HTTPS 连接都直接接受本地服务的自签证书。" + }, + + "derivation": { + "requirement": "handover 6.1 方案 B(用户原话 82、115)与功能清单 G「礼包商店」「兑换码」。被 wto_ws.dll 改道到本地服务的 https 请求(api.gaijinent.com 的 GJN 付款、商品信息、兑换码等)必须能完成 TLS 握手并把请求送达本地服务。", + "cause": "network.blk 的 enableSslCertCheck 只被 0x155c950 的 4 个调用点读取;dagor.http(httpRequest)等请求不读它,保留了 libcurl 默认的证书链和主机名校验。实测日志:newsfeed.gap.gaijin.net 握手后报 SSL peer certificate or SSH remote key was not OK。", + "lighter_options_ruled_out": [ + "network.blk 的 enableSslCertCheck:已设为 false,但 dagor.http 等路径根本不读取这个配置。", + "把本地服务的根证书装进 Windows 系统受信任根证书库:会改动玩家操作系统的全局信任链,影响正版和其他软件,违反隔离原则。" + ], + "conclusion": "在 libcurl 复制连接 SSL 配置的单点清掉 verifypeer 和 verifyhost 两位(仅改 5 字节),同时由于 wto_ws.dll 已拦截所有外部连接,客户端不会连向任何真实外网服务器。", + "if_not_applied": "经 wto_ws.dll 改道到本地服务的 https 请求在 TLS 握手后因自签证书校验失败断开,GJN 付款、商品价格查询(item_info.php)和兑换码等无法到达本地服务。" + }, + + "why_this_site": [ + "aces.exe 只静态链接了一份 libcurl(OpenSSL 后端),AsyncHTTPClient、dagor.http、YuHttp 全部共用它;Curl_clone_primary_ssl_config 是每个连接初始化 SSL 配置的必经入口。", + "0x5646412 原本是清除第 1 位后把 verifyhost 合进 eax,紧接着 0x5646417 写回 [rdx+0x98]。改成 and eax, -4 加两个 nop,一次把第 0 位(verifypeer)和第 1 位(verifyhost)都清零并写回,只改 5 字节,不改变栈和跳转结构。" + ], + + "features": ["A-不连 Gaijin", "G-礼包商店", "G-兑换码"], + "requires": ["online/network-hook-library"], + "evidence": [ + "2.61.0.37 原版 aces.exe:Curl_clone_primary_ssl_config 位于 0x56463c0,由 0x5646360 对主连接(+0x1b0)和代理连接(+0x250)调用;OpenSSL 校验函数 0x63adb70 在 0x63afed5、0x63b0522、0x63b05b7 读取 +0x98 的第 0、1 位。" + ], + "verified_on": [], + + "edit": { + "offset": 82, + "asm": ["and eax, -4", "nop", "nop"], + "bytes": "83e0fc9090", + "expect_original": "83e0fd09c8" + } +} diff --git a/native/wto-net/src/hook_config.c b/native/wto-net/src/hook_config.c index 763cfea..b60a185 100644 --- a/native/wto-net/src/hook_config.c +++ b/native/wto-net/src/hook_config.c @@ -11,6 +11,7 @@ #include "hook_config.h" #include "redirect_rules.h" +#include #include #include #include @@ -60,7 +61,7 @@ void config_load(HMODULE self) find_folder(self); read_port(); if (_snwprintf_s(path, MAX_PATH, _TRUNCATE, L"%swto_ws.log", g_folder) >= 0) - _wfopen_s(&g_log, path, L"w"); + g_log = _wfsopen(path, L"w", _SH_DENYWR); log_line("wto_ws: local service port %u%s", g_service_port, g_service_port ? "" : " (none: outside connections are refused)"); } diff --git a/packages/build/src/network/address-rewrite.ts b/packages/build/src/network/address-rewrite.ts index 1583251..a6c9f55 100644 --- a/packages/build/src/network/address-rewrite.ts +++ b/packages/build/src/network/address-rewrite.ts @@ -5,13 +5,14 @@ * http(s)://host[:port]/path -> http://127.0.0.1:/host/path (host is a Gaijin domain or an external IP) * ws(s)://host[:port]/path -> ws://127.0.0.1:/host/path * host:port -> 127.0.0.1: (raw TCP endpoints: matching, chat) - * host -> 127.0.0.1 (bare Gaijin domain, e.g. the event log host) * - * Everything else (file patterns, placeholders such as "https://not.used", DNS server IPs) - * is left as it is. + * Bare Gaijin host names without a port (e.g. the event log host) are left as they are so the + * client keeps their Host header and SNI; wto_ws.dll resolves them locally and sends their + * connections to the local service port. Everything else (file patterns, + * placeholders such as "https://not.used", DNS server IPs) is also left as it is. */ import { visitParams, type BlkBlock } from '@wto/blk'; -import { hostPort, localUrl, LOOPBACK, type LocalEndpoint } from './local-endpoint.ts'; +import { hostPort, localUrl, type LocalEndpoint } from './local-endpoint.ts'; export interface AddressChange { readonly path: string; @@ -47,7 +48,7 @@ export function rewriteAddress(value: string, endpoint: LocalEndpoint): string | } const hostAndPort = HOST_PORT_PATTERN.exec(value); if (hostAndPort) return isServerHost(hostAndPort[1]!.toLowerCase()) ? hostPort(endpoint) : null; - return isGaijinDomain(value.toLowerCase()) ? LOOPBACK : null; + return null; } function isServerHost(host: string): boolean { diff --git a/packages/build/src/network/login-overrides.ts b/packages/build/src/network/login-overrides.ts index 1101bea..2ec3f63 100644 --- a/packages/build/src/network/login-overrides.ts +++ b/packages/build/src/network/login-overrides.ts @@ -7,12 +7,13 @@ * certain (https://auth.gaijinent.com/login.php); the others are matched by name to the * addresses in the executable's string table. * - * The host keys replace only the host name of every login-related address and keep the - * address's port (yuplay2 YuSession::updateApiHost sets the host part). They therefore get - * the bare loopback address: "127.0.0.1:" would turn the local login URL into - * http://127.0.0.1::/..., which the game rejects as malformed. + * The host-only keys (authHost, ssoHost, storeApiHost, authFallbackHost) are intentionally not + * set: they replace only the host name and keep port 443, and turning the host into 127.0.0.1 + * would strip the original Host header and bypass wto_ws.dll's redirection. Leaving the Gaijin + * host names in place lets wto_ws.dll resolve them to 127.0.0.2 and route their TLS connections + * to the local service port with the original Host header intact. */ -import { localUrl, LOOPBACK, type LocalEndpoint } from './local-endpoint.ts'; +import { localUrl, type LocalEndpoint } from './local-endpoint.ts'; const URL_DEFAULTS: ReadonlyArray = [ ['loginURL', 'auth.gaijinent.com', '/login.php'], @@ -23,12 +24,6 @@ const URL_DEFAULTS: ReadonlyArray { - return [ - ...URL_DEFAULTS.map(([key, host, path]) => [key, localUrl(endpoint, host, path)] as const), - ...HOST_KEYS.map((key) => [key, LOOPBACK] as const), - ['fallbackIP', LOOPBACK], - ]; + return URL_DEFAULTS.map(([key, host, path]) => [key, localUrl(endpoint, host, path)] as const); }