Skip to content

Commit

Permalink
Merge pull request #59 from julesontheroad/Beta
Browse files Browse the repository at this point in the history
Update to v0.87c
  • Loading branch information
julesontheroad authored Jul 8, 2019
2 parents 3d224e6 + 3f00102 commit 5d9b798
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 58 deletions.
13 changes: 13 additions & 0 deletions py/English CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ Luca Fraga's github: https://github.com/LucaFraga
---------------
0. Changelog
---------------
v0.87c- Bugfixes
- Adds check for correct original titlekey for xci conversions from nsx files without
a titlekey.
- Fixes bug when RSV check progress bar multiplies when checking dlc unlockers
- Fixes message "needs RSV check" for non meta files in community-made nca files
(They still won't verify in level2 since they won't have a proper signature1)
- Adds name sanitizing after romaji conversion
- Improves blankspace removal after romaji conversion
- Adds all roman numbers to the bad character list, they will be replaced by it's
multicharacter equivalent.
Example: Assasin's Creed 3 uses the Ⅲ character which corresponds to 1 character.
This is replaced for III which corresponds for 3 characters
- Fixes message "master_key_08 is present but program doesn't have the hash to verify the key"
v0.87- Sanitation of names, romaji convertion and improvements in verification
- Automated removal of bad characters on names in direct-multi function
- Added option to convert japanese and asian names to romaji in direct-multi name
Expand Down
2 changes: 1 addition & 1 deletion py/NSCB.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set "prog_dir=%~dp0"
set "bat_name=%~n0"
set "ofile_name=%bat_name%_options.cmd"
Title NSC_Builder v0.87 -- Profile: %ofile_name% -- by JulesOnTheRoad
Title NSC_Builder v0.87c -- Profile: %ofile_name% -- by JulesOnTheRoad
set "list_folder=%prog_dir%lists"
::-----------------------------------------------------
::EDIT THIS VARIABLE TO LINK OTHER OPTION FILE
Expand Down
2 changes: 1 addition & 1 deletion py/NSCB_KR.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set "prog_dir=%~dp0"
set "bat_name=%~n0"
set "ofile_name=%bat_name%_options.cmd"
Title NSC_Builder v0.86.e -- Profile: %ofile_name% -- by JulesOnTheRoad
Title NSC_Builder v0.87.c -- Profile: %ofile_name% -- by JulesOnTheRoad
set "list_folder=%prog_dir%lists"
::-----------------------------------------------------
::이 옵션을 다른 옵션 파일과 연결되도록 편집하십시오.
Expand Down
71 changes: 50 additions & 21 deletions py/ztools/Fs/Nca.py
Original file line number Diff line number Diff line change
Expand Up @@ -1700,10 +1700,15 @@ def verify(self,feed,targetkg=False,endcheck=False,progress=False,bar=False):
if kgchg == False:
message=(tabs+'* '+"Original titlerights id is : "+(str(hx(tr)).upper())[2:-1]);print(message);feed+=message+'\n'
message=(tabs+'* '+"Original titlekey is : "+(str(hx(titlekey)).upper())[2:-1]);print(message);feed+=message+'\n'
tcheck=(str(hx(titlekey)).upper())[2:-1]
if tcheck == '00000000000000000000000000000000':
message=(tabs+'* '+"WARNING: sum(titlekey)=0 -> S.C. conversion may be incorrect and come from nsx file");print(message);feed+=message+'\n'
elif kgchg == True:
message=(tabs+'* '+"KEYGENERATION WAS CHANGED FROM "+str(orkg)+" TO "+str(currkg));print(message);feed+=message+'\n'
message=(tabs+'* '+"Original titlerights id is -> "+(str(hx(tr)).upper())[2:-1]);print(message);feed+=message+'\n'
message=(tabs+'* '+"Original titlekey is -> "+(str(hx(titlekey)).upper())[2:-1]);print(message);feed+=message+'\n'
message=(tabs+'* '+"Original titlekey is -> "+(str(hx(titlekey)).upper())[2:-1]);print(message);feed+=message+'\n'
if tcheck == '00000000000000000000000000000000':
message=(tabs+'* '+"WARNING: sum(titlekey)=0 -> S.C. conversion may be incorrect and come from nsx file");print(message);feed+=message+'\n'
return True,orig_header,self._path,feed,orkg
else:
message=(indent+self._path+arrow+'was MODIFIED');print(message);feed+=message+'\n'
Expand Down Expand Up @@ -1749,26 +1754,50 @@ def verify(self,feed,targetkg=False,endcheck=False,progress=False,bar=False):
message=(tabs+'* '+"ISGAMECARD WAS CHANGED FROM 1 TO 0");print(message);feed+=message+'\n'
return True,orig_header,self._path,feed,chkkg
else:
if targetkg == False:
message=(indent+self._path+arrow+'needs RSV check');print(message);feed+=message+'\n'
message=(tabs+'* '+"CHECKING INTERNAL HASHES");print(message);feed+=message+'\n'
feed,correct=self.check_cnmt_hashes(feed)
if correct == True:
message=(tabs+'* '+"INTERNAL HASHES MATCH");print(message);feed+=message+'\n'
if correct == False:
message=(tabs+'* '+"INTERNAL HASH MISSMATCH");print(message);feed+=message+'\n'
message=(tabs+'* '+"BAD CNMT FILE!!!");print(message);feed+=message+'\n'
return 'BADCNMT',False,self._path,feed,False
else:
if endcheck == False:
pass
elif endcheck == True:
message=(indent+self._path+arrow+'was MODIFIED');print(message);feed+=message+'\n'
message=(tabs+'* '+"NOT VERIFIABLE!!!");print(message);feed+=message+'\n'
return False,False,self._path,feed,False
message=(indent+self._path+arrow+'was MODIFIED');print(message);feed+=message+'\n'
message=(tabs+'* '+"NOT VERIFIABLE!!!");print(message);feed+=message+'\n'
return False,False,self._path,feed,False
if self.header.contentType == Type.Content.META:
if targetkg == False:
if os.path.exists(self._path):
printname=str(os.path.basename(os.path.abspath(self._path)))
else:
printname=str(self._path)
if progress != False:
pass
else:
message=(indent+self._path+arrow+'needs RSV check');print(message);feed+=message+'\n'
message=(tabs+'* '+"CHECKING INTERNAL HASHES");print(message);feed+=message+'\n'
if progress == False:
feed,correct=self.check_cnmt_hashes(feed)
if correct == True:
if progress != False:
message=(tabs+'* '+"INTERNAL HASHES MATCH");bar.write(message);feed+=message+'\n'
else:
message=(tabs+'* '+"INTERNAL HASHES MATCH");print(message);feed+=message+'\n'
if correct == False:
if progress != False:
message=(tabs+'* '+"INTERNAL HASH MISSMATCH");bar.write(message);feed+=message+'\n'
message=(tabs+'* '+"BAD CNMT FILE!!!");bar.write(message);feed+=message+'\n'
else:
message=(tabs+'* '+"INTERNAL HASH MISSMATCH");print(message);feed+=message+'\n'
message=(tabs+'* '+"BAD CNMT FILE!!!");print(message);feed+=message+'\n'
return 'BADCNMT',False,self._path,feed,False
else:
if endcheck == False:
pass
elif endcheck == True:
message=(indent+self._path+arrow+'was MODIFIED');print(message);feed+=message+'\n'
message=(tabs+'* '+"NOT VERIFIABLE!!!");print(message);feed+=message+'\n'
return False,False,self._path,feed,False
else:
message=(indent+self._path+arrow+'was MODIFIED');print(message);feed+=message+'\n'
message=(tabs+'* '+"NOT VERIFIABLE!!!");print(message);feed+=message+'\n'
return False,False,self._path,feed,False
if progress != False:
message=(indent+self._path+arrow+'was MODIFIED');bar.write(message);feed+=message+'\n'
message=(tabs+'* '+"NOT VERIFIABLE!!!");bar.write(message);feed+=message+'\n'
else:
message=(indent+self._path+arrow+'was MODIFIED');print(message);feed+=message+'\n'
message=(tabs+'* '+"NOT VERIFIABLE!!!");print(message);feed+=message+'\n'
return False,False,self._path,feed,False

def verify_cnmt_withkg(self,targetkg):
targetkg=int(targetkg)
Expand Down
70 changes: 54 additions & 16 deletions py/ztools/Fs/Nsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5203,7 +5203,7 @@ def get_content(self,ofolder,vkeypatch,delta):
return contentlist


def get_content_placeholder(self):
def get_content_placeholder(self,ofolder):
contentlist=list()
ncalist=list()
completefilelist=list()
Expand All @@ -5212,10 +5212,12 @@ def get_content_placeholder(self):
if str(file.header.contentType) != 'Content.META' and str(file.header.contentType) != 'Content.CONTROL':
continue
else:
completefilelist.append(str(file._path))
completefilelist.append(str(file._path))
elif str(file._path).endswith('.xml'):
pass
else:
completefilelist.append(str(file._path))
#print (completefilelist)
print (completefilelist)
for nca in self:
if type(nca) == Nca:
if str(nca.header.contentType) == 'Content.META':
Expand Down Expand Up @@ -5287,6 +5289,30 @@ def get_content_placeholder(self):
nca_meta=str(nca._path)
if nca_meta in completefilelist:
ncalist.append([nca_meta,nca.size])
if ofolder != False:
target = Fs.Nca(nca, 'r+b')
target.rewind()
outf= os.path.join(ofolder, str(nca._path))
fp = open(outf, 'w+b')
for data in iter(lambda: target.read(int(32768)), ""):
fp.write(data)
fp.flush()
if not data:
fp.close()
break
target = Fs.Nca(outf, 'r+b')
block = target.read()
nsha=sha256(block).hexdigest()
target.rewind()
xml=target.xml_gen(ofolder,nsha)
xmlname=nca_meta[:-3]+'xml'
xmlsize=os.path.getsize(xml)
ncalist.append([xmlname,xmlsize])
target.close()
try:
os.remove(outf)
except:
pass
titlerights=titleid2+str('0'*15)+str(crypto2)
contentlist.append([str(self._path),titleid2,titlerights,keygen,ncalist,CTYPE,version])

Expand All @@ -5297,15 +5323,6 @@ def get_content_placeholder(self):
for i in contentlist:
if i[2]==test:
i[4].append([file._path,file.size])
elif file._path.endswith('.xml'):
test=file._path
#print(test)
test=test[:-4]+'.nca'
#print(test)
for i in contentlist:
for j in i[4]:
if j[0]==test:
i[4].append([file._path,file.size])
'''
for i in contentlist:
print('Filename: '+i[0])
Expand All @@ -5318,9 +5335,10 @@ def get_content_placeholder(self):
print (j)
print("")
'''
return contentlist

return contentlist

def append_content(self,outf,target,buffer,t,fat,fx,c,index):
def append_content(self,outf,target,buffer,t,fat='exfat',fx='files',c=0,index=0):
block=4294934528
indent = 1
tabs = '\t' * indent
Expand Down Expand Up @@ -6502,7 +6520,11 @@ def verify(self):
if correct == False and f.header.getRightsId() == 0:
correct = f.pr_noenc_check()
if correct == False and f.header.getRightsId() != 0:
correct = self.verify_nca_key(file)
correct = self.verify_nca_key(file)
if correct == True and f.header.getRightsId() == 0:
correct = f.pr_noenc_check()
if correct == False:
baddec=True
elif file.endswith('.tik'):
tikfile=str(file)
checktik == False
Expand All @@ -6527,6 +6549,8 @@ def verify(self):
message=(tabs+file+' -> is CORRUPT <<<-');print(message);feed+=message+'\n'
elif file.endswith('nca'):
message=(tabs+file+tabs+' -> is CORRUPT <<<-');print(message);feed+=message+'\n'
if baddec == True:
print(tabs+' * NOTE: S.C. CONVERSION WAS PERFORMED WITH BAD KEY')
elif file.endswith('tik'):
message=(tabs+file+tabs+' -> titlekey is INCORRECT <<<-');print(message);feed+=message+'\n'
for nca in self:
Expand Down Expand Up @@ -6724,7 +6748,10 @@ def verify_sig(self,feed,tmpfolder):
cnmtdidverify=True
break
break
else:break
else:break
try:
t.close()
except:pass
if hlisthash == True:
sha0=sha0.hexdigest()
hlisthash=sha0
Expand Down Expand Up @@ -6772,6 +6799,17 @@ def find_addecuatekg(self,ncameta,keygenerationlist):
size=int.from_bytes(size, byteorder='little')
ncatype = cnmt.readInt8()
unknown = cnmt.read(0x1)
for nca in self:
if type(nca) == Nca:
if str(nca.header.contentType) == 'Content.META':
if nca._path == ncameta:
crypto1=nca.header.getCryptoType()
crypto2=nca.header.getCryptoType2()
if crypto2>crypto1:
keygeneration=crypto2
if crypto2<=crypto1:
keygeneration=crypto1
return keygeneration,min_sversion
return False,False


Expand Down
27 changes: 23 additions & 4 deletions py/ztools/Fs/Xci.py
Original file line number Diff line number Diff line change
Expand Up @@ -5969,7 +5969,7 @@ def verify(self):
validfiles.append(str(file._path))

for file in listed_files:
correct=False
correct=False;baddec=False
if file in validfiles:
if file.endswith('cnmt.nca'):
for nspF in self.hfs0:
Expand Down Expand Up @@ -6008,7 +6008,11 @@ def verify(self):
if correct == False and f.header.getRightsId() == 0:
correct = f.pr_noenc_check()
if correct == False and f.header.getRightsId() != 0:
correct = self.verify_nca_key(file)
correct = self.verify_nca_key(file)
if correct == True and f.header.getRightsId() == 0:
correct = f.pr_noenc_check()
if correct == False:
baddec=True
elif file.endswith('.tik'):
tikfile=str(file)
checktik == False
Expand All @@ -6035,7 +6039,9 @@ def verify(self):
if file.endswith('cnmt.nca'):
message=(tabs+file+' -> is CORRUPT <<<-');print(message);feed+=message+'\n'
elif file.endswith('nca'):
message=(tabs+file+tabs+' -> is CORRUPT <<<-');print(message);feed+=message+'\n'
message=(tabs+file+tabs+' -> is CORRUPT <<<-');print(message);feed+=message+'\n'
if baddec == True:
print(tabs+'* NOTE: S.C. CONVERSION WAS PERFORMED WITH BAD KEY')
elif file.endswith('tik'):
message=(tabs+file+tabs+' -> titlekey is INCORRECT <<<-');print(message);feed+=message+'\n'
for nspF in self.hfs0:
Expand Down Expand Up @@ -6293,7 +6299,20 @@ def find_addecuatekg(self,ncameta,keygenerationlist):
size=int.from_bytes(size, byteorder='little')
ncatype = cnmt.readInt8()
unknown = cnmt.read(0x1)
return False,False
for nspF in self.hfs0:
if str(nspF._path)=="secure":
for nca in nspF:
if type(nca) == Nca:
if str(nca.header.contentType) == 'Content.META':
if nca._path == ncameta:
crypto1=nca.header.getCryptoType()
crypto2=nca.header.getCryptoType2()
if crypto2>crypto1:
keygeneration=crypto2
if crypto2<=crypto1:
keygeneration=crypto1
return keygeneration,min_sversion
return False,False

def verify_hash_nca(self,buffer,headerlist,didverify,feed):
verdict=True
Expand Down
2 changes: 1 addition & 1 deletion py/ztools/LEGACY.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:TOP_INIT
CD /d "%prog_dir%"
set "bat_name=%~n0"
Title NSC_Builder v0.87 -- Profile: %ofile_name% -- by JulesOnTheRoad
Title NSC_Builder v0.87.c -- Profile: %ofile_name% -- by JulesOnTheRoad

::Check if user is dragging a folder or a file
if "%~1"=="" goto manual
Expand Down
10 changes: 10 additions & 0 deletions py/ztools/lib/sq_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def kgstring(kg=list()):
kg1=[262144,196608,131072,65536];kg.append(kg1)
kg0=[450,0];kg.append(kg0)
return kg

def kg2masterkey(kg):
if kg == 1:
return 1
else:
return kg-1

def getTopRSV(keygeneration, RSV):
if keygeneration == 0:
Expand Down Expand Up @@ -402,6 +408,10 @@ def verify_nkeys(fileName):
print("master_key_07 is Missing")
else:
counter+=1
if 'master_key_08' not in checkkeys:
print("master_key_08 is Missing")
else:
counter+=1

if 'header_key' not in checkkeys:
print("header_key is Missing")
Expand Down
Loading

0 comments on commit 5d9b798

Please sign in to comment.