Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/rex/text/block_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
smcintyre-r7 marked this conversation as resolved.
Resolved
"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
Expand Down