Skip to content

Commit

Permalink
Update NSTools to 1.2.0 for content identification
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ex4 committed Apr 28, 2024
1 parent 99670af commit 701e1a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ data
/lib
/lib64
/pyvenv.cfg
/share
/share

# pyenv
.python-version
2 changes: 1 addition & 1 deletion app/NSTools
Submodule NSTools updated 51 files
+97 −0 .github/workflows/publish-to-pypi.yml
+60 −0 .github/workflows/publish-to-test-pypi.yml
+9 −0 .gitignore
+21 −21 LICENSE.md
+5 −0 README.md
+0 −0 bat/ns-verify-folder-log.bat
+0 −0 bat/ns-verify-folder.bat
+4 −0 build/bin/ns-verify-folder
+4 −0 build/bin/ns-verify-folder-log
+4 −0 build/bin/ns-verify-folder-log.bat
+4 −0 build/bin/ns-verify-folder.bat
+12 −0 build/setup-build.bat
+9 −0 build/setup-build.sh
+48 −0 build/setup.py
+0 −37 py/Fs/__init__.py
+0 −39 py/lib/Hex.py
+0 −0 py/lib/__init__.py
+12 −4 py/ns_extract_hashes.py
+12 −5 py/ns_extract_meta.py
+11 −1 py/ns_ticket_info.py
+39 −34 py/ns_verify_folder.py
+18 −15 py/nstools/Fs/BaseFs.py
+7 −5 py/nstools/Fs/Bktr.py
+4 −2 py/nstools/Fs/Cnmt.py
+24 −19 py/nstools/Fs/File.py
+35 −20 py/nstools/Fs/Hfs0.py
+9 −6 py/nstools/Fs/Ivfc.py
+7 −3 py/nstools/Fs/Nacp.py
+21 −18 py/nstools/Fs/Nca.py
+19 −14 py/nstools/Fs/Nsp.py
+85 −56 py/nstools/Fs/Pfs0.py
+12 −8 py/nstools/Fs/Rom.py
+13 −11 py/nstools/Fs/Ticket.py
+0 −0 py/nstools/Fs/Type.py
+46 −13 py/nstools/Fs/Xci.py
+27 −0 py/nstools/Fs/__init__.py
+2 −2 py/nstools/lib/BlockDecompressorReader.py
+0 −0 py/nstools/lib/FsCert.py
+17 −28 py/nstools/lib/FsNcaMod.py
+1 −1 py/nstools/lib/FsTools.py
+1 −1 py/nstools/lib/Header.py
+0 −0 py/nstools/lib/NcaKeys.py
+0 −0 py/nstools/lib/PathTools.py
+49 −49 py/nstools/lib/Verify.py
+45 −40 py/nstools/lib/VerifyTools.py
+1 −1 py/nstools/nut/Hex.py
+11 −13 py/nstools/nut/Keys.py
+11 −0 py/nstools/nut/Print.py
+2 −2 py/nstools/nut/Titles.py
+0 −0 py/nstools/nut/aes128.py
+0 −0 py/nut/__init__.py
46 changes: 28 additions & 18 deletions app/titles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+)\]"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 701e1a4

Please sign in to comment.