Add support for spoofed zip Central Dir names at Entry level
parent
46e6f937f1
commit
80b069f161
|
@ -38,9 +38,11 @@ class Archive
|
|||
#
|
||||
# If fdata is set, the file is populated with that data
|
||||
# from the calling method. If fdata is nil, then the
|
||||
# fs is checked for the file.
|
||||
# fs is checked for the file. If central_dir_name is set
|
||||
# it will be used to spoof the name at the Central Directory
|
||||
# at packing time.
|
||||
#
|
||||
def add_file(fname, fdata=nil, xtra=nil, comment=nil)
|
||||
def add_file(fname, fdata=nil, xtra=nil, comment=nil, central_dir_name=nil)
|
||||
if (not fdata)
|
||||
begin
|
||||
st = File.stat(fname)
|
||||
|
@ -62,7 +64,7 @@ class Archive
|
|||
end
|
||||
end
|
||||
|
||||
@entries << Entry.new(fname, fdata, @compmeth, ts, attrs, xtra, comment)
|
||||
@entries << Entry.new(fname, fdata, @compmeth, ts, attrs, xtra, comment, central_dir_name)
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -116,7 +116,11 @@ class CentralDir
|
|||
end
|
||||
|
||||
def pack
|
||||
path = @entry.relative_path
|
||||
if @entry.central_dir_name.blank?
|
||||
path = @entry.relative_path
|
||||
else
|
||||
path = @entry.central_dir_path
|
||||
end
|
||||
|
||||
ret = [ SIGNATURE, ZIP_VERSION ].pack('Vv')
|
||||
ret << [ ZIP_VERSION ].pack('v')
|
||||
|
|
|
@ -8,11 +8,12 @@ module Zip
|
|||
#
|
||||
class Entry
|
||||
|
||||
attr_accessor :name, :flags, :info, :xtra, :comment, :attrs
|
||||
attr_accessor :name, :flags, :info, :xtra, :comment, :attrs, :central_dir_name
|
||||
attr_reader :data
|
||||
|
||||
def initialize(fname, data, compmeth, timestamp=nil, attrs=nil, xtra=nil, comment=nil)
|
||||
def initialize(fname, data, compmeth, timestamp=nil, attrs=nil, xtra=nil, comment=nil, central_dir_name=nil)
|
||||
@name = fname.unpack("C*").pack("C*")
|
||||
@central_dir_name = (central_dir_name ? central_dir_name.unpack("C*").pack("C*") : nil)
|
||||
@data = data.unpack("C*").pack("C*")
|
||||
@xtra = xtra
|
||||
@xtra ||= ''
|
||||
|
@ -71,10 +72,12 @@ class Entry
|
|||
|
||||
|
||||
def relative_path
|
||||
if (@name[0,1] == '/')
|
||||
return @name[1,@name.length]
|
||||
end
|
||||
@name
|
||||
get_relative_path(@name)
|
||||
end
|
||||
|
||||
def central_dir_path
|
||||
return nil if @central_dir_name.blank?
|
||||
get_relative_path(@central_dir_name)
|
||||
end
|
||||
|
||||
|
||||
|
@ -104,6 +107,15 @@ class Entry
|
|||
"#<#{self.class} name:#{name}, data:#{@data.length} bytes>"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_relative_path(path)
|
||||
if (path[0,1] == '/')
|
||||
return path[1, path.length]
|
||||
end
|
||||
path
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue