Class: Rex::Proto::SMB::SimpleClient::OpenFile
- Inherits:
-
Object
- Object
- Rex::Proto::SMB::SimpleClient::OpenFile
- Defined in:
- lib/rex/proto/smb/simpleclient/open_file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
-
#client ⇒ Object
Returns the value of attribute client.
-
#file_id ⇒ Object
Returns the value of attribute file_id.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#name ⇒ Object
Returns the value of attribute name.
-
#tree_id ⇒ Object
Returns the value of attribute tree_id.
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#close ⇒ Object
Close this open file.
- #delete ⇒ Object
-
#initialize(client, name, tree_id, file_id) ⇒ OpenFile
constructor
A new instance of OpenFile.
-
#read(length = nil, offset = 0) ⇒ Object
Read data from the file.
-
#write(data, offset = 0) ⇒ Object
Write data to the file.
Constructor Details
#initialize(client, name, tree_id, file_id) ⇒ OpenFile
Returns a new instance of OpenFile.
10 11 12 13 14 15 16 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 10 def initialize(client, name, tree_id, file_id) self.client = client self.name = name self.tree_id = tree_id self.file_id = file_id self.chunk_size = 48000 end |
Instance Attribute Details
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
8 9 10 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 8 def chunk_size @chunk_size end |
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 8 def client @client end |
#file_id ⇒ Object
Returns the value of attribute file_id.
8 9 10 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 8 def file_id @file_id end |
#mode ⇒ Object
Returns the value of attribute mode.
8 9 10 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 8 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 8 def name @name end |
#tree_id ⇒ Object
Returns the value of attribute tree_id.
8 9 10 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 8 def tree_id @tree_id end |
Instance Method Details
#<<(data) ⇒ Object
72 73 74 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 72 def << (data) self.write(data) end |
#close ⇒ Object
Close this open file
27 28 29 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 27 def close self.client.close(self.file_id, self.tree_id) end |
#delete ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 18 def delete begin self.close rescue end self.client.delete(self.name, self.tree_id) end |
#read(length = nil, offset = 0) ⇒ Object
Read data from the file
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 32 def read(length = nil, offset = 0) if (length == nil) data = '' fptr = offset ok = self.client.read(self.file_id, fptr, self.chunk_size) while (ok and ok['Payload'].v['DataLenLow'] > 0) buff = ok.to_s.slice( ok['Payload'].v['DataOffset'] + 4, ok['Payload'].v['DataLenLow'] ) data << buff if ok['Payload'].v['Remaining'] == 0 break end fptr += ok['Payload'].v['DataLenLow'] begin ok = self.client.read(self.file_id, fptr, self.chunk_size) rescue XCEPT::ErrorCode => e case e.error_code when 0x00050001 # Novell fires off an access denied error on EOF ok = nil else raise e end end end return data else ok = self.client.read(self.file_id, offset, length) data = ok.to_s.slice( ok['Payload'].v['DataOffset'] + 4, ok['Payload'].v['DataLenLow'] ) return data end end |
#write(data, offset = 0) ⇒ Object
Write data to the file
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rex/proto/smb/simpleclient/open_file.rb', line 77 def write(data, offset = 0) # Track our offset into the remote file fptr = offset # Duplicate the data so we can use slice! data = data.dup # Take our first chunk of bytes chunk = data.slice!(0, self.chunk_size) # Keep writing data until we run out while (chunk.length > 0) ok = self.client.write(self.file_id, fptr, chunk) cl = ok['Payload'].v['CountLow'] # Partial write, push the failed data back into the queue if (cl != chunk.length) data = chunk.slice(cl - 1, chunk.length - cl) + data end # Increment our painter and grab the next chunk fptr += cl chunk = data.slice!(0, self.chunk_size) end end |