Merge branch 'bug/redmine-6481-File-open' of https://github.com/jlee-r7/metasploit-framework into jlee-r7-bug/redmine-6481-File-open

unstable
sinn3r 2012-08-30 03:45:03 -05:00
commit e3e566323a
2 changed files with 27 additions and 8 deletions

View File

@ -290,6 +290,25 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::Fs::IO
end
end
#
# With no associated block, File.open is a synonym for ::new. If the optional
# code block is given, it will be passed the opened file as an argument, and
# the File object will automatically be closed when the block terminates. In
# this instance, File.open returns the value of the block.
#
# (doc stolen from http://www.ruby-doc.org/core-1.9.3/File.html#method-c-open)
#
def File.open(name, mode="r", perms=0)
f = new(name, mode, perms)
if block_given?
ret = yield f
f.close
return ret
else
return f
end
end
##
#
# Constructor

View File

@ -199,16 +199,16 @@ class Metasploit4 < Msf::Post
it "should create and remove files" do
res = true
fd = session.fs.file.new("meterpreter-test", "wb")
fd.write("test")
fd.close
res &&= session.fs.file.open("meterpreter-test", "wb") { |fd|
fd.write("test")
}
vprint_status("Wrote to meterpreter-test, checking contents")
fd = session.fs.file.new("meterpreter-test", "rb")
contents = fd.read
vprint_status("Wrote #{contents}")
res &&= (contents == "test")
fd.close
res &&= session.fs.file.open("meterpreter-test", "rb") { |fd|
contents = fd.read
vprint_status("Wrote #{contents}")
(contents == "test")
}
session.fs.file.rm("meterpreter-test")
res &&= !session.fs.dir.entries.include?("meterpreter-test")