ronin-support 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +14 -0
  3. data/.rubocop.yml +109 -0
  4. data/ChangeLog.md +33 -1
  5. data/Gemfile +8 -4
  6. data/README.md +1 -1
  7. data/Rakefile +2 -2
  8. data/examples/ssl_proxy.rb +2 -1
  9. data/examples/tcp_proxy.rb +6 -4
  10. data/lib/ronin/support/archive/core_ext/file.rb +43 -0
  11. data/lib/ronin/support/archive/core_ext.rb +1 -1
  12. data/lib/ronin/support/archive/tar/writer.rb +2 -2
  13. data/lib/ronin/support/archive/tar.rb +4 -4
  14. data/lib/ronin/support/archive/zip/reader.rb +2 -2
  15. data/lib/ronin/support/binary/array.rb +5 -8
  16. data/lib/ronin/support/binary/bit_flip.rb +7 -1
  17. data/lib/ronin/support/binary/buffer.rb +25 -25
  18. data/lib/ronin/support/binary/byte_slice.rb +17 -17
  19. data/lib/ronin/support/binary/core_ext.rb +2 -0
  20. data/lib/ronin/support/binary/cstring.rb +50 -4
  21. data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +4 -0
  22. data/lib/ronin/support/binary/ctypes/arch/arm.rb +3 -0
  23. data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +4 -0
  24. data/lib/ronin/support/binary/ctypes/arch/arm64.rb +3 -0
  25. data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +4 -0
  26. data/lib/ronin/support/binary/ctypes/arch/mips.rb +3 -0
  27. data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +4 -0
  28. data/lib/ronin/support/binary/ctypes/arch/mips64.rb +3 -0
  29. data/lib/ronin/support/binary/ctypes/arch/ppc.rb +3 -0
  30. data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +3 -0
  31. data/lib/ronin/support/binary/ctypes/arch/x86.rb +3 -0
  32. data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +3 -0
  33. data/lib/ronin/support/binary/ctypes/array_type.rb +2 -2
  34. data/lib/ronin/support/binary/ctypes/big_endian.rb +3 -0
  35. data/lib/ronin/support/binary/ctypes/enum_type.rb +2 -2
  36. data/lib/ronin/support/binary/ctypes/little_endian.rb +3 -0
  37. data/lib/ronin/support/binary/ctypes/native.rb +3 -0
  38. data/lib/ronin/support/binary/ctypes/os/bsd.rb +1 -1
  39. data/lib/ronin/support/binary/ctypes/scalar_type.rb +2 -2
  40. data/lib/ronin/support/binary/ctypes/struct_type.rb +3 -3
  41. data/lib/ronin/support/binary/ctypes/type_resolver.rb +7 -8
  42. data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +2 -2
  43. data/lib/ronin/support/binary/ctypes/union_type.rb +3 -3
  44. data/lib/ronin/support/binary/ctypes.rb +3 -3
  45. data/lib/ronin/support/binary/memory.rb +2 -2
  46. data/lib/ronin/support/binary/packet.rb +80 -0
  47. data/lib/ronin/support/binary/stack.rb +6 -7
  48. data/lib/ronin/support/binary/struct/member.rb +5 -3
  49. data/lib/ronin/support/binary/struct.rb +81 -79
  50. data/lib/ronin/support/binary/template.rb +2 -5
  51. data/lib/ronin/support/binary/unhexdump/parser.rb +11 -11
  52. data/lib/ronin/support/binary/union.rb +22 -22
  53. data/lib/ronin/support/binary.rb +1 -0
  54. data/lib/ronin/support/cli/ansi.rb +0 -1
  55. data/lib/ronin/support/cli/io_shell/core_ext/io.rb +1 -1
  56. data/lib/ronin/support/cli/io_shell.rb +4 -4
  57. data/lib/ronin/support/cli/printing.rb +3 -3
  58. data/lib/ronin/support/compression/core_ext/file.rb +16 -0
  59. data/lib/ronin/support/compression/zlib.rb +1 -1
  60. data/lib/ronin/support/core_ext/enumerable.rb +0 -2
  61. data/lib/ronin/support/core_ext/file.rb +1 -1
  62. data/lib/ronin/support/core_ext/kernel.rb +6 -9
  63. data/lib/ronin/support/core_ext/string.rb +2 -2
  64. data/lib/ronin/support/crypto/cert.rb +11 -15
  65. data/lib/ronin/support/crypto/cert_chain.rb +1 -1
  66. data/lib/ronin/support/crypto/cipher/aes.rb +3 -0
  67. data/lib/ronin/support/crypto/cipher/aes128.rb +4 -1
  68. data/lib/ronin/support/crypto/cipher/aes256.rb +4 -1
  69. data/lib/ronin/support/crypto/cipher.rb +1 -1
  70. data/lib/ronin/support/crypto/core_ext/file.rb +33 -1
  71. data/lib/ronin/support/crypto/core_ext/string.rb +34 -2
  72. data/lib/ronin/support/crypto/key/methods.rb +4 -1
  73. data/lib/ronin/support/crypto/key.rb +5 -2
  74. data/lib/ronin/support/crypto/openssl.rb +1 -1
  75. data/lib/ronin/support/crypto.rb +0 -1
  76. data/lib/ronin/support/encoding/base16.rb +2 -2
  77. data/lib/ronin/support/encoding/base32.rb +29 -18
  78. data/lib/ronin/support/encoding/c/core_ext/integer.rb +1 -1
  79. data/lib/ronin/support/encoding/c/core_ext/string.rb +1 -1
  80. data/lib/ronin/support/encoding/c.rb +6 -6
  81. data/lib/ronin/support/encoding/core_ext/string.rb +2 -2
  82. data/lib/ronin/support/encoding/hex/core_ext/string.rb +1 -1
  83. data/lib/ronin/support/encoding/hex.rb +4 -4
  84. data/lib/ronin/support/encoding/js/core_ext/integer.rb +1 -1
  85. data/lib/ronin/support/encoding/js.rb +5 -5
  86. data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +2 -2
  87. data/lib/ronin/support/encoding/powershell.rb +5 -6
  88. data/lib/ronin/support/encoding/quoted_printable.rb +3 -1
  89. data/lib/ronin/support/encoding/ruby.rb +5 -5
  90. data/lib/ronin/support/encoding/shell/core_ext/integer.rb +2 -2
  91. data/lib/ronin/support/encoding/shell.rb +3 -3
  92. data/lib/ronin/support/encoding/sql.rb +1 -1
  93. data/lib/ronin/support/encoding/uuencoding.rb +3 -1
  94. data/lib/ronin/support/encoding/xml.rb +3 -3
  95. data/lib/ronin/support/encoding.rb +95 -0
  96. data/lib/ronin/support/network/asn/list.rb +6 -1
  97. data/lib/ronin/support/network/asn/record.rb +3 -0
  98. data/lib/ronin/support/network/asn/record_set.rb +3 -0
  99. data/lib/ronin/support/network/asn.rb +167 -6
  100. data/lib/ronin/support/network/dns/mixin.rb +2 -10
  101. data/lib/ronin/support/network/dns/resolver.rb +3 -0
  102. data/lib/ronin/support/network/domain.rb +21 -21
  103. data/lib/ronin/support/network/email_address.rb +1 -5
  104. data/lib/ronin/support/network/esmtp/mixin.rb +1 -0
  105. data/lib/ronin/support/network/ftp/mixin.rb +1 -1
  106. data/lib/ronin/support/network/host.rb +75 -47
  107. data/lib/ronin/support/network/http/core_ext/uri/http.rb +8 -0
  108. data/lib/ronin/support/network/http/core_ext.rb +1 -1
  109. data/lib/ronin/support/network/http.rb +317 -80
  110. data/lib/ronin/support/network/ip.rb +49 -23
  111. data/lib/ronin/support/network/ip_range/cidr.rb +1 -5
  112. data/lib/ronin/support/network/ip_range/glob.rb +1 -0
  113. data/lib/ronin/support/network/ip_range/range.rb +1 -1
  114. data/lib/ronin/support/network/ip_range.rb +5 -7
  115. data/lib/ronin/support/network/proxy.rb +4 -4
  116. data/lib/ronin/support/network/public_suffix/list.rb +10 -8
  117. data/lib/ronin/support/network/public_suffix/suffix_set.rb +3 -0
  118. data/lib/ronin/support/network/public_suffix.rb +9 -4
  119. data/lib/ronin/support/network/smtp/email.rb +0 -9
  120. data/lib/ronin/support/network/smtp/mixin.rb +2 -2
  121. data/lib/ronin/support/network/ssl/local_cert.rb +1 -3
  122. data/lib/ronin/support/network/ssl/mixin.rb +13 -13
  123. data/lib/ronin/support/network/ssl/openssl.rb +1 -1
  124. data/lib/ronin/support/network/ssl/proxy.rb +14 -16
  125. data/lib/ronin/support/network/ssl.rb +4 -2
  126. data/lib/ronin/support/network/tcp/proxy.rb +3 -3
  127. data/lib/ronin/support/network/tcp.rb +10 -12
  128. data/lib/ronin/support/network/telnet/mixin.rb +14 -14
  129. data/lib/ronin/support/network/tld/list.rb +2 -1
  130. data/lib/ronin/support/network/tld.rb +7 -4
  131. data/lib/ronin/support/network/tls/proxy.rb +1 -1
  132. data/lib/ronin/support/network/tls.rb +0 -2
  133. data/lib/ronin/support/network/udp/proxy.rb +5 -5
  134. data/lib/ronin/support/network/udp.rb +14 -16
  135. data/lib/ronin/support/path.rb +4 -4
  136. data/lib/ronin/support/text/erb/mixin.rb +3 -0
  137. data/lib/ronin/support/text/homoglyph/core_ext/string.rb +33 -0
  138. data/lib/ronin/support/text/homoglyph/table.rb +3 -3
  139. data/lib/ronin/support/text/patterns/credentials.rb +2 -2
  140. data/lib/ronin/support/text/patterns/crypto.rb +1 -1
  141. data/lib/ronin/support/text/patterns/file_system.rb +3 -4
  142. data/lib/ronin/support/text/patterns/network.rb +21 -21
  143. data/lib/ronin/support/text/patterns/numeric.rb +1 -1
  144. data/lib/ronin/support/text/patterns/source_code.rb +2 -2
  145. data/lib/ronin/support/text/random/mixin.rb +17 -17
  146. data/lib/ronin/support/text/random.rb +25 -25
  147. data/lib/ronin/support/text/typo/core_ext/string.rb +24 -0
  148. data/lib/ronin/support/text/typo/generator.rb +2 -2
  149. data/lib/ronin/support/version.rb +1 -1
  150. data/ronin-support.gemspec +6 -5
  151. metadata +3 -2
@@ -24,6 +24,9 @@ require 'ronin/support/crypto/key/rsa'
24
24
  module Ronin
25
25
  module Support
26
26
  module Crypto
27
+ #
28
+ # Top-level methods for working with public/private keys.
29
+ #
27
30
  module Key
28
31
  #
29
32
  # Parses an PEM encoded key.
@@ -42,7 +45,7 @@ module Ronin
42
45
  #
43
46
  # @raise [ArgumentError]
44
47
  # The key type could not be determined from the key file.
45
- #
48
+ #
46
49
  # @api public
47
50
  #
48
51
  def self.parse(key, password: nil)
@@ -93,7 +96,7 @@ module Ronin
93
96
  #
94
97
  # @raise [ArgumentError]
95
98
  # The key type could not be determined from the key file.
96
- #
99
+ #
97
100
  # @api public
98
101
  #
99
102
  def self.load_file(path)
@@ -18,6 +18,6 @@
18
18
 
19
19
  begin
20
20
  require 'openssl'
21
- rescue ::LoadError
21
+ rescue LoadError
22
22
  warn "WARNING: Ruby was not compiled with OpenSSL support"
23
23
  end
@@ -656,7 +656,6 @@ module Ronin
656
656
  when Key::RSA then key
657
657
  when OpenSSL::PKey::RSA then Key::RSA.new(key)
658
658
  when String then Key::RSA.load(key, password: password)
659
- else
660
659
  end
661
660
  else
662
661
  raise(ArgumentError,"either key: or key_file: keyword arguments must be given")
@@ -51,7 +51,7 @@ module Ronin
51
51
  encoded = String.new
52
52
 
53
53
  data.each_byte do |byte|
54
- encoded << "%.2x" % byte
54
+ encoded << ("%.2x" % byte)
55
55
  end
56
56
 
57
57
  return encoded
@@ -71,7 +71,7 @@ module Ronin
71
71
  # # => "hello"
72
72
  #
73
73
  def self.decode(data)
74
- decoded = String.new
74
+ decoded = String.new(encoding: Encoding::ASCII_8BIT)
75
75
 
76
76
  data.scan(/../).each do |hex_char|
77
77
  decoded << hex_char.to_i(16).chr
@@ -63,7 +63,7 @@ module Ronin
63
63
  # The Base32 decoded String.
64
64
  #
65
65
  def self.decode(data)
66
- decoded = String.new
66
+ decoded = String.new(encoding: Encoding::UTF_8)
67
67
 
68
68
  each_chunk(data,8) do |chunk|
69
69
  chunk.decode(decoded)
@@ -72,14 +72,16 @@ module Ronin
72
72
  return decoded
73
73
  end
74
74
 
75
- private
76
-
77
75
  # Base32 alphabet
76
+ #
77
+ # @api private
78
78
  TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
79
79
 
80
80
  #
81
81
  # Represents a chunk of data.
82
82
  #
83
+ # @api private
84
+ #
83
85
  class Chunk
84
86
 
85
87
  #
@@ -103,8 +105,13 @@ module Ronin
103
105
  #
104
106
  def decode(output=String.new)
105
107
  bytes = @bytes.take_while { |b| b != 61 } # strip padding
106
- n = (bytes.length * 5.0 / 8.0).floor
107
- p = bytes.length < 8 ? 5 - (n * 8) % 5 : 0
108
+
109
+ n = ((bytes.length * 5.0) / 8.0).floor
110
+ p = if bytes.length < 8
111
+ 5 - ((n * 8) % 5)
112
+ else
113
+ 0
114
+ end
108
115
  c = bytes.reduce(0) { |m,o|
109
116
  unless (i = Base32::TABLE.index(o.chr))
110
117
  raise ArgumentError, "invalid character '#{o.chr}'"
@@ -113,8 +120,8 @@ module Ronin
113
120
  (m << 5) + i
114
121
  } >> p
115
122
 
116
- (0..n-1).reverse_each.each do |i|
117
- output << ((c >> i * 8) & 0xff).chr
123
+ (0..(n - 1)).reverse_each do |i|
124
+ output << ((c >> (i * 8)) & 0xff).chr
118
125
  end
119
126
 
120
127
  return output
@@ -130,15 +137,19 @@ module Ronin
130
137
  # The Base32 encoded chunk.
131
138
  #
132
139
  def encode(output=String.new)
133
- n = (@bytes.length * 8.0 / 5.0).ceil
134
- p = n < 8 ? 5 - (@bytes.length * 8) % 5 : 0
135
- c = @bytes.inject(0) {|m,o| (m << 8) + o} << p
136
-
137
- (0..n-1).reverse_each do |i|
138
- output << Base32::TABLE[(c >> i * 5) & 0x1f].chr
140
+ n = ((@bytes.length * 8.0) / 5.0).ceil
141
+ p = if n < 8
142
+ 5 - ((@bytes.length * 8) % 5)
143
+ else
144
+ 0
145
+ end
146
+ c = @bytes.inject(0) { |m,o| (m << 8) + o } << p
147
+
148
+ (0..(n - 1)).reverse_each do |i|
149
+ output << Base32::TABLE[(c >> (i * 5)) & 0x1f].chr
139
150
  end
140
151
 
141
- return output << ("=" * (8-n))
152
+ return output << ("=" * (8 - n))
142
153
  end
143
154
 
144
155
  end
@@ -154,11 +165,11 @@ module Ronin
154
165
  #
155
166
  # @yieldparam [Chunk] chunk
156
167
  #
168
+ # @api private
169
+ #
157
170
  def self.each_chunk(data,size)
158
- bytes = data.bytes
159
-
160
- data.bytes.each_slice(size) do |bytes|
161
- yield Chunk.new(bytes)
171
+ data.bytes.each_slice(size) do |byte_slice|
172
+ yield Chunk.new(byte_slice)
162
173
  end
163
174
  end
164
175
  end
@@ -29,7 +29,7 @@ class Integer
29
29
  # @raise [RangeError]
30
30
  # The integer value is negative.
31
31
  #
32
- # @example
32
+ # @example
33
33
  # 0x41.c_escape
34
34
  # # => "A"
35
35
  # 0x22.c_escape
@@ -47,7 +47,7 @@ class String
47
47
  # The unescaped C String.
48
48
  #
49
49
  # @example
50
- # "\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64".c_unescape
50
+ # "\\x68\\x65\\x6c\\x6c\\x6f\\x20\\x77\\x6f\\x72\\x6c\\x64".c_unescape
51
51
  # # => "hello world"
52
52
  #
53
53
  # @see Ronin::Support::Encoding::C.unescape
@@ -93,7 +93,7 @@ module Ronin
93
93
  # @raise [RangeError]
94
94
  # The integer value is negative.
95
95
  #
96
- # @example
96
+ # @example
97
97
  # Encoding::C.escape_byte(0x41)
98
98
  # # => "A"
99
99
  # Encoding::C.escape_byte(0x22)
@@ -213,21 +213,21 @@ module Ronin
213
213
  # The unescaped C String.
214
214
  #
215
215
  # @example
216
- # Encoding::C.unescape("\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64")
216
+ # Encoding::C.unescape("\\x68\\x65\\x6c\\x6c\\x6f\\x20\\x77\\x6f\\x72\\x6c\\x64")
217
217
  # # => "hello world"
218
218
  #
219
219
  def self.unescape(data)
220
- unescaped = String.new
220
+ unescaped = String.new(encoding: Encoding::UTF_8)
221
221
  scanner = StringScanner.new(data)
222
222
 
223
223
  until scanner.eos?
224
224
  unescaped << case (char = scanner.getch)
225
225
  when "\\" # backslash
226
- if (hex_char = scanner.scan(/x[0-9a-fA-F]{1,2}/)) # \xXX
226
+ if (hex_char = scanner.scan(/x[0-9a-fA-F]{1,2}/)) # \xXX
227
227
  hex_char[1..].to_i(16).chr
228
- elsif (hex_char = scanner.scan(/u[0-9a-fA-F]{4,8}/)) # \u..
228
+ elsif (hex_char = scanner.scan(/u[0-9a-fA-F]{4,8}/)) # \u..
229
229
  hex_char[1..].to_i(16).chr(Encoding::UTF_8)
230
- elsif (octal_char = scanner.scan(/[0-7]{1,3}/)) # \N, \NN, or \NNN
230
+ elsif (octal_char = scanner.scan(/[0-7]{1,3}/)) # \N, \NN, or \NNN
231
231
  octal_char.to_i(8).chr
232
232
  elsif (special_char = scanner.getch) # \[A-Za-z]
233
233
  BACKSLASHED_CHARS.fetch(special_char,special_char)
@@ -48,7 +48,7 @@ class String
48
48
  def encode_bytes(include: nil, exclude: nil)
49
49
  included = (Chars::CharSet.new(*include) if include)
50
50
  excluded = (Chars::CharSet.new(*exclude) if exclude)
51
- formatted = String.new
51
+ formatted = String.new(encoding: ::Encoding::UTF_8)
52
52
 
53
53
  each_byte do |b|
54
54
  formatted << if (included.nil? || included.include_byte?(b)) &&
@@ -90,7 +90,7 @@ class String
90
90
  def encode_chars(include: nil, exclude: nil)
91
91
  included = (Chars::CharSet.new(*include) if include)
92
92
  excluded = (Chars::CharSet.new(*exclude) if exclude)
93
- formatted = String.new
93
+ formatted = String.new(encoding: ::Encoding::UTF_8)
94
94
 
95
95
  each_char do |c|
96
96
  formatted << if (included.nil? || included.include_char?(c)) &&
@@ -79,7 +79,7 @@ class String
79
79
  # The hex unescaped version of the String.
80
80
  #
81
81
  # @example
82
- # "hello\\nworld".hex_escape
82
+ # "hello\\nworld".hex_unescape
83
83
  # # => "hello\nworld"
84
84
  #
85
85
  # @see Ronin::Support::Encoding::Hex.unescape
@@ -188,21 +188,21 @@ module Ronin
188
188
  # the same String if it is not quoted.
189
189
  #
190
190
  # @example
191
- # Encoding::Hex.unescape("\"hello\\nworld\"")
191
+ # Encoding::Hex.unescape("hello\\nworld")
192
192
  # # => "hello\nworld"
193
193
  #
194
194
  def self.unescape(data)
195
- buffer = String.new
195
+ buffer = String.new(encoding: Encoding::UTF_8)
196
196
  scanner = StringScanner.new(data)
197
197
 
198
198
  until scanner.eos?
199
199
  buffer << case (char = scanner.getch)
200
200
  when '\\'
201
- if (hex_escape = scanner.scan(/x[0-9a-fA-F]{4,8}/))
201
+ if (hex_escape = scanner.scan(/x[0-9a-fA-F]{4,8}/))
202
202
  hex_escape[1..].to_i(16).chr(Encoding::UTF_8)
203
203
  elsif (hex_escape = scanner.scan(/x[0-9a-fA-F]{1,2}/))
204
204
  hex_escape[1..].to_i(16).chr
205
- elsif (char = scanner.getch)
205
+ elsif (char = scanner.getch)
206
206
  BACKSLASHED_CHARS.fetch(char,char)
207
207
  end
208
208
  else
@@ -26,7 +26,7 @@ class Integer
26
26
  # @return [String]
27
27
  # The escaped JavaScript character.
28
28
  #
29
- # @example
29
+ # @example
30
30
  # 0x41.js_escape
31
31
  # # => "A"
32
32
  # 0x22.js_escape
@@ -86,7 +86,7 @@ module Ronin
86
86
  # @return [String]
87
87
  # The escaped JavaScript character.
88
88
  #
89
- # @example
89
+ # @example
90
90
  # Encoding::JS.escape_byte(0x41)
91
91
  # # => "A"
92
92
  # Encoding::JS.escape_byte(0x22)
@@ -135,7 +135,7 @@ module Ronin
135
135
  "\\f" => "\f",
136
136
  "\\r" => "\r",
137
137
  "\\\"" => "\"",
138
- "\\\'" => "'",
138
+ "\\'" => "'",
139
139
  "\\\\" => "\\"
140
140
  }
141
141
 
@@ -182,14 +182,14 @@ module Ronin
182
182
  # # => "hello world"
183
183
  #
184
184
  def self.unescape(data)
185
- unescaped = String.new
185
+ unescaped = String.new(encoding: Encoding::UTF_8)
186
186
 
187
187
  data.scan(/[\\%]u[0-9a-fA-F]{1,4}|[\\%][0-9a-fA-F]{1,2}|\\[btnfr\'\"\\]|./) do |c|
188
188
  unescaped << BACKSLASHED_CHARS.fetch(c) do
189
189
  if (c.start_with?("\\u") || c.start_with?("%u"))
190
- c[2..-1].to_i(16)
190
+ c[2..].to_i(16)
191
191
  elsif (c.start_with?("\\") || c.start_with?("%"))
192
- c[1..-1].to_i(16)
192
+ c[1..].to_i(16)
193
193
  else
194
194
  c
195
195
  end
@@ -29,7 +29,7 @@ class Integer
29
29
  # @raise [RangeError]
30
30
  # The integer value is negative.
31
31
  #
32
- # @example
32
+ # @example
33
33
  # 0x41.powershell_encode
34
34
  # # => "[char]0x41"
35
35
  # 0x0a.powershell_encode
@@ -60,7 +60,7 @@ class Integer
60
60
  # @raise [RangeError]
61
61
  # The integer value is negative.
62
62
  #
63
- # @example
63
+ # @example
64
64
  # 0x41.powershell_escape
65
65
  # # => "A"
66
66
  # 0x08.powershell_escape
@@ -68,7 +68,7 @@ module Ronin
68
68
  # @raise [RangeError]
69
69
  # The integer value is negative.
70
70
  #
71
- # @example
71
+ # @example
72
72
  # Encoding::PowerShell.encode_byte(0x41)
73
73
  # # => "[char]0x41"
74
74
  # Encoding::PowerShell.encode_byte(0x0a)
@@ -100,7 +100,7 @@ module Ronin
100
100
  # @raise [RangeError]
101
101
  # The integer value is negative.
102
102
  #
103
- # @example
103
+ # @example
104
104
  # Encoding::PowerShell.escape_byte(0x41)
105
105
  # # => "A"
106
106
  # Encoding::PowerShell.escape_byte(0x08)
@@ -191,15 +191,15 @@ module Ronin
191
191
  # # => "hello\nworld"
192
192
  #
193
193
  def self.unescape(data)
194
- unescaped = String.new
194
+ unescaped = String.new(encoding: Encoding::UTF_8)
195
195
  scanner = StringScanner.new(data)
196
196
 
197
197
  until scanner.eos?
198
198
  unescaped << if (backslash_char = scanner.scan(/`[0abetnvfr]/)) # `c
199
199
  BACKSLASHED_CHARS[backslash_char[1,1]]
200
- elsif (hex_char = scanner.scan(/\$\(\[char\]0x[0-9a-fA-F]{1,2}\)/)) # [char]0xXX
200
+ elsif (hex_char = scanner.scan(/\$\(\[char\]0x[0-9a-fA-F]{1,2}\)/)) # [char]0xXX
201
201
  hex_char[10..-2].to_i(16).chr
202
- elsif (hex_char = scanner.scan(/\$\(\[char\]0x[0-9a-fA-F]{3,}\)/)) # [char]0xXX
202
+ elsif (hex_char = scanner.scan(/\$\(\[char\]0x[0-9a-fA-F]{3,}\)/)) # [char]0xXX
203
203
  hex_char[10..-2].to_i(16).chr(Encoding::UTF_8)
204
204
  elsif (unicode_char = scanner.scan(/`u\{[0-9a-fA-F]+\}/)) # `u{XXXX}'
205
205
  unicode_char[3..-2].to_i(16).chr(Encoding::UTF_8)
@@ -299,7 +299,6 @@ module Ronin
299
299
  data
300
300
  end
301
301
  end
302
-
303
302
  end
304
303
  end
305
304
  end
@@ -22,7 +22,9 @@ module Ronin
22
22
  module Support
23
23
  class Encoding < ::Encoding
24
24
  #
25
- # Contains methods for encoding/decoding Quoted Printable data.
25
+ # Contains methods for encoding/decoding [Quoted Printable] data.
26
+ #
27
+ # [Quoted-Printable]: https://en.wikipedia.org/wiki/Quoted-printable
26
28
  #
27
29
  # ## Core-Ext Methods
28
30
  #
@@ -150,6 +150,7 @@ module Ronin
150
150
  else char
151
151
  end
152
152
  end
153
+
153
154
  UNESCAPE_CHARS['\0'] = "\0"
154
155
  UNESCAPE_CHARS['\a'] = "\a"
155
156
  UNESCAPE_CHARS['\b'] = "\b"
@@ -173,17 +174,17 @@ module Ronin
173
174
  # # => "hello"
174
175
  #
175
176
  def self.unescape(data)
176
- unescaped = String.new
177
+ unescaped = String.new(encoding: Encoding::UTF_8)
177
178
  scanner = StringScanner.new(data)
178
179
 
179
180
  until scanner.eos?
180
181
  unescaped << if (unicode_escape = scanner.scan(/\\(?:[0-7]{1,3}|[0-7])/))
181
182
  unicode_escape[1,3].to_i(8).chr
182
183
  elsif (hex_escape = scanner.scan(/\\u[0-9a-fA-F]{4,8}/))
183
- hex_escape[2..-1].to_i(16).chr(Encoding::UTF_8)
184
+ hex_escape[2..].to_i(16).chr(Encoding::UTF_8)
184
185
  elsif (hex_escape = scanner.scan(/\\x[0-9a-fA-F]{1,2}/))
185
- hex_escape[2..-1].to_i(16).chr
186
- elsif (escape = scanner.scan(/\\./))
186
+ hex_escape[2..].to_i(16).chr
187
+ elsif (escape = scanner.scan(/\\./))
187
188
  UNESCAPE_CHARS[escape]
188
189
  else
189
190
  scanner.getch
@@ -235,7 +236,6 @@ module Ronin
235
236
  data
236
237
  end
237
238
  end
238
-
239
239
  end
240
240
  end
241
241
  end
@@ -29,7 +29,7 @@ class Integer
29
29
  # @raise [RangeError]
30
30
  # The integer value is negative.
31
31
  #
32
- # @example
32
+ # @example
33
33
  # 0x41.shell_encode
34
34
  # # => "\\x41"
35
35
  # 0x0a.shell_encode
@@ -61,7 +61,7 @@ class Integer
61
61
  # @raise [RangeError]
62
62
  # The integer value is negative.
63
63
  #
64
- # @example
64
+ # @example
65
65
  # 0x41.shell_escape
66
66
  # # => "A"
67
67
  # 0x08.shell_escape
@@ -66,7 +66,7 @@ module Ronin
66
66
  # @raise [RangeError]
67
67
  # The byte value is negative.
68
68
  #
69
- # @example
69
+ # @example
70
70
  # Encoding::Shell.encode_byte(0x41)
71
71
  # # => "\\x41"
72
72
  # Encoding::Shell.encode_byte(0x0a)
@@ -98,7 +98,7 @@ module Ronin
98
98
  # @raise [RangeError]
99
99
  # The integer value is negative.
100
100
  #
101
- # @example
101
+ # @example
102
102
  # Encoding::Shell.escape(0x41)
103
103
  # # => "A"
104
104
  # Encoding::Shell.escape(0x08)
@@ -188,7 +188,7 @@ module Ronin
188
188
  until scanner.eos?
189
189
  unescaped << if (backslash_char = scanner.scan(/\\[0abetnvfr\'\"]/)) # \n
190
190
  BACKSLASHED_CHARS[backslash_char[1..]]
191
- elsif (hex_char = scanner.scan(/\\x[0-9a-fA-F]+/)) # \XX
191
+ elsif (hex_char = scanner.scan(/\\x[0-9a-fA-F]+/)) # \XX
192
192
  hex_char[2..].to_i(16).chr
193
193
  elsif (unicode_char = scanner.scan(/\\u[0-9a-fA-F]+/)) # \uXXXX
194
194
  unicode_char[2..].to_i(16).chr(Encoding::UTF_8)
@@ -116,7 +116,7 @@ module Ronin
116
116
  # The decoded String.
117
117
  #
118
118
  def self.decode(data)
119
- if (data =~ /^[0-9a-fA-F]{2,}$/ && (data.length % 2 == 0))
119
+ if (data =~ /^[0-9a-fA-F]{2,}$/ && data.length.even?)
120
120
  raw = String.new
121
121
 
122
122
  data.scan(/../) do |hex_char|
@@ -20,7 +20,9 @@ module Ronin
20
20
  module Support
21
21
  class Encoding < ::Encoding
22
22
  #
23
- # Contains methods for encoding/decoding UUEncoded data.
23
+ # Contains methods for encoding/decoding [UUEncoded][uuencoding] data.
24
+ #
25
+ # [uuencoding]: https://en.wikipedia.org/wiki/Uuencoding
24
26
  #
25
27
  # ## Core-Ext Methods
26
28
  #
@@ -163,7 +163,7 @@ module Ronin
163
163
  if zero_pad then "&#x%.7x;" % byte
164
164
  else "&#x%.2x;" % byte
165
165
  end
166
- when
166
+ else
167
167
  raise(ArgumentError,"case (#{kwargs[:case].inspect}) keyword argument must be either :lower, :upper, or nil")
168
168
  end
169
169
  else
@@ -312,7 +312,7 @@ module Ronin
312
312
  # @see http://rubydoc.info/stdlib/cgi/CGI.unescapeHash
313
313
  #
314
314
  def self.unescape(data)
315
- unescaped = String.new
315
+ unescaped = String.new(encoding: Encoding::UTF_8)
316
316
  scanner = StringScanner.new(data)
317
317
 
318
318
  until scanner.eos?
@@ -320,7 +320,7 @@ module Ronin
320
320
  ESCAPED_CHARS.fetch(named_char.downcase)
321
321
  elsif (decimal_char = scanner.scan(/&#\d+;/))
322
322
  decimal_char[2..-2].to_i.chr(Encoding::UTF_8)
323
- elsif (hex_char = scanner.scan(/&#x[a-f0-9]+;/i))
323
+ elsif (hex_char = scanner.scan(/&#x[a-f0-9]+;/i))
324
324
  hex_char[3..-2].to_i(16).chr(Encoding::UTF_8)
325
325
  else
326
326
  scanner.getch
@@ -38,6 +38,101 @@ module Ronin
38
38
  #
39
39
  # Contains additional encoding/decoding modules.
40
40
  #
41
+ # ## Core-Ext Methods
42
+ #
43
+ # * {Integer#c_encode}
44
+ # * {Integer#c_escape}
45
+ # * {Integer#hex_encode}
46
+ # * {Integer#hex_escape}
47
+ # * {Integer#hex_int}
48
+ # * {Integer#html_encode}
49
+ # * {Integer#html_escape}
50
+ # * {Integer#http_encode}
51
+ # * {Integer#http_escape}
52
+ # * {Integer#js_encode}
53
+ # * {Integer#js_escape}
54
+ # * {Integer#powershell_encode}
55
+ # * {Integer#powershell_escape}
56
+ # * {Integer#shell_encode}
57
+ # * {Integer#shell_escape}
58
+ # * {Integer#uri_encode}
59
+ # * {Integer#uri_escape}
60
+ # * {Integer#uri_form_encode}
61
+ # * {Integer#uri_form_escape}
62
+ # * {Integer#xml_encode}
63
+ # * {Integer#xml_escape}
64
+ # * {String#base16_decode}
65
+ # * {String#base16_encode}
66
+ # * {String#base32_decode}
67
+ # * {String#base32_encode}
68
+ # * {String#base64_decode}
69
+ # * {String#base64_encode}
70
+ # * {String#c_encode}
71
+ # * {String#c_escape}
72
+ # * {String#c_string}
73
+ # * {String#c_unescape}
74
+ # * {String#c_unquote}
75
+ # * {String#hex_decode}
76
+ # * {String#hex_encode}
77
+ # * {String#hex_escape}
78
+ # * {String#hex_string}
79
+ # * {String#hex_unescape}
80
+ # * {String#hex_unquote}
81
+ # * {String#html_decode}
82
+ # * {String#html_encode}
83
+ # * {String#html_escape}
84
+ # * {String#html_unescape}
85
+ # * {String#http_decode}
86
+ # * {String#http_encode}
87
+ # * {String#http_escape}
88
+ # * {String#http_unescape}
89
+ # * {String#js_decode}
90
+ # * {String#js_encode}
91
+ # * {String#js_escape}
92
+ # * {String#js_string}
93
+ # * {String#js_unescape}
94
+ # * {String#js_unquote}
95
+ # * {String#powershell_decode}
96
+ # * {String#powershell_encode}
97
+ # * {String#powershell_escape}
98
+ # * {String#powershell_string}
99
+ # * {String#powershell_unescape}
100
+ # * {String#powershell_unquote}
101
+ # * {String#punycode_decode}
102
+ # * {String#punycode_encode}
103
+ # * {String#quoted_printable_escape}
104
+ # * {String#quoted_printable_unescape}
105
+ # * {String#ruby_decode}
106
+ # * {String#ruby_encode}
107
+ # * {String#ruby_escape}
108
+ # * {String#ruby_string}
109
+ # * {String#ruby_unescape}
110
+ # * {String#ruby_unquote}
111
+ # * {String#shell_decode}
112
+ # * {String#shell_encode}
113
+ # * {String#shell_escape}
114
+ # * {String#shell_string}
115
+ # * {String#shell_unescape}
116
+ # * {String#shell_unquote}
117
+ # * {String#sql_decode}
118
+ # * {String#sql_encode}
119
+ # * {String#sql_escape}
120
+ # * {String#sql_unescape}
121
+ # * {String#uri_decode}
122
+ # * {String#uri_encode}
123
+ # * {String#uri_escape}
124
+ # * {String#uri_form_decode}
125
+ # * {String#uri_form_encode}
126
+ # * {String#uri_form_escape}
127
+ # * {String#uri_form_unescape}
128
+ # * {String#uri_unescape}
129
+ # * {String#uu_decode}
130
+ # * {String#uu_encode}
131
+ # * {String#xml_decode}
132
+ # * {String#xml_encode}
133
+ # * {String#xml_escape}
134
+ # * {String#xml_unescape}
135
+ #
41
136
  # @since 1.0.0
42
137
  #
43
138
  class Encoding < ::Encoding
@@ -145,6 +145,7 @@ module Ronin
145
145
  begin
146
146
  download(url: url, path: path)
147
147
  rescue
148
+ # ignore any network failures
148
149
  end
149
150
  end
150
151
  end
@@ -176,8 +177,10 @@ module Ronin
176
177
  line.chomp!
177
178
 
178
179
  first, last, number, country_code, name = line.split("\t",5)
180
+
179
181
  range = IPRange::Range.new(first,last)
180
182
  number = number.to_i
183
+
181
184
  country_code = nil if country_code == 'None'
182
185
  name = nil if name == 'Not routed'
183
186
 
@@ -219,7 +222,9 @@ module Ronin
219
222
  prefixes = if record.range.ipv6? then @ipv6_prefixes
220
223
  else @ipv4_prefixes
221
224
  end
222
- (prefixes[record.range.prefix] ||= []) << record
225
+
226
+ records = (prefixes[record.range.prefix] ||= [])
227
+ records << record
223
228
  return self
224
229
  end
225
230