rex-text 0.2.42 → 0.2.43
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 +4 -4
- checksums.yaml.gz.sig +3 -1
- data/lib/rex/text/hex.rb +13 -42
- data/lib/rex/text/lang.rb +16 -16
- data/lib/rex/text/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e65388b19aabaf76461efffee8b8b0b5c23265a5eff2f9adee5300a5664210c6
|
4
|
+
data.tar.gz: 4d697d31bf0464783450ff70494bb08f5d00e9186cea660e426e693bc6d025b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef32b2087d8fd1016e69a7584baf2a44999d661d8261468b5e8a462ee42523336b32b5e6dad59b6308b7fdac2b006d848e71bdb3b9c81798c7c70364f0d15ec6
|
7
|
+
data.tar.gz: 14edb8ce455acae1c6caaca90ee259dbc0d29df0b539440f8242c29e919ebc6ad8954d398c00166f74f7bf14b08e9ddb03b0a886e674447cb8b1c98ec30245a4
|
checksums.yaml.gz.sig
CHANGED
data/lib/rex/text/hex.rb
CHANGED
@@ -127,51 +127,22 @@ 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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
# Go through each byte in the string
|
136
|
-
str.each_byte { |byte|
|
137
|
-
count += 1
|
138
|
-
append = ''
|
139
|
-
|
140
|
-
# If this is a new line, prepend with the
|
141
|
-
# line start text
|
142
|
-
if (new_line == true)
|
143
|
-
append << line_start
|
144
|
-
new_line = false
|
145
|
-
end
|
146
|
-
|
147
|
-
# Append the hexified version of the byte
|
148
|
-
append << sprintf("\\x%.2x", byte)
|
149
|
-
cur += append.length
|
150
|
-
|
151
|
-
# If we're about to hit the column or have gone past it,
|
152
|
-
# time to finish up this line
|
153
|
-
if ((cur + line_end.length >= col) or (cur + buf_end.length >= col))
|
154
|
-
new_line = true
|
155
|
-
cur = 0
|
130
|
+
if col < line_start.length + 4 + line_end.length
|
131
|
+
# raise an exception
|
132
|
+
raise ArgumentError.new('insufficient column width')
|
133
|
+
end
|
156
134
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
end
|
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}"
|
164
141
|
end
|
165
|
-
|
166
|
-
output << append
|
167
|
-
}
|
168
|
-
|
169
|
-
# If we were in the middle of a line, finish the buffer at this point
|
170
|
-
if (new_line == false)
|
171
|
-
output << buf_end + "\n"
|
142
|
+
ret << "\\x" << char.unpack('H*')[0]
|
172
143
|
end
|
173
|
-
|
174
|
-
|
144
|
+
ret << "\n" if ret.split("\n").last.length + buf_end.length > col
|
145
|
+
ret << "#{buf_end}\n"
|
175
146
|
end
|
176
147
|
|
177
148
|
#
|
data/lib/rex/text/lang.rb
CHANGED
@@ -29,13 +29,14 @@ module Rex
|
|
29
29
|
|
30
30
|
def self.to_csharp(str, wrap = DefaultWrap, name = "buf")
|
31
31
|
ret = "byte[] #{name} = new byte[#{str.length}] {"
|
32
|
-
|
33
|
-
|
34
|
-
ret << "\n" if
|
35
|
-
ret << "0x" <<
|
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
36
|
end
|
37
|
-
ret = ret[0..ret.length-2] #cut off last comma
|
38
|
-
ret << "
|
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"
|
39
40
|
end
|
40
41
|
|
41
42
|
#
|
@@ -43,21 +44,21 @@ module Rex
|
|
43
44
|
#
|
44
45
|
def self.to_golang(str, wrap = DefaultWrap, name = "buf")
|
45
46
|
ret = "#{name} := []byte{"
|
46
|
-
|
47
|
-
|
48
|
-
ret << "\n" if
|
49
|
-
ret << "0x" <<
|
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] << ","
|
50
51
|
end
|
51
|
-
ret = ret[0..ret.length-
|
52
|
-
ret << "
|
53
|
-
|
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"
|
54
55
|
end
|
55
|
-
|
56
|
+
|
56
57
|
#
|
57
58
|
# Creates a golang style comment
|
58
59
|
#
|
59
60
|
def self.to_golang_comment(str, wrap = DefaultWrap)
|
60
|
-
return "/*\n" + wordwrap(str, 0, wrap, '', '') + "*/\n"
|
61
|
+
return "/*\n" + wordwrap(str, 0, wrap, '', '') + "*/\n"
|
61
62
|
end
|
62
63
|
|
63
64
|
#
|
@@ -181,6 +182,5 @@ module Rex
|
|
181
182
|
return wordwrap(str, 0, wrap, '', '# ')
|
182
183
|
end
|
183
184
|
|
184
|
-
|
185
185
|
end
|
186
186
|
end
|
data/lib/rex/text/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|