Class: Ronin::Wordlists::SearchPaths Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ronin/wordlists/search_paths.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents the wordlist directories to search for wordlists within.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths = []) ⇒ SearchPaths

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the wordlist search paths.

Parameters:

  • paths (Array<String>) (defaults to: [])

    The paths to the wordlist directories to search.



47
48
49
50
51
52
53
# File 'lib/ronin/wordlists/search_paths.rb', line 47

def initialize(paths=[])
  @paths = []

  paths.each do |path|
    self << path
  end
end

Instance Attribute Details

#pathsArray<WordlistDir> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The paths of the wordlist directories.

Returns:



39
40
41
# File 'lib/ronin/wordlists/search_paths.rb', line 39

def paths
  @paths
end

Class Method Details

.[](*paths) ⇒ SearchPaths

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the wordlist search paths.

Parameters:

  • paths (Array<String>)

    The paths to the wordlist directories to search.

Returns:



64
65
66
# File 'lib/ronin/wordlists/search_paths.rb', line 64

def self.[](*paths)
  new(paths)
end

Instance Method Details

#<<(new_dir) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a new wordlist directory to the search paths.

Parameters:

  • new_dir (String)

    A new wordlist directory to add to the search directories.

Returns:

  • (self)


92
93
94
95
# File 'lib/ronin/wordlists/search_paths.rb', line 92

def <<(new_dir)
  @paths.unshift(WordlistDir.new(new_dir))
  return self
end

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enumerates over each wordlist directory within the search paths.

Yields:

  • (wordlist_dir)

    If a block is given, each wordlist directory will be yielded.

Yield Parameters:

  • wordlist_dir (WordlistDir)

    A wordlist directory within the search paths.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.



80
81
82
# File 'lib/ronin/wordlists/search_paths.rb', line 80

def each(&block)
  @paths.each(&block)
end

#find(name) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds a wordlist within one of the wordlist directories.

Parameters:

  • name (String)

    The wordlist file name.

Returns:

  • (String, nil)

    The path to the wordlist or nil if the wordlist could not be found.



106
107
108
109
110
111
112
113
114
# File 'lib/ronin/wordlists/search_paths.rb', line 106

def find(name)
  @paths.each do |wordlist_dir|
    if (wordlist_path = wordlist_dir.find(name))
      return wordlist_path
    end
  end

  return nil
end

#list(name = '*') ⇒ Set<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lists all wordlists in the wordlist directories.

Parameters:

  • name (String) (defaults to: '*')

    Optional file name to search for.

Returns:

  • (Set<String>)

    The wordlist files within the wordlist directories.



125
126
127
128
129
# File 'lib/ronin/wordlists/search_paths.rb', line 125

def list(name='*')
  each_with_object(Set.new) do |wordlist_dir,files|
    files.merge(wordlist_dir.list(name))
  end
end

#open(name) ⇒ Wordlist::File

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Opens a wordlist from one of the wordlist directories.

Parameters:

  • name (String)

    The wordlist file name.

Returns:

  • (Wordlist::File)

    The opened wordlist file.

Raises:



143
144
145
146
147
148
149
# File 'lib/ronin/wordlists/search_paths.rb', line 143

def open(name)
  if (path = find(name))
    Wordlist.open(path)
  else
    raise(WordlistNotFound,"wordlist not found: #{name.inspect}")
  end
end