Sha256: e4b0a1518bcef55ebcac4fbe50c53930ea54cfe5a337420ce1dd42f3caf0292a

Contents?: true

Size: 972 Bytes

Versions: 30

Compression:

Stored size: 972 Bytes

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]/, '')
        extractions = nil
        fingerprints.each do |fp|
          break if (extractions = fp.match(line))
        end

        if extractions
          extractions['data'] = line
          reporter.match "MATCH: #{extractions.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

30 entries across 30 versions & 1 rubygems

Version Path
recog-2.0.15 lib/recog/matcher.rb
recog-2.0.14 lib/recog/matcher.rb
recog-2.0.13 lib/recog/matcher.rb
recog-2.0.12 lib/recog/matcher.rb
recog-2.0.11 lib/recog/matcher.rb
recog-2.0.10 lib/recog/matcher.rb
recog-2.0.9 lib/recog/matcher.rb
recog-2.0.8 lib/recog/matcher.rb
recog-2.0.7 lib/recog/matcher.rb
recog-2.0.6 lib/recog/matcher.rb
recog-2.0.5 lib/recog/matcher.rb
recog-2.0.4 lib/recog/matcher.rb
recog-2.0.2 lib/recog/matcher.rb
recog-2.0.1 lib/recog/matcher.rb
recog-2.0.0 lib/recog/matcher.rb
recog-1.0.29 lib/recog/matcher.rb
recog-1.0.28 lib/recog/matcher.rb
recog-1.0.27 lib/recog/matcher.rb
recog-1.0.26 lib/recog/matcher.rb
recog-1.0.25 lib/recog/matcher.rb