pyctr.type.save.partdesc.ivfc module

exception pyctr.type.save.partdesc.ivfc.IVFCReadOnlyError[source]

Bases: PartitionDescriptorError

The DPFS level is read-only.

class pyctr.type.save.partdesc.ivfc.IVFC(master_hash_size, lv1, lv2, lv3, lv4, descriptor_size)[source]

Bases: NamedTuple

Parameters:
master_hash_size: int

Alias for field number 0

lv1: LevelData

Alias for field number 1

lv2: LevelData

Alias for field number 2

lv3: LevelData

Alias for field number 3

lv4: LevelData

Alias for field number 4

descriptor_size: int

Alias for field number 5

classmethod from_bytes(data)[source]
Parameters:

data (bytes)

to_bytes()[source]
class pyctr.type.save.partdesc.ivfc.IVFCLevel4Reader(tree, verify=True, deep_verify=True)[source]

Bases: RawIOBase

Parameters:
read(size=-1)[source]
Parameters:

size (int)

Return type:

bytes

seek(offset, whence=0)[source]

Change the stream position to the given byte offset.

offset

The stream position, relative to ‘whence’.

whence

The relative position to seek from.

The offset is interpreted relative to the position indicated by whence. Values for whence are:

  • os.SEEK_SET or 0 – start of stream (the default); offset should be zero or positive

  • os.SEEK_CUR or 1 – current stream position; offset may be negative

  • os.SEEK_END or 2 – end of stream; offset is usually negative

Return the new absolute position.

Parameters:
Return type:

int

write(data)[source]
Parameters:

data (bytes)

Return type:

int

class pyctr.type.save.partdesc.ivfc.IVFCHashTree(fp, ivfc, master_hashes, *, lv4_fp=None, update_master_hashes_callback=None)[source]

Bases: object

Implements an IVFC hash tree. This covers levels 1, 2, and 3. IVFC Level 4 contains the actual data.

Parameters:
  • fp (BinaryIO) – A file-like object with levels 1, 2, and 3. If lv4_fp is not specified, this must also contain level 4.

  • master_hashes (list[bytes]) – Master hashes from the partition descriptor, which verify IVFC Level 1.

  • lv4_fp (BinaryIO) – A file-like object with level 4. Only used if the DIFI header has enabled external IVFC Level 4.

  • update_master_hashes_callback (Callable[[list[bytes]], None]) – Function to be called when master hashes are updated. This is used by DISA and DIFF to write the master hashes to the partition descriptor.

  • ivfc (IVFC)

get_block(level, block, *, verify=True, deep_verify=True)[source]

Get the data from a block. The data is validated using the IVFC levels above the requested one.

Parameters:
  • level (int) – Level containing the data.

  • block (int) – The block to read.

  • verify (bool) – Verify the block’s hash using the level above.

  • deep_verify (bool) – Verify the hashes in all above levels, not just the upper.

Returns:

The data, and if the hash of it was valid. True if valid, False if invalid, None if uninitialized (expected hash is all zeros) or verify was false.

Return type:

tuple[bytes, bool | None]

write_data(level, offset, data)[source]

Write the data to a level. This will update hashes in the above levels.

Parameters:
  • level (int) – Level to write the data to.

  • offset (int) – The offset to write the data to.

  • data (bytes) – Data to write.

Returns: