"""Reader for the .nup game container (little endian, nothing encrypted). 0x00 superblock, 0x80 bytes: "NUP\\x01", u16 0x80, u16 1, u64 toc offset, u64 toc size, sha256(toc), u64 blob offset, u64 file size, u32 package count, u32 0, 16-byte unique id, 32 zero bytes TOC: u32 "TOC\\x01", u32 packages, u64 dirs, u64 files, u64 name pool offset (from the TOC), u64 pool length, u64 0 packages, 0x40 each: u64 title id, u32 root dir, u32 exefs dir, u32 romfs dir, u32 version, u8 kind (0 base, 1 update, 2 dlc), u8 flags, u16, u32, u64 meta offset, u32 meta length, 20 bytes dirs, 0x18 each: u32 name offset, u32 name length, u32 first child, u32 child count, u64 files, 0x50 each: u32 name offset, u32 name length, u64 size, u64 data offset (absolute), u64 stored size, sha256 of the file's bytes, u8 codec (0 stored, 1 one zstd frame), padding children: u32 each, a directory below the dir count, else dir count + file index names: the pool Each thread reads through its own handle: seeks on one shared handle race. Standard library plus zstandard. """ import hashlib import struct import threading SUPER = struct.Struct('<4sHHQQ32sQQII16s32s') PACKAGE = struct.Struct('