Class: Rex::Post::IO

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/post/io.rb

Overview

Base IO class that is modeled after the ruby IO class.

This is an abstract base class that defines the interface for post-exploitation I/O operations. Subclasses must implement the actual I/O functionality.

Direct Known Subclasses

Meterpreter::Extensions::Stdapi::Fs::IO

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filed ⇒ Object (protected)

Returns the value of attribute filed.



14
15
16
# File 'lib/rex/post/io.rb', line 14

def filed
  @filed
end

#mode ⇒ Object (protected)

Returns the value of attribute mode.



14
15
16
# File 'lib/rex/post/io.rb', line 14

def mode
  @mode
end

Instance Method Details

#binmode ⇒ IO

Sets the stream to binary mode.

Returns:

  • (IO) —

    self

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



53
54
55
# File 'lib/rex/post/io.rb', line 53

def binmode
  raise NotImplementedError
end

#close ⇒ nil

Closes the I/O stream.

Returns:

  • (nil)

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



62
63
64
# File 'lib/rex/post/io.rb', line 62

def close
  raise NotImplementedError
end

#close_read ⇒ nil

Closes the read end of a duplex I/O stream.

Returns:

  • (nil)

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



71
72
73
# File 'lib/rex/post/io.rb', line 71

def close_read
  raise NotImplementedError
end

#close_write ⇒ nil

Closes the write end of a duplex I/O stream.

Returns:

  • (nil)

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



80
81
82
# File 'lib/rex/post/io.rb', line 80

def close_write
  raise NotImplementedError
end

#closed? ⇒ Boolean

Checks if the I/O stream is closed.

Returns:

  • (Boolean) —

    true if stream is closed

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



33
34
35
# File 'lib/rex/post/io.rb', line 33

def closed?
  raise NotImplementedError
end

#each(sep = $/) {|String| ... } ⇒ void

This method returns an undefined value.

Iterates over each line in the stream.

Parameters:

  • sep (String) (defaults to: $/) —

    line separator (default: $/)

Yields:

  • (String) —

    each line from the stream

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



92
93
94
# File 'lib/rex/post/io.rb', line 92

def each(sep = $/, &block)
  raise NotImplementedError
end

#each_byte {|Integer| ... } ⇒ void

This method returns an undefined value.

Iterates over each byte in the stream.

Yields:

  • (Integer) —

    each byte from the stream

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



115
116
117
# File 'lib/rex/post/io.rb', line 115

def each_byte(&block)
  raise NotImplementedError
end

#each_line(sep = $/) {|String| ... } ⇒ void

This method returns an undefined value.

Alias for #each.

Parameters:

  • sep (String) (defaults to: $/) —

    line separator (default: $/)

Yields:

  • (String) —

    each line from the stream

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



104
105
106
# File 'lib/rex/post/io.rb', line 104

def each_line(sep = $/, &block)
  raise NotImplementedError
end

#eof ⇒ Boolean

Checks if end of file has been reached.

Returns:

  • (Boolean) —

    true if at end of file

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



124
125
126
# File 'lib/rex/post/io.rb', line 124

def eof
  raise NotImplementedError
end

#eof? ⇒ Boolean

Checks if the end of file has been reached.

Returns:

  • (Boolean) —

    true if at end of file



24
25
26
# File 'lib/rex/post/io.rb', line 24

def eof?
  return eof
end

#fcntl(cmd, arg) ⇒ Integer

Performs low-level file control operation.

Parameters:

  • cmd (Integer) —

    control command

  • arg (Integer, String) —

    command argument

Returns:

  • (Integer) —

    result of operation

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



136
137
138
# File 'lib/rex/post/io.rb', line 136

def fcntl(cmd, arg)
  raise NotImplementedError
end

#flush ⇒ IO

Flushes buffered data to the underlying I/O stream.

Returns:

  • (IO) —

    self

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



145
146
147
# File 'lib/rex/post/io.rb', line 145

def flush
  raise NotImplementedError
end

#fsync ⇒ 0

Synchronizes all buffered data with the storage device.

Returns:

  • (0) —

    zero on success

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



154
155
156
# File 'lib/rex/post/io.rb', line 154

def fsync
  raise NotImplementedError
end

#getc ⇒ Integer?

Reads a single character from the stream.

Returns:

  • (Integer, nil) —

    character code or nil at EOF

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



163
164
165
# File 'lib/rex/post/io.rb', line 163

def getc
  raise NotImplementedError
end

#gets(sep = $/) ⇒ String?

Reads the next line from the stream.

Parameters:

  • sep (String) (defaults to: $/) —

    line separator (default: $/)

Returns:

  • (String, nil) —

    next line or nil at EOF

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



174
175
176
# File 'lib/rex/post/io.rb', line 174

def gets(sep = $/)
  raise NotImplementedError
end

#ioctl(cmd, arg) ⇒ Integer

Performs low-level I/O control operation.

Parameters:

  • cmd (Integer) —

    control command

  • arg (Integer, String) —

    command argument

Returns:

  • (Integer) —

    result of operation

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



186
187
188
# File 'lib/rex/post/io.rb', line 186

def ioctl(cmd, arg)
  raise NotImplementedError
end

#isatty ⇒ Boolean

Checks if the stream is associated with a terminal device.

Returns:

  • (Boolean) —

    true if stream is a TTY

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



195
196
197
# File 'lib/rex/post/io.rb', line 195

def isatty
  raise NotImplementedError
end

#lineno ⇒ Integer

Gets the current line number.

Returns:

  • (Integer) —

    current line number

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



204
205
206
# File 'lib/rex/post/io.rb', line 204

def lineno
  raise NotImplementedError
end

#pos ⇒ Integer

Gets the current file position.

Returns:

  • (Integer) —

    current byte offset

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



213
214
215
# File 'lib/rex/post/io.rb', line 213

def pos
  raise NotImplementedError
end

Writes a string to the stream.

Returns:

  • (Integer) —

    number of bytes written

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



222
223
224
# File 'lib/rex/post/io.rb', line 222

def print
  raise NotImplementedError
end

#printf(fmt, *args) ⇒ nil

Writes a formatted string to the stream.

Parameters:

  • fmt (String) —

    format string

  • args (Array) —

    values to format

Returns:

  • (nil)

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



234
235
236
# File 'lib/rex/post/io.rb', line 234

def printf(fmt, *args)
  raise NotImplementedError
end

#putc(obj) ⇒ Integer

Writes a character to the stream.

Parameters:

  • obj (Integer) —

    character code to write

Returns:

  • (Integer) —

    the character code written

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



245
246
247
# File 'lib/rex/post/io.rb', line 245

def putc(obj)
  raise NotImplementedError
end

#puts(obj) ⇒ nil

Writes a string followed by newline to the stream.

Parameters:

  • obj (String) —

    data to write

Returns:

  • (nil)

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



256
257
258
# File 'lib/rex/post/io.rb', line 256

def puts(obj)
  raise NotImplementedError
end

#read(length = nil, buffer = nil) ⇒ String?

Reads data from the stream.

Parameters:

  • length (Integer, nil) (defaults to: nil) —

    number of bytes to read (nil = read all)

  • buffer (String, nil) (defaults to: nil) —

    buffer to read into

Returns:

  • (String, nil) —

    data read or nil at EOF

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



268
269
270
# File 'lib/rex/post/io.rb', line 268

def read(length = nil, buffer = nil)
  raise NotImplementedError
end

#readchar ⇒ String?

Reads a single character as a string.

Returns:

  • (String, nil) —

    character or nil at EOF

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



277
278
279
# File 'lib/rex/post/io.rb', line 277

def readchar
  raise NotImplementedError
end

#readline(sep = $/) ⇒ String

Reads the next line from the stream.

Parameters:

  • sep (String) (defaults to: $/) —

    line separator (default: $/)

Returns:

  • (String) —

    next line

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass

  • (EOFError) —

    if at end of file



289
290
291
# File 'lib/rex/post/io.rb', line 289

def readline(sep = $/)
  raise NotImplementedError
end

#readlines(sep = $/) ⇒ Array<String>

Reads all lines from the stream into an array.

Parameters:

  • sep (String) (defaults to: $/) —

    line separator (default: $/)

Returns:

  • (Array<String>) —

    array of lines

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



300
301
302
# File 'lib/rex/post/io.rb', line 300

def readlines(sep = $/)
  raise NotImplementedError
end

#rewind ⇒ 0

Repositions the stream to the beginning.

Returns:

  • (0) —

    zero on success

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



309
310
311
# File 'lib/rex/post/io.rb', line 309

def rewind
  raise NotImplementedError
end

#seek(offset, whence = SEEK_SET) ⇒ 0

Repositions the file pointer.

Parameters:

  • offset (Integer) —

    byte offset

  • whence (Integer) (defaults to: SEEK_SET) —

    position reference (SEEK_SET, SEEK_CUR, SEEK_END)

Returns:

  • (0) —

    zero on success

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



321
322
323
# File 'lib/rex/post/io.rb', line 321

def seek(offset, whence = SEEK_SET)
  raise NotImplementedError
end

#stat ⇒ File::Stat

Gets file status information.

Returns:

  • (File::Stat) —

    file status object

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



330
331
332
# File 'lib/rex/post/io.rb', line 330

def stat
  raise NotImplementedError
end

#sync ⇒ IO

Synchronizes the stream with the underlying storage.

Returns:

  • (IO) —

    self

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



339
340
341
# File 'lib/rex/post/io.rb', line 339

def sync
  raise NotImplementedError
end

#sysread(length) ⇒ String

Reads data at the system level.

Parameters:

  • length (Integer) —

    number of bytes to read

Returns:

  • (String) —

    data read

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



350
351
352
# File 'lib/rex/post/io.rb', line 350

def sysread(length)
  raise NotImplementedError
end

#sysseek(offset, whence = SEEK_SET) ⇒ Integer

Repositions the file pointer at the system level.

Parameters:

  • offset (Integer) —

    byte offset

  • whence (Integer) (defaults to: SEEK_SET) —

    position reference (SEEK_SET, SEEK_CUR, SEEK_END)

Returns:

  • (Integer) —

    new file offset

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



362
363
364
# File 'lib/rex/post/io.rb', line 362

def sysseek(offset, whence = SEEK_SET)
  raise NotImplementedError
end

#syswrite(buf) ⇒ Integer

Writes data to the stream at the OS level.

Parameters:

  • buf (String) —

    data to write

Returns:

  • (Integer) —

    number of bytes written

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



373
374
375
# File 'lib/rex/post/io.rb', line 373

def syswrite(buf)
  raise NotImplementedError
end

#tell ⇒ Integer

Gets the current file position (alias for #pos).

Returns:

  • (Integer) —

    current byte offset



380
381
382
# File 'lib/rex/post/io.rb', line 380

def tell
  return pos
end

#tty? ⇒ Boolean

Checks if the I/O stream is a terminal device.

Returns:

  • (Boolean) —

    true if stream is a TTY



40
41
42
# File 'lib/rex/post/io.rb', line 40

def tty?
  return isatty
end

#ungetc(val) ⇒ nil

Pushes a character back onto the stream.

Parameters:

  • val (Integer) —

    character code to push back

Returns:

  • (nil)

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



391
392
393
# File 'lib/rex/post/io.rb', line 391

def ungetc(val)
  raise NotImplementedError
end

#write(buf) ⇒ Integer

Writes data to the stream.

Parameters:

  • buf (String) —

    data to write

Returns:

  • (Integer) —

    number of bytes written

Raises:

  • (NotImplementedError) —

    Must be implemented by subclass



402
403
404
# File 'lib/rex/post/io.rb', line 402

def write(buf)
  raise NotImplementedError
end