rex-text 0.2.46 → 0.2.47

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95af94249afe1b19de73e1090346169a280f87a8d3519838983630fb7e1cf69d
4
- data.tar.gz: '06227846a02fc5b531e89b8114e17611a474ae231e3913adc1c2de72b53343c6'
3
+ metadata.gz: e6669fedd30c2456c0b6203cbe8dcfcdec690726fb1de674a601a4fea68166c7
4
+ data.tar.gz: a83499bb2a5e324dd71e58f7e62662a7ad937cbde461fd90d7ae4ce60995c1dc
5
5
  SHA512:
6
- metadata.gz: da78d18313b0d2c43819df1c2f812fe4e0b90ba8d1b47f8ab8beabe1025014e77c1c4651b9c9e25047bfdd52b7260ac872727dc0dd6d157129ade62d62c86aee
7
- data.tar.gz: 92ee63cde2940b9eafe27264087f97210dfdd368754f4c84905c4b941590b0c28083c01b6b5f22d3110de8d9b2bb78f6dd42255432e762af07c95bffb3da215a
6
+ metadata.gz: 37973a9f478fd2b849cf6af27cdeb979d9f8ad819f7971bc54b640f2c066ce6da42fb869724d85fb9f5f36391f835e1ce696871c5ec033d24bc983c32ed30e15
7
+ data.tar.gz: 3455a6a84bf2a28205c4a0647d86b264a1ad228f28ad2d7b04e2f295ac902b8554b28cae45c8666efbf0e5991cf2dce001fc1ef2f0b40a9892ac4435d05af55f
checksums.yaml.gz.sig CHANGED
Binary file
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.47"
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.47
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: 2022-12-12 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