Land #62, Add support for Ruby 3.3.0-preview1

This commit is contained in:
dwelch-r7 2023-06-14 12:51:15 +01:00 committed by GitHub
commit 43cd4523e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 5 deletions

View File

@ -37,6 +37,7 @@ jobs:
- '3.0'
- '3.1'
- '3.2'
- '3.3.0-preview1'
os:
- ubuntu-20.04
- ubuntu-latest

View File

@ -28,15 +28,15 @@ module Rex
# Creates a comma separated list of dwords
#
def self.to_dword(str, wrap = DefaultWrap)
code = str
code = str.dup.force_encoding('ASCII-8BIT')
alignnr = str.length % 4
if (alignnr > 0)
code << "\x00" * (4 - alignnr)
end
codevalues = Array.new
code.split("").each_slice(4) do |chars4|
code.chars.each_slice(4) do |chars4|
chars4 = chars4.join("")
dwordvalue = chars4.unpack('*V')
dwordvalue = chars4.unpack('V')
codevalues.push(dwordvalue[0])
end
buff = ""

View File

@ -22,7 +22,7 @@ module Rex
# the regex the first time it is used and never check again. Since we
# want to know how many to capture on every instance, we do it this
# way.
return str.unpack('H*')[0].gsub(Regexp.new(".{#{count * 2}}", nil, 'n')) { |s| prefix + s }
return str.unpack('H*')[0].gsub(Regexp.new(".{#{count * 2}}", Regexp::NOENCODING)) { |s| prefix + s }
end
#
@ -40,7 +40,7 @@ module Rex
# their escaped hex representation
def self.to_hex_ascii(str, prefix = "\\x", count = 1, suffix=nil)
raise ::RuntimeError, "unable to chunk into #{count} byte chunks" if ((str.length % count) > 0)
return str.unpack('H*')[0].gsub(Regexp.new(".{#{count * 2}}", nil, 'n')) { |s|
return str.unpack('H*')[0].gsub(Regexp.new(".{#{count * 2}}", Regexp::NOENCODING)) { |s|
(0x20..0x7e) === s.to_i(16) ? s.to_i(16).chr : prefix + s + suffix.to_s
}
end

View File

@ -0,0 +1,24 @@
require 'spec_helper'
describe Rex::Text do
describe '.to_dword' do
[
{ input: '', expected: "\r\n" },
{ input: 'a', expected: "0x00000061\r\n" },
{ input: 'ab', expected: "0x00006261\r\n" },
{ input: 'abc', expected: "0x00636261\r\n" },
{ input: 'abcd', expected: "0x64636261\r\n" },
{ input: 'abcde', expected: "0x64636261, 0x00000065\r\n" },
{ input: 'abcdef', expected: "0x64636261, 0x00006665\r\n" },
{ input: 'abcdefg', expected: "0x64636261, 0x00676665\r\n" },
{ input: 'abcdefgh', expected: "0x64636261, 0x68676665\r\n" },
{ input: 'abcdefghi', expected: "0x64636261, 0x68676665, 0x00000069\r\n" },
{ input: ('a'..'z').to_a.join, expected: "0x64636261, 0x68676665, 0x6c6b6a69, 0x706f6e6d, 0x74737271, 0x78777675, 0x00007a79\r\n" },
{ input: "这是中文".force_encoding("UTF-8"), expected: "0xe699bfe8, 0xb8e4af98, 0x8796e6ad\r\n" }
].each do |test|
it "returns the expected output when the input is #{test[:input]}" do
expect(described_class.to_dword(test[:input])).to eq test[:expected]
end
end
end
end