Top Level Namespace
Defined Under Namespace
Modules: Rex
Instance Method Summary collapse
- #add_file(zip, path) ⇒ Object
-
#add_files(zip, path, recursive = nil) ⇒ Object
If it’s a directory, Walk the directory and add each item.
- #rand_text_alpha(len) ⇒ Object
Instance Method Details
#add_file(zip, path) ⇒ Object
16 17 18 |
# File 'lib/rex/zip/samples/recursive.rb', line 16 def add_file(zip, path) zip.add_file(path) end |
#add_files(zip, path, recursive = nil) ⇒ Object
If it’s a directory, Walk the directory and add each item
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 52 53 |
# File 'lib/rex/zip/samples/recursive.rb', line 24 def add_files(zip, path, recursive = nil) if (not add_file(zip, path)) return nil end if (recursive and File.stat(path).directory?) begin dir = Dir.open(path) rescue # skip this file return nil end dir.each { |f| next if (f == '.') next if (f == '..') full_path = path + '/' + f st = File.stat(full_path) if (st.directory?) puts "adding dir #{full_path}" add_files(zip, full_path, recursive) elsif (st.file?) puts "adding file #{full_path}" add_file(zip, full_path) end } end end |
#rand_text_alpha(len) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rex/zip/samples/mkwar.rb', line 18 def rand_text_alpha(len) buff = "" foo = [] foo += ('A' .. 'Z').to_a foo += ('a' .. 'z').to_a # Generate a buffer from the remaining bytes if foo.length >= 256 len.times { buff << Kernel.rand(256) } else len.times { buff << foo[ rand(foo.length) ] } end return buff end |