Skip to content

Commit

Permalink
updated squirrel
Browse files Browse the repository at this point in the history
  • Loading branch information
julesontheroad committed Dec 5, 2018
1 parent cace694 commit 00caef5
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 9 deletions.
27 changes: 26 additions & 1 deletion ztools/Fs/Nca.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,32 @@ def write_req_system(self, verNumber):
self.seek(cmt_offset+0x28)
min_sversion=self.readInt64()
Print.info(tabs + 'New RequiredSystemVersion = ' + str(min_sversion))
return min_sversion
return min_sversion

def write_version(self, verNumber):
indent = 1
tabs = '\t' * indent
file = None
mode = 'r+b'
for f in self:
cryptoType=f.get_cryptoType()
cryptoKey=f.get_cryptoKey()
cryptoCounter=f.get_cryptoCounter()
pfs0_offset=0xC00+self.header.get_htable_offset()+self.header.get_pfs0_offset()
super(Nca, self).open(file, mode, cryptoType, cryptoKey, cryptoCounter)
self.seek(pfs0_offset+0x8)
pfs0_table_size=self.readInt32()
cmt_offset=pfs0_offset+0x28+pfs0_table_size
self.seek(cmt_offset)
titleid=self.readInt64()
tnumber = verNumber.to_bytes(0x04, byteorder='little')
titleversion = self.write(tnumber)
#Print.info('Original RequiredSystemVersion = ' + str(min_sversion))
self.seek(cmt_offset)
titleid=self.readInt64()
titleversion = self.read(0x4)
Print.info('version = ' + str(int.from_bytes(titleversion, byteorder='little')))
return titleversion

def removeTitleRightsnca(self, masterKeyRev, titleKeyDec):
Print.info('titleKeyDec =\t' + str(hx(titleKeyDec)))
Expand Down
Binary file modified ztools/Fs/__pycache__/Nca.cpython-37.pyc
Binary file not shown.
Binary file modified ztools/Fs/__pycache__/Xci.cpython-37.pyc
Binary file not shown.
129 changes: 121 additions & 8 deletions ztools/squirrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
parser.add_argument('-i', '--info', help='show info about title or file')
parser.add_argument('--NSP_filelist', nargs='+', help='Prints file list in an nsp')
parser.add_argument('--Read_cnmt', nargs='+', help='Read cnmt file inside NSP\XCI')
parser.add_argument('--update_hash', nargs='+', help='Read cnmt file inside NSP\XCI')
parser.add_argument('--update_hash', nargs='+', help='Updates cnmt.nca hashes')
parser.add_argument('--set_cnmt_version', nargs='+', help='Changes cnmt.nca version number')
parser.add_argument('--set_cnmt_RSV', nargs='+', help='Changes cnmt.nca RSV')

# REPACK
parser.add_argument('-c', '--create', help='create / pack a NSP')
Expand Down Expand Up @@ -129,7 +131,7 @@
parser.add_argument('-o', '--ofolder', nargs='+', help='Set output folder for copy instructions')
parser.add_argument('-b', '--buffer', nargs='+', help='Set buffer for copy instructions')
parser.add_argument('-ext', '--external', nargs='+', help='Set original nsp or ticket for remove nca titlerights functions')
parser.add_argument('-pv', '--patchversion', nargs='+', help='Patch Required system version')
parser.add_argument('-pv', '--patchversion', nargs='+', help='Number fot patch Required system version or program, patch or addcontent version')
parser.add_argument('-pe', '--pathend', nargs='+', help='Output to subfolder')
parser.add_argument('-cskip', nargs='+', help='Skip dlc or update')

Expand Down Expand Up @@ -1610,15 +1612,81 @@
Print.error('Exception: ' + str(e))

# ...................................................
# Update hashes in cnmt file
# Change Required System Version in a nca file
# ...................................................
if args.patchversion:
for input in args.patchversion:
try:
number = input
except BaseException as e:
Print.error('Exception: ' + str(e))
else:
number = 336592896
if args.set_cnmt_RSV:
for filename in args.set_cnmt_RSV:
if filename.endswith('.nca'):
try:
f = Fs.Nca(filename, 'r+b')
f.write_req_system(number)
f.flush()
f.close()
############################
f = Fs.Nca(filename, 'r+b')
sha=f.calc_pfs0_hash()
f.flush()
f.close()
f = Fs.Nca(filename, 'r+b')
f.set_pfs0_hash(sha)
f.flush()
f.close()
############################
f = Fs.Nca(filename, 'r+b')
sha2=f.calc_htable_hash()
f.flush()
f.close()
f = Fs.Nca(filename, 'r+b')
f.header.set_htable_hash(sha2)
f.flush()
f.close()
########################
f = Fs.Nca(filename, 'r+b')
sha3=f.header.calculate_hblock_hash()
f.flush()
f.close()
f = Fs.Nca(filename, 'r+b')
f.header.set_hblock_hash(sha3)
f.flush()
f.close()
########################
with open(filename, 'r+b') as file:
nsha=sha256(file.read()).hexdigest()
newname=nsha[:32] + '.cnmt.nca'
Print.info('New name: ' + newname )
dir=os.path.dirname(os.path.abspath(filename))
newpath=dir+ '/' + newname
os.rename(filename, newpath)
except BaseException as e:
Print.error('Exception: ' + str(e))
Status.close()

# ...................................................
# Change version number from nca
# ...................................................

if args.update_hash:
for filename in args.update_hash:
if args.patchversion:
for input in args.patchversion:
try:
number = input
except BaseException as e:
Print.error('Exception: ' + str(e))
else:
number = 65536*0
if args.set_cnmt_version:
for filename in args.set_cnmt_version:
if filename.endswith('.nca'):
try:
f = Fs.Nca(filename, 'r+b')
f.write_req_system(336592896)
f.write_version(number)
f.flush()
f.close()
############################
Expand Down Expand Up @@ -1659,6 +1727,53 @@
except BaseException as e:
Print.error('Exception: ' + str(e))
Status.close()

# ...................................................
# Update hashes in cnmt file
# ...................................................

if args.update_hash:
for filename in args.update_hash:
if filename.endswith('.nca'):
try:
f = Fs.Nca(filename, 'r+b')
sha=f.calc_pfs0_hash()
f.flush()
f.close()
f = Fs.Nca(filename, 'r+b')
f.set_pfs0_hash(sha)
f.flush()
f.close()
############################
f = Fs.Nca(filename, 'r+b')
sha2=f.calc_htable_hash()
f.flush()
f.close()
f = Fs.Nca(filename, 'r+b')
f.header.set_htable_hash(sha2)
f.flush()
f.close()
########################
f = Fs.Nca(filename, 'r+b')
sha3=f.header.calculate_hblock_hash()
f.flush()
f.close()
f = Fs.Nca(filename, 'r+b')
f.header.set_hblock_hash(sha3)
f.flush()
f.close()
########################
with open(filename, 'r+b') as file:
nsha=sha256(file.read()).hexdigest()
newname=nsha[:32] + '.cnmt.nca'
Print.info('New name: ' + newname )
dir=os.path.dirname(os.path.abspath(filename))
newpath=dir+ '/' + newname
os.rename(filename, newpath)
except BaseException as e:
Print.error('Exception: ' + str(e))
Status.close()


except KeyboardInterrupt:
Config.isRunning = False
Expand All @@ -1669,7 +1784,5 @@
raise






0 comments on commit 00caef5

Please sign in to comment.