Method: Rex::Proto::SMB::SimpleClient::OpenFile#write

Defined in:
lib/rex/proto/smb/simpleclient/open_file.rb

#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