rex-text 0.2.61 → 0.2.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 116788ee4b0c5a6c7564e7300089bb7c80e90434b3e3cb081a4644d9a1308543
4
- data.tar.gz: 6dd36af9873d02b69f60cc27097838d0c34dea3627bdac25b3793a193468ae46
3
+ metadata.gz: 38b05e7a7c130d9db696f9d524e28f9cd2625dd0bea7679af45d42bd1a80e9c5
4
+ data.tar.gz: 6c5eb25945c58e4bc70c9b27e670afda87f12a989c201c8bd17e92b0638aa44e
5
5
  SHA512:
6
- metadata.gz: 1397d7812e81ed8ae765f5b2fb99a8299bb40fa1c54ca72f99cb814b1b44dab0b7ce2872396310b95267709a99e2a251b7084502c981919a5cbb4438baab80aa
7
- data.tar.gz: 50bc007eea070ebd889159e4fa92bbd78bde8614a040bc1656fcec0bddb4930cb56fc59df3d1ed599652d0da20b28cf6897022c8457322514d951acb96623a53
6
+ metadata.gz: d7b7005302c8640bbee97b198c3059605521af4ea7b5f7bf7ac055aaf28f16c4be47c8289a0c77c4b45c73f65eeae769e142433396060158827419c437e03b56
7
+ data.tar.gz: 65998e0159a9fea9ac51c0e9e290cb98138254250d4fb8953f80a88926e7b83480bbe0eeb8223d3efb9f3aa064a0df5e193b50768d6267e347540cb21973648a
@@ -11,22 +11,25 @@ module Rex
11
11
  #
12
12
  # @param mod [String] The name of the module containing the target function.
13
13
  # @param fun [String] The name of the function.
14
+ # @param iv [Integer] The 32-bit initialization vector (IV) to use for the hash operation
14
15
  #
15
16
  # @return [String] The hash of the mod/fun pair in string format
16
- def self.block_api_hash(mod, func)
17
- unicode_mod = (mod.upcase + "\x00").unpack('C*').pack('v*')
18
- mod_hash = self.ror13_hash(unicode_mod)
19
- fun_hash = self.ror13_hash(func + "\x00")
20
- "0x#{(mod_hash + fun_hash & 0xFFFFFFFF).to_s(16)}"
17
+ def self.block_api_hash(mod, func, iv: 0)
18
+ unicode_mod = (mod.upcase).unpack('C*').pack('v*')
19
+ mod_hash = self.ror13_hash(unicode_mod, iv: iv)
20
+ fun_hash = self.ror13_hash(func + "\x00", iv: mod_hash)
21
+ "0x#{(fun_hash & 0xFFFFFFFF).to_s(16)}"
21
22
  end
22
23
 
23
24
  #
24
25
  # Calculate the ROR13 hash of a given string
26
+ # @param string [String] The string to hash
27
+ # @param iv [Integer] The 32-bit initialization vector (IV) to use for the hash operation
25
28
  #
26
29
  # @return [Integer]
27
- def self.ror13_hash(name)
28
- hash = 0
29
- name.unpack("C*").each {|c| hash = ror(hash, 13); hash += c }
30
+ def self.ror13_hash(string, iv: 0)
31
+ hash = (iv & 0xFFFFFFFF)
32
+ string.unpack("C*").each {|c| hash = ror(hash, 13); hash += c }
30
33
  hash
31
34
  end
32
35
  end
data/lib/rex/text/hex.rb CHANGED
@@ -166,6 +166,25 @@ module Rex
166
166
  str.gsub!(regex) { |x| x[2,2].to_i(16).chr }
167
167
  end
168
168
 
169
+ #
170
+ # Converts a string to a comma-separated hex byte sequence suitable for
171
+ # use in assembly `db` directives.
172
+ #
173
+ # @example
174
+ # Rex::Text.to_hex_cstring("hi") # => "0x68, 0x69, 0x00"
175
+ # Rex::Text.to_hex_cstring("") # => "0x00"
176
+ # Rex::Text.to_hex_cstring("hi", nullbyte: false) # => "0x68, 0x69"
177
+ # Rex::Text.to_hex_cstring("", nullbyte: false) # => ""
178
+ #
179
+ # @param str [String] The string to convert
180
+ # @param nullbyte [Boolean] Whether to append a null terminator (default: true)
181
+ # @return [String] Comma-separated hex bytes
182
+ def self.to_hex_cstring(str, nullbyte: true)
183
+ bytes = str.to_s.bytes
184
+ bytes.push(0) if nullbyte
185
+ bytes.map { |byte| '0x%02x' % byte }.join(', ')
186
+ end
187
+
169
188
  private
170
189
 
171
190
  #
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Text
3
- VERSION = "0.2.61"
3
+ VERSION = "0.2.63"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rex-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.61
4
+ version: 0.2.63
5
5
  platform: ruby
6
6
  authors:
7
7
  - Metasploit Hackers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-09 00:00:00.000000000 Z
11
+ date: 2026-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake