Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Parsing Binary Data

Parsing Binary Data

A lighting talk about parsing binary data in ruby with bindata gem.

Avatar for Jan Krutisch

Jan Krutisch

June 29, 2012
Tweet

More Decks by Jan Krutisch

Other Decks in Programming

Transcript

  1. ‣ Instrument Metadata ‣ Sample Data ‣ Pattern Data ‣

    Sequence Data Mod File Contents Array of Structs (=Array of Hashes)
  2. ‣ Instrument Metadata ‣ Sample Data ‣ Pattern Data ‣

    Sequence Data Mod File Contents Array of Structs (=Array of Hashes) Array of Blobs
  3. ‣ Instrument Metadata ‣ Sample Data ‣ Pattern Data ‣

    Sequence Data Mod File Contents Array of Structs (=Array of Hashes) Array of Blobs Arrays of Arrays of Arrays of Structs
  4. ‣ Instrument Metadata ‣ Sample Data ‣ Pattern Data ‣

    Sequence Data Mod File Contents Array of Structs (=Array of Hashes) Array of Blobs Arrays of Arrays of Arrays of Structs Array of Integers
  5. Protracker Datatypes ‣ 8Bit signed binary blobs ‣ UInt8 ‣

    UInt16 (Endianness?) ‣ \0-Terminated/Padded Strings
  6. Protracker Datatypes ‣ 8Bit signed binary blobs ‣ UInt8 ‣

    UInt16 (Endianness?) ‣ \0-Terminated/Padded Strings ‣ Int4 (Yes, that‘s a signed halfbyte)
  7. class ProtrackerModule < BinData::Record endian :big string :name, :length =>

    20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]
  8. class ProtrackerModule < BinData::Record endian :big string :name, :length =>

    20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]
  9. class ProtrackerModule < BinData::Record endian :big string :name, :length =>

    20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]
  10. class ProtrackerModule < BinData::Record endian :big string :name, :length =>

    20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]
  11. class ProtrackerModule < BinData::Record endian :big string :name, :length =>

    20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]