diff --git a/lib/rex/text/block_api.rb b/lib/rex/text/block_api.rb index a1df02e..54710dc 100644 --- a/lib/rex/text/block_api.rb +++ b/lib/rex/text/block_api.rb @@ -11,22 +11,25 @@ module Text # # @param mod [String] The name of the module containing the target function. # @param fun [String] The name of the function. + # @param iv [Integer] The 32-bit initialization vector (IV) to use for the hash operation # # @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)}" + def self.block_api_hash(mod, func, iv: 0) + unicode_mod = (mod.upcase).unpack('C*').pack('v*') + mod_hash = self.ror13_hash(unicode_mod, iv: iv) + fun_hash = self.ror13_hash(func + "\x00", iv: mod_hash) + "0x#{(fun_hash & 0xFFFFFFFF).to_s(16)}" end # # Calculate the ROR13 hash of a given string + # @param string [String] The string to hash + # @param iv [Integer] The 32-bit initialization vector (IV) to use for the hash operation # # @return [Integer] - def self.ror13_hash(name) - hash = 0 - name.unpack("C*").each {|c| hash = ror(hash, 13); hash += c } + def self.ror13_hash(string, iv: 0) + hash = (iv & 0xFFFFFFFF) + string.unpack("C*").each {|c| hash = ror(hash, 13); hash += c } hash end end