Class: Ronin::PostEx::RemoteFile
- Includes:
- FakeIO
- Defined in:
- lib/ronin/post_ex/remote_file.rb,
lib/ronin/post_ex/remote_file/stat.rb
Overview
file_close(fd : Integer)
fs_readfile(path : String) -> String | nil
fs_stat(path : String) => Hash[Symbol, Object] | nil
Defined Under Namespace
Classes: Stat
Constant Summary collapse
- SEEK_SET =
Seeks from beginning of file.
File::SEEK_SET
- SEEK_CUR =
Seeks from current position.
File::SEEK_CUR
- SEEK_END =
Seeks from end of file.
File::SEEK_END
- SEEK_DATA =
Seeks to next data.
(File::SEEK_DATA) && File::SEEK_DATA) || 3
- SEEK_HOLE =
Seeks to next hole.
(File::SEEK_HOLE) && File::SEEK_HOLE) || 4
- WHENCE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mapping of
SEEK_*
constants to their String values. { SEEK_SET => 'SEEK_SET', SEEK_CUR => 'SEEK_CUR', SEEK_END => 'SEEK_END', SEEK_DATA => 'SEEK_DATA', SEEK_HOLE => 'SEEK_HOLE' }
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.open(session, path) {|file| ... } ⇒ RemoteFile?
Opens a file.
Instance Method Summary collapse
-
#close ⇒ nil
Flushes the file before closing it.
-
#fcntl(command, argument) ⇒ Integer
Executes a low-level command to control or query the file stream.
-
#flush ⇒ self
Flushes the file.
-
#initialize(session, path, mode = 'r') ⇒ RemoteFile
constructor
Creates a new remote controlled File object.
-
#inspect ⇒ String
Inspects the open file.
-
#ioctl(command, argument) ⇒ Integer
Executes a low-level command to control or query the IO stream.
-
#reopen(path) ⇒ RemoteFile
Re-opens the file.
-
#seek(new_pos, whence = SEEK_SET) ⇒ Integer
Sets the position in the file to read.
-
#stat ⇒ Stat
The status information for the file.
-
#tell ⇒ Integer
The current offset in the file.
Methods inherited from Resource
#interact, #supports, #supports?
Constructor Details
#initialize(session, path, mode = 'r') ⇒ RemoteFile
This method may use the file_open
method, if it is defined by
Ronin::PostEx::Resource#session.
Creates a new remote controlled File object.
71 72 73 74 75 76 77 78 |
# File 'lib/ronin/post_ex/remote_file.rb', line 71 def initialize(session,path,mode='r') @session = session @path = path.to_s @mode = mode.to_s super() end |
Class Method Details
.open(session, path) {|file| ... } ⇒ RemoteFile?
Opens a file.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ronin/post_ex/remote_file.rb', line 100 def self.open(session,path) io = new(session,path) if block_given? yield(io) io.close return else return io end end |
Instance Method Details
#close ⇒ nil
Flushes the file before closing it.
312 313 314 315 |
# File 'lib/ronin/post_ex/remote_file.rb', line 312 def close flush if @mode.include?('w') super() end |
#fcntl(command, argument) ⇒ Integer
This method requires the file_fnctl
API method.
Executes a low-level command to control or query the file stream.
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/ronin/post_ex/remote_file.rb', line 240 def fcntl(command,argument) unless @session.respond_to?(:file_fcntl) raise(NotImplementedError,"#{@session.inspect} does not define file_fcntl") end if @fd == nil raise(RuntimeError,"file_ioctl requires a file-descriptor") end return @session.file_fcntl(@fd,command,argument) end |
#flush ⇒ self
This method may use the file_flush
API method, if it is defined
Flushes the file.
299 300 301 302 303 304 305 |
# File 'lib/ronin/post_ex/remote_file.rb', line 299 def flush if @session.respond_to?(:file_flush) @session.file_flush end return self end |
#inspect ⇒ String
Inspects the open file.
323 324 325 |
# File 'lib/ronin/post_ex/remote_file.rb', line 323 def inspect "#<#{self.class}:#{@path}>" end |
#ioctl(command, argument) ⇒ Integer
This method requires the file_ioctl
API method.
Executes a low-level command to control or query the IO stream.
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/ronin/post_ex/remote_file.rb', line 210 def ioctl(command,argument) unless @session.respond_to?(:file_ioctl) raise(NotImplementedError,"#{@session.inspect} does not define file_ioctl") end if @fd == nil raise(RuntimeError,"file_ioctl requires a file-descriptor") end return @session.file_ioctl(@fd,command,argument) end |
#reopen(path) ⇒ RemoteFile
This method may use the file_close
and file_open
API methods,
if they are defined by Ronin::PostEx::Resource#session.
Re-opens the file.
266 267 268 269 270 271 |
# File 'lib/ronin/post_ex/remote_file.rb', line 266 def reopen(path) close @path = path.to_s return open end |
#seek(new_pos, whence = SEEK_SET) ⇒ Integer
This method may use the file_seek
API method, if it is defined
Sets the position in the file to read.
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ronin/post_ex/remote_file.rb', line 156 def seek(new_pos,whence=SEEK_SET) clear_buffer! unless WHENCE.has_key?(whence) raise(ArgumentError,"invalid whence value: #{whence.inspect}") end if @session.respond_to?(:file_seek) @session.file_seek(@fd,new_pos,WHENCE[whence]) end @pos = new_pos end |
#stat ⇒ Stat
This method relies on the fs_stat
API method.
The status information for the file.
282 283 284 285 286 287 288 |
# File 'lib/ronin/post_ex/remote_file.rb', line 282 def stat if @fd Stat.new(@session, fd: @fd) else Stat.new(@session, path: @path) end end |
#tell ⇒ Integer
This method may use the file_tell
API method, if it is defined by
Ronin::PostEx::Resource#session.
The current offset in the file.
181 182 183 184 185 186 187 |
# File 'lib/ronin/post_ex/remote_file.rb', line 181 def tell if @session.respond_to?(:file_tell) @pos = @session.file_tell(@fd) else @pos end end |