You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
739 B
Ruby

#! /usr/bin/env ruby
require 'bindata'
class GarbageString < BinData::Primitive
mandatory_parameter :length
string :data, length: :length
def get; data.gsub(/\0.*/, ''); end
def set v; self.data = v; end
end
class Header < BinData::Record
endian :little
garbage_string :hdr, length: 17
array :files, read_until: :eof do
garbage_string :name, length: 16
uint32 :offs
end
end
fail "Usage: #{$0} HED DAT out_dir" unless ARGV.size == 3
h = File.open(ARGV[0], 'r') { |f| Header.read f }
fail unless h.files[0].offs == 0
fail unless h.files[-1].name == 'end'
File.open ARGV[1], 'r' do |data|
h.files.each_cons 2 do |t,n|
out = File.join ARGV[2], t.name
File.write out, data.read(n.offs-t.offs)
end
end