Sha256: 0ad80425f87219b478bb639f2abf0fa3b54f1980399285cde095f348dd3ad76b

Contents?: true

Size: 1.09 KB

Versions: 13

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 [Fixnum]
    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

13 entries across 13 versions & 1 rubygems

Version Path
rex-text-0.2.10 lib/rex/text/block_api.rb
rex-text-0.2.9 lib/rex/text/block_api.rb
rex-text-0.2.8 lib/rex/text/block_api.rb
rex-text-0.2.7 lib/rex/text/block_api.rb
rex-text-0.2.6 lib/rex/text/block_api.rb
rex-text-0.2.5 lib/rex/text/block_api.rb
rex-text-0.2.4 lib/rex/text/block_api.rb
rex-text-0.2.3 lib/rex/text/block_api.rb
rex-text-0.2.1 lib/rex/text/block_api.rb
rex-text-0.2.0 lib/rex/text/block_api.rb
rex-text-0.1.2 lib/rex/text/block_api.rb
rex-text-0.1.1 lib/rex/text/block_api.rb
rex-text-0.1.0 lib/rex/text/block_api.rb