# -*- coding: utf-8 -*- # Thanks to Herbert Oppmann (herby) for all your work! from .ansi import RESET, RED from .chksum import ChkSum from .rgnbin import RgnBin from struct import unpack import configparser RGN_SIG = b"KpGr" DEFAULT_BUILDER = "SQA" # RGN structure might be: RGN > BIN or RGN > RGN > BIN # RGN = outside hull # BIN = firmware + hwid + checksum REGION_TYPES = { 0x000a: "dskimg.bin", 0x000c: "boot.bin", 0x000e: "fw_all.bin", 0x0010: "logo.bin", 0x004e: "ZIP file", 0x0055: "fw_all2.bin", 0x00f5: "GCD firmware update file", 0x00ff: "pk_text.zip", } class ParseException(Exception): pass class Rgn: def __init__(self, filename: str=None): self.filename = filename self.struct = [] if filename is not None: self.load() def load(self): if self.filename is None: return False last_tlv6 = None last_tlv7 = None with open(self.filename, "rb") as f: sig = f.read(4) if sig != RGN_SIG: raise ParseException("Signature mismatch ({}, should be {})!".format(repr(sig), repr(RGN_SIG))) self.version = unpack("