From 49b575d036f6a3cfbaa63e85ca37013f10138ec9 Mon Sep 17 00:00:00 2001 From: Remik1r3n Date: Fri, 7 Feb 2025 14:47:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=B0=8F=E9=BB=91=E5=B1=8B=E6=A6=82?= =?UTF-8?q?=E5=BF=B5=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ForceLogout.py | 91 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 29 deletions(-) diff --git a/ForceLogout.py b/ForceLogout.py index a1cc44f..a926724 100644 --- a/ForceLogout.py +++ b/ForceLogout.py @@ -8,12 +8,34 @@ from HelperLogInOut import apiLogout import json from loguru import logger import time -import datetime +from datetime import datetime + def isUserLoggedIn(userId): + return True return json.loads(apiGetUserPreview(userId))['isLogin'] +def getUNIXTime(mmddhhmmss, year=2025): + # 解析 MMDDHHMMSS 格式的时间,返回 Unix 时间戳 + try: + date_time_str = f"{year}{mmddhhmmss}" + date_time_obj = datetime.strptime(date_time_str, '%Y%m%d%H%M%S') + # 将 datetime 对象转换为 Unix 时间戳 + unix_timestamp = int(time.mktime(date_time_obj.timetuple())) + logger.info(f"转换出了时间戳: {unix_timestamp}") + return unix_timestamp + except ValueError as e: + print(f"时间格式错误: {e}") + return None + def logOut(userId, Timestamp): + DEBUGMODE = True + if DEBUGMODE: + # 用于调试的时间戳 + debugRealTimestamp = 1738663945 + logger.info(f"调试模式: 传入的时间戳和调试时间戳之差: {Timestamp - debugRealTimestamp}") + time.sleep(0.2) + return True try: result = apiLogout(Timestamp, userId) loadedResult = json.loads(result) @@ -22,32 +44,43 @@ def logOut(userId, Timestamp): except: return False -def forceLogout(userId, beginTimestamp): - # 将人类可读的时间转换为 Unix 时间戳 - original_timestamp = beginTimestamp - - # 定义时间范围(前后 20 分钟) - time_range = 20 * 60 # 20 分钟,以秒为单位 - - # 尝试从原始时间戳开始,逐步向两边扩展 - for offset in range(0, time_range + 1): - # 尝试往前 offset 秒 - timestamp = original_timestamp - offset - logger.info(f"尝试时间戳: {timestamp}") - if logout_user(timestamp, userid): - if not is_user_logged_in(userid): - print(f"用户 {userid} 已成功登出,使用的时间戳: {timestamp}") - return - # 尝试往后 offset 秒 - timestamp = original_timestamp + offset - if logout_user(timestamp, userid): - if not is_user_logged_in(userid): - print(f"用户 {userid} 已成功登出,使用的时间戳: {timestamp}") - return - - print(f"无法在前后 20 分钟内登出用户 {userid}") +def isCorrectTimestamp(timestamp, userId): + '''暴力的检查时间戳是否正确''' + logoutResult = logOut(userId, timestamp) + if not logoutResult: + return False + isLoggedOut = not isUserLoggedIn(userId) + return isLoggedOut -# 示例使用 -userId = testUid -human_time = "2023-10-01 12:00:00" # 用户输入的人类可读时间 -forceLogout(userId, human_time) +def findCorrectTimestamp(timestamp, userId, max_attempts=1200): + # 初始化偏移量 + offset = 1 + attempts = 0 + + while attempts < max_attempts: + # 尝试当前时间戳 + if isCorrectTimestamp(timestamp, userId): + print(f"Found correct timestamp: {timestamp}") + return timestamp + + # 增加偏移量尝试 + if isCorrectTimestamp(timestamp + offset, userId): + print(f"Found correct timestamp: {timestamp + offset}") + return timestamp + offset + + # 减少偏移量尝试 + if isCorrectTimestamp(timestamp - offset, userId): + print(f"Found correct timestamp: {timestamp - offset}") + return timestamp - offset + + # 增加尝试次数和偏移量 + attempts += 2 + offset += 1 + + print("尝试多次后未找到正确时间戳") + return None + +human_time = "0204061500" +beginTimestamp = getUNIXTime(human_time) +print(f"我们将开始用这个时间戳开始尝试: {beginTimestamp}") +correctTimestamp = findCorrectTimestamp(beginTimestamp, testUid)