Class: Rex::Zip::Archive
- Inherits:
-
Object
- Object
- Rex::Zip::Archive
- Defined in:
- lib/rex/zip/archive.rb
Overview
This represents an entire archive.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #add_file(fname, fdata = nil, xtra = nil, comment = nil) ⇒ Object
-
#initialize(compmeth = CM_DEFLATE) ⇒ Archive
constructor
A new instance of Archive.
- #inspect ⇒ Object
- #pack ⇒ Object
- #save_to(fname) ⇒ Object
- #set_comment(comment) ⇒ Object
Constructor Details
#initialize(compmeth = CM_DEFLATE) ⇒ Archive
Returns a new instance of Archive.
14 15 16 17 |
# File 'lib/rex/zip/archive.rb', line 14 def initialize(compmeth=CM_DEFLATE) @compmeth = compmeth @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
12 13 14 |
# File 'lib/rex/zip/archive.rb', line 12 def entries @entries end |
Instance Method Details
#add_file(fname, fdata = nil, xtra = nil, comment = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rex/zip/archive.rb', line 20 def add_file(fname, fdata=nil, xtra=nil, comment=nil) if (not fdata) begin st = File.stat(fname) rescue return nil end ts = st.mtime if (st.directory?) attrs = EFA_ISDIR fname += '/' else f = File.open(fname, 'rb') fdata = f.read(f.stat.size) f.close end end @entries << Entry.new(fname, fdata, @compmeth, ts, attrs, xtra, comment) end |
#inspect ⇒ Object
89 90 91 |
# File 'lib/rex/zip/archive.rb', line 89 def inspect "#<#{self.class} entries = [#{@entries.map{|e| e.name}.join(",")}]>" end |
#pack ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rex/zip/archive.rb', line 55 def pack ret = '' # save the offests offsets = [] # file 1 .. file n @entries.each { |ent| offsets << ret.length ret << ent.pack } # archive decryption header (unsupported) # archive extra data record (unsupported) # central directory cfd_offset = ret.length idx = 0 @entries.each { |ent| cfd = CentralDir.new(ent, offsets[idx]) ret << cfd.pack idx += 1 } # zip64 end of central dir record (unsupported) # zip64 end of central dir locator (unsupported) # end of central directory record cur_offset = ret.length - cfd_offset ret << CentralDirEnd.new(@entries.length, cur_offset, cfd_offset, @comment).pack ret end |
#save_to(fname) ⇒ Object
48 49 50 51 52 |
# File 'lib/rex/zip/archive.rb', line 48 def save_to(fname) f = File.open(fname, 'wb') f.write(pack) f.close end |
#set_comment(comment) ⇒ Object
43 44 45 |
# File 'lib/rex/zip/archive.rb', line 43 def set_comment(comment) @comment = comment end |