ronin-support 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/.document +4 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +1 -0
  4. data/COPYING.txt +504 -0
  5. data/ChangeLog.md +4 -0
  6. data/Gemfile +23 -0
  7. data/README.md +98 -0
  8. data/Rakefile +29 -0
  9. data/gemspec.yml +20 -0
  10. data/lib/ronin/extensions.rb +28 -0
  11. data/lib/ronin/extensions/file.rb +63 -0
  12. data/lib/ronin/extensions/ip_addr.rb +220 -0
  13. data/lib/ronin/extensions/kernel.rb +45 -0
  14. data/lib/ronin/extensions/meta.rb +22 -0
  15. data/lib/ronin/extensions/meta/object.rb +24 -0
  16. data/lib/ronin/extensions/string.rb +200 -0
  17. data/lib/ronin/formatting.rb +26 -0
  18. data/lib/ronin/formatting/binary.rb +22 -0
  19. data/lib/ronin/formatting/digest.rb +22 -0
  20. data/lib/ronin/formatting/extensions.rb +25 -0
  21. data/lib/ronin/formatting/extensions/binary.rb +24 -0
  22. data/lib/ronin/formatting/extensions/binary/file.rb +35 -0
  23. data/lib/ronin/formatting/extensions/binary/integer.rb +147 -0
  24. data/lib/ronin/formatting/extensions/binary/string.rb +363 -0
  25. data/lib/ronin/formatting/extensions/digest.rb +23 -0
  26. data/lib/ronin/formatting/extensions/digest/file.rb +117 -0
  27. data/lib/ronin/formatting/extensions/digest/string.rb +80 -0
  28. data/lib/ronin/formatting/extensions/http.rb +23 -0
  29. data/lib/ronin/formatting/extensions/http/integer.rb +57 -0
  30. data/lib/ronin/formatting/extensions/http/string.rb +102 -0
  31. data/lib/ronin/formatting/extensions/text.rb +23 -0
  32. data/lib/ronin/formatting/extensions/text/array.rb +125 -0
  33. data/lib/ronin/formatting/extensions/text/string.rb +206 -0
  34. data/lib/ronin/formatting/http.rb +22 -0
  35. data/lib/ronin/formatting/text.rb +22 -0
  36. data/lib/ronin/network.rb +29 -0
  37. data/lib/ronin/network/esmtp.rb +22 -0
  38. data/lib/ronin/network/extensions.rb +29 -0
  39. data/lib/ronin/network/extensions/esmtp.rb +22 -0
  40. data/lib/ronin/network/extensions/esmtp/net.rb +100 -0
  41. data/lib/ronin/network/extensions/http.rb +22 -0
  42. data/lib/ronin/network/extensions/http/net.rb +661 -0
  43. data/lib/ronin/network/extensions/imap.rb +22 -0
  44. data/lib/ronin/network/extensions/imap/net.rb +124 -0
  45. data/lib/ronin/network/extensions/pop3.rb +22 -0
  46. data/lib/ronin/network/extensions/pop3/net.rb +92 -0
  47. data/lib/ronin/network/extensions/smtp.rb +22 -0
  48. data/lib/ronin/network/extensions/smtp/net.rb +110 -0
  49. data/lib/ronin/network/extensions/ssl.rb +22 -0
  50. data/lib/ronin/network/extensions/ssl/net.rb +147 -0
  51. data/lib/ronin/network/extensions/tcp.rb +22 -0
  52. data/lib/ronin/network/extensions/tcp/net.rb +304 -0
  53. data/lib/ronin/network/extensions/telnet.rb +22 -0
  54. data/lib/ronin/network/extensions/telnet/net.rb +156 -0
  55. data/lib/ronin/network/extensions/udp.rb +22 -0
  56. data/lib/ronin/network/extensions/udp/net.rb +226 -0
  57. data/lib/ronin/network/http.rb +24 -0
  58. data/lib/ronin/network/http/exceptions.rb +22 -0
  59. data/lib/ronin/network/http/exceptions/unknown_request.rb +29 -0
  60. data/lib/ronin/network/http/http.rb +290 -0
  61. data/lib/ronin/network/http/proxy.rb +307 -0
  62. data/lib/ronin/network/imap.rb +49 -0
  63. data/lib/ronin/network/network.rb +41 -0
  64. data/lib/ronin/network/pop3.rb +49 -0
  65. data/lib/ronin/network/smtp.rb +24 -0
  66. data/lib/ronin/network/smtp/email.rb +143 -0
  67. data/lib/ronin/network/smtp/smtp.rb +68 -0
  68. data/lib/ronin/network/ssl.rb +47 -0
  69. data/lib/ronin/network/tcp.rb +22 -0
  70. data/lib/ronin/network/telnet.rb +109 -0
  71. data/lib/ronin/network/udp.rb +22 -0
  72. data/lib/ronin/path.rb +132 -0
  73. data/lib/ronin/support.rb +28 -0
  74. data/lib/ronin/support/inflector.rb +40 -0
  75. data/lib/ronin/support/version.rb +27 -0
  76. data/lib/ronin/templates.rb +23 -0
  77. data/lib/ronin/templates/erb.rb +75 -0
  78. data/lib/ronin/templates/template.rb +161 -0
  79. data/ronin-support.gemspec +10 -0
  80. data/spec/extensions/file_spec.rb +24 -0
  81. data/spec/extensions/ip_addr_spec.rb +171 -0
  82. data/spec/extensions/kernel_spec.rb +30 -0
  83. data/spec/extensions/string_spec.rb +177 -0
  84. data/spec/formatting/binary/helpers/hexdumps.rb +16 -0
  85. data/spec/formatting/binary/helpers/hexdumps/ascii.bin +0 -0
  86. data/spec/formatting/binary/helpers/hexdumps/hexdump_decimal_shorts.txt +17 -0
  87. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_bytes.txt +17 -0
  88. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_shorts.txt +17 -0
  89. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_bytes.txt +17 -0
  90. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_shorts.txt +17 -0
  91. data/spec/formatting/binary/helpers/hexdumps/hexdump_repeated.txt +6 -0
  92. data/spec/formatting/binary/helpers/hexdumps/od_decimal_bytes.txt +17 -0
  93. data/spec/formatting/binary/helpers/hexdumps/od_decimal_ints.txt +17 -0
  94. data/spec/formatting/binary/helpers/hexdumps/od_decimal_quads.txt +17 -0
  95. data/spec/formatting/binary/helpers/hexdumps/od_decimal_shorts.txt +17 -0
  96. data/spec/formatting/binary/helpers/hexdumps/od_hex_bytes.txt +17 -0
  97. data/spec/formatting/binary/helpers/hexdumps/od_hex_ints.txt +17 -0
  98. data/spec/formatting/binary/helpers/hexdumps/od_hex_quads.txt +17 -0
  99. data/spec/formatting/binary/helpers/hexdumps/od_hex_shorts.txt +17 -0
  100. data/spec/formatting/binary/helpers/hexdumps/od_octal_bytes.txt +17 -0
  101. data/spec/formatting/binary/helpers/hexdumps/od_octal_ints.txt +17 -0
  102. data/spec/formatting/binary/helpers/hexdumps/od_octal_quads.txt +17 -0
  103. data/spec/formatting/binary/helpers/hexdumps/od_octal_shorts.txt +17 -0
  104. data/spec/formatting/binary/helpers/hexdumps/od_repeated.txt +6 -0
  105. data/spec/formatting/binary/helpers/hexdumps/repeated.bin +1 -0
  106. data/spec/formatting/binary/integer_spec.rb +140 -0
  107. data/spec/formatting/binary/string_spec.rb +306 -0
  108. data/spec/formatting/digest/string_spec.rb +82 -0
  109. data/spec/formatting/http/integer_spec.rb +42 -0
  110. data/spec/formatting/http/string_spec.rb +76 -0
  111. data/spec/formatting/text/array_spec.rb +105 -0
  112. data/spec/formatting/text/string_spec.rb +180 -0
  113. data/spec/network/http/http_spec.rb +280 -0
  114. data/spec/network/http/proxy_spec.rb +150 -0
  115. data/spec/network/network_spec.rb +8 -0
  116. data/spec/network/ssl_spec.rb +14 -0
  117. data/spec/path_spec.rb +84 -0
  118. data/spec/spec_helper.rb +4 -0
  119. data/spec/support_spec.rb +8 -0
  120. data/spec/templates/classes/example_erb.rb +11 -0
  121. data/spec/templates/classes/example_template.rb +35 -0
  122. data/spec/templates/erb_spec.rb +21 -0
  123. data/spec/templates/helpers/data.rb +9 -0
  124. data/spec/templates/helpers/data/includes/_relative.erb +1 -0
  125. data/spec/templates/helpers/data/templates/example.erb +1 -0
  126. data/spec/templates/template_spec.rb +54 -0
  127. metadata +286 -0
@@ -0,0 +1,17 @@
1
+ 0000000 0706050403020100 0f0e0d0c0b0a0908
2
+ 0000020 1716151413121110 1f1e1d1c1b1a1918
3
+ 0000040 2726252423222120 2f2e2d2c2b2a2928
4
+ 0000060 3736353433323130 3f3e3d3c3b3a3938
5
+ 0000100 4746454443424140 4f4e4d4c4b4a4948
6
+ 0000120 5756555453525150 5f5e5d5c5b5a5958
7
+ 0000140 6766656463626160 6f6e6d6c6b6a6968
8
+ 0000160 7776757473727170 7f7e7d7c7b7a7978
9
+ 0000200 8786858483828180 8f8e8d8c8b8a8988
10
+ 0000220 9796959493929190 9f9e9d9c9b9a9998
11
+ 0000240 a7a6a5a4a3a2a1a0 afaeadacabaaa9a8
12
+ 0000260 b7b6b5b4b3b2b1b0 bfbebdbcbbbab9b8
13
+ 0000300 c7c6c5c4c3c2c1c0 cfcecdcccbcac9c8
14
+ 0000320 d7d6d5d4d3d2d1d0 dfdedddcdbdad9d8
15
+ 0000340 e7e6e5e4e3e2e1e0 efeeedecebeae9e8
16
+ 0000360 f7f6f5f4f3f2f1f0 fffefdfcfbfaf9f8
17
+ 0000400
@@ -0,0 +1,17 @@
1
+ 0000000 0100 0302 0504 0706 0908 0b0a 0d0c 0f0e
2
+ 0000020 1110 1312 1514 1716 1918 1b1a 1d1c 1f1e
3
+ 0000040 2120 2322 2524 2726 2928 2b2a 2d2c 2f2e
4
+ 0000060 3130 3332 3534 3736 3938 3b3a 3d3c 3f3e
5
+ 0000100 4140 4342 4544 4746 4948 4b4a 4d4c 4f4e
6
+ 0000120 5150 5352 5554 5756 5958 5b5a 5d5c 5f5e
7
+ 0000140 6160 6362 6564 6766 6968 6b6a 6d6c 6f6e
8
+ 0000160 7170 7372 7574 7776 7978 7b7a 7d7c 7f7e
9
+ 0000200 8180 8382 8584 8786 8988 8b8a 8d8c 8f8e
10
+ 0000220 9190 9392 9594 9796 9998 9b9a 9d9c 9f9e
11
+ 0000240 a1a0 a3a2 a5a4 a7a6 a9a8 abaa adac afae
12
+ 0000260 b1b0 b3b2 b5b4 b7b6 b9b8 bbba bdbc bfbe
13
+ 0000300 c1c0 c3c2 c5c4 c7c6 c9c8 cbca cdcc cfce
14
+ 0000320 d1d0 d3d2 d5d4 d7d6 d9d8 dbda dddc dfde
15
+ 0000340 e1e0 e3e2 e5e4 e7e6 e9e8 ebea edec efee
16
+ 0000360 f1f0 f3f2 f5f4 f7f6 f9f8 fbfa fdfc fffe
17
+ 0000400
@@ -0,0 +1,17 @@
1
+ 0000000 000 001 002 003 004 005 006 007 010 011 012 013 014 015 016 017
2
+ 0000020 020 021 022 023 024 025 026 027 030 031 032 033 034 035 036 037
3
+ 0000040 040 041 042 043 044 045 046 047 050 051 052 053 054 055 056 057
4
+ 0000060 060 061 062 063 064 065 066 067 070 071 072 073 074 075 076 077
5
+ 0000100 100 101 102 103 104 105 106 107 110 111 112 113 114 115 116 117
6
+ 0000120 120 121 122 123 124 125 126 127 130 131 132 133 134 135 136 137
7
+ 0000140 140 141 142 143 144 145 146 147 150 151 152 153 154 155 156 157
8
+ 0000160 160 161 162 163 164 165 166 167 170 171 172 173 174 175 176 177
9
+ 0000200 200 201 202 203 204 205 206 207 210 211 212 213 214 215 216 217
10
+ 0000220 220 221 222 223 224 225 226 227 230 231 232 233 234 235 236 237
11
+ 0000240 240 241 242 243 244 245 246 247 250 251 252 253 254 255 256 257
12
+ 0000260 260 261 262 263 264 265 266 267 270 271 272 273 274 275 276 277
13
+ 0000300 300 301 302 303 304 305 306 307 310 311 312 313 314 315 316 317
14
+ 0000320 320 321 322 323 324 325 326 327 330 331 332 333 334 335 336 337
15
+ 0000340 340 341 342 343 344 345 346 347 350 351 352 353 354 355 356 357
16
+ 0000360 360 361 362 363 364 365 366 367 370 371 372 373 374 375 376 377
17
+ 0000400
@@ -0,0 +1,17 @@
1
+ 0000000 00300400400 00701402404 01302404410 01703406414
2
+ 0000020 02304410420 02705412424 03306414430 03707416434
3
+ 0000040 04310420440 04711422444 05312424450 05713426454
4
+ 0000060 06314430460 06715432464 07316434470 07717436474
5
+ 0000100 10320440500 10721442504 11322444510 11723446514
6
+ 0000120 12324450520 12725452524 13326454530 13727456534
7
+ 0000140 14330460540 14731462544 15332464550 15733466554
8
+ 0000160 16334470560 16735472564 17336474570 17737476574
9
+ 0000200 20340500600 20741502604 21342504610 21743506614
10
+ 0000220 22344510620 22745512624 23346514630 23747516634
11
+ 0000240 24350520640 24751522644 25352524650 25753526654
12
+ 0000260 26354530660 26755532664 27356534670 27757536674
13
+ 0000300 30360540700 30761542704 31362544710 31763546714
14
+ 0000320 32364550720 32765552724 33366554730 33767556734
15
+ 0000340 34370560740 34771562744 35372564750 35773566754
16
+ 0000360 36374570760 36775572764 37376574770 37777576774
17
+ 0000400
@@ -0,0 +1,17 @@
1
+ 0000000 0034060120200300400400 0074160320601302404410
2
+ 0000020 0134260521202304410420 0174360721603306414430
3
+ 0000040 0234461122204310420440 0274561322605312424450
4
+ 0000060 0334661523206314430460 0374761723607316434470
5
+ 0000100 0435062124210320440500 0475162324611322444510
6
+ 0000120 0535262525212324450520 0575362725613326454530
7
+ 0000140 0635463126214330460540 0675563326615332464550
8
+ 0000160 0735663527216334470560 0775763727617336474570
9
+ 0000200 1036064130220340500600 1076164330621342504610
10
+ 0000220 1136264531222344510620 1176364731623346514630
11
+ 0000240 1236465132224350520640 1276565332625352524650
12
+ 0000260 1336665533226354530660 1376765733627356534670
13
+ 0000300 1437066134230360540700 1477166334631362544710
14
+ 0000320 1537266535232364550720 1577366735633366554730
15
+ 0000340 1637467136234370560740 1677567336635372564750
16
+ 0000360 1737667537236374570760 1777767737637376574770
17
+ 0000400
@@ -0,0 +1,17 @@
1
+ 0000000 000400 001402 002404 003406 004410 005412 006414 007416
2
+ 0000020 010420 011422 012424 013426 014430 015432 016434 017436
3
+ 0000040 020440 021442 022444 023446 024450 025452 026454 027456
4
+ 0000060 030460 031462 032464 033466 034470 035472 036474 037476
5
+ 0000100 040500 041502 042504 043506 044510 045512 046514 047516
6
+ 0000120 050520 051522 052524 053526 054530 055532 056534 057536
7
+ 0000140 060540 061542 062544 063546 064550 065552 066554 067556
8
+ 0000160 070560 071562 072564 073566 074570 075572 076574 077576
9
+ 0000200 100600 101602 102604 103606 104610 105612 106614 107616
10
+ 0000220 110620 111622 112624 113626 114630 115632 116634 117636
11
+ 0000240 120640 121642 122644 123646 124650 125652 126654 127656
12
+ 0000260 130660 131662 132664 133666 134670 135672 136674 137676
13
+ 0000300 140700 141702 142704 143706 144710 145712 146714 147716
14
+ 0000320 150720 151722 152724 153726 154730 155732 156734 157736
15
+ 0000340 160740 161742 162744 163746 164750 165752 166754 167756
16
+ 0000360 170760 171762 172764 173766 174770 175772 176774 177776
17
+ 0000400
@@ -0,0 +1,6 @@
1
+ 0000000 062550 066154 020157 020040 020040 020040 020040 020040
2
+ 0000020 020040 020040 020040 020040 020040 020040 020040 020040
3
+ *
4
+ 0000060 020040 020040 020040 020040 020040 063440 067557 061144
5
+ 0000100 062571 000012
6
+ 0000103
@@ -0,0 +1 @@
1
+ hello goodbye
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+ require 'ronin/formatting/binary'
3
+
4
+ require 'ostruct'
5
+
6
+ describe Integer do
7
+ subject { 0x41 }
8
+
9
+ it "should provide Integer#bytes" do
10
+ should respond_to(:bytes)
11
+ end
12
+
13
+ it "should provide Integer#pack" do
14
+ should respond_to(:pack)
15
+ end
16
+
17
+ it "should provide Integer#hex_escape" do
18
+ should respond_to(:hex_escape)
19
+ end
20
+
21
+ it "should alias char to the #chr method" do
22
+ subject.char.should == subject.chr
23
+ end
24
+
25
+ describe "hex_escape" do
26
+ subject { 42 }
27
+
28
+ it "should hex escape an Integer" do
29
+ subject.hex_escape.should == "\\x2a"
30
+ end
31
+ end
32
+
33
+ describe "bytes" do
34
+ let(:little_endian_char) { [0x37] }
35
+ let(:little_endian_short) { [0x37, 0x13] }
36
+ let(:little_endian_long) { [0x37, 0x13, 0x0, 0x0] }
37
+ let(:little_endian_quad) { [0x37, 0x13, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0] }
38
+
39
+ let(:big_endian_char) { [0x37] }
40
+ let(:big_endian_short) { [0x13, 0x37] }
41
+ let(:big_endian_long) { [0, 0, 0x13, 0x37] }
42
+ let(:big_endian_quad) { [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x13, 0x37] }
43
+
44
+ subject { 0x1337 }
45
+
46
+ it "should return the bytes in little endian ordering by default" do
47
+ subject.bytes(4).should == little_endian_long
48
+ end
49
+
50
+ it "should return the bytes for a char in little endian ordering" do
51
+ subject.bytes(1, :little).should == little_endian_char
52
+ end
53
+
54
+ it "should return the bytes for a short in little endian ordering" do
55
+ subject.bytes(2, :little).should == little_endian_short
56
+ end
57
+
58
+ it "should return the bytes for a long in little endian ordering" do
59
+ subject.bytes(4, :little).should == little_endian_long
60
+ end
61
+
62
+ it "should return the bytes for a quad in little endian ordering" do
63
+ subject.bytes(8, :little).should == little_endian_quad
64
+ end
65
+
66
+ it "should return the bytes for a char in big endian ordering" do
67
+ subject.bytes(1, :big).should == big_endian_char
68
+ end
69
+
70
+ it "should return the bytes for a short in big endian ordering" do
71
+ subject.bytes(2, :big).should == big_endian_short
72
+ end
73
+
74
+ it "should return the bytes for a long in big endian ordering" do
75
+ subject.bytes(4, :big).should == big_endian_long
76
+ end
77
+
78
+ it "should return the bytes for a quad in big endian ordering" do
79
+ subject.bytes(8, :big).should == big_endian_quad
80
+ end
81
+ end
82
+
83
+ describe "pack" do
84
+ let(:i386) do
85
+ OpenStruct.new(:endian => :little, :address_length => 4)
86
+ end
87
+
88
+ let(:ppc) do
89
+ OpenStruct.new(:endian => :big, :address_length => 4)
90
+ end
91
+
92
+ subject { 0x1337 }
93
+
94
+ let(:i386_packed_int) { "7\023\000\000" }
95
+ let(:i386_packed_short) { "7\023" }
96
+ let(:i386_packed_long) { "7\023\000\000" }
97
+ let(:i386_packed_quad) { "7\023\000\000\000\000\000\000" }
98
+
99
+ let(:ppc_packed_int) { "\000\000\0237" }
100
+ let(:ppc_packed_short) { "\0237" }
101
+ let(:ppc_packed_long) { "\000\000\0237" }
102
+ let(:ppc_packed_quad) { "\000\000\000\000\000\000\0237" }
103
+
104
+ it "should pack itself for a little-endian architecture by default" do
105
+ subject.pack(i386).should == i386_packed_int
106
+ end
107
+
108
+ it "should pack itself as a short for a little-endian architecture" do
109
+ subject.pack(i386,2).should == i386_packed_short
110
+ end
111
+
112
+ it "should pack itself as a long for a little-endian architecture" do
113
+ subject.pack(i386,4).should == i386_packed_long
114
+ end
115
+
116
+ it "should pack itself as a quad for a little-endian architecture" do
117
+ subject.pack(i386,8).should == i386_packed_quad
118
+ end
119
+
120
+ it "should pack itself for a big-endian architecture" do
121
+ subject.pack(ppc).should == ppc_packed_int
122
+ end
123
+
124
+ it "should pack itself as a short for a big-endian architecture" do
125
+ subject.pack(ppc,2).should == ppc_packed_short
126
+ end
127
+
128
+ it "should pack itself as a long for a big-endian architecture" do
129
+ subject.pack(ppc,4).should == ppc_packed_long
130
+ end
131
+
132
+ it "should pack itself as a quad for a big-endian architecture" do
133
+ subject.pack(ppc,8).should == ppc_packed_quad
134
+ end
135
+
136
+ it "should accept Array#pack template strings" do
137
+ subject.pack('L').should == i386_packed_long
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,306 @@
1
+ require 'spec_helper'
2
+ require 'ronin/formatting/binary'
3
+
4
+ require 'formatting/binary/helpers/hexdumps'
5
+ require 'ostruct'
6
+
7
+ describe String do
8
+ subject { "hello" }
9
+
10
+ it "should provide String#depack" do
11
+ should respond_to(:depack)
12
+ end
13
+
14
+ it "should provide String#zlib_inflate" do
15
+ should respond_to(:zlib_inflate)
16
+ end
17
+
18
+ it "should provide String#zlib_deflate" do
19
+ should respond_to(:zlib_deflate)
20
+ end
21
+
22
+ it "should provide String#hex_unescape" do
23
+ should respond_to(:hex_unescape)
24
+ end
25
+
26
+ it "should provide String#xor" do
27
+ should respond_to(:xor)
28
+ end
29
+
30
+ it "should provide String#unhexdump" do
31
+ should respond_to(:unhexdump)
32
+ end
33
+
34
+ describe "depack" do
35
+ subject { 0x1337 }
36
+
37
+ let(:i386) do
38
+ OpenStruct.new(:endian => :little, :address_length => 4)
39
+ end
40
+
41
+ let(:ppc) do
42
+ OpenStruct.new(:endian => :big, :address_length => 4)
43
+ end
44
+
45
+ let(:i386_packed_int) { "7\023\000\000" }
46
+ let(:i386_packed_short) { "7\023" }
47
+ let(:i386_packed_long) { "7\023\000\000" }
48
+ let(:i386_packed_quad) { "7\023\000\000\000\000\000\000" }
49
+
50
+ let(:ppc_packed_int) { "\000\000\0237" }
51
+ let(:ppc_packed_short) { "\0237" }
52
+ let(:ppc_packed_long) { "\000\000\0237" }
53
+ let(:ppc_packed_quad) { "\000\000\000\000\000\000\0237" }
54
+
55
+ it "should depack itself for a little-endian architecture" do
56
+ i386_packed_int.depack(i386).should == subject
57
+ end
58
+
59
+ it "should depack itself as a short for a little-endian architecture" do
60
+ i386_packed_short.depack(i386,2).should == subject
61
+ end
62
+
63
+ it "should depack itself as a long for a little-endian architecture" do
64
+ i386_packed_long.depack(i386,4).should == subject
65
+ end
66
+
67
+ it "should depack itself as a quad for a little-endian architecture" do
68
+ i386_packed_quad.depack(i386,8).should == subject
69
+ end
70
+
71
+ it "should depack itself for a big-endian architecture" do
72
+ ppc_packed_int.depack(ppc).should == subject
73
+ end
74
+
75
+ it "should depack itself as a short for a big-endian architecture" do
76
+ ppc_packed_short.depack(ppc,2).should == subject
77
+ end
78
+
79
+ it "should depack itself as a long for a big-endian architecture" do
80
+ ppc_packed_long.depack(ppc,4).should == subject
81
+ end
82
+
83
+ it "should depack itself as a quad for a big-endian architecture" do
84
+ ppc_packed_quad.depack(ppc,8).should == subject
85
+ end
86
+
87
+ it "should accept String#unpack template strings" do
88
+ i386_packed_long.depack('L').should == [subject]
89
+ end
90
+ end
91
+
92
+ describe "base64_encode" do
93
+ subject { "hello\0" }
94
+
95
+ it "should base64 encode a String" do
96
+ subject.base64_encode.should == "aGVsbG8A\n"
97
+ end
98
+ end
99
+
100
+ describe "base64_decode" do
101
+ subject { "aGVsbG8A\n" }
102
+
103
+ it "should base64 decode a String" do
104
+ subject.base64_decode.should == "hello\0"
105
+ end
106
+ end
107
+
108
+ describe "zlib_inflate" do
109
+ subject do
110
+ "x\xda3H\xb3H3MM6\xd354II\xd651K5\xd7M43N\xd4M\xb3\xb0L2O14423Mb\0\0\xc02\t\xae"
111
+ end
112
+
113
+ it "should inflate a zlib deflated String" do
114
+ subject.zlib_inflate.should == "0f8f5ec6-14dc-46e7-a63a-f89b7d11265b\0"
115
+ end
116
+ end
117
+
118
+ describe "zlib_deflate" do
119
+ subject { "hello" }
120
+
121
+ it "should zlib deflate a String" do
122
+ subject.zlib_deflate.should == "x\x9c\xcbH\xcd\xc9\xc9\a\0\x06,\x02\x15"
123
+ end
124
+ end
125
+
126
+ describe "hex_escape" do
127
+ subject { "hello\x4e" }
128
+
129
+ it "should hex escape a String" do
130
+ subject.hex_escape.should == "\\x68\\x65\\x6c\\x6c\\x6f\\x4e"
131
+ end
132
+ end
133
+
134
+ describe "hex_unescape" do
135
+ it "should unescape a normal String" do
136
+ "hello".hex_unescape.should == "hello"
137
+ end
138
+
139
+ it "should unescape a hex String" do
140
+ "\\x68\\x65\\x6c\\x6c\\x6f\\x4e".hex_unescape.should == "hello\x4e"
141
+ end
142
+
143
+ it "should unescape an octal String" do
144
+ "hello\012".hex_unescape.should == "hello\n"
145
+ end
146
+
147
+ it "should unescape control characters" do
148
+ "hello\\n".hex_unescape.should == "hello\n"
149
+ end
150
+ end
151
+
152
+ describe "xor" do
153
+ subject { 'hello' }
154
+
155
+ let(:key) { 0x50 }
156
+ let(:keys) { [0x50, 0x55] }
157
+
158
+ it "should not contain the key used in the xor" do
159
+ should_not include(key.chr)
160
+ end
161
+
162
+ it "should not equal the original string" do
163
+ subject.xor(key).should_not == subject
164
+ end
165
+
166
+ it "should be able to be decoded with another xor" do
167
+ subject.xor(key).xor(key).should == subject
168
+ end
169
+
170
+ it "should allow xoring against a single key" do
171
+ subject.xor(key).should == "85<<?"
172
+ end
173
+
174
+ it "should allow xoring against multiple keys" do
175
+ subject.xor(keys).should == "80<9?"
176
+ end
177
+ end
178
+
179
+ describe "unhexdump" do
180
+ include Helpers
181
+
182
+ describe "GNU hexdump" do
183
+ let(:ascii) { load_binary_data('ascii') }
184
+ let(:repeated) { load_binary_data('repeated') }
185
+
186
+ it "should unhexdump octal-byte hexdump output" do
187
+ hexdump = load_hexdump('hexdump_octal_bytes')
188
+
189
+ hexdump.unhexdump(:format => :hexdump, :encoding => :octal_bytes).should == ascii
190
+ end
191
+
192
+ it "should unhexdump hex-byte hexdump output" do
193
+ hexdump = load_hexdump('hexdump_hex_bytes')
194
+
195
+ hexdump.unhexdump(:format => :hexdump, :encoding => :hex_bytes).should == ascii
196
+ end
197
+
198
+ it "should unhexdump decimal-short hexdump output" do
199
+ hexdump = load_hexdump('hexdump_decimal_shorts')
200
+
201
+ hexdump.unhexdump(:format => :hexdump, :encoding => :decimal_shorts).should == ascii
202
+ end
203
+
204
+ it "should unhexdump octal-short hexdump output" do
205
+ hexdump = load_hexdump('hexdump_octal_shorts')
206
+
207
+ hexdump.unhexdump(:format => :hexdump, :encoding => :octal_shorts).should == ascii
208
+ end
209
+
210
+ it "should unhexdump hex-short hexdump output" do
211
+ hexdump = load_hexdump('hexdump_hex_shorts')
212
+
213
+ hexdump.unhexdump(:format => :hexdump, :encoding => :hex_shorts).should == ascii
214
+ end
215
+
216
+ it "should unhexdump repeated hexdump output" do
217
+ hexdump = load_hexdump('hexdump_repeated')
218
+
219
+ hexdump.unhexdump(:format => :hexdump, :encoding => :hex_bytes).should == repeated
220
+ end
221
+ end
222
+
223
+ describe "od" do
224
+ let(:ascii) { load_binary_data('ascii') }
225
+ let(:repeated) { load_binary_data('repeated') }
226
+
227
+ it "should unhexdump octal-byte hexdump output" do
228
+ hexdump = load_hexdump('od_octal_bytes')
229
+
230
+ hexdump.unhexdump(:format => :od, :encoding => :octal_bytes).should == ascii
231
+ end
232
+
233
+ it "should unhexdump octal-shorts hexdump output" do
234
+ hexdump = load_hexdump('od_octal_shorts')
235
+
236
+ hexdump.unhexdump(:format => :od, :encoding => :octal_shorts).should == ascii
237
+ end
238
+
239
+ it "should unhexdump octal-ints hexdump output" do
240
+ hexdump = load_hexdump('od_octal_ints')
241
+
242
+ hexdump.unhexdump(:format => :od, :encoding => :octal_ints).should == ascii
243
+ end
244
+
245
+ it "should unhexdump octal-quads hexdump output" do
246
+ hexdump = load_hexdump('od_octal_quads')
247
+
248
+ hexdump.unhexdump(:format => :od, :encoding => :octal_quads).should == ascii
249
+ end
250
+
251
+ it "should unhexdump decimal-byte hexdump output" do
252
+ hexdump = load_hexdump('od_decimal_bytes')
253
+
254
+ hexdump.unhexdump(:format => :od, :encoding => :decimal_bytes).should == ascii
255
+ end
256
+
257
+ it "should unhexdump decimal-shorts hexdump output" do
258
+ hexdump = load_hexdump('od_decimal_shorts')
259
+
260
+ hexdump.unhexdump(:format => :od, :encoding => :decimal_shorts).should == ascii
261
+ end
262
+
263
+ it "should unhexdump decimal-ints hexdump output" do
264
+ hexdump = load_hexdump('od_decimal_ints')
265
+
266
+ hexdump.unhexdump(:format => :od, :encoding => :decimal_ints).should == ascii
267
+ end
268
+
269
+ it "should unhexdump decimal-quads hexdump output" do
270
+ hexdump = load_hexdump('od_decimal_quads')
271
+
272
+ hexdump.unhexdump(:format => :od, :encoding => :decimal_quads).should == ascii
273
+ end
274
+
275
+ it "should unhexdump hex-byte hexdump output" do
276
+ hexdump = load_hexdump('od_hex_bytes')
277
+
278
+ hexdump.unhexdump(:format => :od, :encoding => :hex_bytes).should == ascii
279
+ end
280
+
281
+ it "should unhexdump hex-shorts hexdump output" do
282
+ hexdump = load_hexdump('od_hex_shorts')
283
+
284
+ hexdump.unhexdump(:format => :od, :encoding => :hex_shorts).should == ascii
285
+ end
286
+
287
+ it "should unhexdump hex-ints hexdump output" do
288
+ hexdump = load_hexdump('od_hex_ints')
289
+
290
+ hexdump.unhexdump(:format => :od, :encoding => :hex_ints).should == ascii
291
+ end
292
+
293
+ it "should unhexdump hex-quads hexdump output" do
294
+ hexdump = load_hexdump('od_hex_quads')
295
+
296
+ hexdump.unhexdump(:format => :od, :encoding => :hex_quads).should == ascii
297
+ end
298
+
299
+ it "should unhexdump repeated hexdump output" do
300
+ hexdump = load_hexdump('od_repeated')
301
+
302
+ hexdump.unhexdump(:format => :od, :encoding => :octal_shorts).should == repeated
303
+ end
304
+ end
305
+ end
306
+ end