Sha256: ec895f004245bf39064e9932d6248a279ff25164a19ee361cd1175f1758e8bd3

Contents?: true

Size: 1.2 KB

Versions: 15

Compression:

Stored size: 1.2 KB

Contents

module Recog
class Matcher
  attr_reader :fingerprints, :reporter

  def initialize(fingerprints, reporter)
    @fingerprints = fingerprints
    @reporter = reporter
  end

  def match_banners(banners_file)
    reporter.report do

      fd = $stdin
      file_source = false

      if banners_file and banners_file != "-"
        fd = File.open(banners_file, "rb")
        file_source = true
      end

      fd.each_line do |line|
        reporter.increment_line_count

        line = line.to_s.unpack("C*").pack("C*").strip.gsub(/\\[rn]/, '')
        found = nil
        fingerprints.each do |fp|
          m = line.match(fp.regex)
          if m
            found = [fp, m]
            break
          end
        end

        if found
          info = { }
          fp, m = found
          fp.params.each_pair do |k,v|
            if v[0] == 0
              info[k] = v[1]
            else
              info[k] = m[ v[0] ]
            end
          end
          info['data'] = line
          reporter.match "MATCH: #{info.inspect}"
        else
          reporter.failure "FAIL: #{line}"
        end

        if reporter.stop?
          break
        end
      end

      fd.close if file_source

    end
  end
end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
recog-1.0.14 lib/recog/matcher.rb
recog-1.0.13 lib/recog/matcher.rb
recog-1.0.12 lib/recog/matcher.rb
recog-1.0.11 lib/recog/matcher.rb
recog-1.0.10 lib/recog/matcher.rb
recog-1.0.9 lib/recog/matcher.rb
recog-1.0.8 lib/recog/matcher.rb
recog-1.0.7 lib/recog/matcher.rb
recog-1.0.6 lib/recog/matcher.rb
recog-1.0.5 lib/recog/matcher.rb
recog-1.0.4 lib/recog/matcher.rb
recog-1.0.3 lib/recog/matcher.rb
recog-1.0.2 lib/recog/matcher.rb
recog-1.0.1 lib/recog/matcher.rb
recog-1.0.0 lib/recog/matcher.rb