Sha256: 58af3b9a0aafa4dff045bb9ba107aa6cf7d7f0d85d30e17edb71037b7d91b9b2

Contents?: true

Size: 1.09 KB

Versions: 5

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, fun)
      unicode_mod = (mod.upcase + "\x00").unpack('C*').pack('v*')
      mod_hash = self.ror13_hash(unicode_mod)
      fun_hash = self.ror13_hash(fun + "\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

5 entries across 5 versions & 1 rubygems

Version Path
rex-text-0.2.15 lib/rex/text/block_api.rb
rex-text-0.2.14 lib/rex/text/block_api.rb
rex-text-0.2.13 lib/rex/text/block_api.rb
rex-text-0.2.12 lib/rex/text/block_api.rb
rex-text-0.2.11 lib/rex/text/block_api.rb