class documentation

Parser for flash headers

A flash file can contain up to three headers, though usually only one.

Class Raw Raw bytes container for TIFlashHeader
Class Method get_type Gets the subclass corresponding to a type ID if one is registered
Class Method open Creates a new header from a file given a filename
Class Method register Registers a subtype with this class for coercion
Static Method next_header_length Helper function to determine the length of the next flash header in a bytestream
Method __init__ Creates an empty flash header with specified meta and data values
Method __len__ No summary
Method binary_flag Whether this flash header's data is in binary (0x00) or Intel (0x01) format
Method bytes No summary
Method calc_data The data stored in the flash header
Method coerce Coerces this header to a subclass if possible using the header's type ID
Method data The data stored in the flash header as either raw binary or Intel blocks
Method date The date attached to the flash header as a 3-tuple
Method device_type The (first) device targeted by the flash header
Method devices The devices targeted by the flash header
Method extension Determines the header's file extension given a targeted model
Method filename Determines the header's filename given a targeted model
Method load_bytes Loads a byte string or bytestream into this header
Method load_from_file Loads this header from a file given a file pointer and offset
Method magic The file magic for the flash header
Method name The name or basecode attached to the flash header
Method object_type The object type of the flash header
Method product_id The product ID for the header
Method revision The revision of the flash header
Method save Saves this header to the current directory given a filename and targeted model
Method type_id The (first) type ID of the flash header
Class Variable extensions The file extension used for this header per-model
Instance Variable raw Undocumented
Property calc_data_size The length of the data stored in the flash header, measured in chars
Property checksum The checksum for the flash header
Property name_length The length of the name or basecode attached to the flash header
Method __init_subclass__ Undocumented
Class Variable _type_id Undocumented
Class Variable _type_ids Undocumented
Instance Variable _has_checksum Undocumented

Inherited from Dock:

Method load Loads data into an instance by delegating to Loader methods based on the input's type
Class Variable loaders Undocumented
@classmethod
def get_type(cls, type_id: int) -> type[TIFlashHeader] | None: (source)

Gets the subclass corresponding to a type ID if one is registered

Parameters
type_id:intThe type ID to search by
Returns
type[TIFlashHeader] | NoneA subclass of TIFlashHeader with corresponding type ID or None
@classmethod
def open(cls, filename: str) -> Self: (source)

Creates a new header from a file given a filename

Parameters
filename:strA filename to open
Returns
SelfThe (first) header stored in the file
@classmethod
def register(cls, var_type: type[TIFlashHeader], override: int = None): (source)

Registers a subtype with this class for coercion

Parameters
var_type:type[TIFlashHeader]The TIFlashHeader subtype to register
override:intA type ID to use for registry that differs from that of the var type
@staticmethod
def next_header_length(stream: BinaryIO) -> int: (source)

Helper function to determine the length of the next flash header in a bytestream

Parameters
stream:BinaryIOA bytestream
Returns
intThe length of the next header in the bytestream
def __init__(self, init=None, *, magic: str = '**TIFL**', revision: str = '0.0', binary_format: bool = False, object_type: int = 136, date: tuple[int, int, int] = (0, 0, 0), name: str = 'UNNAMED', device_type: int = 115, product_id: int = 0, data: bytes = b':00000001FF'): (source)

Creates an empty flash header with specified meta and data values

Parameters
initValues to initialize the header's data (defaults to None)
magic:strFile magic at the start of the header (defaults to **TIFL**)
revision:strThe header's revision number (defaults to 0.0)
binary_format:boolWhether the header's data is stored in binary format (defaults to False)
object_type:intThe header's object type (defaults to $88)
date:tuple[int, int, int]The header's stored date as a tuple (dd, mm, yyyy) (defaults to null)
name:strThe name of the headers (defaults to UNNAMED)
device_type:intThe device type of the header (defaults to $73, the 83+ series)
product_id:intThe targeted model's product ID (defaults to $00)
data:bytesThe header's data (defaults to empty)
def __len__(self) -> int: (source)
Returns
intThe total length of this header's bytes
@Section(1, Bits[:])
def binary_flag(self) -> int: (source)

Whether this flash header's data is in binary (0x00) or Intel (0x01) format

def bytes(self) -> bytes: (source)
Returns
bytesThe bytes contained in this header
@Section()
def calc_data(self) -> bytes: (source)

The data stored in the flash header

def coerce(self): (source)

Coerces this header to a subclass if possible using the header's type ID

Valid types must be registered to be considered for coercion.

The data stored in the flash header as either raw binary or Intel blocks

If binary_flag == $01, the data is returned as list[TIFlashBlock]. Otherwise, the data is returned as bytes.

@Section(4, BCDDate)
def date(self) -> tuple[int, int, int]: (source)

The date attached to the flash header as a 3-tuple

@View(devices, DeviceType)[0:1]
def device_type(self) -> int: (source)

The (first) device targeted by the flash header

The devices targeted by the flash header

Each device is a (device_type, type_id) tuple. The type_id should be constant throughout. Only licenses may be expected to have more than one device.

def extension(self, model: TIModel = TI_84PCE) -> str: (source)

Determines the header's file extension given a targeted model

Parameters
model:TIModelA model to target (defaults to TI_84PCE)
Returns
strThe header's file extension for that model
def filename(self, model: TIModel = TI_84PCE) -> str: (source)

Determines the header's filename given a targeted model

The filename is the concatenation of the header name and extension (see TIFlashHeader.extension).

Parameters
model:TIModelA model to target (defaults to TI_84PCE)
Returns
strThe header's filename
@Loader[bytes, bytearray, BytesIO]
def load_bytes(self, data: bytes | BytesIO): (source)

Loads a byte string or bytestream into this header

Parameters
data:bytes | BytesIOThe bytes to load
@Loader[BinaryIO]
def load_from_file(self, file: BinaryIO, *, offset: int = 0): (source)

Loads this header from a file given a file pointer and offset

Parameters
file:BinaryIOA binary file to read from
offset:intThe offset of the header to read
@Section(8, String)
def magic(self) -> str: (source)

The file magic for the flash header

@Section(31, String)
def name(self) -> str: (source)

The name or basecode attached to the flash header

@Section(1, Bits[:])
def object_type(self) -> int: (source)

The object type of the flash header

@Section(1, Bits[:])
def product_id(self) -> int: (source)

The product ID for the header

While used to identify the model the var was created on, it has no actual functional ramifications. Furthermore, it does not constitute a 1-to-1 mapping to distinct models.

@Section(2, BCDRevision)
def revision(self) -> int: (source)

The revision of the flash header

def save(self, filename: str = None, model: TIModel = TI_84PCE): (source)

Saves this header to the current directory given a filename and targeted model

Parameters
filename:strA filename to save to (defaults to the header's name and extension)
model:TIModelA model to target (defaults to TI_84PCE)
@View(devices, Bits[:])[1:2]
def type_id(self) -> int: (source)

The (first) type ID of the flash header

Undocumented

@property
calc_data_size: int = (source)

The length of the data stored in the flash header, measured in chars

The checksum for the flash header

This is equal to the lower 2 bytes of the sum of all bytes in the header.

@property
name_length: int = (source)

The length of the name or basecode attached to the flash header

def __init_subclass__(cls, /, register=False, override=None, **kwargs): (source)

Undocumented

_type_ids: dict = (source)

Undocumented

_has_checksum: bool = (source)

Undocumented