Created
July 4, 2018 15:29
-
-
Save Freaky/fb0fb195e5705e37114792a5f02dd064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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