#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import hashlib import warnings from struct import unpack from binascii import hexlify from glob import glob from shutil import rmtree from subprocess import run, PIPE from os import makedirs, remove from os.path import basename, exists, join from configparser import ConfigParser from sys import argv from zipfile import ZipFile, ZIP_STORED, ZipInfo from requests import request from requests.exceptions import HTTPError try: from anynet import tls except ImportError: print("Module 'anynet' not found. Install it with: pip install anynet") exit(1) warnings.filterwarnings("ignore") ENV = "lp1" VERSION = argv[1] if len(argv) > 1 else "" def readdata(f, addr, size): f.seek(addr) return f.read(size) def utf8(s): return s.decode("utf-8") def sha256(s): return hashlib.sha256(s).digest() def readint(f, addr=None): if addr is not None: f.seek(addr) return unpack(" Verified Hash: {actual_hash}") else: print(f"[ERROR] {fname}") print(f" Expected : {expected_hash}") print(f" Actual : {actual_hash}") hash_failed = True else: print(f"[MISSING] {fname}") hash_failed = True if hash_failed: print("\nCRITICAL: Hash verification failed for one or more files. Archive will not be created.") exit(1) else: print("\nINFO: All files successfully verified against CNMT records.") out_zip = f"{ver_dir}.zip" if exists(out_zip): remove(out_zip) zipdir(ver_dir, out_zip) h = hashlib.sha256() with open(out_zip, "rb") as f: for chunk in iter(lambda: f.read(1048576), b""): h.update(chunk) zip_sha256 = h.hexdigest() print("\nDOWNLOAD COMPLETE!") print(f"Archive created: {out_zip}") print(f"SystemVersion NCA FAT: {sv_nca_fat or 'Not Found'}") print(f"SystemVersion NCA exFAT: {sv_nca_exfat or 'Not Found'}") print(f"Archive SHA256: {zip_sha256}") print("Verify hashes before installation!")