From 421c2dc09b28e3de7e7a502e1a4dcd43394a7374 Mon Sep 17 00:00:00 2001 From: beerpsi Date: Wed, 24 Jul 2024 08:07:18 +0700 Subject: [PATCH] idk --- chuni/calc_title_server_enc_key.py | 23 +++---------- geki/calc_title_server_enc_key.py | 52 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/chuni/calc_title_server_enc_key.py b/chuni/calc_title_server_enc_key.py index d0dbca1..8ce8423 100644 --- a/chuni/calc_title_server_enc_key.py +++ b/chuni/calc_title_server_enc_key.py @@ -4,11 +4,8 @@ import struct import sys import re -from Crypto.Hash import SHA1 import pefile -from Crypto.Protocol.KDF import PBKDF2 - def rva2offset(pe: pefile.PE, rva: int): for section in pe.sections: if section.contains_rva(rva): @@ -41,16 +38,10 @@ if (pmatch := KEY_PASSWORD_RE.search(exe)) and (smatch := KEY_SALT_RE.search(exe soffset = rva2offset(pe, struct.unpack(" ") - exit(1) +parser = argparse.ArgumentParser() +_ = parser.add_argument("mu3_data_path", type=Path) +_ = parser.add_argument("key_iv_digest_fixed", type=bytes.fromhex, nargs="?", default=KEY_IV_DIGEST_FIXED) -with open(sys.argv[1], "rb") as f: - key = blake2b( - f.read(), - digest_size=32, - key=KEY_IV_DIGEST_FIXED, - ).hexdigest() +args = parser.parse_args() - print(f"Key: {key}") +env = Environment() -with open(sys.argv[2], "rb") as f: - iv = blake2b( - f.read(), - digest_size=32, - key=KEY_IV_DIGEST_FIXED, - ).hexdigest() +with (cast(Path, args.mu3_data_path) / "resources.assets").open("rb") as f: + env.load_file(f) - print(f"IV: {iv}") + for object in env.objects: + if object.type.name != "TextAsset": + continue -with open(sys.argv[3], "rb") as f: - salt = blake2b( - f.read(), - digest_size=32, - key=KEY_IV_DIGEST_FIXED, - ).hexdigest() + data = cast(TextAsset, object.read()) - print(f"Endpoint salt: {salt}") + if data.name in FILE_MAP: + key = blake2b(data.m_Script, digest_size=32, key=args.key_iv_digest_fixed).hexdigest() + + print(f"{FILE_MAP[data.name]}: {key}")