init 标题服务器组件 aimedb 组件
This commit is contained in:
1 parent
8d761e5e5a
commit
64fc2a5e2a
7 files changed
+254
No files matched your search
@@ -0,0 +1,28 @@
|
|||||||
|
import argparse
|
||||||
|
|
||||||
|
from src.title import Title
|
||||||
|
from src import aimedb, payload
|
||||||
|
|
||||||
|
def GetUserPreviewApi():
|
||||||
|
parser = argparse.ArgumentParser(description="Title GetUserPreviewApi")
|
||||||
|
|
||||||
|
parser.add_argument("--userId", type=int, required=True, help="userId")
|
||||||
|
parser.add_argument("--accessCode", type=str, required=True, help="AiME Access Code")
|
||||||
|
parser.add_argument("--serial", type=str, required=True, help="AiME Serial Mifare Only now")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
data = payload.GetUserPreview(args.userId)
|
||||||
|
|
||||||
|
aimedb.CMD4(args.accessCode, args.serial)
|
||||||
|
|
||||||
|
res = Title(
|
||||||
|
userId=args.userId,
|
||||||
|
ApiType="GetUserPreviewApi",
|
||||||
|
data = data
|
||||||
|
)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(GetUserPreviewApi())
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import argparse
|
||||||
|
|
||||||
|
from src.title import Title
|
||||||
|
from src import aimedb, payload
|
||||||
|
|
||||||
|
def UserLoginApi():
|
||||||
|
parser = argparse.ArgumentParser(description="Title UserLoginApi")
|
||||||
|
|
||||||
|
parser.add_argument("--userId", type=int, required=True, help="userId")
|
||||||
|
parser.add_argument("--accessCode", type=str, required=True, help="AiME Access Code")
|
||||||
|
parser.add_argument("--serial", type=str, required=True, help="AiME Serial Mifare Only now")
|
||||||
|
parser.add_argument("--dateTime", type=int, required=True, help="时间戳")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
aimedb.CMD4(args.accessCode, args.serial)
|
||||||
|
|
||||||
|
data = payload.UserLogin(args.userId, args.accessCode, args.dateTime)
|
||||||
|
|
||||||
|
res = Title(
|
||||||
|
userId=args.userId,
|
||||||
|
ApiType="UserLoginApi",
|
||||||
|
data = data
|
||||||
|
)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(UserLoginApi())
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
AesKey = "kO2MK]93m4bVTrB0AJBfW314EWKb22ca"
|
||||||
|
AesIV = "NNCJ]cRObKSMUI:U"
|
||||||
|
ObfuscateParam = "wB99DfTb"
|
||||||
|
|
||||||
|
MaiEncoding = "1.65"
|
||||||
|
Endpoint = "mai2exp.sic-rd1.jp:42081"
|
||||||
|
|
||||||
|
regionId = 534
|
||||||
|
regionName = "Aomen"
|
||||||
|
placeId = 7850
|
||||||
|
placeName = "YURAKUCHO"
|
||||||
|
clientId = "A63E01E0264"
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import socket
|
||||||
|
import re
|
||||||
|
from binascii import unhexlify, hexlify
|
||||||
|
from Crypto.Cipher import AES
|
||||||
|
|
||||||
|
def CMD4(accessCode, serial):
|
||||||
|
key = b'Copyright(C)SEGA'
|
||||||
|
# https://sega.bsnk.me/allnet/aimedb/common/
|
||||||
|
magic = "3ea1"
|
||||||
|
version = "2140"
|
||||||
|
command_id = "0400" # ID = 4
|
||||||
|
length = "3000" # 48
|
||||||
|
gameId = "534447410000" # SDGA
|
||||||
|
storeId = "bc310000"
|
||||||
|
keychip_ID = "413633453031453032363400" # A63E01E0264
|
||||||
|
header = magic + version + command_id + length + "0000" + gameId + storeId + keychip_ID
|
||||||
|
|
||||||
|
access_code = str(accessCode)
|
||||||
|
serial = str(serial)
|
||||||
|
company_code = "00"
|
||||||
|
firmware_version = "02"
|
||||||
|
|
||||||
|
|
||||||
|
plaintext_hex_stream = header + access_code + company_code + firmware_version + serial
|
||||||
|
|
||||||
|
plaintext = unhexlify(plaintext_hex_stream)
|
||||||
|
|
||||||
|
cipher = AES.new(key, AES.MODE_ECB)
|
||||||
|
encrypted_message = cipher.encrypt(plaintext)
|
||||||
|
|
||||||
|
encrypted_hex_stream = hexlify(encrypted_message).decode('utf-8')
|
||||||
|
|
||||||
|
server_address = ('aime.naominet.jp', 22345)
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||||
|
sock.connect(server_address)
|
||||||
|
sock.sendall(encrypted_message)
|
||||||
|
|
||||||
|
response = sock.recv(1024)
|
||||||
|
|
||||||
|
decrypted_response = cipher.decrypt(response)
|
||||||
|
|
||||||
|
decrypted_hex_stream = hexlify(decrypted_response).decode('utf-8')
|
||||||
|
|
||||||
|
match = re.search(r'[0-9a-f]{64}([0-9a-f]{6})', decrypted_hex_stream)
|
||||||
|
if match:
|
||||||
|
six_digit_code = match.group(1)
|
||||||
|
|
||||||
|
rearranged_hex = six_digit_code[4:6] + six_digit_code[2:4] + six_digit_code[0:2]
|
||||||
|
|
||||||
|
decimal_value = int(rearranged_hex, 16)
|
||||||
|
return decimal_value
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import base64
|
||||||
|
import hashlib
|
||||||
|
import random
|
||||||
|
|
||||||
|
from Crypto.Cipher import AES
|
||||||
|
from Crypto.Util.Padding import pad, unpad
|
||||||
|
|
||||||
|
from config import AesKey, AesIV, ObfuscateParam
|
||||||
|
|
||||||
|
class aes_pkcs7(object):
|
||||||
|
def __init__(self, key: str, iv: str):
|
||||||
|
self.key = key.encode('utf-8')
|
||||||
|
self.iv = iv.encode('utf-8')
|
||||||
|
self.mode = AES.MODE_CBC
|
||||||
|
|
||||||
|
def encrypt(self, content: bytes) -> bytes:
|
||||||
|
cipher = AES.new(self.key, self.mode, self.iv)
|
||||||
|
content_padded = pad(content, AES.block_size)
|
||||||
|
encrypted_bytes = cipher.encrypt(content_padded)
|
||||||
|
return encrypted_bytes
|
||||||
|
|
||||||
|
def decrypt(self, content):
|
||||||
|
cipher = AES.new(self.key, self.mode, self.iv)
|
||||||
|
decrypted_padded = cipher.decrypt(content)
|
||||||
|
decrypted = unpad(decrypted_padded, AES.block_size)
|
||||||
|
return decrypted
|
||||||
|
|
||||||
|
def pkcs7unpadding(self, text):
|
||||||
|
length = len(text)
|
||||||
|
unpadding = ord(text[length - 1])
|
||||||
|
return text[0:length - unpadding]
|
||||||
|
|
||||||
|
def pkcs7padding(self, text):
|
||||||
|
bs = 16
|
||||||
|
length = len(text)
|
||||||
|
bytes_length = len(text.encode('utf-8'))
|
||||||
|
padding_size = length if (bytes_length == length) else bytes_length
|
||||||
|
padding = bs - padding_size % bs
|
||||||
|
padding_text = chr(padding) * padding
|
||||||
|
return text + padding_text
|
||||||
|
|
||||||
|
aes = aes_pkcs7(AesKey, AesIV)
|
||||||
|
|
||||||
|
def ApiHashEncode(ApiType: str):
|
||||||
|
return hashlib.md5((ApiType+"MaimaiExp"+ObfuscateParam).encode()).hexdigest()
|
||||||
|
|
||||||
|
def CalcRandom():
|
||||||
|
max = 1037933
|
||||||
|
num2 = random.randint(1, max) * 2069
|
||||||
|
|
||||||
|
num2 += 1024 # specialnum
|
||||||
|
num3 = 0
|
||||||
|
for i in range(0, 32):
|
||||||
|
num3 <<= 1
|
||||||
|
num3 += num2 % 2
|
||||||
|
num2 >>= 1
|
||||||
|
|
||||||
|
return num3
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
from config import *
|
||||||
|
|
||||||
|
def GetUserPreview(userId):
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"userId": userId,
|
||||||
|
"segaIdAuthKey":""
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def UserLogin(userId, accessCode, dateTime):
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"userId": userId,
|
||||||
|
"accessCode": accessCode,
|
||||||
|
"regionId": regionId,
|
||||||
|
"placeId": placeId,
|
||||||
|
"clientId": clientId,
|
||||||
|
"dateTime": dateTime,
|
||||||
|
"loginDateTime": dateTime,
|
||||||
|
"isContinue": False,
|
||||||
|
"genericFlag": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def UserLogout(userId, accessCode, dateTime):
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"userId": userId,
|
||||||
|
"accessCode": accessCode,
|
||||||
|
"regionId": regionId,
|
||||||
|
"placeId": placeId,
|
||||||
|
"clientId": clientId,
|
||||||
|
"loginDateTime": dateTime,
|
||||||
|
"type": 4
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import httpx
|
||||||
|
import zlib
|
||||||
|
import json
|
||||||
|
|
||||||
|
from .cipher import ApiHashEncode, aes
|
||||||
|
|
||||||
|
from config import MaiEncoding, Endpoint
|
||||||
|
|
||||||
|
def Title(userId: int, ApiType: str, data: dict):
|
||||||
|
|
||||||
|
ApiTypeHash = ApiHashEncode(ApiType)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"User-Agent": f"{ApiTypeHash}#{userId}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Mai-Encoding": MaiEncoding,
|
||||||
|
"Accept-Encoding": "",
|
||||||
|
"Charset": "UTF-8",
|
||||||
|
"Content-Encoding": "deflate"
|
||||||
|
}
|
||||||
|
|
||||||
|
data = bytes(json.dumps(data, ensure_ascii=False), encoding="utf-8")
|
||||||
|
CompressedData = zlib.compress(data)
|
||||||
|
AESEncrptedData = aes.encrypt(CompressedData)
|
||||||
|
|
||||||
|
TitleResponse = httpx.post(
|
||||||
|
f"https://{Endpoint}/Maimai2Servlet/{ApiTypeHash}",
|
||||||
|
headers = headers,
|
||||||
|
data = AESEncrptedData,
|
||||||
|
verify = True
|
||||||
|
)
|
||||||
|
|
||||||
|
CompressedData = aes.decrypt(TitleResponse.content)
|
||||||
|
data = zlib.decompress(CompressedData).decode('utf-8')
|
||||||
|
|
||||||
|
return data
|
||||||
Reference in new issue
Block a user