added eof

git-svn-id: file:///home/svn/incoming/trunk@2373 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Matt Miller 2005-04-12 06:39:33 +00:00
parent 63213353f0
commit f43c076313
5 changed files with 62 additions and 6 deletions

View File

@ -153,7 +153,11 @@ class Channel
request.add_tlv(TLV_TYPE_LENGTH, length)
request.add_tlvs(addends)
response = self.client.send_request(request)
begin
response = self.client.send_request(request)
rescue
return nil
end
# If the channel is in synchronous mode, the response should contain
# data that was read from the remote side of the channel

View File

@ -48,6 +48,20 @@ class Pool < Rex::Post::Meterpreter::Channel
#
##
# Synonym for tell
def pos
return tell
end
# Wraps the read operation to raise end-of-file as necessary
def read(length = nil)
if (self.eof)
raise EOFError
end
return super(length)
end
# Stub for seeking to a different location on the remote half of the
# channel
def seek(offset, whence = SEEK_SET)
@ -60,10 +74,8 @@ class Pool < Rex::Post::Meterpreter::Channel
raise NotImplementedError
end
# Synonym for tell
def pos
return tell
end
protected
attr_accessor :_eof
end

View File

@ -34,6 +34,31 @@ TLV_TYPE_SEEK_POS = TLV_META_TYPE_UINT | (TLV_TEMP + 2)
super(client, cid, type, flags)
end
##
#
# I/O operations
#
##
# Checks to see if the end-of-file has been reached
def eof
request = Packet.create_request('stdapi_fs_file_eof')
request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)
begin
response = self.client.send_request(request)
rescue
return true
end
if (response.has_tlv?(TLV_TYPE_BOOL))
return response.get_tlv_value(TLV_TYPE_BOOL)
end
return false
end
# Seeks to a different location in the file
def seek(offset, whence = SEEK_SET)
sane = 0

View File

@ -42,6 +42,11 @@ class File < Rex::Post::Meterpreter::Extensions::Stdapi::IO
# IO implementators
#
##
# Returns whether or not the file has reach EOF
def eof
return self.filed.eof
end
# Returns the current position of the file pointer
def pos

View File

@ -128,7 +128,11 @@ class Tlv
elsif (self.type & TLV_META_TYPE_UINT == TLV_META_TYPE_UINT)
raw = [value].pack("N")
elsif (self.type & TLV_META_TYPE_BOOL == TLV_META_TYPE_BOOL)
raw = [value].pack("c")
if (value == true)
raw = [1].pack("c")
else
raw = [0].pack("c")
end
end
return [raw.length + 8, self.type].pack("NN") + raw
@ -150,6 +154,12 @@ class Tlv
self.value = raw.unpack("NNN")[2]
elsif (self.type & TLV_META_TYPE_BOOL == TLV_META_TYPE_BOOL)
self.value = raw.unpack("NNc")[2]
if (self.value == 1)
self.value = true
else
self.value = false
end
else
self.value = raw[8..raw.length-1]
end