-
Notifications
You must be signed in to change notification settings - Fork 5
/
unpack.rb
executable file
·52 lines (38 loc) · 971 Bytes
/
unpack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
# stdlib
require 'stringio'
require 'zlib'
def inflate(data)
Zlib::Inflate.inflate(data)
end
def deflate(data)
Zlib::Deflate.deflate(data)
end
# there is not a difference for us, in these two
def inflate2(data)
zlib = Zlib::Inflate.new(15)
buff = zlib.inflate(data)
zlib.finish
zlib.close
buff
end
def load_dictionary(data)
data.split("\x00")
end
if $0 == __FILE__
abort("usage: %s <bin_file> ..." % __FILE__) unless (ARGV.length > 0)
ARGV.each do |arg|
file = File.open(arg)
z_data_io = StringIO.new(file.read())
data = inflate(z_data_io.read())
e_pos = deflate(data).bytesize()
z_data_io.seek(e_pos)
puts "data is:"
puts load_dictionary(data).map {|x| "\t#{x}" }
puts "dictionary stats:"
puts "\tcompressed size: %d" % deflate(data).bytesize()
puts "\tuncompressed size: %d" % data.bytesize()
buf = z_data_io.read()
puts "Read %d bytes\n" % buf.bytesize()
end
end