Sha256: f379b8081d8406b553ee4f0379a0891a3afbde90063bf44db56434c98d0f1101

Contents?: true

Size: 1.09 KB

Versions: 44

Compression:

Stored size: 1.09 KB

Contents

# -*- coding: binary -*-
module Rex
  module Text
    # We are re-opening the module to add these module methods.
    # Breaking them up this way allows us to maintain a little higher
    # degree of organisation and make it easier to find what you're looking for
    # without hanging the underlying calls that we historically rely upon.

    #
    # Calculate the block API hash for the given module/function
    #
    # @param mod [String] The name of the module containing the target function.
    # @param fun [String] The name of the function.
    #
    # @return [String] The hash of the mod/fun pair in string format
    def self.block_api_hash(mod, func)
      unicode_mod = (mod.upcase + "\x00").unpack('C*').pack('v*')
      mod_hash = self.ror13_hash(unicode_mod)
      fun_hash = self.ror13_hash(func + "\x00")
      "0x#{(mod_hash + fun_hash & 0xFFFFFFFF).to_s(16)}"
    end

    #
    # Calculate the ROR13 hash of a given string
    #
    # @return [Integer]
    def self.ror13_hash(name)
      hash = 0
      name.unpack("C*").each {|c| hash = ror(hash, 13); hash += c }
      hash
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
rex-text-0.2.60 lib/rex/text/block_api.rb
rex-text-0.2.59 lib/rex/text/block_api.rb
rex-text-0.2.57 lib/rex/text/block_api.rb
rex-text-0.2.56 lib/rex/text/block_api.rb
rex-text-0.2.55 lib/rex/text/block_api.rb
rex-text-0.2.54 lib/rex/text/block_api.rb
rex-text-0.2.53 lib/rex/text/block_api.rb
rex-text-0.2.52 lib/rex/text/block_api.rb
rex-text-0.2.51 lib/rex/text/block_api.rb
rex-text-0.2.50 lib/rex/text/block_api.rb
rex-text-0.2.49 lib/rex/text/block_api.rb
rex-text-0.2.48 lib/rex/text/block_api.rb
rex-text-0.2.47 lib/rex/text/block_api.rb
rex-text-0.2.46 lib/rex/text/block_api.rb
rex-text-0.2.45 lib/rex/text/block_api.rb
rex-text-0.2.44 lib/rex/text/block_api.rb
rex-text-0.2.43 lib/rex/text/block_api.rb
rex-text-0.2.42 lib/rex/text/block_api.rb
rex-text-0.2.41 lib/rex/text/block_api.rb
rex-text-0.2.40 lib/rex/text/block_api.rb