class Object

Public Instance Methods

add_file(zip, path) click to toggle source
# File lib/rex/zip/samples/recursive.rb, line 15
def add_file(zip, path)
  zip.add_file(path)
end
add_files(zip, path, recursive = nil) click to toggle source

If it's a directory, Walk the directory and add each item

# File lib/rex/zip/samples/recursive.rb, line 23
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) click to toggle source
# File lib/rex/zip/samples/mkwar.rb, line 17
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