From 701e1a425dd36b96d97ce1e8238697d1ee4883e2 Mon Sep 17 00:00:00 2001 From: Alexandre Pulido Date: Sun, 28 Apr 2024 23:54:58 +0200 Subject: [PATCH] Update NSTools to 1.2.0 for content identification --- .gitignore | 5 ++++- app/NSTools | 2 +- app/titles.py | 46 ++++++++++++++++++++++++++++------------------ 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 1f79f48..5d402be 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,7 @@ data /lib /lib64 /pyvenv.cfg -/share \ No newline at end of file +/share + +# pyenv +.python-version \ No newline at end of file diff --git a/app/NSTools b/app/NSTools index 1955cc3..6b05a56 160000 --- a/app/NSTools +++ b/app/NSTools @@ -1 +1 @@ -Subproject commit 1955cc357dae72e70054b529c967374f3f6cbf9b +Subproject commit 6b05a56e89c5e8eab86dc3c281d1f19ba000e73d diff --git a/app/titles.py b/app/titles.py index ccee799..d7998d9 100644 --- a/app/titles.py +++ b/app/titles.py @@ -10,9 +10,11 @@ from binascii import hexlify as hx, unhexlify as uhx sys.path.append(APP_DIR + '/NSTools/py') -from Fs import Pfs0, Nca, Type, factory -from lib import FsTools -from nut import Keys +from nstools.Fs import Pfs0, Nca, Type, factory +from nstools.lib import FsTools +from nstools.nut import Keys + +Pfs0.Print.silent = True app_id_regex = r"\[([0-9A-Fa-f]{16})\]" version_regex = r"\[v(\d+)\]" @@ -132,25 +134,33 @@ def identify_file_from_filename(filename): return app_id, title_id, app_type, version def identify_file_from_cnmt(filepath): + titleId = None + version = None + titleType = None container = factory(Path(filepath).resolve()) container.open(filepath, 'rb') if filepath.lower().endswith(('.xci', '.xcz')): container = container.hfs0['secure'] - for nspf in container: - if isinstance(nspf, Nca.Nca) and nspf.header.contentType == Type.Content.META: - for section in nspf: - if isinstance(section, Pfs0.Pfs0): - Cnmt = section.getCnmt() - - titleType = FsTools.parse_cnmt_type_n(hx(Cnmt.titleType.to_bytes(length=(min(Cnmt.titleType.bit_length(), 1) + 7) // 8, byteorder = 'big'))) - if titleType == 'GAME': - titleType = APP_TYPE_BASE - - # print(f'\n:: CNMT: {Cnmt._path}\n') - # print(f'Title ID: {Cnmt.titleId.upper()}') - # print(f'Version: {Cnmt.version}') - # print(f'Title Type: {titleType}') - return Cnmt.titleId.upper(), Cnmt.version, titleType + try: + for nspf in container: + if isinstance(nspf, Nca.Nca) and nspf.header.contentType == Type.Content.META: + for section in nspf: + if isinstance(section, Pfs0.Pfs0): + Cnmt = section.getCnmt() + + titleType = FsTools.parse_cnmt_type_n(hx(Cnmt.titleType.to_bytes(length=(min(Cnmt.titleType.bit_length(), 1) + 7) // 8, byteorder = 'big'))) + titleId = Cnmt.titleId.upper() + version = Cnmt.version + # print(f'\n:: CNMT: {Cnmt._path}\n') + # print(f'Title ID: {titleId}') + # print(f'Version: {version}') + # print(f'Title Type: {titleType}') + # print(f'Title ID: {titleId} Title Type: {titleType} Version: {version} ') + + finally: + container.close() + + return titleId, version, titleType def identify_file(filepath, valid_keys=False): filedir, filename = os.path.split(filepath)