Skip to content

PSSI tag parser will fail on version=1 song structure data #199

@devicelocksmith

Description

@devicelocksmith

Bug

The PSSI (Song Structure) tag parser in anlz/structs.py uses Const(24, Int32ub) as the first field of the tag content:

AnlzTagSongStructure = Struct(
    "len_entry_bytes" / Const(24, Int32ub),
    "len_entries" / Int16ub,
    ...
)

This interprets bytes 0-3 of the tag content as a single 32-bit constant 0x00000018. However, the actual binary layout is two separate 16-bit fields:

Offset Size Field
0-1 Int16ub version (0 or 1)
2-3 Int16ub entry_size (24 = 0x0018)
4-5 Int16ub entry_count
6-7 Int16ub mood

For version=0, bytes 0-3 are 00 00 00 18, which happens to match Const(24, Int32ub). But for version=1, bytes 0-3 would be 00 01 00 18 = 0x00010018, causing a ConstError.

Hardware devices that parse ANLZ files validate version > 1 and reject with an "unsupported version" error, confirming that both version 0 and version 1 are valid tag versions.

Suggested Fix

AnlzTagSongStructure = Struct(
    "version" / Int16ub,                    # 0 or 1
    "len_entry_bytes" / Const(24, Int16ub), # always 0x0018
    "len_entries" / Int16ub,
    ...
)

The XOR deobfuscation mask start index also depends on the version field: mask_start = version % 19.

Additional context

The XOR deobfuscation mask is derived from the ASCII string "Kanzen-niRikaishita" (19 bytes). Each byte of the base mask is seed_char + 0x80, and entry_count is added per-byte at runtime. This matches your existing static mask + entry_count formulation — just a different (equivalent) way to express the same computation. Documenting the seed string may be useful for understanding future format changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions