Skip to content

Instantly share code, notes, and snippets.

@Freaky
Created July 4, 2018 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Freaky/fb0fb195e5705e37114792a5f02dd064 to your computer and use it in GitHub Desktop.
Save Freaky/fb0fb195e5705e37114792a5f02dd064 to your computer and use it in GitHub Desktop.
# unmodfile.rb: Unpack a Starshatter data file
require 'zlib'
require 'ftools'
Header = Struct.new(:magic, :file_count, :index_size, :super_secret_drm_key, :index_offset)
Entry = Struct.new(:filename, :size_unpacked, :size, :offset)
File.open(ARGV[0] || 'shatter.dat', 'rb') do |f|
hdr = Header.new(*f.read(20).unpack("i5"))
f.pos = 20 + hdr.index_offset
index = Zlib::Inflate.inflate(f.read(hdr.index_size))
(0..(index.length-76)).step(76) do |i|
p e = Entry.new(*index[i,76].unpack("Z64i3"))
f.pos = 20 + e.offset
File.makedirs(File.dirname(e.filename))
File.open(e.filename, 'wb') { |o| o.write(Zlib::Inflate.inflate(f.read(e.size))) }
end
end # 17 lines (15 SLOC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment