Class: Rex::Zip::Entry
- Inherits:
-
Object
- Object
- Rex::Zip::Entry
- Defined in:
- lib/rex/zip/entry.rb
Overview
An Entry represents a logical file or directory to be stored in an Archive
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#data ⇒ Object
Returns the value of attribute data.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#info ⇒ Object
Returns the value of attribute info.
-
#name ⇒ Object
Returns the value of attribute name.
-
#xtra ⇒ Object
Returns the value of attribute xtra.
Instance Method Summary collapse
-
#compress ⇒ Object
Compress the #data and store it for later use.
-
#initialize(fname, data, compmeth, timestamp = nil, attrs = nil, xtra = nil, comment = nil) ⇒ Entry
constructor
A new instance of Entry.
- #inspect ⇒ Object
-
#pack ⇒ Object
Return the compressed data in a format suitable for adding to an Archive.
- #relative_path ⇒ Object
Constructor Details
#initialize(fname, data, compmeth, timestamp = nil, attrs = nil, xtra = nil, comment = nil) ⇒ Entry
Returns a new instance of Entry.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rex/zip/entry.rb', line 16 def initialize(fname, data, compmeth, =nil, attrs=nil, xtra=nil, comment=nil) @name = fname @data = data @xtra = xtra @xtra ||= '' @comment = comment @comment ||= '' @attrs = attrs @attrs ||= 0 # XXX: sanitize timestmap (assume now) ||= Time.now @flags = CompFlags.new(0, compmeth, ) if (@data) compress else @data = '' @info = CompInfo.new(0, 0, 0) end @compdata ||= '' end |
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs.
13 14 15 |
# File 'lib/rex/zip/entry.rb', line 13 def attrs @attrs end |
#comment ⇒ Object
Returns the value of attribute comment.
13 14 15 |
# File 'lib/rex/zip/entry.rb', line 13 def comment @comment end |
#data ⇒ Object
Returns the value of attribute data.
14 15 16 |
# File 'lib/rex/zip/entry.rb', line 14 def data @data end |
#flags ⇒ Object
Returns the value of attribute flags.
13 14 15 |
# File 'lib/rex/zip/entry.rb', line 13 def flags @flags end |
#info ⇒ Object
Returns the value of attribute info.
13 14 15 |
# File 'lib/rex/zip/entry.rb', line 13 def info @info end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/rex/zip/entry.rb', line 13 def name @name end |
#xtra ⇒ Object
Returns the value of attribute xtra.
13 14 15 |
# File 'lib/rex/zip/entry.rb', line 13 def xtra @xtra end |
Instance Method Details
#compress ⇒ Object
Compress the #data and store it for later use. If this entry’s compression method produces a larger blob than the original data, the method is changed to CM_STORE.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rex/zip/entry.rb', line 48 def compress @crc = Zlib.crc32(@data, 0) case @flags.compmeth when CM_STORE @compdata = @data when CM_DEFLATE z = Zlib::Deflate.new(Zlib::BEST_COMPRESSION) @compdata = z.deflate(@data, Zlib::FINISH) z.close @compdata = @compdata[2, @compdata.length-6] else raise 'Unsupported compression method: %u' % @flags.compmeth end # if compressing doesn't help, just store it if (@compdata.length > @data.length) @compdata = @data @flags.compmeth = CM_STORE end @info = CompInfo.new(@crc, @compdata.length, @data.length) end |
#inspect ⇒ Object
107 108 109 |
# File 'lib/rex/zip/entry.rb', line 107 def inspect "#<#{self.class} name:#{name}, data:#{@data.length} bytes>" end |
#pack ⇒ Object
Return the compressed data in a format suitable for adding to an Archive
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rex/zip/entry.rb', line 86 def pack ret = '' # - lfh 1 lfh = LocalFileHdr.new(self) ret << lfh.pack # - data 1 if (@compdata) ret << @compdata end if (@gpbf & GPBF_USE_DATADESC) # - data desc 1 dd = DataDesc.new(@info) ret << dd.pack end ret end |
#relative_path ⇒ Object
75 76 77 78 79 80 |
# File 'lib/rex/zip/entry.rb', line 75 def relative_path if (@name[0,1] == '/') return @name[1,@name.length] end @name end |