ronin 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/History.txt +25 -0
  2. data/Manifest.txt +36 -11
  3. data/README.txt +6 -8
  4. data/Rakefile +2 -1
  5. data/lib/ronin/config.rb +0 -3
  6. data/lib/ronin/environment.rb +1 -1
  7. data/lib/ronin/extensions/string.rb +0 -11
  8. data/lib/ronin/formatting/extensions/binary/integer.rb +24 -12
  9. data/lib/ronin/formatting/extensions/binary/string.rb +166 -0
  10. data/lib/ronin/formatting/extensions/text/string.rb +4 -4
  11. data/lib/ronin/license.rb +42 -12
  12. data/lib/ronin/os.rb +3 -2
  13. data/lib/ronin/platform/extension.rb +11 -141
  14. data/lib/ronin/platform/extension_cache.rb +11 -0
  15. data/lib/ronin/platform/overlay.rb +56 -25
  16. data/lib/ronin/platform/overlay_cache.rb +1 -1
  17. data/lib/ronin/platform/platform.rb +14 -3
  18. data/lib/ronin/platform/ronin.rb +20 -1
  19. data/lib/ronin/platform/tasks/spec.rb +9 -0
  20. data/lib/ronin/{chars.rb → static.rb} +2 -2
  21. data/lib/ronin/static/finders.rb +144 -0
  22. data/lib/ronin/static/static.rb +53 -0
  23. data/lib/ronin/ui/command_line/commands/add.rb +21 -5
  24. data/lib/ronin/ui/command_line/commands/install.rb +19 -3
  25. data/lib/ronin/ui/command_line/commands/rm.rb +1 -1
  26. data/lib/ronin/ui/command_line/commands/uninstall.rb +1 -1
  27. data/lib/ronin/ui/command_line/commands/update.rb +9 -2
  28. data/lib/ronin/version.rb +1 -1
  29. data/spec/extensions/string_spec.rb +0 -10
  30. data/spec/formatting/binary/helpers/hexdumps.rb +14 -0
  31. data/spec/formatting/binary/helpers/hexdumps/hexdump_decimal_shorts.txt +17 -0
  32. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_bytes.txt +17 -0
  33. data/spec/formatting/binary/helpers/hexdumps/hexdump_hex_shorts.txt +17 -0
  34. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_bytes.txt +17 -0
  35. data/spec/formatting/binary/helpers/hexdumps/hexdump_octal_shorts.txt +17 -0
  36. data/spec/formatting/binary/helpers/hexdumps/hexdump_repeated.txt +6 -0
  37. data/spec/formatting/binary/helpers/hexdumps/od_decimal_bytes.txt +17 -0
  38. data/spec/formatting/binary/helpers/hexdumps/od_decimal_ints.txt +17 -0
  39. data/spec/formatting/binary/helpers/hexdumps/od_decimal_quads.txt +17 -0
  40. data/spec/formatting/binary/helpers/hexdumps/od_decimal_shorts.txt +17 -0
  41. data/spec/formatting/binary/helpers/hexdumps/od_hex_bytes.txt +17 -0
  42. data/spec/formatting/binary/helpers/hexdumps/od_hex_ints.txt +17 -0
  43. data/spec/formatting/binary/helpers/hexdumps/od_hex_quads.txt +17 -0
  44. data/spec/formatting/binary/helpers/hexdumps/od_hex_shorts.txt +17 -0
  45. data/spec/formatting/binary/helpers/hexdumps/od_octal_bytes.txt +17 -0
  46. data/spec/formatting/binary/helpers/hexdumps/od_octal_ints.txt +17 -0
  47. data/spec/formatting/binary/helpers/hexdumps/od_octal_quads.txt +17 -0
  48. data/spec/formatting/binary/helpers/hexdumps/od_octal_shorts.txt +17 -0
  49. data/spec/formatting/binary/helpers/hexdumps/od_repeated.txt +6 -0
  50. data/spec/formatting/binary/helpers/hexdumps/repeated.bin +1 -0
  51. data/spec/formatting/binary/integer_spec.rb +61 -1
  52. data/spec/formatting/binary/string_spec.rb +166 -9
  53. data/spec/platform/extension_cache_spec.rb +8 -0
  54. data/spec/platform/helpers/overlays.yaml.erb +3 -0
  55. data/spec/platform/helpers/overlays/hello/ronin.xml +1 -1
  56. data/spec/platform/helpers/overlays/random/random/extension.rb +7 -0
  57. data/spec/platform/helpers/overlays/random/ronin.xml +26 -0
  58. data/spec/platform/helpers/overlays/test1/ronin.xml +2 -2
  59. data/spec/platform/helpers/overlays/test2/ronin.xml +2 -2
  60. data/spec/platform/overlay_cache_spec.rb +5 -3
  61. data/spec/platform/overlay_spec.rb +35 -0
  62. data/spec/platform/ronin_spec.rb +13 -1
  63. data/spec/static/finders_spec.rb +55 -0
  64. data/spec/static/helpers/static.rb +11 -0
  65. data/spec/static/helpers/static1/dir/two.txt +0 -0
  66. data/spec/static/helpers/static1/one.txt +0 -0
  67. data/spec/static/helpers/static2/dir/two.txt +0 -0
  68. data/spec/static/helpers/static_class.rb +7 -0
  69. data/spec/static/static_spec.rb +24 -0
  70. data/static/{overlay.xsl → ronin/platform/overlay.xsl} +0 -0
  71. metadata +50 -17
  72. data/bin/ronin-ext +0 -12
  73. data/bin/ronin-overlay +0 -12
  74. data/lib/ronin/chars/char_set.rb +0 -198
  75. data/lib/ronin/chars/chars.rb +0 -190
  76. data/lib/ronin/ui/command_line/commands/ext.rb +0 -70
  77. data/lib/ronin/ui/command_line/commands/overlay.rb +0 -189
  78. data/spec/chars/char_set_spec.rb +0 -175
  79. data/spec/chars/chars_spec.rb +0 -107
  80. data/static/extension.rb +0 -9
data/History.txt CHANGED
@@ -1,3 +1,28 @@
1
+ === 0.2.2 / 2009-03-26
2
+
3
+ * Split out Ronin::Chars into the Chars library.
4
+ * Split out ronin-overlay and ronin-ext sub-commands into the Ronin Gen
5
+ library.
6
+ * Require chars >= 0.1.0.
7
+ * Require repertoire >= 0.2.1.
8
+ * Removed String#to_method_name, use Extlib instead.
9
+ * Refactored Ronin::Platform::Overlay.
10
+ * Renamed Overlay#media_type to Overlay#media.
11
+ * Fixed parsing bugs in Overlay#initialize_metadata.
12
+ * Allow Extensions to be accessed via constants.
13
+ * Added the Creative Commons Zero license to Ronin::License.
14
+ * Added the Integer#bytes method.
15
+ * Added the String#hex_unescape method.
16
+ * Added the String#unhexdump method.
17
+ * Added Ronin::Static for managing static resources.
18
+ * Added Ronin::Static::Finders for searching for static files.
19
+ * Added static directories to Overlays and Extensions.
20
+ * Added ronin/platform/tasks:
21
+ * Added ronin/platform/tasks/spec task for running RSpec tests in an
22
+ Overlay.
23
+ * Added the ExtensionCache#reload! method.
24
+ * Added more specs.
25
+
1
26
  === 0.2.1 / 2009-02-23
2
27
 
3
28
  * Added Ronin::UI::Verbose.
data/Manifest.txt CHANGED
@@ -7,16 +7,17 @@ Rakefile
7
7
  bin/ronin
8
8
  bin/ronin-add
9
9
  bin/ronin-console
10
- bin/ronin-ext
11
10
  bin/ronin-help
12
11
  bin/ronin-install
13
12
  bin/ronin-ls
14
- bin/ronin-overlay
15
13
  bin/ronin-rm
16
14
  bin/ronin-uninstall
17
15
  bin/ronin-update
18
16
  lib/ronin.rb
19
17
  lib/ronin/config.rb
18
+ lib/ronin/static.rb
19
+ lib/ronin/static/static.rb
20
+ lib/ronin/static/finders.rb
20
21
  lib/ronin/extensions.rb
21
22
  lib/ronin/extensions/meta.rb
22
23
  lib/ronin/extensions/meta/object.rb
@@ -41,9 +42,6 @@ lib/ronin/formatting/extensions/text.rb
41
42
  lib/ronin/formatting/extensions/text/string.rb
42
43
  lib/ronin/formatting/extensions/http.rb
43
44
  lib/ronin/formatting/extensions/http/string.rb
44
- lib/ronin/chars.rb
45
- lib/ronin/chars/char_set.rb
46
- lib/ronin/chars/chars.rb
47
45
  lib/ronin/translators.rb
48
46
  lib/ronin/translators/translator.rb
49
47
  lib/ronin/path.rb
@@ -122,6 +120,7 @@ lib/ronin/objectify/objectify.rb
122
120
  lib/ronin/models.rb
123
121
  lib/ronin/environment.rb
124
122
  lib/ronin/platform.rb
123
+ lib/ronin/platform/tasks/spec.rb
125
124
  lib/ronin/platform/exceptions.rb
126
125
  lib/ronin/platform/exceptions/extension_not_found.rb
127
126
  lib/ronin/platform/exceptions/overlay_cached.rb
@@ -151,8 +150,6 @@ lib/ronin/ui/command_line/command.rb
151
150
  lib/ronin/ui/command_line/options.rb
152
151
  lib/ronin/ui/command_line/param_parser.rb
153
152
  lib/ronin/ui/command_line/commands/console.rb
154
- lib/ronin/ui/command_line/commands/overlay.rb
155
- lib/ronin/ui/command_line/commands/ext.rb
156
153
  lib/ronin/ui/command_line/commands/add.rb
157
154
  lib/ronin/ui/command_line/commands/install.rb
158
155
  lib/ronin/ui/command_line/commands/ls.rb
@@ -166,16 +163,42 @@ lib/ronin/version.rb
166
163
  tasks/spec.rb
167
164
  spec/helpers.rb
168
165
  spec/spec_helper.rb
166
+ spec/static/helpers/static1/one.txt
167
+ spec/static/helpers/static1/dir/two.txt
168
+ spec/static/helpers/static2/dir/two.txt
169
+ spec/static/helpers/static.rb
170
+ spec/static/helpers/static_class.rb
171
+ spec/static/finders_spec.rb
172
+ spec/static/static_spec.rb
169
173
  spec/arch_spec.rb
170
174
  spec/author_spec.rb
171
- spec/chars/char_set_spec.rb
172
- spec/chars/chars_spec.rb
173
175
  spec/translators/translator_spec.rb
174
176
  spec/objectify/objectify_spec.rb
175
177
  spec/extensions/hash_spec.rb
176
178
  spec/extensions/string_spec.rb
177
179
  spec/extensions/uri/http_spec.rb
178
180
  spec/extensions/uri/query_params_spec.rb
181
+ spec/formatting/binary/helpers/hexdumps.rb
182
+ spec/formatting/binary/helpers/hexdumps/repeated.bin
183
+ spec/formatting/binary/helpers/hexdumps/hexdump_octal_bytes.txt
184
+ spec/formatting/binary/helpers/hexdumps/hexdump_octal_shorts.txt
185
+ spec/formatting/binary/helpers/hexdumps/hexdump_decimal_shorts.txt
186
+ spec/formatting/binary/helpers/hexdumps/hexdump_hex_bytes.txt
187
+ spec/formatting/binary/helpers/hexdumps/hexdump_hex_shorts.txt
188
+ spec/formatting/binary/helpers/hexdumps/hexdump_repeated.txt
189
+ spec/formatting/binary/helpers/hexdumps/od_octal_bytes.txt
190
+ spec/formatting/binary/helpers/hexdumps/od_octal_shorts.txt
191
+ spec/formatting/binary/helpers/hexdumps/od_octal_ints.txt
192
+ spec/formatting/binary/helpers/hexdumps/od_octal_quads.txt
193
+ spec/formatting/binary/helpers/hexdumps/od_decimal_bytes.txt
194
+ spec/formatting/binary/helpers/hexdumps/od_decimal_shorts.txt
195
+ spec/formatting/binary/helpers/hexdumps/od_decimal_ints.txt
196
+ spec/formatting/binary/helpers/hexdumps/od_decimal_quads.txt
197
+ spec/formatting/binary/helpers/hexdumps/od_hex_bytes.txt
198
+ spec/formatting/binary/helpers/hexdumps/od_hex_shorts.txt
199
+ spec/formatting/binary/helpers/hexdumps/od_hex_ints.txt
200
+ spec/formatting/binary/helpers/hexdumps/od_hex_quads.txt
201
+ spec/formatting/binary/helpers/hexdumps/od_repeated.txt
179
202
  spec/formatting/binary/integer_spec.rb
180
203
  spec/formatting/binary/string_spec.rb
181
204
  spec/formatting/digest_spec.rb
@@ -197,7 +220,10 @@ spec/platform/helpers/overlays/test2/ronin.xml
197
220
  spec/platform/helpers/overlays/test2/test/extension.rb
198
221
  spec/platform/helpers/overlays/hello/ronin.xml
199
222
  spec/platform/helpers/overlays/hello/hello/extension.rb
223
+ spec/platform/helpers/overlays/random/ronin.xml
224
+ spec/platform/helpers/overlays/random/random/extension.rb
200
225
  spec/platform/extension_spec.rb
226
+ spec/platform/overlay_spec.rb
201
227
  spec/platform/overlay_cache_spec.rb
202
228
  spec/platform/extension_cache_spec.rb
203
229
  spec/platform/platform_spec.rb
@@ -206,5 +232,4 @@ spec/ui/verbose_spec.rb
206
232
  spec/ui/command_line/helpers/example_command.rb
207
233
  spec/ui/command_line/param_parser_spec.rb
208
234
  spec/ronin_spec.rb
209
- static/overlay.xsl
210
- static/extension.rb
235
+ static/ronin/platform/overlay.xsl
data/README.txt CHANGED
@@ -29,7 +29,7 @@ users to pick and choose what functionality they want in Ronin.
29
29
 
30
30
  Ronin does not have a central repository of exploits and payloads which
31
31
  all developers contribute to. Instead Ronin has Overlays, repositories of
32
- code that can be hosted on any CVS/SVN/Git/Rsync server. Users can then use
32
+ code that can be hosted on any SVN/Hg/Git/Rsync server. Users can then use
33
33
  Ronin to quickly install or update Overlays. This allows developers and
34
34
  users to form their own communities, independent of the main developers
35
35
  of Ronin.
@@ -38,11 +38,10 @@ of Ronin.
38
38
 
39
39
  * Supports installing/updating/uninstalling of Overlays.
40
40
  * Supports accessing Overlays from various media types:
41
- * CVS
42
41
  * Subversion (SVN)
42
+ * Mercurial (Hg)
43
43
  * Git
44
44
  * Rsync
45
- * Darcs
46
45
  * Allows for the loading of Extensions from one or more Overlays.
47
46
  * Provides persistent storage of objects using DataMapper.
48
47
  * Caches and mirrors objects stored in Overlays using DataMapper.
@@ -147,13 +146,12 @@ Google (tm) Dorks functionality.
147
146
  Ronin Exploits is a Ruby library for Ronin that provides exploitation and
148
147
  payload crafting functionality.
149
148
 
150
- === Ronin HTML
149
+ === Ronin Gen
151
150
 
152
- * http://ronin.rubyforge.org/html/
153
- * http://github.com/postmodern/ronin-html
151
+ * http://ronin.rubyforge.org/gen/
152
+ * http://github.com/postmodern/ronin-gen
154
153
 
155
- Ronin HTML is a Ruby library for Ronin that provides support for generating
156
- complex HTML/JavaScript or crafting XSS/CSRF attacks.
154
+ Ronin Gen is a Ruby library for Ronin that provides various generators.
157
155
 
158
156
  === Ronin SQL
159
157
 
data/Rakefile CHANGED
@@ -19,10 +19,11 @@ Hoe.new('ronin', Ronin::VERSION) do |p|
19
19
  ['dm-aggregates', '>=0.9.9'],
20
20
  ['dm-validations', '>=0.9.9'],
21
21
  ['dm-predefined', '>=0.1.0'],
22
+ ['chars', '>=0.1.0'],
22
23
  ['parameters', '>=0.1.3'],
23
24
  ['contextify', '>=0.1.2'],
24
25
  ['reverse-require', '>=0.3.1'],
25
- ['repertoire', '>=0.1.2']
26
+ ['repertoire', '>=0.2.1']
26
27
  ]
27
28
  end
28
29
 
data/lib/ronin/config.rb CHANGED
@@ -31,9 +31,6 @@ module Ronin
31
31
  # Ronin home directory
32
32
  PATH = FileUtils.mkdir_p(File.join(HOME,'.ronin'))
33
33
 
34
- # Path to static directory
35
- STATIC_DIR = File.expand_path(File.join(File.dirname(__FILE__),'..','..','static'))
36
-
37
34
  # Main configuration file
38
35
  CONFIG_PATH = File.join(PATH,'config.rb')
39
36
 
@@ -24,13 +24,13 @@
24
24
  require 'ronin/config'
25
25
  require 'ronin/extensions'
26
26
  require 'ronin/formatting'
27
- require 'ronin/chars'
28
27
  require 'ronin/path'
29
28
  require 'ronin/network'
30
29
  require 'ronin/models'
31
30
  require 'ronin/ui'
32
31
  require 'ronin/ronin'
33
32
 
33
+ require 'chars'
34
34
  require 'pp'
35
35
 
36
36
  Ronin::Config.load
@@ -23,17 +23,6 @@
23
23
 
24
24
  class String
25
25
 
26
- #
27
- # Converts the +String+ into an appropriate method name.
28
- #
29
- # 'GPL 2'.to_method_name # => "gpl_2"
30
- #
31
- # 'Ronin::Arch' # => "ronin_arch"
32
- #
33
- def to_method_name
34
- downcase.gsub(/(::|[\s\-])/,'_')
35
- end
36
-
37
26
  #
38
27
  # Returns the common prefix of the string and the specified _other_
39
28
  # string. If no common prefix can be found an empty string will be
@@ -26,29 +26,28 @@ require 'ronin/arch'
26
26
  class Integer
27
27
 
28
28
  #
29
- # Packs the integer using the specified _arch_ and the given
30
- # _address_length_. The _address_length_ will default to the address
31
- # length of the _arch_.
32
- #
33
- # 0x41.pack(Arch.i686) # => "A\000\000\000"
29
+ # Returns an Array of bytes which represent the integer, using the
30
+ # specified _address_length_ and given _endian_.
34
31
  #
35
- # 0x41.pack(Arch.ppc,2) # => "\000A"
32
+ # _endian_ must be either <tt>:little</tt>, <tt>:big</tt> or
33
+ # <tt>:net</tt>.
36
34
  #
37
- def pack(arch,address_length=arch.address_length)
38
- buffer = ""
35
+ def bytes(address_length,endian=:little)
36
+ endian = endian.to_s
37
+ buffer = []
39
38
 
40
- if arch.endian=='little'
39
+ if (endian == 'little' || endian == 'net')
41
40
  mask = 0xff
42
41
 
43
42
  address_length.times do |i|
44
- buffer+=((self & mask) >> (i*8)).chr
43
+ buffer << ((self & mask) >> (i*8))
45
44
  mask <<= 8
46
45
  end
47
- elsif arch.endian=='big'
46
+ elsif endian == 'big'
48
47
  mask = (0xff << ((address_length-1)*8))
49
48
 
50
49
  address_length.times do |i|
51
- buffer+=((self & mask) >> ((address_length-i-1)*8)).chr
50
+ buffer << ((self & mask) >> ((address_length-i-1)*8))
52
51
  mask >>= 8
53
52
  end
54
53
  end
@@ -56,6 +55,19 @@ class Integer
56
55
  return buffer
57
56
  end
58
57
 
58
+ #
59
+ # Packs the integer using the specified _arch_ and the given
60
+ # _address_length_. The _address_length_ will default to the address
61
+ # length of the _arch_.
62
+ #
63
+ # 0x41.pack(Arch.i686) # => "A\000\000\000"
64
+ #
65
+ # 0x41.pack(Arch.ppc,2) # => "\000A"
66
+ #
67
+ def pack(arch,address_length=arch.address_length)
68
+ bytes(address_length,arch.endian).map { |b| b.chr }.join
69
+ end
70
+
59
71
  #
60
72
  # Returns the hex escaped form of the integer.
61
73
  #
@@ -21,6 +21,7 @@
21
21
  #++
22
22
  #
23
23
 
24
+ require 'ronin/formatting/extensions/binary/integer'
24
25
  require 'ronin/formatting/extensions/text'
25
26
  require 'ronin/arch'
26
27
 
@@ -67,6 +68,61 @@ class String
67
68
  format_bytes(options) { |b| "\\x%.2x" % b }
68
69
  end
69
70
 
71
+ #
72
+ # Returns an unescaped version of the hex escaped string.
73
+ #
74
+ # "\\x68\\x65\\x6c\\x6c\\x6f".hex_unescape
75
+ # # => "hello"
76
+ #
77
+ def hex_unescape
78
+ buffer = ''
79
+ hex_index = 0
80
+ hex_length = length
81
+
82
+ while (hex_index < hex_length)
83
+ hex_substring = self[hex_index..-1]
84
+
85
+ if hex_substring =~ /^\\[0-7]{3}/
86
+ buffer << hex_substring[0..3].to_i(8)
87
+ hex_index += 3
88
+ elsif hex_substring =~ /^\\x[0-9a-fA-F]{1,2}/
89
+ hex_substring[2..-1].scan(/^[0-9a-fA-F]{1,2}/) do |hex_byte|
90
+ buffer << hex_byte.to_i(16)
91
+ hex_index += (2 + hex_byte.length)
92
+ end
93
+ elsif hex_substring =~ /^\\./
94
+ escaped_char = hex_substring[1..1]
95
+
96
+ buffer << case escaped_char
97
+ when '0'
98
+ "\0"
99
+ when 'a'
100
+ "\a"
101
+ when 'b'
102
+ "\b"
103
+ when 't'
104
+ "\t"
105
+ when 'n'
106
+ "\n"
107
+ when 'v'
108
+ "\v"
109
+ when 'f'
110
+ "\f"
111
+ when 'r'
112
+ "\r"
113
+ else
114
+ escaped_char
115
+ end
116
+ hex_index += 2
117
+ else
118
+ buffer << hex_substring[0]
119
+ hex_index += 1
120
+ end
121
+ end
122
+
123
+ return buffer
124
+ end
125
+
70
126
  #
71
127
  # XOR encodes the string using the specified _key_.
72
128
  #
@@ -91,4 +147,114 @@ class String
91
147
  Base64.decode64(self)
92
148
  end
93
149
 
150
+ #
151
+ # Converts a multitude of hexdump formats back into the original
152
+ # raw-data using the given _options_.
153
+ #
154
+ # _options_ may contain the following keys:
155
+ # <tt>:format</tt>:: The expected format of the hexdump. Must be either
156
+ # <tt>:od</tt> or <tt>:hexdump</tt>.
157
+ # <tt>:encoding</tt>:: Denotes the encoding used for the bytes within the
158
+ # hexdump. Must be one of the following:
159
+ # <tt>:binary</tt>:: Binary encoded bytes.
160
+ # <tt>:octal</tt>:: Octal encoding.
161
+ # <tt>:octal_bytes</tt>:: Octal encoded bytes.
162
+ # <tt>:octal_shorts</tt>:: Octal encoded shorts.
163
+ # <tt>:octal_ints</tt>:: Octal encoded integers.
164
+ # <tt>:octal_quads</tt>:: Octal encoded quads.
165
+ # <tt>:decimal</tt>:: Unsigned decimal encoding.
166
+ # <tt>:decimal_bytes</tt>:: Unsigned decimal bytes.
167
+ # <tt>:decimal_shorts</tt>:: Unsigned decimal shorts.
168
+ # <tt>:decimal_ints</tt>:: Unsigned decimal ints.
169
+ # <tt>:decimal_quads</tt>:: Unsigned decimal quads.
170
+ # <tt>:hex</tt>:: Hexadecimal encoding.
171
+ # <tt>:hex_bytes</tt>:: Hexadecimal bytes.
172
+ # <tt>:hex_shorts</tt>:: Hexadecimal shorts.
173
+ # <tt>:hex_ints</tt>:: Hexadecimal ints.
174
+ # <tt>:hex_quads</tt>:: Hexadecimal quads.
175
+ # <tt>:segment</tt>:: The length in bytes of each segment in the hexdump.
176
+ # Defaults to 16, if not specified.
177
+ #
178
+ def unhexdump(options={})
179
+ case (format = options[:format])
180
+ when :od
181
+ address_base = base = 8
182
+ word_size = 2
183
+ when :hexdump
184
+ address_base = base = 16
185
+ word_size = 2
186
+ else
187
+ address_base = base = 16
188
+ word_size = 1
189
+ end
190
+
191
+ case options[:encoding]
192
+ when :binary
193
+ base = 2
194
+ when :octal, :octal_bytes, :octal_shorts, :octal_ints, :octal_quads
195
+ base = 8
196
+ when :decimal, :decimal_bytes, :decimal_shorts, :decimal_ints, :decimal_quads
197
+ base = 10
198
+ when :hex, :hex_bytes, :hex_shorts, :hex_ints, :hex_quads
199
+ base = 16
200
+ end
201
+
202
+ case options[:encoding]
203
+ when :binary, :octal_bytes, :decimal_bytes, :hex_bytes
204
+ word_size = 1
205
+ when :octal_shorts, :decimal_shorts, :hex_shorts
206
+ word_size = 2
207
+ when :octal_ints, :decimal_ints, :hex_ints
208
+ word_size = 4
209
+ when :octal_quads, :decimal_quads, :hex_quads
210
+ word_size = 8
211
+ end
212
+
213
+ current_addr = last_addr = first_addr = nil
214
+ repeated = false
215
+
216
+ segment_length = (options[:segment] || 16)
217
+ segment = []
218
+ buffer = []
219
+
220
+ each_line do |line|
221
+ if format == :hexdump
222
+ line = line.gsub(/\s+\|.+\|\s*$/,'')
223
+ end
224
+
225
+ words = line.split
226
+
227
+ if words.first == '*'
228
+ repeated = true
229
+ elsif words.length > 0
230
+ current_addr = words.shift.to_i(address_base)
231
+ first_addr ||= current_addr
232
+
233
+ if repeated
234
+ (((current_addr - last_addr) / segment.length) - 1).times do
235
+ buffer += segment
236
+ end
237
+
238
+ repeated = false
239
+ end
240
+
241
+ segment.clear
242
+
243
+ words.each do |word|
244
+ if (base != 10 && word =~ /^(\\[0abtnvfr\\]|.)$/)
245
+ word.hex_unescape.each_byte { |b| segment << b }
246
+ else
247
+ segment += word.to_i(base).bytes(word_size)
248
+ end
249
+ end
250
+
251
+ segment = segment[0...segment_length]
252
+ buffer += segment
253
+ last_addr = current_addr
254
+ end
255
+ end
256
+
257
+ return buffer[0...(last_addr - first_addr)]
258
+ end
259
+
94
260
  end