Exemplo n.º 1
0
def install(filepath=None,
            destiny="SD",
            verification=True,
            outfolder=None,
            ch_medium=True,
            check_fw=True,
            patch_keygen=False):
    kgwarning = False
    dopatch = False
    keygeneration = 0
    tgkg = 0
    if filepath == "":
        filepath = None
    if filepath == None:
        print("File input = null")
        return False
    if verification == True or str(verification).upper() == "HASH":
        if str(verification).upper() == "HASH":
            verdict, isrestored, cnmt_is_patched = file_verification(filepath,
                                                                     hash=True)
        else:
            verdict, isrestored, cnmt_is_patched = file_verification(filepath)
        if verdict == False:
            print("File didn't pass verification. Skipping...")
            return False
    print("- Retrieving Space on device")
    SD_ds, SD_fs, NAND_ds, NAND_fs, FW, device = get_storage_info()
    print("- Calculating Installed size")
    dbDict = get_DB_dict(filepath)
    installedsize = dbDict['InstalledSize']
    if destiny == "SD":
        print(f"  * SD free space: {SD_fs} ({sq_tools.getSize(SD_fs)})")
        print(
            f"  * File installed size: {installedsize} ({sq_tools.getSize(installedsize)})"
        )
        if installedsize > SD_fs:
            if installedsize < NAND_fs and ch_medium == True:
                print("  Not enough space on SD. Changing target to EMMC")
                print(
                    f"  * EMMC free space: {NAND_fs} ({sq_tools.getSize(NAND_fs)})"
                )
                destiny = "NAND"
            elif ch_medium == False:
                sys.exit("   NOT ENOUGH SPACE SD STORAGE")
            else:
                sys.exit("   NOT ENOUGH SPACE ON DEVICE")
    else:
        print(f"  * EMMC free space: {NAND_fs} ({sq_tools.getSize(NAND_fs)})")
        print(
            f"  * File installed size: {installedsize} ({sq_tools.getSize(installedsize)})"
        )
        if installedsize > NAND_fs:
            if installedsize < SD_fs and ch_medium == True:
                print("  Not enough space on EMMC. Changing target to SD")
                print(
                    f"  * SD free space: {SD_fs} ({sq_tools.getSize(SD_fs)})")
                destiny = "SD"
            elif ch_medium == False:
                sys.exit("   NOT ENOUGH SPACE EMMC STORAGE")
            else:
                sys.exit("   NOT ENOUGH SPACE ON DEVICE")
    if check_fw == True:
        keygeneration = dbDict['keygeneration']
        if FW != 'unknown':
            try:
                FW_RSV, RRSV = sq_tools.transform_fw_string(FW)
                FW_kg = sq_tools.kg_by_RSV(FW_RSV)
            except BaseException as e:
                Print.error('Exception: ' + str(e))
                FW = 'unknown'
                FW_kg = 'unknown'
                pass
        if FW != 'unknown' and FW_kg != 'unknown':
            if int(keygeneration) > int(FW_kg):
                kgwarning = True
                tgkg = int(FW_kg)
            else:
                tgkg = keygeneration
        else:
            tgkg = keygeneration
        print(f"- Console Firmware: {FW} ({FW_RSV}) - keygen {FW_kg})")
        print(f"- File keygeneration: {keygeneration}")
    if kgwarning == True and patch_keygen == False:
        print("File requires a higher firmware. Skipping...")
        return False
    elif kgwarning == True and patch_keygen == True:
        print("File requires a higher firmware. It'll will be prepatch")
        dopatch = True
    if filepath.endswith('xci') or dopatch == True:
        install_converted(filepath=filepath,
                          outfolder=outfolder,
                          destiny=destiny,
                          kgpatch=dopatch,
                          tgkg=keygeneration)
        return
    process = subprocess.Popen(
        [nscb_mtp, "Install", "-ori", filepath, "-dst", destiny])
    while process.poll() == None:
        if process.poll() != None:
            process.terminate()
Exemplo n.º 2
0
def generate_xci_and_transfer(filepath=None,outfolder=None,destiny="SD",kgpatch=False,verification=False):
	if destiny=="SD":
		destiny="1: External SD Card\\"
	from mtpinstaller import get_storage_info,get_DB_dict
	tgkg=0;kgwarning=False
	if filepath=="":
		filepath=None	
	if filepath==None:
		print("File input = null")
		return False		
	if outfolder=="":
		outfolder=None			
	if outfolder==None:
		outfolder=cachefolder
		if not os.path.exists(cachefolder):
			os.makedirs(cachefolder)
	if not os.path.exists(outfolder):
		os.makedirs(outfolder)	
	for f in os.listdir(outfolder):
		fp = os.path.join(outfolder, f)
		try:
			shutil.rmtree(fp)
		except OSError:
			os.remove(fp)	
	if verification==True or str(verification).upper()=="HASH":	
		if str(verification).upper()=="HASH":
			verdict,isrestored,cnmt_is_patched=file_verification(filepath,hash=True)		
		else:
			verdict,isrestored,cnmt_is_patched=file_verification(filepath)
		if verdict==False:
			print("File didn't pass verification. Skipping...")
			return False			
	dopatch=False		
	print("- Retrieving Space on device")
	SD_ds,SD_fs,NAND_ds,NAND_fs,FW,device=get_storage_info()			
	print("- Calculating Size")	
	head_xci_size,keygeneration,sz=get_header_size(filepath)
	installedsize=head_xci_size+sz
	print(f"  * SD free space: {SD_fs} ({sq_tools.getSize(SD_fs)})")	
	print(f"  * File installed size: {installedsize} ({sq_tools.getSize(installedsize)})")
	if installedsize>SD_fs:
		sys.exit("   NOT ENOUGH SPACE SD STORAGE")		
	if kgpatch==True:	
		if FW!='unknown':	
			try:
				FW_RSV,RRSV=sq_tools.transform_fw_string(FW)
				FW_kg=sq_tools.kg_by_RSV(FW_RSV)
			except BaseException as e:
				Print.error('Exception: ' + str(e))
				FW='unknown'
				FW_kg='unknown'
				pass
		if FW!='unknown' and FW_kg!='unknown':			
			if int(keygeneration)>int(FW_kg):
				kgwarning=True
				tgkg=int(FW_kg)
			else:
				tgkg=keygeneration
		else:
			tgkg=keygeneration
		print(f"- Console Firmware: {FW} ({FW_RSV}) - keygen {FW_kg})")		
		print(f"- File keygeneration: {keygeneration}")				
	else:
		tgkg=keygeneration
	if kgwarning==True: 	
		print("File requires a higher firmware. It'll will be prepatch")
		dopatch=True	
	keypatch=int(tgkg)	
	tname=str(os.path.basename(filepath))[:-3]+'xci'
	tmpfile=os.path.join(outfolder,tname)	
	if isExe==False:
		process0=subprocess.Popen([sys.executable,squirrel,"-lib_call","mtp.mtpxci","generate_and_transfer_st1","-xarg",filepath,outfolder,str(keypatch)])	
	else:
		process0=subprocess.Popen([squirrel,"-lib_call","mtp.mtpxci","generate_and_transfer_st1","-xarg",filepath,outfolder,str(keypatch)])		
	while process0.poll()==None:
		if process0.poll()!=None:
			process0.terminate();
	if isExe==False:
		process1=subprocess.Popen([sys.executable,squirrel,"-renf",tmpfile,"-t","xci","-renm","force","-nover","xci_no_v0","-addl","false","-roma","TRUE"])
	else:	
		process1=subprocess.Popen([sys.executable,squirrel,"-renf",tmpfile,"-t","xci","-renm","force","-nover","xci_no_v0","-addl","false","-roma","TRUE"])		
	while process1.poll()==None:
		if process1.poll()!=None:
			process1.terminate();	
	files2transfer=listmanager.folder_to_list(outfolder,['xci'])
	for f in files2transfer:
		bname=str(os.path.basename(f))
		destinypath=os.path.join(destiny,bname)
		process=subprocess.Popen([nscb_mtp,"Transfer","-ori",f,"-dst",destinypath])		
		while process.poll()==None:
			if process.poll()!=None:
				process.terminate();	
	try:			
		for f in os.listdir(outfolder):
			fp = os.path.join(outfolder, f)
			try:
				shutil.rmtree(fp)
			except OSError:
				os.remove(fp)	
	except:pass			
Exemplo n.º 3
0
def generate_multixci_and_transfer(tfile=None,outfolder=None,destiny="SD",kgpatch=False,verification=False):
	if destiny==False or destiny=="pick" or destiny=="":
		destiny=pick_transfer_folder()	
	if destiny=="SD":
		destiny="1: External SD Card\\"
	from mtpinstaller import get_storage_info,get_DB_dict
	tgkg=0;kgwarning=False
	if tfile=="":
		tfile=None	
	if tfile==None:
		print("File input = null")
		return False	
	if not os.path.exists(tfile):
		sys.exit(f"Couldn't find {tfile}")			
	if outfolder=="":
		outfolder=None			
	if outfolder==None:
		outfolder=cachefolder
		if not os.path.exists(cachefolder):
			os.makedirs(cachefolder)
	if not os.path.exists(outfolder):
		os.makedirs(outfolder)	
	for f in os.listdir(outfolder):
		fp = os.path.join(outfolder, f)
		try:
			shutil.rmtree(fp)
		except OSError:
			os.remove(fp)	
	file_list=listmanager.read_lines_to_list(tfile,all=True)
	if verification==True or str(verification).upper()=="HASH":	
		verdict=False
		for fp in file_list:	
			if str(verification).upper()=="HASH":
				verdict,isrestored,cnmt_is_patched=file_verification(fp,hash=True)		
			else:
				verdict,isrestored,cnmt_is_patched=file_verification(fp)
			if verdict==False:
				print(f"{fp} didn't pass verification. Skipping {tfile}")
				return False						
	dopatch=False		
	print("- Retrieving Space on device")
	SD_ds,SD_fs,NAND_ds,NAND_fs,FW,device=get_storage_info()			
	print("- Calculating Size")	
	fullxcisize=0;maxkg=0
	for fp in file_list:	
		head_xci_size,keygeneration,sz=get_header_size(fp)
		installedsize=head_xci_size+sz
		fullxcisize+=installedsize
		if int(maxkg)<int(keygeneration):
			maxkg=keygeneration
	print(f"  * SD free space: {SD_fs} ({sq_tools.getSize(SD_fs)})")	
	print(f"  * File installed size: {installedsize} ({sq_tools.getSize(installedsize)})")
	if installedsize>SD_fs:
		sys.exit("   NOT ENOUGH SPACE SD STORAGE")		
	if kgpatch==True:	
		if FW!='unknown':	
			try:
				FW_RSV,RRSV=sq_tools.transform_fw_string(FW)
				FW_kg=sq_tools.kg_by_RSV(FW_RSV)
			except BaseException as e:
				Print.error('Exception: ' + str(e))
				FW='unknown'
				FW_kg='unknown'
				pass
		if FW!='unknown' and FW_kg!='unknown':			
			if int(keygeneration)>int(FW_kg):
				kgwarning=True
				tgkg=int(FW_kg)
			else:
				tgkg=keygeneration
		else:
			tgkg=keygeneration
		print(f"- Console Firmware: {FW} ({FW_RSV}) - keygen {FW_kg})")		
		print(f"- File keygeneration: {keygeneration}")				
	else:
		tgkg=keygeneration
	if kgwarning==True: 	
		print("File requires a higher firmware. It'll will be prepatch")
		dopatch=True	
	keypatch=int(tgkg)	
	
	if isExe==False:
		process0=subprocess.Popen([sys.executable,squirrel,"-b","65536","-pv","true","-kp",str(keypatch),"--RSVcap","268435656","-fat","exfat","-fx","files","-ND","true","-t","xci","-o",outfolder,"-tfile",tfile,"-roma","TRUE","-dmul","calculate"])
	else:
		process0=subprocess.Popen([squirrel,"-b","65536","-pv","true","-kp",str(keypatch),"--RSVcap","268435656","-fat","exfat","-fx","files","-ND","true","-t","xci","-o",outfolder,"-tfile",tfile,"-roma","TRUE","-dmul","calculate"])	
	while process0.poll()==None:
		if process0.poll()!=None:
			process0.terminate();
	files2transfer=listmanager.folder_to_list(outfolder,['xci'])
	for f in files2transfer:
		bname=str(os.path.basename(f))
		destinypath=os.path.join(destiny,bname)
		process=subprocess.Popen([nscb_mtp,"Transfer","-ori",f,"-dst",destinypath])		
		while process.poll()==None:
			if process.poll()!=None:
				process.terminate();	
	try:			
		for f in os.listdir(outfolder):
			fp = os.path.join(outfolder, f)
			try:
				shutil.rmtree(fp)
			except OSError:
				os.remove(fp)	
	except:pass		
def public_gdrive_install(filepath,destiny="SD",truecopy=True,outfolder=None,ch_medium=True,check_fw=True,patch_keygen=False,ch_base=False,ch_other=False,installed_list=False):
	check_connection()
	lib,TD,libpath=get_cache_lib()
	if lib==None:
		sys.exit(f"Google Drive Public Links are only supported via cache folder")	
	filename=addtodrive(filepath,truecopy=truecopy)
	ID,name,type,size,md5,remote=DrivePrivate.get_Data(filename,TD=TD,Print=False)	
	token=remote.access_token
	name=remote.name
	sz=remote.size
	URL='https://www.googleapis.com/drive/v3/files/'+remote.ID+'?alt=media'	
	ext=name.split('.')
	ext=ext[-1]
	if not name.endswith('nsp') and not name.endswith('nsz') and not  name.endswith('xci') and not name.endswith('xcz'):
		print(f"Extension not supported for direct instalation {ext} in {name}")
		return False
	print("- Retrieving Space on device")
	SD_ds,SD_fs,NAND_ds,NAND_fs,FW,device=get_storage_info()
	print("- Calculating Installed size")	
	filesize=int(sz)
	if destiny=="SD":
		print(f"  * SD free space: {SD_fs} ({sq_tools.getSize(SD_fs)})")	
		print(f"  * File size: {filesize} ({sq_tools.getSize(filesize)})")		
		if filesize>SD_fs:
			if filesize<NAND_fs and ch_medium==True:
				print("  Not enough space on SD. Changing target to EMMC")
				print(f"  * EMMC free space: {NAND_fs} ({sq_tools.getSize(NAND_fs)})")						
				destiny="NAND"
			elif  ch_medium==False:	
				sys.exit("   NOT ENOUGH SPACE SD STORAGE")				
			else:
				sys.exit("   NOT ENOUGH SPACE ON DEVICE")				
	else:
		print(f"  * EMMC free space: {NAND_fs} ({sq_tools.getSize(NAND_fs)})")	
		print(f"  * File size: {filesize} ({sq_tools.getSize(filesize)})")		
		if filesize>NAND_fs:		
			if filesize<SD_fs and ch_medium==True:
				print("  Not enough space on EMMC. Changing target to SD")			
				print(f"  * SD free space: {SD_fs} ({sq_tools.getSize(SD_fs)})")					
				destiny="SD"
			elif  ch_medium==False:	
				sys.exit("   NOT ENOUGH SPACE EMMC STORAGE")							
			else:
				sys.exit("   NOT ENOUGH SPACE ON DEVICE")
	kgwarning=False						
	if check_fw==True:	
		try:
			cnmtdata,files_list,remote=DriveTools.get_cnmt_data(file=remote)		
			keygeneration=int(cnmtdata['keygeneration'])
			if FW!='unknown':	
				try:
					FW_RSV,RRSV=sq_tools.transform_fw_string(FW)
					FW_kg=sq_tools.kg_by_RSV(FW_RSV)
				except BaseException as e:
					Print.error('Exception: ' + str(e))
					FW='unknown'
					FW_kg='unknown'
					pass
			if FW!='unknown' and FW_kg!='unknown':			
				if int(keygeneration)>int(FW_kg):
					kgwarning=True
					tgkg=int(FW_kg)
				else:
					tgkg=keygeneration
			else:
				tgkg=keygeneration
			print(f"- Console Firmware: {FW} ({FW_RSV}) - keygen {FW_kg})")		
			print(f"- File keygeneration: {keygeneration}")				
			if kgwarning==True:
				print("File requires a higher firmware. Skipping...")
				return False
		except:	
			print("Error getting cnmtdata from file")		
	if installed_list!=False:
		try:
			fileid,fileversion,cctag,nG,nU,nD,baseid=listmanager.parsetags(name)
			fileversion=int(fileversion)
			if fileid.endswith('000') and fileversion==0 and fileid in installed_list.keys() and ch_base==True:
				print("Base game already installed. Skipping...")
				return False	
			elif fileid.endswith('000') and fileid in installed_list.keys() and ch_other==True:
				updid=fileid[:-3]+'800'
				if fileversion>((installed_list[fileid])[2]):
					print("Asking DBI to delete previous content")
					process=subprocess.Popen([nscb_mtp,"DeleteID","-ID",fileid])	
					while process.poll()==None:
						if process.poll()!=None:
							process.terminate();					
					process=subprocess.Popen([nscb_mtp,"DeleteID","-ID",updid])		
					while process.poll()==None:
						if process.poll()!=None:
							process.terminate();					
				else:
					print("The update is a previous version than the installed on device.Skipping..")
					listmanager.striplines(tfile,counter=True)
					return False		
			elif ch_other==True	and fileid in installed_list.keys():
				if fileversion>((installed_list[fileid])[2]):
					print("Asking DBI to delete previous update")
					process=subprocess.Popen([nscb_mtp,"DeleteID","-ID",fileid])					
					while process.poll()==None:
						if process.poll()!=None:
							process.terminate();
				else:
					print("The update is a previous version than the installed on device.Skipping..")
					listmanager.striplines(tfile,counter=True)
					return False	
		except:pass			
	if name.endswith('xci') or name.endswith('xcz'):
		from mtpxci_remote import install_xci_csv
		install_xci_csv(remote=remote,destiny=destiny,cachefolder=outfolder)
	else:			
		process=subprocess.Popen([nscb_mtp,"DriveInstall","-ori",URL,"-dst",destiny,"-name",name,"-size",sz,"-tk",token])
		while process.poll()==None:
			if process.poll()!=None:
				process.terminate();