import os
import sys
import subprocess
if len(sys.argv) == 1:
print("no argv")
sys.exit(1)
ES_NCA = ""
FIRMWARE_DIR = sys.argv[1]
print("Checking files in " + FIRMWARE_DIR + " folder.")
for filename in os.listdir(FIRMWARE_DIR):
if filename.endswith(".nca"):
outlines = subprocess.check_output(['hactool', '--disablekeywarns', FIRMWARE_DIR + '/' + filename])
for line in outlines.splitlines():
line = line.decode('ascii').replace(" ","")
if line.startswith("TitleID:0100000000000033") and not filename.endswith(".cnmt.nca"):
print("Found! Filename : " + filename)
ES_NCA = filename
break
if ES_NCA:
print("Using hactool to extract exefsdir")
subprocess.run(["hactool","-t nca","--exefsdir=.","--disablekeywarns", FIRMWARE_DIR + '/' + filename], stdout=subprocess.DEVNULL)
if os.path.exists("main"):
outlines = subprocess.check_output(['hactool','--keyset=prod.keys','--intype=nso','--disablekeywarns','--uncompressed=main_dec','main'])
print("Using hactool to uncompress main")
for line in outlines.splitlines():
line = line.decode('ascii').replace(" ","")
if line.startswith("BuildId:"):
print("Found Build ID : " + line.replace("BuildId:","")[0:40])
break