Skip to content

Commit f85e797

Browse files
committed
Land rapid7#6999, Msf::Util::EXE.to_zip
2 parents 81f30ca + 129b449 commit f85e797

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/msf/util/exe.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ def self.read_replace_script_template(filename, hash_sub)
7474
template % hash_sub
7575
end
7676

77+
78+
# Generates a ZIP file.
79+
#
80+
# @param files [Array<Hash>] Items to compress. Each item is a hash that supports these options:
81+
# * :data - The content of the file.
82+
# * :fname - The file path in the ZIP file
83+
# * :comment - A comment
84+
# @example Compressing two files, one in a folder called 'test'
85+
# Msf::Util::EXE.to_zip([{data: 'AAAA', fname: "file1.txt"}, {data: 'data', fname: 'test/file2.txt'}])
86+
# @return [String]
87+
def self.to_zip(files)
88+
zip = Rex::Zip::Archive.new
89+
90+
files.each do |f|
91+
data = f[:data]
92+
fname = f[:fname]
93+
comment = f[:comment] || ''
94+
zip.add_file(fname, data, comment)
95+
end
96+
97+
zip.pack
98+
end
99+
77100
# Executable generators
78101
#
79102
# @param arch [Array<String>] The architecture of the system (i.e :x86, :x64)

0 commit comments

Comments
 (0)