#!/usr/bin/env python3 """ check_nids.py - proves that every ScePaf/CommonGuiDialog import of an application exists in real firmware modules, without running anything on hardware. check_nids.py build/FileManager.velf /vs0/sys/external/libpaf.suprx \ /vs0/sys/external/common_gui_dialog.suprx Reads the import table of the .velf and the export tables of decrypted SELF modules (such as a Vita3K firmware install). Exits non-zero when a NID is missing. """ import struct import sys import zlib CHECKED_PREFIXES = ("ScePaf", "SceCommonGuiDialog") def load_self(path): """Returns the ELF program segments of a decrypted SELF as [(vaddr, bytes)], and the module info.""" d = open(path, "rb").read() if d[:4] != b"SCE\0": raise SystemExit("%s: not a SELF" % path) elf_off, ph_off = struct.unpack_from("> 30 info_off = entry & 0x3FFFFFFF return segs, seg_index, info_off def exports_of(path): segs, si, off = load_self(path) base, blob = segs[si] # module info: attr(2) ver(2) name(27) type(1) gp(4) ent_top(4) ent_end(4) stub_top(4) stub_end(4) ent_top, ent_end = struct.unpack_from("