更新
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
"""复现"把广告文本当成登录二维码"的误判,并验证替代判据。
|
||||
|
||||
纯读:只截图、只计算,不点击、不发送。
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import wechat_bot as bot_module # noqa: E402
|
||||
|
||||
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "secgate")
|
||||
|
||||
|
||||
def report(img: np.ndarray, label: str) -> None:
|
||||
height, width = img.shape[:2]
|
||||
rgb = img[:, :, :3].astype(np.float32)
|
||||
gray = rgb.mean(axis=2)
|
||||
nav_width = max(16, int(width * 0.06))
|
||||
nav = gray[int(height * 0.08):int(height * 0.92), :nav_width]
|
||||
center = gray[
|
||||
int(height * 0.32):int(height * 0.70),
|
||||
int(width * 0.32):int(width * 0.68),
|
||||
]
|
||||
nav_dark_ratio = float((nav < 120).mean())
|
||||
dark = center < 75
|
||||
light_ratio = float((center > 220).mean())
|
||||
transition_ratio = float(
|
||||
(dark[:, 1:] != dark[:, :-1]).mean() + (dark[1:, :] != dark[:-1, :]).mean()
|
||||
)
|
||||
qr_like = (
|
||||
float(dark.mean()) >= 0.025 and light_ratio >= 0.45 and transition_ratio >= 0.035
|
||||
)
|
||||
print(f"--- {label} {width}x{height}")
|
||||
print(f" nav_dark_ratio = {nav_dark_ratio:.4f} (需 < 0.12)")
|
||||
print(f" center dark = {float(dark.mean()):.4f} (需 >= 0.025)")
|
||||
print(f" light_ratio = {light_ratio:.4f} (需 >= 0.45)")
|
||||
print(f" transition = {transition_ratio:.4f} (需 >= 0.035)")
|
||||
print(f" qr_like = {qr_like}")
|
||||
print(f" 旧判据结论 = {nav_dark_ratio < 0.12 and qr_like}")
|
||||
|
||||
gray8 = cv2.cvtColor(img[:, :, :3], cv2.COLOR_BGR2GRAY)
|
||||
detector = cv2.QRCodeDetector()
|
||||
ok, points = detector.detect(gray8)
|
||||
print(f" cv2 真的找到二维码 = {bool(ok)}")
|
||||
if ok and points is not None:
|
||||
for quad in np.asarray(points).reshape(-1, 4, 2):
|
||||
w = np.linalg.norm(quad[0] - quad[1])
|
||||
h = np.linalg.norm(quad[1] - quad[2])
|
||||
print(f" 四角={quad.astype(int).tolist()} 边长≈{w:.0f}x{h:.0f}")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
os.makedirs(OUT, exist_ok=True)
|
||||
bot = bot_module.WeChatBot()
|
||||
bot.safe_window_mode = True
|
||||
bot.auto_activate_window = False
|
||||
if not bot.connect(activate=False, wait_if_missing=False):
|
||||
print("[-] 未挂载到企业微信窗口")
|
||||
return
|
||||
img = bot._capture_full_window()
|
||||
if img is None:
|
||||
print("[-] 截屏失败")
|
||||
return
|
||||
cv2.imwrite(os.path.join(OUT, "full.png"), img[:, :, :3])
|
||||
report(img, "当前企业微信主界面(不该被判为验证页)")
|
||||
print()
|
||||
print(f"looks_like_security_verification() = "
|
||||
f"{bot_module.looks_like_security_verification(img)}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user