SKN file format specification

Discussion in 'NDS - Emulation and Homebrew' started by Stormwave, Jul 3, 2010.

  1. Stormwave

    Stormwave GBAtemp Regular

    Apr 22, 2010
    I figured I'd share this knowledge, so any other programmers can make SKN extractors/previewers etc. It explains the file format, to the best of my knowledge, for Moonshell2 and Sakura skn files (and probably any ohers that use these aswell).

    Feel free to add this to any FAQs or anything.

    SKN format Specification
    Following is the SKN file format specification for Moonshell2 and Sakura.
    BytesÂÂÂÂ Description
    -----ÂÂÂÂ -----------
    1ÂÂÂÂÂÂÂÂ Header String Length (N)
    N+1ÂÂÂÂÂÂ Header = Header String Length + 1 null byte
    4ÂÂÂÂÂÂÂÂ File Count (FC)
    4ÂÂÂÂÂÂÂÂ Header Length
    Then follows the file list table, it is a series of small structures. One for each file represented by File Count.
    File Data
    BytesÂÂÂÂ Description
    -----ÂÂÂÂ -----------
    4ÂÂÂÂÂÂÂÂ Name Offset (exact offset is Name Offset + 0x34)
    4ÂÂÂÂÂÂÂÂ Uncompressed Size
    4ÂÂÂÂÂÂÂÂ Compressed Size
    4ÂÂÂÂÂÂÂÂ Data Offset
    Total File Data table size therefore is (16 * File Count).
    After that you can read in the names for all of the files. This will be in the immediate bytes following the File Data table, so you can simply continue reading the file. Alternatively, you can use Name Offset + 0x34 to get to the exact offset.
    All file name strings are represented as follows
    BytesÂÂÂÂ Description
    -----ÂÂÂÂ -----------
    1ÂÂÂÂÂÂÂÂ String Length (N)
    NÂÂÂÂÂÂÂÂ String Data
    1ÂÂÂÂÂÂÂÂ Null Byte (0)
    If you're opening a MoonShell2 type.5 skin, then you will need to read 3 bytes (unsure of their purpose) at this point.
    Then follows the data section, using the following layout format
    BytesÂÂÂÂ Description
    -----ÂÂÂÂ -----------
    2ÂÂÂÂÂÂÂÂ Unknown
    CS(n)*FCÂÂData (where CS is "Compressed Size" for each item, and FC is the file count)
    Each data segment is a compressed file. The compression uses the "Deflate" algorithm, which is widely used and can be performed easily using the zlib library.
    And that is all!
    - There are a few bytes at the end of the compressed data that I have no idea what they do. They do not affect decompression at all, but seem necessary to the skin. I'm not sure entirely what these bytes are for, or how to replicate them, hence the reason DS Skin Maker uses MakeSkin.exe still.
    - This spec only covers type 3 and type 5 skins. I'm not sure about any other types.
    - This works completely with Sakura and Moonshell2 (and potentially any other firmware that uses MoonShell 2 SKN files)
  2. DeltaBurnt

    DeltaBurnt I'm bored

    Feb 21, 2009
    United States
    Where intellect matters
    Thanks, maybe when I get more into C++ (or other languages) I can try writing my own decompresser for fun.
  3. env

    env GBAtemp Regular

    Aug 20, 2009
    [​IMG] Felt kinda sad about this, IDK but for some skin makers (like myself), SKN file "extractors" are one of the factors that indisposed us from making more skins, that no matter how we try to attract skin makers to try making MS2 skins, and share it, they just.. ah forget it.
    (XD look who's taking anti-pirate now lol .. [​IMG] )