Sha256: a2c45b96717db8b3c6e314aad9f86e844150be47679da43b1cda54d0c5e6eaa9

Contents?: true

Size: 1.82 KB

Versions: 272

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require 'barby'
require 'rqrcode'
require 'chunky_png'

module PWN
  module Plugins
    # This plugin is used to Create Scannable BarCodes and QR Codes
    module ScannableCodes
      # Supported Method Parameters::
      # response = PWN::Plugins::ScannableCodes.generate(
      #   data: 'required - data to encode',
      #   type: 'optional - :barcode || :qrcode (defaults to :qrcode)',
      #   path: 'optional - path to save image (defaults to "./#{data}.png")'
      # )

      public_class_method def self.generate(opts = {})
        data = opts[:data]
        raise 'ERROR: option data is required.' unless data

        type = opts[:type]
        type ||= :qrcode

        path = opts[:path]
        path ||= "./#{data}.png"

        case type
        when :barcode
          barcode = Barby::Code128B.new(data)
          barcode.to_png.save(path)
        when :qrcode
          qrcode = RQRCode::QRCode.new(data)
          png = qrcode.as_png
          png.resize(200, 200).save(path)
        else
          raise 'ERROR: type must be :barcode or :qrcode.'
        end

        puts "Saved #{type} to #{path}"
      rescue Interrupt
        puts "\nGoodbye."
      rescue StandardError => e
        raise e
      end

      # Author(s):: 0day Inc. <request.pentest@0dayinc.com>

      public_class_method def self.authors
        "AUTHOR(S):
          0day Inc. <request.pentest@0dayinc.com>
        "
      end

      # Display Usage for this Module

      public_class_method def self.help
        puts "USAGE:
          #{self}.generate(
            data: 'required - data to encode',
            type: 'optional - :barcode || :qrcode (defaults to :qrcode)',
            path: 'optional - path to save image (defaults to \"./\#{data}.png\")'
          )

          #{self}.authors
        "
      end
    end
  end
end

Version data entries

272 entries across 272 versions & 1 rubygems

Version Path
pwn-0.5.104 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.103 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.102 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.101 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.100 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.99 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.98 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.97 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.96 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.95 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.94 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.93 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.92 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.91 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.90 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.89 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.88 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.87 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.86 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.85 lib/pwn/plugins/scannable_codes.rb