Class: Ronin::Wordlist
- Includes:
- Enumerable
- Defined in:
- lib/ronin/wordlist.rb
Overview
An Enumerable class for iterating over wordlist files or lists of words.
Instance Attribute Summary collapse
-
#mutations ⇒ Object
readonly
Mutation rules to apply to every word in the list.
-
#path ⇒ Object
readonly
The path to the wordlist file.
-
#words ⇒ Object
readonly
The words for the list.
Class Method Summary collapse
-
.build(text, mutations = {}) ⇒ Wordlist
Builds a new wordlist from the text.
-
.create(path, text, mutations = {}) ⇒ Wordlist
Creates a new wordlist file.
-
.parse(text) {|word| ... } ⇒ SortedSet
Parses the text into a unique Set of words.
Instance Method Summary collapse
-
#each {|word| ... } ⇒ Enumerator
Iterates over each word, and each mutation, from the list.
-
#each_n_words(n) {|words| ... } ⇒ Enumerator
Iterates over every n words.
-
#each_word {|word| ... } ⇒ Enumerator
Iterates over each word in the list.
-
#initialize(wordlist, mutations = {}) {|wordlist| ... } ⇒ Wordlist
constructor
Initializes the wordlist.
-
#list ⇒ String, Enumerable
The wordlist file or list of words.
-
#save(path) ⇒ Wordlist
Saves the words to a new file.
Methods included from Enumerable
Constructor Details
#initialize(wordlist, mutations = {}) {|wordlist| ... } ⇒ Wordlist
Initializes the wordlist.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ronin/wordlist.rb', line 80 def initialize(wordlist,mutations={}) case wordlist when String @path = wordlist @words = nil when Enumerable @path = nil @words = wordlist else raise(TypeError,"wordlist must be a path or Enumerable") end @mutations = mutations yield self if block_given? end |
Instance Attribute Details
#mutations ⇒ Object (readonly)
Mutation rules to apply to every word in the list
47 48 49 |
# File 'lib/ronin/wordlist.rb', line 47 def mutations @mutations end |
#path ⇒ Object (readonly)
The path to the wordlist file
39 40 41 |
# File 'lib/ronin/wordlist.rb', line 39 def path @path end |
#words ⇒ Object (readonly)
The words for the list
44 45 46 |
# File 'lib/ronin/wordlist.rb', line 44 def words @words end |
Class Method Details
.build(text, mutations = {}) ⇒ Wordlist
Builds a new wordlist from the text.
141 142 143 |
# File 'lib/ronin/wordlist.rb', line 141 def self.build(text,mutations={}) new(parse(text),mutations) end |
.create(path, text, mutations = {}) ⇒ Wordlist
Creates a new wordlist file.
162 163 164 165 166 |
# File 'lib/ronin/wordlist.rb', line 162 def self.create(path,text,mutations={}) wordlist = build(text,mutations) return wordlist.save(path) end |
.parse(text) {|word| ... } ⇒ SortedSet
Parses the text into a unique Set of words.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ronin/wordlist.rb', line 113 def self.parse(text) words_seen = SortedSet[] text.each_line do |line| line.scan(Regexp::WORD) do |word| if block_given? yield word unless words_seen.include?(word) end words_seen << word end end return words_seen end |
Instance Method Details
#each {|word| ... } ⇒ Enumerator
Iterates over each word, and each mutation, from the list.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/ronin/wordlist.rb', line 225 def each(&block) return enum_for(__method__) unless block mutator = unless @mutations.empty? Fuzzing::Mutator.new(@mutations) end each_word do |word| yield word if mutator # perform additional mutations mutator.each(word,&block) end end end |
#each_n_words(n) {|words| ... } ⇒ Enumerator
Iterates over every n words.
259 260 261 |
# File 'lib/ronin/wordlist.rb', line 259 def each_n_words(n,&block) Fuzzing::Template[[each, n]].each(&block) end |
#each_word {|word| ... } ⇒ Enumerator
Iterates over each word in the list.
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ronin/wordlist.rb', line 197 def each_word(&block) return enum_for(__method__) unless block if @path File.open(@path) do |file| file.each_line do |line| yield line.chomp end end elsif @words @words.each(&block) end end |
#list ⇒ String, Enumerable
The wordlist file or list of words.
176 177 178 |
# File 'lib/ronin/wordlist.rb', line 176 def list @path || @words end |