Class: Ronin::Fuzzing::Template
- Inherits:
-
Object
- Object
- Ronin::Fuzzing::Template
- Includes:
- Enumerable
- Defined in:
- lib/ronin/fuzzing/template.rb
Overview
Fuzzing class that generates Strings based on a template.
Class Method Summary collapse
Instance Method Summary collapse
-
#each {|string| ... } ⇒ Enumerator
Generate permutations of Strings from a format template.
-
#initialize(fields) ⇒ Template
constructor
Initializes a new Fuzzing template.
Constructor Details
#initialize(fields) ⇒ Template
Initializes a new Fuzzing template.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ronin/fuzzing/template.rb', line 51 def initialize(fields) @enumerators = [] fields.each do |(set,length)| enum = case set when String [set].each when Enumerable set.each when Symbol name = set.upcase unless Chars.const_defined?(name) raise(ArgumentError,"unknown charset #{set.inspect}") end Chars.const_get(name).each_char else raise(TypeError,"set must be a String, Symbol or Enumerable") end case length when Integer length.times { @enumerators << enum.dup } when Array, Range @enumerators << Combinatorics::Generator.new do |g| length.each do |sublength| superset = Array.new(sublength) { enum.dup } superset.comprehension { |strings| g.yield strings.join } end end when nil @enumerators << enum else raise(TypeError,"length must be an Integer, Range or Array") end end end |
Class Method Details
.[](*fields) ⇒ Object
94 95 96 |
# File 'lib/ronin/fuzzing/template.rb', line 94 def self.[](*fields) new(fields) end |
Instance Method Details
#each {|string| ... } ⇒ Enumerator
Generate permutations of Strings from a format template.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/ronin/fuzzing/template.rb', line 110 def each return enum_for(__method__) unless block_given? @enumerators.comprehension do |fields| string = '' fields.each do |field| string << case field when Integer field.chr else field.to_s end end yield string end return nil end |