1010from nstools .nut import Keys
1111
1212from nstools .Fs import factory
13- from nstools .Fs import Pfs0 , Nca , Type
13+ from nstools .Fs import Pfs0 , Xci , Nsp , Nca , Type
1414
1515from nstools .lib import FsTools
1616
@@ -44,6 +44,38 @@ def send_hook(message_content):
4444 except :
4545 pass
4646
47+ def get_cnmts (container ):
48+ cnmts = []
49+ if isinstance (container , Nsp .Nsp ):
50+ try :
51+ cnmt = container .cnmt ()
52+ cnmts .append (cnmt )
53+ except Exception as e :
54+ print (e )
55+
56+ elif isinstance (container , Xci .Xci ):
57+ container = container .hfs0 ['secure' ]
58+ for nspf in container :
59+ if isinstance (nspf , Nca .Nca ) and nspf .header .contentType == Type .Content .META :
60+ cnmts .append (nspf )
61+
62+ return cnmts
63+
64+ def extract_meta_from_cnmt (cnmt_sections ):
65+ for section in cnmt_sections :
66+ if isinstance (section , Pfs0 .Pfs0 ):
67+ Cnmt = section .getCnmt ()
68+ print (f'\n :: CNMT: { Cnmt ._path } \n ' )
69+ print (f'Title ID: { Cnmt .titleId .upper ()} ' )
70+ print (f'Version: { Cnmt .version } ' )
71+ print (f'Title Type: { Cnmt .titleType } ' )
72+
73+ for entry in Cnmt .contentEntries :
74+ entryType = FsTools .get_metacontent_type (hx (entry .type .to_bytes (length = (min (entry .type .bit_length (), 1 ) + 7 ) // 8 , byteorder = 'big' )))
75+ print (f'\n :{ Cnmt .titleId } - Content.{ entryType } ' )
76+ print (f'> NCA ID: { entry .ncaId } ' )
77+ print (f'> HASH: { entry .hash .hex ()} ' )
78+
4779def scan_file ():
4880 ipath = os .path .abspath (INCP_PATH )
4981 if not os .path .isfile (ipath ):
@@ -52,28 +84,11 @@ def scan_file():
5284 return
5385
5486 container = factory (Path (ipath ).resolve ())
55- container .open (ipath , 'rb' )
56- if ipath .lower ().endswith (('.xci' , '.xcz' )):
57- container = container .hfs0 ['secure' ]
87+ container .open (ipath , 'rb' , meta_only = True )
5888 try :
59- for nspf in container :
60- if isinstance (nspf , Nca .Nca ) and nspf .header .contentType == Type .Content .META :
61- for section in nspf :
62- if isinstance (section , Pfs0 .Pfs0 ):
63- Cnmt = section .getCnmt ()
64-
65- titleType = FsTools .parse_cnmt_type_n (hx (Cnmt .titleType .to_bytes (length = (min (Cnmt .titleType .bit_length (), 1 ) + 7 ) // 8 , byteorder = 'big' )))
66-
67- print (f'\n :: CNMT: { Cnmt ._path } \n ' )
68- print (f'Title ID: { Cnmt .titleId .upper ()} ' )
69- print (f'Version: { Cnmt .version } ' )
70- print (f'Title Type: { titleType } ' )
71-
72- for entry in Cnmt .contentEntries :
73- entryType = FsTools .get_metacontent_type (hx (entry .type .to_bytes (length = (min (entry .type .bit_length (), 1 ) + 7 ) // 8 , byteorder = 'big' )))
74- print (f'\n :{ Cnmt .titleId } - Content.{ entryType } ' )
75- print (f'> NCA ID: { entry .ncaId } ' )
76- print (f'> HASH: { entry .hash .hex ()} ' )
89+ for cnmt in get_cnmts (container ):
90+ extract_meta_from_cnmt (cnmt )
91+
7792 finally :
7893 container .close ()
7994
0 commit comments