Class: Ronin::PostExploitation::Dir

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ronin/post_exploitation/dir.rb

Overview

The Dir class represents directories on a remote system.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, entries = []) ⇒ Dir

Creates a new Dir object.


44
45
46
47
48
49
# File 'lib/ronin/post_exploitation/dir.rb', line 44

def initialize(path,entries=[])
  @path    = path
  @entries = entries
  @pos     = 0
  @closed  = false
end

Instance Attribute Details

#pathObject (readonly)

The path of the directory


33
34
35
# File 'lib/ronin/post_exploitation/dir.rb', line 33

def path
  @path
end

Instance Method Details

#closeObject

Closes the opened directory.


184
185
186
187
# File 'lib/ronin/post_exploitation/dir.rb', line 184

def close
  @closed = true
  return nil
end

#each {|entry| ... } ⇒ Enumerator

Iterates through the entries within the directory.

Yields:

  • (entry)

    The given block will be passed each entry.

Yield Parameters:

  • entry (String)

    An entry from the directory.

Raises:

  • (IOError)

    The directory is closed.


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ronin/post_exploitation/dir.rb', line 141

def each
  return enum_for(__method__) unless block_given?

  if @closed
    raise(IOError,"closed directory")
  end

  @pos = 0

  @entries.each do |entry|
    yield entry
    @pos += 1
  end

  return self
end

#inspectString

Inspects the directory.


195
196
197
# File 'lib/ronin/post_exploitation/dir.rb', line 195

def inspect
  "<#{self.class}:#{@path}>"
end

#pos(new_pos = nil) ⇒ Object

Gets or sets the position of the opened directory.

See Also:


57
58
59
60
61
62
63
# File 'lib/ronin/post_exploitation/dir.rb', line 57

def pos(new_pos=nil)
  if new_pos
    seek(new_pos)
  else
    tell(new_pos)
  end
end

#readString?

Reads the next entry from the directory.

Raises:

  • (IOError)

    The directory is closed.


168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/ronin/post_exploitation/dir.rb', line 168

def read
  if @closed
    raise(IOError,"closed directory")
  end

  if @pos < @entries.length
    next_entry = @entries[@pos]

    @pos += 1
    return next_entry
  end
end

#rewindDir

Rewinds the opened directory.

Raises:

  • (IOError)

    The directory is closed.


90
91
92
93
94
95
96
97
# File 'lib/ronin/post_exploitation/dir.rb', line 90

def rewind
  if @closed
    raise(IOError,"closed directory")
  end

  @pos = 0
  return self
end

#seek(new_pos) ⇒ Dir

Sets the position within the open directory.

Raises:

  • (Errno::EINVAL)

    The new position was out of bounds.

  • (IOError)

    The directory is closed.


113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ronin/post_exploitation/dir.rb', line 113

def seek(new_pos)
  if @closed
    raise(IOError,"closed directory")
  end

  if (new_pos < 0) || (new_pos >= @entries.length)
    raise(Errno::EINVAL,"invalid seek position")
  end

  @pos = new_pos
  return self
end

#tellInteger

Returns the position in the opened directory.

Raises:

  • (IOError)

    The directory is closed.


74
75
76
77
78
79
80
# File 'lib/ronin/post_exploitation/dir.rb', line 74

def tell
  if @closed
    raise(IOError,"closed directory")
  end

  return @pos
end