132 lines
6.3 KiB
Python
132 lines
6.3 KiB
Python
"""Manual validation utility for 5.0.11.6018; never starts an automatic listener."""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
import time
|
|
|
|
TARGET_VERSION = '5.0.11.6018'
|
|
TOOL_VERSION = '6018-validation-1'
|
|
|
|
|
|
def self_test():
|
|
import sqlite3
|
|
import tempfile
|
|
import win32api
|
|
from Crypto.Cipher import AES
|
|
from wecom_native_builds import build_for_version, build_for_hash
|
|
from wecom_native_stub import STUBS, relocate
|
|
from wxwork_db import WXWorkDB
|
|
from wxwork_local_setup import key_worker_main
|
|
from wecom_native_verification import run_send_test
|
|
profile = build_for_version(TARGET_VERSION)
|
|
if build_for_hash(profile.sha256) is not profile or profile.send_argument_bytes != 16:
|
|
raise RuntimeError('Target build profile is missing')
|
|
fields = {name: 0x100000 + index * 256 for index, (name, _) in enumerate(STUBS[profile.send_stub][1])}
|
|
if len(relocate(profile.send_stub, fields)) != 269:
|
|
raise RuntimeError('Call stub is incomplete')
|
|
if AES.new(bytes(16), AES.MODE_ECB).encrypt(bytes(16)).hex() != '66e94bd4ef8a2c3b884cfa59ca342b2e':
|
|
raise RuntimeError('AES dependency failed')
|
|
with tempfile.TemporaryDirectory(prefix='wecom-validation-') as temporary:
|
|
root = Path(temporary) / '中文 空格' / 'WXWork'
|
|
path = root / '100' / 'Data' / 'message.db'
|
|
path.parent.mkdir(parents=True)
|
|
connection = sqlite3.connect(path)
|
|
connection.execute('CREATE TABLE message_table(sender_id TEXT, conversation_id TEXT, content_type INT, send_time INT, content TEXT)')
|
|
connection.commit()
|
|
connection.close()
|
|
database = WXWorkDB(str(root), {}, str(Path(temporary) / 'cache'))
|
|
try:
|
|
if not database.health_check(account='100') or database.health_check(account='101'):
|
|
raise RuntimeError('Account-bound database self-check failed')
|
|
finally:
|
|
database.close()
|
|
if not win32api.GetModuleFileName(0):
|
|
raise RuntimeError('Windows API dependency failed')
|
|
print(json.dumps({'toolVersion': TOOL_VERSION, 'selfTest': 'passed', 'messageSent': False}))
|
|
return 0
|
|
|
|
|
|
def run_validation(*, check_only=False, output=None, ask=input):
|
|
from runtime_paths import application_data_dir
|
|
from wxwork_protocol_probe import probe_installed_client, export_probe_report
|
|
from wecom_native_verification import run_send_test
|
|
if output:
|
|
directory = Path(output)
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
else:
|
|
directory = (Path(sys.executable).resolve().parent if getattr(sys, 'frozen', False) else Path(__file__).resolve().parent) / 'reports'
|
|
try:
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
test_path = directory / f'.write-check-{os.getpid()}'
|
|
test_path.write_bytes(b'')
|
|
test_path.unlink()
|
|
except OSError:
|
|
directory = application_data_dir() / 'protocol-validation-reports'
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
stamp = time.strftime('%Y%m%d-%H%M%S') + '-' + str(os.getpid())
|
|
environment_path = directory / f'wecom-6018-environment-{stamp}.json'
|
|
send_path = directory / f'wecom-6018-send-{stamp}.json'
|
|
print('企业微信 5.0.11.6018 收发验证工具\n本工具只做环境检测和指定会话的单次测试,不启动自动回复。')
|
|
print('正在检查版本、当前账号和本机消息库,请稍候……', flush=True)
|
|
report = probe_installed_client(initialize_database=not check_only)
|
|
report['validationToolVersion'] = TOOL_VERSION
|
|
export_probe_report(report, environment_path)
|
|
print('客户端:' + report.get('clientVersion', '未检测到'))
|
|
print('安装位置:' + report.get('clientInstallPath', '未检测到'))
|
|
print('状态:' + report.get('label', '未知'))
|
|
print(report.get('message', ''))
|
|
print('环境报告:' + str(environment_path))
|
|
if check_only:
|
|
return 0
|
|
if report.get('clientVersion') != TARGET_VERSION or report.get('status') not in ('native_validation_required', 'native_ready'):
|
|
print('当前环境不能进行本次发送验证。请将环境报告返回开发者。')
|
|
return 2
|
|
account = report['nativeAccount']
|
|
print('当前账号标识:' + account)
|
|
name = ask('请输入当前账号中已有的专用测试单聊完整名称(回车退出):').strip()
|
|
if not name:
|
|
return 2
|
|
print(f'测试会话:{name}\n测试内容:协议通道测试,请忽略')
|
|
if ask('确认发送这一条测试消息,请输入“发送”(其他输入取消):').strip() != '发送':
|
|
print('已取消,未发送。')
|
|
return 2
|
|
status = run_send_test(['--protocol-send-test', name, '--report', str(send_path),
|
|
'--expected-client', TARGET_VERSION, '--expected-account', account])
|
|
receipt_report = json.loads(send_path.read_text(encoding='utf-8'))
|
|
if status == 0:
|
|
print('已核对原账号身份、测试内容和服务器消息编号。重复测试同一会话会返回已有回执。')
|
|
else:
|
|
print('未完成确认:' + receipt_report.get('error', '结果待核对'))
|
|
print('如果消息显示已发出,请勿再次发送;保留报告供核对。')
|
|
print('发送报告:' + str(send_path))
|
|
print('请将本次两份 JSON 报告返回开发者;不用提供聊天数据库或账号密钥。')
|
|
return status
|
|
|
|
|
|
def main(argv=None):
|
|
arguments = sys.argv[1:] if argv is None else argv
|
|
if arguments == ['--wechat-db-key-worker']:
|
|
from wxwork_local_setup import key_worker_main
|
|
return key_worker_main()
|
|
parser = argparse.ArgumentParser(description='5.0.11.6018 手动收发验证;不是正式安装包')
|
|
parser.add_argument('--self-test', action='store_true')
|
|
parser.add_argument('--check-only', action='store_true')
|
|
parser.add_argument('--output', type=Path)
|
|
args = parser.parse_args(arguments)
|
|
if args.self_test:
|
|
return self_test()
|
|
try:
|
|
result = run_validation(check_only=args.check_only, output=args.output)
|
|
except Exception as exc:
|
|
print('验证未完成:' + str(exc))
|
|
result = 2
|
|
if not args.check_only and sys.stdin.isatty():
|
|
input('按回车关闭……')
|
|
return result
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|