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

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

#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