This commit is contained in:
gr
2026-09-28 10:02:07 +08:00
parent d79a2fa489
commit b112dcc6be
303 changed files with 5039 additions and 49659 deletions
+63 -3
View File
@@ -206,13 +206,19 @@ def probe_installed_client(*, deep=False, initialize_database=False):
def _probe_installed_client(*, deep=False, initialize_database=False, timings):
"""File/process presence is deliberately not treated as a login or send proof."""
from wecom_native_builds import build_for_version, client_support_text
from wecom_native_builds import (
KNOWN_VERSION_FAMILIES, build_for_hash, build_for_version,
classify_version, client_support_text, sha256_file,
)
result = {
"schemaVersion": 3, "checkedAt": time.time(), "readOnly": not initialize_database,
"status": "not_checked", "label": "待检测", "message": "",
"canSend": False, "loginVerified": False, "adapterInstalled": False,
"sendVerified": False, "receiptVerified": False,
"clients": [], "binaries": [], "bundledAgents": [], "errors": [],
"versionDetection": [], "clientVersionFamily": "",
"buildFingerprints": [], "buildMatchMode": "",
"needsAdapterUpdate": False,
"supportedClient": client_support_text(),
"host": {"os": platform.system(), "release": platform.release(),
"machine": platform.machine(), "processBits": struct.calcsize("P") * 8},
@@ -266,6 +272,10 @@ def _probe_installed_client(*, deep=False, initialize_database=False, timings):
except Exception as exc:
result["errors"].append(f"{target.name}: {type(exc).__name__}")
versions = sorted({item.get("version") for item in result["clients"] if item.get("version")})
detections = [classify_version(value) for value in versions]
families = sorted({item["family"] for item in detections if item.get("family")})
result["versionDetection"] = detections
result["clientVersionFamily"] = " / ".join(families)
result["clientVersion"] = " / ".join(versions)
result["architecture"] = " / ".join(sorted({
item.get("architecture") for item in result["clients"] if item.get("architecture")}))
@@ -286,10 +296,60 @@ def _probe_installed_client(*, deep=False, initialize_database=False, timings):
return result
from wecom_native_sender import discover, NativeUnavailable
version_matches = [item for item in result["clients"] if build_for_version(item.get("version")) is not None]
# The version resource is only a hint. Hash an unregistered image once so
# a localized/malformed version string cannot prevent an exact known build
# from being selected. A matching hash is still checked again by
# NativeClient against the live process before any write is possible.
hash_matches = []
fingerprint_paths = set()
if not version_matches:
result.update(status="unsupported_client_version", label="企业微信版本尚未适配",
message=f"本机检测到 {result['clientVersion'] or '未知版本'};当前协议适配范围为 {result['supportedClient']}。安装盘符不影响识别;其他版本需要单独验证发送接口与回执。")
for item in result["clients"]:
path = item.get("path")
if not path:
continue
identity = os.path.normcase(os.path.abspath(path))
if identity in fingerprint_paths:
continue
fingerprint_paths.add(identity)
try:
digest = sha256_file(path)
except (OSError, ValueError, TypeError):
continue
match = build_for_hash(digest)
result["buildFingerprints"].append({
"path": str(path), "sha256": digest,
"adapterId": match.adapter_id if match is not None else "",
})
if match is not None:
hash_matches.append(item)
if hash_matches:
version_matches = hash_matches
result["buildMatchMode"] = "sha256"
if not version_matches:
known_families = sorted({
detection.get("family") for detection in detections
if detection.get("state") == "known_family_new_patch"
and detection.get("family") in KNOWN_VERSION_FAMILIES
})
if known_families:
family_text = "、".join(known_families)
result.update(
status="known_client_family_requires_adapter",
label="检测到新版,等待精确适配",
needsAdapterUpdate=True,
message=(
f"已自动识别本机企业微信 {result['clientVersion'] or '未知版本'} "
f"属于 {family_text} 系列,但当前没有该补丁的精确接口布局。"
"已阻止协议写入;请导出此报告,在该版本完成一次接口与服务器回执验证后再启用。"
f"当前已登记适配:{result['supportedClient']}。"
),
)
else:
result.update(status="unsupported_client_version", label="企业微信版本尚未适配",
message=f"本机检测到 {result['clientVersion'] or '未知版本'};当前协议适配范围为 {result['supportedClient']}。安装盘符不影响识别;其他版本需要单独验证发送接口与回执。")
return result
if not result.get("buildMatchMode"):
result["buildMatchMode"] = "version"
if not any(item.get("architecture") == "x86" for item in version_matches):
result.update(status="unsupported_client_architecture", label="企业微信架构尚未适配",
message=f"本机企业微信为 {result['architecture'] or '未知架构'};协议适配器目前要求 x86 企业微信(可运行在 64 位 Windows 上)。")