From 2efa414b1b6b5773552a55b04c9a9ab3acb20c6d Mon Sep 17 00:00:00 2001 From: seiya-git Date: Sat, 28 Oct 2023 09:06:19 +0300 Subject: [PATCH] add ticket info tool --- py/ns_extract_hashes.py | 3 +-- py/ns_ticket_info.py | 54 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 py/ns_ticket_info.py diff --git a/py/ns_extract_hashes.py b/py/ns_extract_hashes.py index c968904a..7e2353e6 100644 --- a/py/ns_extract_hashes.py +++ b/py/ns_extract_hashes.py @@ -45,10 +45,9 @@ def scan_file(): for section in nspf: if isinstance(section, Pfs0.Pfs0): Cnmt = section.getCnmt() - print(Cnmt.__dict__) for entry in Cnmt.contentEntries: print(f'\n:{Cnmt.titleId} - Content.{Type.Content(entry.type)._name_}') - print(f'> FILENAME: {entry.ncaId}') + print(f'> NCA ID: {entry.ncaId}') print(f'> HASH: {entry.hash.hex()}') finally: container.close() diff --git a/py/ns_ticket_info.py b/py/ns_ticket_info.py new file mode 100644 index 00000000..7effe0ba --- /dev/null +++ b/py/ns_ticket_info.py @@ -0,0 +1,54 @@ +import os +import sys + +from pathlib import Path +from Fs import Ticket, factory + +# set app path +appPath = Path(sys.argv[0]) +while not appPath.is_dir(): + appPath = appPath.parents[0] +appPath = os.path.abspath(appPath) +print(f'[:INFO:] App Path: {appPath}') + +# set logs path +# logs_dir = os.path.abspath(os.path.join(appPath, '..', 'logs')) +# print(f'[:INFO:] Logs Path: {logs_dir}') + +import argparse +parser = argparse.ArgumentParser(formatter_class = argparse.ArgumentDefaultsHelpFormatter) +parser.add_argument('-i', '--input', help = 'input file') +args = parser.parse_args() + +INCP_PATH = args.input + +def send_hook(message_content): + try: + print(message_content) + except: + pass + +def scan_file(): + ipath = os.path.abspath(INCP_PATH) + if not os.path.isfile(ipath): + return + if not ipath.lower().endswith(('.nsp', '.nsz')): + return + + container = factory(Path(ipath).resolve()) + container.open(ipath, 'rb') + + try: + for nspf in container: + if isinstance(nspf, Ticket.Ticket): + nspf.printInfo() + finally: + container.close() + + +if __name__ == "__main__": + if INCP_PATH: + scan_file() + else: + parser.print_help() + print()