Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
Change RSV patch to minimun value of keygeneration range istead of top value.
Add new patching system to xci.
  • Loading branch information
julesontheroad committed Dec 4, 2018
1 parent f95b0be commit cace694
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 199 deletions.
2 changes: 1 addition & 1 deletion ztools/Fs/Nsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ def patch_meta(self,filepath,text_file,outfolder):
Print.info(tabs + 'Checking meta: ')
meta_nca = Fs.Nca(filepath, 'r+b')
keygen=meta_nca.header.getCryptoType2()
RSV=sq_tools.getRSV(keygen,meta_nca.get_req_system())
RSV=sq_tools.getMinRSV(keygen,meta_nca.get_req_system())
if meta_nca.get_req_system() > RSV:
meta_nca.write_req_system(RSV)
meta_nca.flush()
Expand Down
256 changes: 60 additions & 196 deletions ztools/Fs/Xci.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,55 +298,7 @@ def copy_nca(self,ofolder,buffer,token,metapatch):
fp.close()
if metapatch == 'true':
if str(nca.header.contentType) == 'Content.META':
Print.info(tabs + '-------------------------------------')
Print.info(tabs + 'Checking meta: ')
meta_nca = Fs.Nca(filepath, 'r+b')
keygen=meta_nca.header.getCryptoType2()
RSV=sq_tools.getRSV(keygen,meta_nca.get_req_system())
if meta_nca.get_req_system() > RSV:
meta_nca.write_req_system(RSV)
meta_nca.flush()
meta_nca.close()
Print.info(tabs + 'Updating cnmt hashes: ')
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha=meta_nca.calc_pfs0_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.set_pfs0_hash(sha)
meta_nca.flush()
meta_nca.close()
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha2=meta_nca.calc_htable_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_htable_hash(sha2)
meta_nca.flush()
meta_nca.close()
########################
meta_nca = Fs.Nca(filepath, 'r+b')
sha3=meta_nca.header.calculate_hblock_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_hblock_hash(sha3)
meta_nca.flush()
meta_nca.close()
########################
with open(filepath, 'r+b') as file:
nsha=sha256(file.read()).hexdigest()
newname=nsha[:32] + '.cnmt.nca'
Print.info(tabs +'New name: ' + newname )
dir=os.path.dirname(os.path.abspath(filepath))
newpath=dir+ '/' + newname
os.rename(filepath, newpath)
Print.info(tabs + '-------------------------------------')
else:
Print.info(tabs +'-> No need to patch the meta' )
Print.info(tabs + '-------------------------------------')
self.patch_meta(filepath,outfolder)


#Copy nca files from secure skipping deltas
Expand Down Expand Up @@ -387,55 +339,7 @@ def copy_nca_nd(self,ofolder,buffer,metapatch):
fp.close()
if metapatch == 'true':
if str(nca.header.contentType) == 'Content.META':
Print.info(tabs + '-------------------------------------')
Print.info(tabs + 'Checking meta: ')
meta_nca = Fs.Nca(filepath, 'r+b')
keygen=meta_nca.header.getCryptoType2()
RSV=sq_tools.getRSV(keygen,meta_nca.get_req_system())
if meta_nca.get_req_system() > RSV:
meta_nca.write_req_system(RSV)
meta_nca.flush()
meta_nca.close()
Print.info(tabs + 'Updating cnmt hashes: ')
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha=meta_nca.calc_pfs0_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.set_pfs0_hash(sha)
meta_nca.flush()
meta_nca.close()
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha2=meta_nca.calc_htable_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_htable_hash(sha2)
meta_nca.flush()
meta_nca.close()
########################
meta_nca = Fs.Nca(filepath, 'r+b')
sha3=meta_nca.header.calculate_hblock_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_hblock_hash(sha3)
meta_nca.flush()
meta_nca.close()
########################
with open(filepath, 'r+b') as file:
nsha=sha256(file.read()).hexdigest()
newname=nsha[:32] + '.cnmt.nca'
Print.info(tabs +'New name: ' + newname )
dir=os.path.dirname(os.path.abspath(filepath))
newpath=dir+ '/' + newname
os.rename(filepath, newpath)
Print.info(tabs + '-------------------------------------')
else:
Print.info(tabs +'-> No need to patch the meta' )
Print.info(tabs + '-------------------------------------')
self.patch_meta(filepath,outfolder)



Expand Down Expand Up @@ -507,55 +411,7 @@ def cr_tr_nca(self,ofolder,buffer,metapatch):
fp.close()
if metapatch == 'true':
if str(nca.header.contentType) == 'Content.META':
Print.info(tabs + '-------------------------------------')
Print.info(tabs + 'Checking meta: ')
meta_nca = Fs.Nca(filepath, 'r+b')
keygen=meta_nca.header.getCryptoType2()
RSV=sq_tools.getRSV(keygen,meta_nca.get_req_system())
if meta_nca.get_req_system() > RSV:
meta_nca.write_req_system(RSV)
meta_nca.flush()
meta_nca.close()
Print.info(tabs + 'Updating cnmt hashes: ')
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha=meta_nca.calc_pfs0_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.set_pfs0_hash(sha)
meta_nca.flush()
meta_nca.close()
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha2=meta_nca.calc_htable_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_htable_hash(sha2)
meta_nca.flush()
meta_nca.close()
########################
meta_nca = Fs.Nca(filepath, 'r+b')
sha3=meta_nca.header.calculate_hblock_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_hblock_hash(sha3)
meta_nca.flush()
meta_nca.close()
########################
with open(filepath, 'r+b') as file:
nsha=sha256(file.read()).hexdigest()
newname=nsha[:32] + '.cnmt.nca'
Print.info(tabs +'New name: ' + newname )
dir=os.path.dirname(os.path.abspath(filepath))
newpath=dir+ '/' + newname
os.rename(filepath, newpath)
Print.info(tabs + '-------------------------------------')
else:
Print.info(tabs +'-> No need to patch the meta' )
Print.info(tabs + '-------------------------------------')
self.patch_meta(filepath,outfolder)


#COPY AND CLEAN NCA FILES FROM SECURE SKIPPING DELTAS AND PATCH NEEDED SYSTEM VERSION
Expand Down Expand Up @@ -637,56 +493,64 @@ def cr_tr_nca_nd(self,ofolder,buffer,metapatch):
fp.close()
if metapatch == 'true':
if str(nca.header.contentType) == 'Content.META':
Print.info(tabs + '-------------------------------------')
Print.info(tabs + 'Checking meta: ')
meta_nca = Fs.Nca(filepath, 'r+b')
keygen=meta_nca.header.getCryptoType2()
RSV=sq_tools.getRSV(keygen,meta_nca.get_req_system())
if meta_nca.get_req_system() > RSV:
meta_nca.write_req_system(RSV)
meta_nca.flush()
meta_nca.close()
Print.info(tabs + 'Updating cnmt hashes: ')
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha=meta_nca.calc_pfs0_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.set_pfs0_hash(sha)
meta_nca.flush()
meta_nca.close()
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha2=meta_nca.calc_htable_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_htable_hash(sha2)
meta_nca.flush()
meta_nca.close()
########################
meta_nca = Fs.Nca(filepath, 'r+b')
sha3=meta_nca.header.calculate_hblock_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_hblock_hash(sha3)
meta_nca.flush()
meta_nca.close()
########################
with open(filepath, 'r+b') as file:
nsha=sha256(file.read()).hexdigest()
newname=nsha[:32] + '.cnmt.nca'
Print.info(tabs +'New name: ' + newname )
dir=os.path.dirname(os.path.abspath(filepath))
newpath=dir+ '/' + newname
os.rename(filepath, newpath)
Print.info(tabs + '-------------------------------------')
else:
Print.info(tabs +'-> No need to patch the meta' )
Print.info(tabs + '-------------------------------------')
self.patch_meta(filepath,outfolder)

#///////////////////////////////////////////////////
#PATCH META FUNCTION
#///////////////////////////////////////////////////
def patch_meta(self,filepath,outfolder):
indent = 1
tabs = '\t' * indent
Print.info(tabs + '-------------------------------------')
Print.info(tabs + 'Checking meta: ')
meta_nca = Fs.Nca(filepath, 'r+b')
keygen=meta_nca.header.getCryptoType2()
RSV=sq_tools.getMinRSV(keygen,meta_nca.get_req_system())
if meta_nca.get_req_system() > RSV:
meta_nca.write_req_system(RSV)
meta_nca.flush()
meta_nca.close()
Print.info(tabs + 'Updating cnmt hashes: ')
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha=meta_nca.calc_pfs0_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.set_pfs0_hash(sha)
meta_nca.flush()
meta_nca.close()
############################
meta_nca = Fs.Nca(filepath, 'r+b')
sha2=meta_nca.calc_htable_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_htable_hash(sha2)
meta_nca.flush()
meta_nca.close()
########################
meta_nca = Fs.Nca(filepath, 'r+b')
sha3=meta_nca.header.calculate_hblock_hash()
meta_nca.flush()
meta_nca.close()
meta_nca = Fs.Nca(filepath, 'r+b')
meta_nca.header.set_hblock_hash(sha3)
meta_nca.flush()
meta_nca.close()
########################
with open(filepath, 'r+b') as file:
nsha=sha256(file.read()).hexdigest()
newname=nsha[:32] + '.cnmt.nca'
Print.info(tabs +'New name: ' + newname )
dir=os.path.dirname(os.path.abspath(filepath))
newpath=dir+ '/' + newname
os.rename(filepath, newpath)
Print.info(tabs + '-------------------------------------')
else:
Print.info(tabs +'-> No need to patch the meta' )
Print.info(tabs + '-------------------------------------')

#Check if titlerights
def trights_set(self):
for nspF in self.hfs0:
Expand Down
Binary file modified ztools/Fs/__pycache__/Nsp.cpython-37.pyc
Binary file not shown.
Binary file modified ztools/Fs/__pycache__/Xci.cpython-37.pyc
Binary file not shown.
Binary file modified ztools/lib/__pycache__/sq_tools.cpython-37.pyc
Binary file not shown.
29 changes: 27 additions & 2 deletions ztools/lib/sq_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
404750376: "6.2.0" -> keygeneration = 7
'''

def getRSV(keygeneration, RSV):
def getTopRSV(keygeneration, RSV):
if keygeneration == 0:
return 450
if keygeneration == 1:
Expand All @@ -41,4 +41,29 @@ def getRSV(keygeneration, RSV):
if keygeneration == 7:
return 404750376
else:
return RSV
return RSV

def getMinRSV(keygeneration, RSV):
if keygeneration == 0:
return 0
if keygeneration == 1:
return 65796
if keygeneration == 2:
return 201327002
if keygeneration == 3:
return 201392178
if keygeneration == 4:
return 268435656
if keygeneration == 5:
return 335544750
if keygeneration == 6:
return 402653494
if keygeneration == 7:
return 404750376
else:
return RSV





0 comments on commit cace694

Please sign in to comment.