From 4c9b08486dd610e6320d7fc949e14af6cf121583 Mon Sep 17 00:00:00 2001 From: seiya-git Date: Wed, 1 Nov 2023 17:16:35 +0300 Subject: [PATCH] more key paths --- .gitignore | 2 ++ py/ns_verify_folder.py | 4 +++- py/nut/Keys.py | 51 +++++++++++++++++++++++++++++------------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 0a3647c5..0e1d0ed8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ __pycache__ +smartgit* *.xci *.xcz @@ -6,4 +7,5 @@ __pycache__ *.nsz *.log +prod.keys keys.txt diff --git a/py/ns_verify_folder.py b/py/ns_verify_folder.py index bce80fd3..454dad7e 100644 --- a/py/ns_verify_folder.py +++ b/py/ns_verify_folder.py @@ -29,7 +29,9 @@ WHOOK_URL = args.webhook_url SAVE_VLOG = bool(args.save_log) -def send_hook(message_content, PadPrint = False): +def send_hook(message_content: str = '', PadPrint: bool = False): + if message_content == '': + return try: print_msg = message_content if PadPrint == True: diff --git a/py/nut/Keys.py b/py/nut/Keys.py index 1746328e..735d0d5d 100644 --- a/py/nut/Keys.py +++ b/py/nut/Keys.py @@ -153,25 +153,44 @@ def load(fileName): keyAreaKeys[i][0] = generateKek(key_area_key_application_source, masterKey, aes_kek_generation_source, aes_key_generation_source) keyAreaKeys[i][1] = generateKek(key_area_key_ocean_source, masterKey, aes_kek_generation_source, aes_key_generation_source) keyAreaKeys[i][2] = generateKek(key_area_key_system_source, masterKey, aes_kek_generation_source, aes_key_generation_source) + + return True except BaseException as e: Print.error(format_exc()) Print.error(str(e)) - - - -keyScriptPath = Path(sys.argv[0]) -#While loop to get rid of things like C:\\Python37\\Scripts\\app.exe\\__main__.py -while not keyScriptPath.is_dir(): - keyScriptPath = keyScriptPath.parents[0] -keypath = keyScriptPath.joinpath('keys.txt') -dumpedKeys = Path.home().joinpath(".switch", "prod.keys") -if keypath.is_file(): - load(str(keypath)) -elif dumpedKeys.is_file(): - load(str(dumpedKeys)) -else: - errorMsg = "{0} or {1} not found!\nPlease dump your keys using https://github.com/shchmue/Lockpick_RCM/releases".format(str(keypath), str(dumpedKeys)) + + return False + + +keyPyPath = Path(sys.argv[0]) +while not keyPyPath.is_dir(): + keyPyPath = keyPyPath.parents[0] +keyRootPath = Path(os.path.abspath(os.path.join(str(keyPyPath), '..'))) + +keyfiles = [ + Path.home().joinpath(".switch", "prod.keys"), + Path.home().joinpath(".switch", "keys.txt"), + keyRootPath.joinpath("prod.keys"), + keyRootPath.joinpath("keys.txt"), + keyPyPath.joinpath("prod.keys"), + keyPyPath.joinpath("keys.txt"), +] + +loaded = False +for kf in keyfiles: + if kf.is_file(): + loaded = load(str(kf)) + if loaded == True: + print(f'[:INFO:] Keys Loaded: {str(kf)}') + break + +if loaded == False: + errorMsg = "" + for kf in keyfiles: + if errorMsg != "": + errorMsg += "or " + errorMsg += f"{str(kf)} not found\n" + errorMsg += "\nPlease dump your keys using https://github.com/shchmue/Lockpick_RCM/releases\n" Print.error(errorMsg) input("Press Enter to exit...") sys.exit(1) -