class Metasm::ZIP::CentralHeader
Attributes
comment[RW]
data[RW]
extra[RW]
fname[RW]
Public Instance Methods
decode(zip)
click to toggle source
Calls superclass method
Metasm::SerialStruct#decode
# File metasm/exe_format/zip.rb, line 108 def decode(zip) super(zip) raise "Invalid ZIP signature #{@signature.to_s(16)}" if @signature != MAGIC_CENTRALHEADER @fname = zip.encoded.read(@fname_len) if @fname_len > 0 @extra = zip.encoded.read(@extra_len) if @extra_len > 0 @comment = zip.encoded.read(@comment_len) if @comment_len > 0 end
encode(zip)
click to toggle source
Calls superclass method
Metasm::SerialStruct#encode
# File metasm/exe_format/zip.rb, line 123 def encode(zip) ed = super(zip) ed << fname << extra << comment end
encode_data(zip)
click to toggle source
encode the data, fixup related fields
# File metasm/exe_format/zip.rb, line 152 def encode_data(zip) data = file_data(zip) @compress_method = 'NONE' if data == '' @crc32 = Zlib.crc32(data) @uncompressed_sz = data.length case compress_method when 'NONE' when 'DEFLATE' data = zlib_deflate(data) when nil # autodetect compression method # compress if we win more than 10% space cdata = zlib_deflate(data) ratio = cdata.length * 100 / data.length if ratio < 90 @compress_method = 'DEFLATE' data = cdata else @compress_method = 'NONE' end end @compressed_sz = data.length data end
file_data(zip)
click to toggle source
reads the raw file data from the archive
# File metasm/exe_format/zip.rb, line 129 def file_data(zip) return @data if data zip.encoded.ptr = @localhdr_off LocalHeader.decode(zip) raw = zip.encoded.read(@compressed_sz) @data = case @compress_method when 'NONE' raw when 'DEFLATE' z = Zlib::Inflate.new(-Zlib::MAX_WBITS) z.inflate(raw) else raise "Unsupported zip compress method #@compress_method" end end
set_default_values(zip)
click to toggle source
Calls superclass method
Metasm::SerialStruct#set_default_values
# File metasm/exe_format/zip.rb, line 116 def set_default_values(zip) @fname_len = fname ? @fname.length : 0 @extra_len = extra ? @extra.length : 0 @comment_len = comment ? @comment.length : 0 super(zip) end
zlib_deflate(data, level=Zlib::DEFAULT_COMPRESSION)
click to toggle source
# File metasm/exe_format/zip.rb, line 146 def zlib_deflate(data, level=Zlib::DEFAULT_COMPRESSION) z = Zlib::Deflate.new(level, -Zlib::MAX_WBITS) z.deflate(data) + z.finish end