rex-text 0.2.45 → 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: 35b8656aec1d2bd88d707649036693d4421362967f7602e1d18de3aae6e3ea57
4
- data.tar.gz: 974fe908dd1312fe9a0ccdaa3844b9a537e83e6f001afe5ae28dc153350e5261
3
+ metadata.gz: e6669fedd30c2456c0b6203cbe8dcfcdec690726fb1de674a601a4fea68166c7
4
+ data.tar.gz: a83499bb2a5e324dd71e58f7e62662a7ad937cbde461fd90d7ae4ce60995c1dc
5
5
  SHA512:
6
- metadata.gz: 7c3599bb12273e92655678f398595257fc357e0875e8c52ef109e16cb8861c226da817a901a3d884437e0ce2c051796005e297f5c2e33127e48c288e8d72f253
7
- data.tar.gz: 1cab334469f0ed24807b4d651c87b2c677ab9a9b46616822f3715326e8917bfd0716f157e92b6ae4169c9b98b5dfc89b57bab928834c7c34ebbe7f3495284073
6
+ metadata.gz: 37973a9f478fd2b849cf6af27cdeb979d9f8ad819f7971bc54b640f2c066ce6da42fb869724d85fb9f5f36391f835e1ce696871c5ec033d24bc983c32ed30e15
7
+ data.tar.gz: 3455a6a84bf2a28205c4a0647d86b264a1ad228f28ad2d7b04e2f295ac902b8554b28cae45c8666efbf0e5991cf2dce001fc1ef2f0b40a9892ac4435d05af55f
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- T3�vM��r�)��T�C������S���?�f��B-�/�5���13�� ,���oܚ���<[���9BaM��ϐ n5E�B@�H�o6EH�m���1[V�_*+������Z��q�"�M��Y
2
- '=�j��"����#�C��C6�Ԙ��3B~ߔ�4�ITK�{�,� �q�`��{یO���%N8_��ԎJ��֯G>�����ာ�kU J�����ϱWSvP��|�R��[�_�%N
1
+ Ya�����M�C�e
2
+ ͠`p�@�L��=E�[�����U���J���_�5M���s���"E��蟊���SR'Ƥ���z"��5My����ԓZ)1��[eRP�8�d��+�lTy ������b[�M��͞J�
3
+ ~�#�k[r��|�/��yq�ݓ�ߛ�N�
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
  #
@@ -86,6 +60,20 @@ module Rex
86
60
  return "#[\n" + wordwrap(str, 0, wrap, '', '') + "]#\n"
87
61
  end
88
62
 
63
+ #
64
+ # Converts to a Rust style array of bytes
65
+ #
66
+ def self.to_rust(str, wrap = DefaultWrap, name = "buf")
67
+ return numhexify(str, wrap, '', '', "let #{name}: [u8; #{str.length}] = [", "];", ',')
68
+ end
69
+
70
+ #
71
+ # Creates a Rust style comment
72
+ #
73
+ def self.to_rust_comment(str, wrap = DefaultWrap)
74
+ return "/*\n" + wordwrap(str, 0, wrap, '', ' * ') + " */\n"
75
+ end
76
+
89
77
  #
90
78
  # Creates a c-style comment
91
79
  #
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Text
3
- VERSION = "0.2.45"
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.45
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-09-06 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