forked from Kohaku/maimaiDX-Api
87 lines
2.7 KiB
Python
87 lines
2.7 KiB
Python
# 解小黑屋实现
|
|
# 未完工
|
|
|
|
from Config import *
|
|
from API_TitleServer import *
|
|
from GetPreview import apiGetUserPreview
|
|
from HelperLogInOut import apiLogout
|
|
import json
|
|
from loguru import logger
|
|
import time
|
|
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)
|
|
if loadedResult['returnCode'] == 1:
|
|
return True
|
|
except:
|
|
return False
|
|
|
|
def isCorrectTimestamp(timestamp, userId):
|
|
'''暴力的检查时间戳是否正确'''
|
|
logoutResult = logOut(userId, timestamp)
|
|
if not logoutResult:
|
|
return False
|
|
isLoggedOut = not isUserLoggedIn(userId)
|
|
return isLoggedOut
|
|
|
|
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)
|