ronin-support 0.2.0.rc1 → 0.2.0.rc2

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.
@@ -14,9 +14,13 @@
14
14
  * Added {Net.smtp_send_message}.
15
15
  * Added {Net.http_status}.
16
16
  * Added YARD `@api` tags to define the public, semi-public and private APIs.
17
+ * Renamed `Kernel#attempt` to {Kernel#try}.
17
18
  * Allow `:method` to be used with {Net.http_ok?}.
18
19
  * Fixed a bug in {Ronin::Network::HTTP.expand_url} where `:host` and `:port`
19
20
  options were being overridden.
21
+ * Improved the performance of {Integer#bytes}.
22
+ * Only redefine {String#dump} for Ruby 1.8.x.
23
+ * Ruby >= 1.9.1 correctly hex-escapes special characters.
20
24
  * Fixed a bug in {String#format_chars}, where it was not using `each_char`
21
25
  for unicode characters.
22
26
  * Deprecated {String#common_postfix}, in favor of {String#common_suffix}.
data/README.md CHANGED
@@ -22,8 +22,9 @@ or payloads over many common Source-Code-Management (SCM) systems.
22
22
  * Binary
23
23
  * Text
24
24
  * HTTP
25
- * HTML
26
25
  * URIs
26
+ * HTML
27
+ * JavaScript
27
28
  * Generating random text.
28
29
  * Networking:
29
30
  * TCP
@@ -22,4 +22,4 @@ dependencies:
22
22
 
23
23
  development_dependencies:
24
24
  bundler: ~> 1.0.10
25
- yard: ~> 0.6.4
25
+ yard: ~> 0.7.0
@@ -35,11 +35,13 @@ module Kernel
35
35
  #
36
36
  # @api public
37
37
  #
38
- def attempt
38
+ def try
39
39
  begin
40
40
  yield() if block_given?
41
41
  rescue Exception
42
42
  return nil
43
43
  end
44
44
  end
45
+
46
+ alias attempt try
45
47
  end
@@ -185,53 +185,52 @@ class String
185
185
  return self[prefix.length...(length - postfix.length)]
186
186
  end
187
187
 
188
- #
189
- # Dumps the string as a C-style string.
190
- #
191
- # @return [String]
192
- # The C-style encoded version of the String.
193
- #
194
- # @example
195
- # "hello\x00\073\x90\r\n".dump
196
- # # => "hello\0;\x90\r\n"
197
- #
198
- # @api public
199
- #
200
- def dump
201
- c_string = ''
202
-
203
- each_byte do |b|
204
- c_string << case b
205
- when 0x00
206
- "\\0"
207
- when 0x07
208
- "\\a"
209
- when 0x08
210
- "\\b"
211
- when 0x09
212
- "\\t"
213
- when 0x0a
214
- "\\n"
215
- when 0x0b
216
- "\\v"
217
- when 0x0c
218
- "\\f"
219
- when 0x0d
220
- "\\r"
221
- when 0x22
222
- "\\\""
223
- when 0x5c
224
- "\\\\"
225
- when (0x20..0x7e)
226
- b.chr
227
- else
228
- ("\\x%.2x" % b)
229
- end
188
+ if RUBY_VERSION < '1.9.'
189
+ ESCAPE_BYTES = {
190
+ 0x00 => '\0',
191
+ 0x07 => '\a',
192
+ 0x08 => '\b',
193
+ 0x09 => '\t',
194
+ 0x0a => '\n',
195
+ 0x0b => '\v',
196
+ 0x0c => '\f',
197
+ 0x0d => '\r',
198
+ 0x22 => '\"',
199
+ 0x5c => '\\'
200
+ }
201
+
202
+ #
203
+ # Dumps the string as a C-style string.
204
+ #
205
+ # @return [String]
206
+ # The C-style encoded version of the String.
207
+ #
208
+ # @example
209
+ # "hello\x00\073\x90\r\n".dump
210
+ # # => "hello\0;\x90\r\n"
211
+ #
212
+ # @note
213
+ # This method is only defined on Ruby 1.8.x.
214
+ #
215
+ # @api public
216
+ #
217
+ def dump
218
+ dumped_string = ''
219
+
220
+ each_byte do |b|
221
+ dumped_string << if (b >= 0x20 && b <= 0x7e)
222
+ b.chr
223
+ elsif ESCAPE_BYTES.has_key?(b)
224
+ ESCAPE_BYTES[b]
225
+ else
226
+ ("\\x%.2X" % b)
227
+ end
228
+ end
229
+
230
+ return "\"#{dumped_string}\""
230
231
  end
231
232
 
232
- return "\"#{c_string}\""
233
+ alias inspect dump
233
234
  end
234
235
 
235
- alias inspect dump
236
-
237
236
  end
@@ -53,17 +53,23 @@ class Integer
53
53
  case endian
54
54
  when :little, :net
55
55
  mask = 0xff
56
+ shift = 0
56
57
 
57
58
  address_length.times do |i|
58
- buffer << ((self & mask) >> (i*8))
59
+ buffer << ((self & mask) >> shift)
60
+
59
61
  mask <<= 8
62
+ shift += 8
60
63
  end
61
64
  when :big
62
- mask = (0xff << ((address_length-1)*8))
65
+ shift = ((address_length - 1) * 8)
66
+ mask = (0xff << shift)
63
67
 
64
68
  address_length.times do |i|
65
- buffer << ((self & mask) >> ((address_length-i-1)*8))
69
+ buffer << ((self & mask) >> shift)
70
+
66
71
  mask >>= 8
72
+ shift -= 8
67
73
  end
68
74
  else
69
75
  raise(ArgumentError,"invalid endian #{endian}")
@@ -220,8 +220,6 @@ class String
220
220
 
221
221
  self.bytes.inject('') { |result,b| result << (b ^ key.next).chr }
222
222
  end
223
-
224
-
225
223
 
226
224
  #
227
225
  # Base64 encodes a string.
@@ -20,6 +20,6 @@
20
20
  module Ronin
21
21
  module Support
22
22
  # ronin-support version
23
- VERSION = '0.2.0.rc1'
23
+ VERSION = '0.2.0.rc2'
24
24
  end
25
25
  end
@@ -2,28 +2,28 @@ require 'spec_helper'
2
2
  require 'ronin/extensions/kernel'
3
3
 
4
4
  describe Kernel do
5
- it "should provide Kernel#attempt" do
6
- Kernel.should respond_to('attempt')
5
+ it "should provide Kernel#try" do
6
+ Kernel.should respond_to('try')
7
7
  end
8
8
 
9
- describe "#attempt" do
9
+ describe "#try" do
10
10
  it "should return the result of the block if nothing is raised" do
11
- attempt { 2 + 2 }.should == 4
11
+ try { 2 + 2 }.should == 4
12
12
  end
13
13
 
14
14
  it "should return nil if an exception is raised" do
15
- attempt { 2 + 'a' }.should be_nil
15
+ try { 2 + 'a' }.should be_nil
16
16
  end
17
17
 
18
18
  it "should rescue RuntimeError exceptions" do
19
19
  lambda {
20
- attempt { raise(RuntimeError,"something happened",caller) }
20
+ try { raise(RuntimeError,"something happened",caller) }
21
21
  }.should_not raise_error(RuntimeError)
22
22
  end
23
23
 
24
24
  it "should rescue StandardError exceptions" do
25
25
  lambda {
26
- attempt { raise(StandardError,"not allowed to do that",caller) }
26
+ try { raise(StandardError,"not allowed to do that",caller) }
27
27
  }.should_not raise_error(StandardError)
28
28
  end
29
29
  end
@@ -167,11 +167,11 @@ describe String do
167
167
  end
168
168
 
169
169
  it "should dump strings containing non-printable characters" do
170
- "hello\x90\x05\xef".dump.should == '"hello\x90\x05\xef"'
170
+ "hello\x90\x05\xEF".dump.should == '"hello\x90\x05\xEF"'
171
171
  end
172
172
 
173
173
  it "should dump the string when calling the inspect method" do
174
- "hello\x90\x05\xef".inspect.should == '"hello\x90\x05\xef"'
174
+ "hello\x90\x05\xEF".inspect.should == '"hello\x90\x05\xEF"'
175
175
  end
176
176
  end
177
177
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ronin-support
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 0.2.0.rc1
5
+ version: 0.2.0.rc2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Postmodern
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-14 00:00:00 Z
13
+ date: 2011-06-07 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: chars
@@ -88,7 +88,7 @@ dependencies:
88
88
  requirements:
89
89
  - - ~>
90
90
  - !ruby/object:Gem::Version
91
- version: 0.6.4
91
+ version: 0.7.0
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: *id007