rex-text 0.2.46 → 0.2.48

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: 95af94249afe1b19de73e1090346169a280f87a8d3519838983630fb7e1cf69d
4
- data.tar.gz: '06227846a02fc5b531e89b8114e17611a474ae231e3913adc1c2de72b53343c6'
3
+ metadata.gz: 4e3ab248f34fa3b7917bad07015868aebb7e91af8af1a210fa90cb89da7b8edc
4
+ data.tar.gz: 853d7652f999e24504754ad1416faed2a68377c0c29e4d74ff1189b2c7194f01
5
5
  SHA512:
6
- metadata.gz: da78d18313b0d2c43819df1c2f812fe4e0b90ba8d1b47f8ab8beabe1025014e77c1c4651b9c9e25047bfdd52b7260ac872727dc0dd6d157129ade62d62c86aee
7
- data.tar.gz: 92ee63cde2940b9eafe27264087f97210dfdd368754f4c84905c4b941590b0c28083c01b6b5f22d3110de8d9b2bb78f6dd42255432e762af07c95bffb3da215a
6
+ metadata.gz: 5d49ba31b089bc450704c14d0d93f5b2a5c40519c4d324474fa6f8c27faacb8808f71c9f36f9c8baa519084b9f20e39b9569868504d061c422fa65fc3ed1e94e
7
+ data.tar.gz: a11d6dbc2323b7e9e0aa92aa7bbdf8b67a2cbc1329ff637e4a4cfd047191ea347c58ae40bb6a5f0a4cfc614cf6e7c3561e9de629c1172e18c930534cdf5a7f25
checksums.yaml.gz.sig CHANGED
Binary file
@@ -33,15 +33,16 @@ jobs:
33
33
  fail-fast: true
34
34
  matrix:
35
35
  ruby:
36
- - 2.7
37
- - 3.0
38
- - 3.1
36
+ - '2.7'
37
+ - '3.0'
38
+ - '3.1'
39
+ - '3.2'
39
40
  os:
40
41
  - ubuntu-20.04
41
42
  - ubuntu-latest
42
43
  exclude:
43
- - { os: ubuntu-latest, ruby: 2.7 }
44
- - { os: ubuntu-latest, ruby: 3.0 }
44
+ - { os: ubuntu-latest, ruby: '2.7' }
45
+ - { os: ubuntu-latest, ruby: '3.0' }
45
46
  test_cmd:
46
47
  - bundle exec rspec
47
48
 
data/lib/rex/text/hex.rb CHANGED
@@ -127,22 +127,13 @@ module Rex
127
127
  # Converts a string to a hex version with wrapping support
128
128
  #
129
129
  def self.hexify(str, col = DefaultWrap, line_start = '', line_end = '', buf_start = '', buf_end = '')
130
- if col < line_start.length + 4 + line_end.length
131
- # raise an exception
132
- raise ArgumentError.new('insufficient column width')
133
- end
130
+ self.hexify_general(str, "\\x", col, line_start, line_end, buf_start, buf_end)
131
+ end
134
132
 
135
- ret = buf_start.dup
136
- ret << line_start if ret.end_with?("\n")
137
- str.each_char do |char|
138
- # "\x##".length is 4, check if we're going over the wrap boundary
139
- if (ret.split("\n").last || '').length + 4 + line_end.length > col
140
- ret << "#{line_end}\n#{line_start}"
141
- end
142
- ret << "\\x" << char.unpack('H*')[0]
143
- end
144
- ret << "\n" if ret.split("\n").last.length + buf_end.length > col
145
- ret << "#{buf_end}\n"
133
+ #
134
+ # Converts a string to hex, with each character prefixed with 0x; with wrapping support
135
+ def self.numhexify(str, col = DefaultWrap, line_start = '', line_end = '', buf_start = '', buf_end = '', between = '')
136
+ self.hexify_general(str, "0x", col, line_start, line_end, buf_start, buf_end, between)
146
137
  end
147
138
 
148
139
  #
@@ -175,5 +166,35 @@ module Rex
175
166
  str.gsub!(regex) { |x| x[2,2].to_i(16).chr }
176
167
  end
177
168
 
169
+ private
170
+
171
+ #
172
+ # General-case method to handle both "\xAA\xBB\xCC" format and 0xAA,0xBB,0xCC format
173
+ #
174
+ def self.hexify_general(str, char_prefix, col = DefaultWrap, line_start = '', line_end = '', buf_start = '', buf_end = '', between='')
175
+ encoded_char_length = 2 + char_prefix.length + between.length
176
+ if col < line_start.length + encoded_char_length + line_end.length
177
+ # raise an exception
178
+ raise ArgumentError.new('insufficient column width')
179
+ end
180
+
181
+ ret = buf_start.dup
182
+ ret << line_start if ret.end_with?("\n")
183
+ last_newline = ret.rindex("\n") || -1
184
+ last_line_length = ret.length - last_newline - 1
185
+ str.each_char do |char|
186
+ # Check if we're going over the wrap boundary
187
+ if last_line_length + encoded_char_length + line_end.length > col
188
+ ret << "#{line_end}\n#{line_start}"
189
+ last_line_length = line_start.length
190
+ end
191
+ ret << char_prefix << char.unpack('H*')[0] << between
192
+ last_line_length += encoded_char_length
193
+ end
194
+ # Remove the last in-between characters, if required
195
+ ret = ret[0..ret.length - 1 - between.length] unless str.empty?
196
+ ret << "\n" if last_line_length + buf_end.length > col
197
+ ret << "#{buf_end}\n"
198
+ end
178
199
  end
179
200
  end
data/lib/rex/text/lang.rb CHANGED
@@ -28,30 +28,14 @@ module Rex
28
28
  end
29
29
 
30
30
  def self.to_csharp(str, wrap = DefaultWrap, name = "buf")
31
- ret = "byte[] #{name} = new byte[#{str.length}] {"
32
- str.each_char do |char|
33
- # "0x##,".length is 5, check if we're going over the wrap boundary
34
- ret << "\n" if ret.split("\n").last.length + 5 > wrap
35
- ret << "0x" << char.unpack('H*')[0] << ","
36
- end
37
- ret = ret[0..ret.length - 2] unless str.empty? # cut off last comma
38
- ret << "\n" if ret.split("\n").last.length + 2 > wrap
39
- ret << "};\n"
31
+ return numhexify(str, wrap, '', '', "byte[] #{name} = new byte[#{str.length}] {", "};", ',')
40
32
  end
41
33
 
42
34
  #
43
35
  # Converts to a golang style array of bytes
44
36
  #
45
37
  def self.to_golang(str, wrap = DefaultWrap, name = "buf")
46
- ret = "#{name} := []byte{"
47
- str.each_char do |char|
48
- # "0x##,".length is 5, check if we're going over the wrap boundary
49
- ret << "\n" if ret.split("\n").last.length + 5 > wrap
50
- ret << "0x" << char.unpack('H*')[0] << ","
51
- end
52
- ret = ret[0..ret.length - 2] unless str.empty? # cut off last comma
53
- ret << "\n" if ret.split("\n").last.length + 2 > wrap
54
- ret << "};\n"
38
+ return numhexify(str, wrap, '', '', "#{name} := []byte{", "};", ',')
55
39
  end
56
40
 
57
41
  #
@@ -66,17 +50,7 @@ module Rex
66
50
  #
67
51
  def self.to_nim(str, wrap = DefaultWrap, name = "buf")
68
52
  raise ArgumentError.new('str can not be empty') if str.empty?
69
-
70
- ret = "var #{name}: array[#{str.length}, byte] = [\n"
71
- ret << "byte "
72
- str.each_char do |char|
73
- # "0x##,".length is 5, check if we're going over the wrap boundary
74
- ret << "\n" if ret.split("\n").last.length + 5 > wrap
75
- ret << "0x" << char.unpack('H*')[0] << ","
76
- end
77
- ret = ret[0..ret.length - 2] unless str.empty? # cut off last comma
78
- ret << "\n" if ret.split("\n").last.length + 1 > wrap
79
- ret << "]\n"
53
+ return numhexify(str, wrap, '', '', "var #{name}: array[#{str.length}, byte] = [\nbyte ", "]", ',')
80
54
  end
81
55
 
82
56
  #
@@ -90,15 +64,7 @@ module Rex
90
64
  # Converts to a Rust style array of bytes
91
65
  #
92
66
  def self.to_rust(str, wrap = DefaultWrap, name = "buf")
93
- ret = "let #{name}: [u8; #{str.length}] = ["
94
- str.each_char do |char|
95
- # "0x##,".length is 5, check if we're going over the wrap boundary
96
- ret << "\n" if ret.split("\n").last.length + 5 > wrap
97
- ret << "0x" << char.unpack('H*')[0] << ","
98
- end
99
- ret = ret[0..ret.length - 2] unless str.empty? # cut off last comma
100
- ret << "\n" if ret.split("\n").last.length + 2 > wrap
101
- ret << "];\n"
67
+ return numhexify(str, wrap, '', '', "let #{name}: [u8; #{str.length}] = [", "];", ',')
102
68
  end
103
69
 
104
70
  #
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Text
3
- VERSION = "0.2.46"
3
+ VERSION = "0.2.48"
4
4
  end
5
5
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rex-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.46
4
+ version: 0.2.48
5
5
  platform: ruby
6
6
  authors:
7
7
  - Metasploit Hackers
@@ -93,7 +93,7 @@ cert_chain:
93
93
  EknWpNgVhohbot1lfVAMmIhdtOVaRVcQQixWPwprDj/ydB8ryDMDosIMcw+fkoXU
94
94
  9GJsSaSRRYQ9UUkVL27b64okU8D48m8=
95
95
  -----END CERTIFICATE-----
96
- date: 2022-10-31 00:00:00.000000000 Z
96
+ date: 2023-01-31 00:00:00.000000000 Z
97
97
  dependencies:
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rake
@@ -185,8 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  requirements: []
188
- rubyforge_project:
189
- rubygems_version: 2.7.10
188
+ rubygems_version: 3.3.26
190
189
  signing_key:
191
190
  specification_version: 4
192
191
  summary: Provides Text Manipulation Methods for Exploitation
metadata.gz.sig CHANGED
Binary file