ronin 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +95 -0
  3. data/Manifest.txt +55 -25
  4. data/README.txt +64 -52
  5. data/Rakefile +21 -14
  6. data/bin/ronin +1 -1
  7. data/bin/ronin-add +1 -1
  8. data/bin/ronin-console +1 -1
  9. data/bin/ronin-help +1 -1
  10. data/bin/ronin-install +1 -1
  11. data/bin/ronin-list +1 -1
  12. data/bin/ronin-remove +1 -1
  13. data/bin/ronin-uninstall +1 -1
  14. data/bin/ronin-update +1 -1
  15. data/lib/ronin.rb +2 -4
  16. data/lib/ronin/arch.rb +66 -21
  17. data/lib/ronin/author.rb +27 -18
  18. data/lib/ronin/cacheable.rb +63 -23
  19. data/lib/ronin/code/emittable.rb +1 -4
  20. data/lib/ronin/code/reference.rb +2 -5
  21. data/lib/ronin/code/symbol_table.rb +1 -4
  22. data/lib/ronin/code/token.rb +1 -4
  23. data/lib/ronin/config.rb +31 -10
  24. data/lib/ronin/database.rb +1 -4
  25. data/lib/ronin/database/database.rb +42 -23
  26. data/lib/ronin/database/exceptions.rb +1 -4
  27. data/lib/ronin/database/exceptions/invalid_config.rb +1 -4
  28. data/lib/ronin/environment.rb +1 -5
  29. data/lib/ronin/extensions.rb +1 -5
  30. data/lib/ronin/extensions/array.rb +8 -6
  31. data/lib/ronin/extensions/file.rb +9 -4
  32. data/lib/ronin/extensions/ip_addr.rb +33 -13
  33. data/lib/ronin/extensions/kernel.rb +44 -9
  34. data/lib/ronin/extensions/meta.rb +1 -4
  35. data/lib/ronin/extensions/string.rb +8 -7
  36. data/lib/ronin/extensions/uri.rb +1 -4
  37. data/lib/ronin/extensions/uri/http.rb +1 -48
  38. data/lib/ronin/extensions/uri/query_params.rb +27 -8
  39. data/lib/ronin/formatting.rb +1 -4
  40. data/lib/ronin/formatting/binary.rb +1 -4
  41. data/lib/ronin/formatting/digest.rb +1 -4
  42. data/lib/ronin/formatting/extensions.rb +1 -4
  43. data/lib/ronin/formatting/extensions/binary.rb +1 -4
  44. data/lib/ronin/formatting/extensions/binary/file.rb +3 -28
  45. data/lib/ronin/formatting/extensions/binary/integer.rb +31 -12
  46. data/lib/ronin/formatting/extensions/binary/string.rb +59 -36
  47. data/lib/ronin/formatting/extensions/digest.rb +1 -4
  48. data/lib/ronin/formatting/extensions/digest/string.rb +31 -9
  49. data/lib/ronin/formatting/extensions/http.rb +1 -4
  50. data/lib/ronin/formatting/extensions/http/string.rb +16 -9
  51. data/lib/ronin/formatting/extensions/text.rb +1 -4
  52. data/lib/ronin/formatting/extensions/text/array.rb +17 -7
  53. data/lib/ronin/formatting/extensions/text/string.rb +70 -27
  54. data/lib/ronin/formatting/http.rb +1 -4
  55. data/lib/ronin/formatting/text.rb +1 -4
  56. data/lib/ronin/license.rb +72 -65
  57. data/lib/ronin/model.rb +1 -4
  58. data/lib/ronin/model/has_description.rb +37 -8
  59. data/lib/ronin/model/has_license.rb +12 -8
  60. data/lib/ronin/model/has_name.rb +10 -7
  61. data/lib/ronin/model/has_version.rb +14 -4
  62. data/lib/ronin/model/model.rb +71 -14
  63. data/lib/ronin/network.rb +1 -4
  64. data/lib/ronin/network/esmtp.rb +1 -4
  65. data/lib/ronin/network/extensions.rb +1 -4
  66. data/lib/ronin/network/extensions/esmtp.rb +1 -4
  67. data/lib/ronin/network/extensions/esmtp/net.rb +49 -21
  68. data/lib/ronin/network/extensions/http.rb +1 -4
  69. data/lib/ronin/network/extensions/http/net.rb +319 -531
  70. data/lib/ronin/network/extensions/imap.rb +1 -4
  71. data/lib/ronin/network/extensions/imap/net.rb +50 -23
  72. data/lib/ronin/network/extensions/pop3.rb +1 -4
  73. data/lib/ronin/network/extensions/pop3/net.rb +40 -17
  74. data/lib/ronin/network/extensions/smtp.rb +1 -4
  75. data/lib/ronin/network/extensions/smtp/net.rb +49 -21
  76. data/lib/ronin/network/extensions/tcp.rb +1 -4
  77. data/lib/ronin/network/extensions/tcp/net.rb +234 -31
  78. data/lib/ronin/network/extensions/telnet.rb +1 -4
  79. data/lib/ronin/network/extensions/telnet/net.rb +83 -51
  80. data/lib/ronin/network/extensions/udp.rb +1 -4
  81. data/lib/ronin/network/extensions/udp/net.rb +164 -27
  82. data/lib/ronin/{sessions.rb → network/helpers.rb} +10 -13
  83. data/lib/ronin/network/helpers/esmtp.rb +129 -0
  84. data/lib/ronin/{sessions/session.rb → network/helpers/helper.rb} +25 -17
  85. data/lib/ronin/network/helpers/http.rb +444 -0
  86. data/lib/ronin/network/helpers/imap.rb +115 -0
  87. data/lib/ronin/network/helpers/pop3.rb +110 -0
  88. data/lib/ronin/network/helpers/smtp.rb +123 -0
  89. data/lib/ronin/network/helpers/tcp.rb +309 -0
  90. data/lib/ronin/network/helpers/telnet.rb +158 -0
  91. data/lib/ronin/network/helpers/udp.rb +197 -0
  92. data/lib/ronin/network/http.rb +3 -156
  93. data/lib/ronin/network/http/exceptions.rb +1 -4
  94. data/lib/ronin/network/http/exceptions/unknown_request.rb +1 -4
  95. data/lib/ronin/network/http/http.rb +214 -0
  96. data/lib/ronin/network/http/proxy.rb +308 -0
  97. data/lib/ronin/network/imap.rb +7 -6
  98. data/lib/ronin/network/pop3.rb +7 -6
  99. data/lib/ronin/network/smtp.rb +1 -4
  100. data/lib/ronin/network/smtp/email.rb +34 -18
  101. data/lib/ronin/network/smtp/smtp.rb +19 -7
  102. data/lib/ronin/network/tcp.rb +1 -4
  103. data/lib/ronin/network/telnet.rb +25 -12
  104. data/lib/ronin/network/udp.rb +1 -4
  105. data/lib/ronin/os.rb +43 -21
  106. data/lib/ronin/path.rb +29 -9
  107. data/lib/ronin/platform.rb +1 -4
  108. data/lib/ronin/platform/exceptions.rb +1 -4
  109. data/lib/ronin/platform/exceptions/extension_not_found.rb +1 -4
  110. data/lib/ronin/platform/exceptions/overlay_cached.rb +1 -4
  111. data/lib/ronin/platform/exceptions/overlay_not_found.rb +1 -4
  112. data/lib/ronin/platform/extension.rb +195 -52
  113. data/lib/ronin/platform/extension_cache.rb +60 -24
  114. data/lib/ronin/platform/maintainer.rb +15 -8
  115. data/lib/ronin/platform/object_cache.rb +29 -8
  116. data/lib/ronin/platform/overlay.rb +82 -26
  117. data/lib/ronin/platform/overlay_cache.rb +179 -56
  118. data/lib/ronin/platform/platform.rb +154 -58
  119. data/lib/ronin/platform/ronin.rb +38 -11
  120. data/lib/ronin/product.rb +17 -17
  121. data/lib/ronin/rpc.rb +1 -4
  122. data/lib/ronin/rpc/call.rb +1 -4
  123. data/lib/ronin/rpc/client.rb +1 -4
  124. data/lib/ronin/rpc/console.rb +1 -4
  125. data/lib/ronin/rpc/exceptions.rb +1 -4
  126. data/lib/ronin/rpc/exceptions/not_implemented.rb +1 -4
  127. data/lib/ronin/rpc/exceptions/response_missing.rb +1 -4
  128. data/lib/ronin/rpc/response.rb +1 -4
  129. data/lib/ronin/rpc/service.rb +1 -4
  130. data/lib/ronin/rpc/shell.rb +1 -4
  131. data/lib/ronin/scanners.rb +1 -4
  132. data/lib/ronin/scanners/exceptions.rb +1 -4
  133. data/lib/ronin/scanners/exceptions/unknown_category.rb +1 -4
  134. data/lib/ronin/scanners/scanner.rb +82 -26
  135. data/lib/ronin/static.rb +1 -4
  136. data/lib/ronin/static/finders.rb +1 -4
  137. data/lib/ronin/static/static.rb +16 -7
  138. data/lib/ronin/templates.rb +2 -4
  139. data/lib/ronin/templates/erb.rb +24 -10
  140. data/lib/ronin/templates/template.rb +130 -0
  141. data/lib/ronin/ui.rb +2 -6
  142. data/lib/ronin/ui/command_line.rb +1 -4
  143. data/lib/ronin/ui/command_line/command.rb +137 -68
  144. data/lib/ronin/ui/command_line/command_line.rb +52 -29
  145. data/lib/ronin/ui/command_line/commands/add.rb +39 -67
  146. data/lib/ronin/ui/command_line/commands/console.rb +23 -27
  147. data/lib/ronin/ui/command_line/commands/help.rb +10 -29
  148. data/lib/ronin/ui/command_line/commands/install.rb +31 -56
  149. data/lib/ronin/ui/command_line/commands/list.rb +34 -52
  150. data/lib/ronin/ui/command_line/commands/remove.rb +12 -32
  151. data/lib/ronin/ui/command_line/commands/uninstall.rb +11 -31
  152. data/lib/ronin/ui/command_line/commands/update.rb +15 -35
  153. data/lib/ronin/ui/command_line/exceptions.rb +1 -4
  154. data/lib/ronin/ui/command_line/exceptions/unknown_command.rb +1 -4
  155. data/lib/ronin/ui/console.rb +54 -23
  156. data/lib/ronin/ui/hexdump.rb +1 -4
  157. data/lib/ronin/ui/hexdump/extensions.rb +1 -4
  158. data/lib/ronin/ui/hexdump/extensions/file.rb +8 -6
  159. data/lib/ronin/ui/hexdump/extensions/kernel.rb +4 -5
  160. data/lib/ronin/ui/hexdump/hexdump.rb +8 -5
  161. data/lib/ronin/{sessions/exceptions.rb → ui/output.rb} +3 -5
  162. data/lib/ronin/ui/output/handler.rb +121 -0
  163. data/lib/ronin/ui/output/helpers.rb +110 -0
  164. data/lib/ronin/ui/output/output.rb +144 -0
  165. data/lib/ronin/ui/shell.rb +38 -12
  166. data/lib/ronin/version.rb +2 -5
  167. data/lib/ronin/{sessions/exceptions/variable_missing.rb → yard.rb} +2 -10
  168. data/lib/ronin/{ronin.rb → yard/handlers.rb} +5 -15
  169. data/lib/ronin/yard/handlers/ruby.rb +27 -0
  170. data/lib/ronin/yard/handlers/ruby/base.rb +27 -0
  171. data/lib/ronin/yard/handlers/ruby/belongs_to_handler.rb +45 -0
  172. data/lib/ronin/yard/handlers/ruby/eval_block_handler.rb +18 -0
  173. data/lib/ronin/yard/handlers/ruby/has_handler.rb +49 -0
  174. data/lib/ronin/yard/handlers/ruby/legacy.rb +26 -0
  175. data/lib/ronin/yard/handlers/ruby/legacy/belongs_to_handler.rb +41 -0
  176. data/lib/ronin/yard/handlers/ruby/legacy/eval_block_handler.rb +19 -0
  177. data/lib/ronin/yard/handlers/ruby/legacy/has_handler.rb +34 -0
  178. data/lib/ronin/yard/handlers/ruby/legacy/metaclass_eval_handler.rb +21 -0
  179. data/lib/ronin/yard/handlers/ruby/legacy/property_handler.rb +41 -0
  180. data/lib/ronin/yard/handlers/ruby/legacy/scanner_handler.rb +61 -0
  181. data/lib/ronin/yard/handlers/ruby/metaclass_eval_handler.rb +18 -0
  182. data/lib/ronin/yard/handlers/ruby/property_handler.rb +45 -0
  183. data/lib/ronin/yard/handlers/ruby/scanner_handler.rb +66 -0
  184. data/spec/author_spec.rb +3 -3
  185. data/spec/extensions/classes/some_class.rb +2 -0
  186. data/spec/extensions/kernel_spec.rb +17 -0
  187. data/spec/extensions/uri/http_spec.rb +0 -31
  188. data/spec/formatting/binary/integer_spec.rb +4 -0
  189. data/spec/formatting/text/string_spec.rb +96 -0
  190. data/spec/license_spec.rb +6 -6
  191. data/spec/model/classes/basic_model.rb +13 -0
  192. data/spec/model/classes/custom_model.rb +17 -0
  193. data/spec/model/classes/described_model.rb +10 -0
  194. data/spec/model/has_description_spec.rb +42 -0
  195. data/spec/model/has_license_spec.rb +18 -4
  196. data/spec/model/model_spec.rb +68 -0
  197. data/spec/network/helpers/classes/test_helper.rb +11 -0
  198. data/spec/network/helpers/classes/uses_test_helper.rb +10 -0
  199. data/spec/network/helpers/helper_spec.rb +25 -0
  200. data/spec/network/{http_spec.rb → http/http_spec.rb} +0 -0
  201. data/spec/network/http/proxy_spec.rb +116 -0
  202. data/spec/os_spec.rb +4 -4
  203. data/spec/platform/extension_cache_spec.rb +14 -0
  204. data/spec/platform/extension_spec.rb +11 -0
  205. data/spec/platform/platform_spec.rb +8 -0
  206. data/spec/product_spec.rb +9 -9
  207. data/spec/spec_helper.rb +1 -1
  208. data/spec/templates/classes/{uses_erb.rb → example_erb.rb} +1 -1
  209. data/spec/templates/classes/example_template.rb +21 -0
  210. data/spec/templates/erb_spec.rb +2 -2
  211. data/spec/templates/helpers/static.rb +5 -0
  212. data/spec/templates/helpers/static/templates/_relative.erb +1 -0
  213. data/spec/templates/helpers/static/templates/example.erb +1 -0
  214. data/spec/templates/template_spec.rb +41 -0
  215. data/spec/ui/command_line/classes/test_command.rb +23 -0
  216. data/spec/ui/command_line/command_spec.rb +31 -0
  217. data/spec/ui/output_spec.rb +29 -0
  218. data/static/ronin/platform/overlay.xsl +135 -114
  219. data/tasks/spec.rb +1 -0
  220. data/tasks/yard.rb +18 -0
  221. metadata +98 -59
  222. metadata.gz.sig +0 -0
  223. data/TODO.txt +0 -15
  224. data/lib/ronin/extensions/hash.rb +0 -62
  225. data/lib/ronin/sessions/esmtp.rb +0 -57
  226. data/lib/ronin/sessions/http.rb +0 -678
  227. data/lib/ronin/sessions/imap.rb +0 -54
  228. data/lib/ronin/sessions/pop3.rb +0 -52
  229. data/lib/ronin/sessions/smtp.rb +0 -57
  230. data/lib/ronin/sessions/tcp.rb +0 -100
  231. data/lib/ronin/sessions/telnet.rb +0 -55
  232. data/lib/ronin/sessions/udp.rb +0 -73
  233. data/lib/ronin/ui/command_line/options.rb +0 -136
  234. data/lib/ronin/ui/diagnostics.rb +0 -66
  235. data/lib/ronin/ui/verbose.rb +0 -58
  236. data/spec/extensions/hash_spec.rb +0 -38
  237. data/spec/sessions/classes/test_session.rb +0 -11
  238. data/spec/sessions/classes/uses_test_session.rb +0 -10
  239. data/spec/sessions/session_spec.rb +0 -25
  240. data/spec/ui/verbose_spec.rb +0 -17
@@ -1,7 +1,5 @@
1
1
  #
2
- #--
3
- # Ronin - A Ruby platform designed for information security and data
4
- # exploration tasks.
2
+ # Ronin - A Ruby platform for exploit development and security research.
5
3
  #
6
4
  # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
5
  #
@@ -18,7 +16,6 @@
18
16
  # You should have received a copy of the GNU General Public License
19
17
  # along with this program; if not, write to the Free Software
20
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- #++
22
19
  #
23
20
 
24
21
  require 'ronin/platform/exceptions/overlay_cached'
@@ -42,9 +39,17 @@ module Ronin
42
39
  attr_reader :path
43
40
 
44
41
  #
45
- # Create a new OverlayCache object with the specified _path_. The
46
- # _path_ defaults to <tt>CACHE_FILE</tt>. If a _block_ is given,
47
- # it will be passed the newly created OverlayCache object.
42
+ # Create a new OverlayCache object.
43
+ #
44
+ # @param [String] path
45
+ # The path of the overlay cache file.
46
+ #
47
+ # @yield [cache]
48
+ # If a block is given, it will be passed the newly created overlay
49
+ # cache.
50
+ #
51
+ # @yieldparam [OverlayCache] cache
52
+ # The newly created overly cache.
48
53
  #
49
54
  def initialize(path=CACHE_FILE,&block)
50
55
  super()
@@ -52,23 +57,7 @@ module Ronin
52
57
  @path = path
53
58
  @dirty = false
54
59
 
55
- if File.file?(@path)
56
- descriptions = YAML.load_file(@path)
57
-
58
- if descriptions.kind_of?(Array)
59
- descriptions.each do |overlay|
60
- if overlay.kind_of?(Hash)
61
- overlay = Overlay.new(
62
- overlay[:path],
63
- overlay[:media],
64
- overlay[:uri]
65
- )
66
-
67
- self[overlay.name] = overlay
68
- end
69
- end
70
- end
71
- end
60
+ load!()
72
61
 
73
62
  at_exit(&method(:save))
74
63
 
@@ -76,15 +65,50 @@ module Ronin
76
65
  end
77
66
 
78
67
  #
79
- # Returns +true+ if the overlay cache has been modified, returns
80
- # +false+ otherwise.
68
+ # Loads the overlays from the cache-file at the +path+.
69
+ #
70
+ def load!
71
+ return false unless File.file?(@path)
72
+
73
+ descriptions = YAML.load_file(@path)
74
+
75
+ return false unless descriptions.kind_of?(Array)
76
+
77
+ descriptions.each do |overlay|
78
+ if overlay.kind_of?(Hash)
79
+ overlay = Overlay.new(
80
+ overlay[:path],
81
+ overlay[:media],
82
+ overlay[:uri]
83
+ )
84
+
85
+ self[overlay.name] = overlay
86
+ end
87
+ end
88
+
89
+ return true
90
+ end
91
+
92
+ #
93
+ # Clears the overlay cache, and reloads it's contents from the same
94
+ # cache-file.
95
+ #
96
+ def reload!
97
+ clear
98
+ load!
99
+ end
100
+
101
+ #
102
+ # @return [Boolean]
103
+ # Specifies whether the overlay cache has been modified.
81
104
  #
82
105
  def dirty?
83
106
  @dirty == true
84
107
  end
85
108
 
86
109
  #
87
- # Returns the sorted names of the overlays within the cache.
110
+ # @return [Array]
111
+ # The sorted names of the overlays within the cache.
88
112
  #
89
113
  def names
90
114
  keys.sort
@@ -94,8 +118,19 @@ module Ronin
94
118
  alias each_overlay each_value
95
119
 
96
120
  #
97
- # Returns the Ovlerays which match the specified _block_.
121
+ # Selects overlays from the overlay cache.
98
122
  #
123
+ # @yield [overlay]
124
+ # The block that will be passed each overlay. Overlays will be
125
+ # selected based on the return value of the block.
126
+ #
127
+ # @yieldparam [Overlay] overlay
128
+ # An overlay from the cache.
129
+ #
130
+ # @return [Array]
131
+ # The selected overlay.
132
+ #
133
+ # @example
99
134
  # cache.with do |overlay|
100
135
  # overlay.author == 'the dude'
101
136
  # end
@@ -105,15 +140,31 @@ module Ronin
105
140
  end
106
141
 
107
142
  #
108
- # Returns +true+ if the cache contains the Overlay with the
109
- # matching _name_, returns +false+ otherwise.
143
+ # Searches for the overlay with the specified _name_.
144
+ #
145
+ # @param [String] name
146
+ # The name of the overlay to search for.
147
+ #
148
+ # @return [Boolean]
149
+ # Specifies whether the cache contains the Overlay with the
150
+ # matching _name_.
110
151
  #
111
152
  def has?(name)
112
153
  has_key?(name.to_s)
113
154
  end
114
155
 
115
156
  #
116
- # Returns the Overlay with the matching _name_.
157
+ # Searches for the overlay with the specified _name_.
158
+ #
159
+ # @param [String] name
160
+ # The name of the overlay to search for.
161
+ #
162
+ # @return [Overlay]
163
+ # The overlay with the matching _name_.
164
+ #
165
+ # @raise [OverlayNotFound]
166
+ # No overlay with the matching _name_ could be found in the
167
+ # overlay cache.
117
168
  #
118
169
  def get(name)
119
170
  name = name.to_s
@@ -126,16 +177,22 @@ module Ronin
126
177
  end
127
178
 
128
179
  #
129
- # Returns the paths of the Overlays contained in the cache.
180
+ # @return [Array]
181
+ # The paths of the overlays contained in the cache.
130
182
  #
131
183
  def paths
132
184
  overlays.map { |overlay| overlay.path }
133
185
  end
134
186
 
135
187
  #
136
- # Returns +true+ if the extension with the specified _name_ exists
137
- # within any of the overlays in the overlay cache, returns +false+
138
- # otherwise.
188
+ # Searches for an extension within all overlays in the overlay cache.
189
+ #
190
+ # @param [String] name
191
+ # The name of the extension to search for.
192
+ #
193
+ # @return [Boolean]
194
+ # Specifies whether the extension with the specified _name_ exists
195
+ # within any of the overlays in the overlay cache.
139
196
  #
140
197
  def has_extension?(name)
141
198
  each_overlay do |overlay|
@@ -146,7 +203,8 @@ module Ronin
146
203
  end
147
204
 
148
205
  #
149
- # Returns the names of all extensions within the overlay cache.
206
+ # @return [Array]
207
+ # The names of all extensions within the overlay cache.
150
208
  #
151
209
  def extensions
152
210
  ext_names = []
@@ -161,7 +219,14 @@ module Ronin
161
219
  end
162
220
 
163
221
  #
164
- # Returns the paths of all extensions with the specified _name_.
222
+ # Selects the paths of extensions that have the specified _name_, in
223
+ # all overlays in the overlay cache.
224
+ #
225
+ # @param [String] name
226
+ # The name of the extension to gather paths for.
227
+ #
228
+ # @return [Array]
229
+ # The paths of all extensions with the matching _name_.
165
230
  #
166
231
  def extension_paths(name)
167
232
  ext_paths = []
@@ -176,8 +241,16 @@ module Ronin
176
241
  end
177
242
 
178
243
  #
179
- # Adds the specified _overlay_ with the specified _name_ to the
180
- # overlay cache.
244
+ # Adds an overlay with the specified _name_ to the overlay cache.
245
+ #
246
+ # @param [String] name
247
+ # The name of the overlay.
248
+ #
249
+ # @param [Overlay] overlay
250
+ # The new overlay.
251
+ #
252
+ # @return [Overlay]
253
+ # The new overlay.
181
254
  #
182
255
  def []=(name,overlay)
183
256
  super(name.to_s,overlay)
@@ -187,38 +260,62 @@ module Ronin
187
260
  end
188
261
 
189
262
  #
190
- # Adds the _overlay_ to the cache. If a _block_ is given, it will
191
- # be passed the cache after the _overlay_ is added. The _overlay_
192
- # will be returned.
263
+ # Adds an overlay to the cache.
264
+ #
265
+ # @param [Overlay] overlay
266
+ # The overlay to add.
267
+ #
268
+ # @yield [overlay]
269
+ # If a block is given, it will be passed the overlay after it has
270
+ # been added to the cache.
271
+ #
272
+ # @yieldparam [Overlay] overlay
273
+ # The newly added overlay.
193
274
  #
275
+ # @return [Overlay]
276
+ # The newly added overlay.
277
+ #
278
+ # @example
194
279
  # cache.add(overlay)
195
280
  # # => #<Ronin::Platform::Overlay: ...>
196
281
  #
282
+ # @example
197
283
  # cache.add(overlay) do |cache|
198
284
  # puts "Overlay #{overlay} added"
199
285
  # end
200
286
  #
287
+ # @raise [OverlayCache]
288
+ # The specified _overlay_ has already been cached.
289
+ #
201
290
  def add(overlay,&block)
202
291
  name = overlay.name.to_s
203
292
 
204
293
  if has?(name)
205
- raise(OverlayCached,"overlay #{name.dump} already present in the cache #{self.to_s.dump}",caller)
294
+ raise(OverlayCached,"overlay #{name.dump} is already present in the cache #{self.to_s.dump}",caller)
206
295
  end
207
296
 
208
297
  self[overlay.name.to_s] = overlay
209
298
  dirty!
210
299
 
211
- block.call(self) if block
212
- return self
300
+ block.call(overlay) if block
301
+ return overlay
213
302
  end
214
303
 
215
304
  #
216
- # Updates all the cached Overlays. If a _block_ is given it will
217
- # be passed the overlays as they are updated.
305
+ # Updates all overlays in the cache.
306
+ #
307
+ # @yield [overlay]
308
+ # If a block is given, it will be passed each overlay after it has
309
+ # been updated.
218
310
  #
311
+ # @yieldparam [Overlay] overlay
312
+ # Each updated overlay in the cache.
313
+ #
314
+ # @example
219
315
  # update
220
316
  # # => #<Ronin::Platform::OverlayCache: ...>
221
317
  #
318
+ # @example
222
319
  # update do |overlay|
223
320
  # puts "#{overaly} is updated"
224
321
  # end
@@ -234,13 +331,26 @@ module Ronin
234
331
  end
235
332
 
236
333
  #
237
- # Removes the overlay with the specified _name_ from the cache. If a
238
- # _block_ is given, it will be passed the removed overlay. The cache
239
- # will be returned, after the overlay is removed.
334
+ # Removes an overlay from the overlay cache, but leaves the contents
335
+ # of the overlay intact.
336
+ #
337
+ # @param [String] name
338
+ # The name of the overlay to remove.
339
+ #
340
+ # @yield [overlay]
341
+ # If a block is given, it will be passed the removed overlay.
240
342
  #
343
+ # @yieldparam [Overlay] overlay
344
+ # The removed overlay.
345
+ #
346
+ # @return [Overlay]
347
+ # The removed overlay.
348
+ #
349
+ # @example
241
350
  # cache.remove('hello_word')
242
351
  # # => #<Ronin::Platform::Overlay: ...>
243
352
  #
353
+ # @example
244
354
  # cache.remove('hello_word') do |overlay|
245
355
  # puts "Overlay #{overlay} removed"
246
356
  # end
@@ -255,17 +365,27 @@ module Ronin
255
365
  dirty!
256
366
 
257
367
  block.call(overlay) if block
258
- return self
368
+ return overlay
259
369
  end
260
370
 
261
371
  #
262
- # Uninstalls the overlay with the specified _name_. If a _block_
263
- # is given, it will be passed the uninstalled overlay. The cache
264
- # will be returned, after the overlay is removed.
372
+ # Uninstalls an overlay and its contents from the overlay cache.
265
373
  #
374
+ # @param [String] name
375
+ # The name of the overlay to uninstall.
376
+ #
377
+ # @yield [overlay]
378
+ # If a block is given, it will be passed the overlay, after it has
379
+ # been uninstalled.
380
+ #
381
+ # @yieldparam [Overlay] overlay
382
+ # The uninstalled overlay.
383
+ #
384
+ # @example
266
385
  # cache.uninstall('hello_word')
267
386
  # # => #<Ronin::Platform::Overlay: ...>
268
387
  #
388
+ # @example
269
389
  # cache.uninstall('hello_word') do |overlay|
270
390
  # puts "Overlay #{overlay} uninstalled"
271
391
  # end
@@ -274,10 +394,12 @@ module Ronin
274
394
  remove(name) do |overlay|
275
395
  overlay.uninstall(&block)
276
396
  end
397
+
398
+ return nil
277
399
  end
278
400
 
279
401
  #
280
- # Saves the overlay cache.
402
+ # Saves the overlay cache to the path.
281
403
  #
282
404
  def save
283
405
  return false unless dirty?
@@ -304,7 +426,8 @@ module Ronin
304
426
  end
305
427
 
306
428
  #
307
- # Returns the +path+ of the cache.
429
+ # @return [String]
430
+ # The path of the cache.
308
431
  #
309
432
  def to_s
310
433
  @path.to_s
@@ -1,7 +1,5 @@
1
1
  #
2
- #--
3
- # Ronin - A Ruby platform designed for information security and data
4
- # exploration tasks.
2
+ # Ronin - A Ruby platform for exploit development and security research.
5
3
  #
6
4
  # Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
7
5
  #
@@ -18,7 +16,6 @@
18
16
  # You should have received a copy of the GNU General Public License
19
17
  # along with this program; if not, write to the Free Software
20
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- #++
22
19
  #
23
20
 
24
21
  require 'ronin/platform/exceptions/overlay_not_found'
@@ -31,34 +28,66 @@ require 'uri'
31
28
  module Ronin
32
29
  module Platform
33
30
  #
34
- # Load the overlay cache from the given _path_. If a _block_ is
35
- # given it will be passed the current overlay cache.
31
+ # Load the overlay cache.
36
32
  #
33
+ # @param [String] path
34
+ # The optional path to the overlay cache file.
35
+ #
36
+ # @return [OverlayCache]
37
+ # The newly loaded overlay cache.
38
+ #
39
+ # @example
40
+ # Overlay.load_overlays
41
+ # # => #<Ronin::Platform::OverlayCache: ...>
42
+ #
43
+ # @example
37
44
  # Overlay.load_overlays('/custom/overlays/cache.yaml')
38
45
  # # => #<Ronin::Platform::OverlayCache: ...>
39
46
  #
40
- def Platform.load_overlays(path)
47
+ def Platform.load_overlays(path=OverlayCache::CACHE_FILE)
41
48
  @@ronin_overlay_cache = OverlayCache.new(path)
42
49
  end
43
50
 
44
51
  #
45
- # Returns the current overlay cache, or loads the default overlay
46
- # cache if not already loaded.
52
+ # @return [OverlayCache]
53
+ # The current overlay cache. If no overlay cache is present, the
54
+ # default overlay will be loaded.
47
55
  #
48
56
  def Platform.overlays
49
57
  @@ronin_overlay_cache ||= OverlayCache.new
50
58
  end
51
59
 
52
60
  #
53
- # Adds a new Overlay with the given _options_. If a _block_ is given
54
- # it will be passed the newly added overlay.
61
+ # Adds a new overlay to the overlay cache.
62
+ #
63
+ # @param [Hash] options
64
+ # Additional options.
65
+ #
66
+ # @option options [String] :path
67
+ # A pre-existing path to the overlay.
68
+ #
69
+ # @option options [Symbol] :media
70
+ # The media type of the overlay, may be either +:git+, +:hg+,
71
+ # +:svn+ or +:rsync+.
72
+ #
73
+ # @option options [String, URI::HTTP, URI::HTTPS] uri
74
+ # The URI of the overlay.
75
+ #
76
+ # @yield [overlay]
77
+ # If a block is given, it will be passed the overlay after it has
78
+ # been added to the cache.
79
+ #
80
+ # @yieldparam [Overlay] overlay
81
+ # The newly added overlay.
82
+ #
83
+ # @return [Overlay]
84
+ # The newly added overlay.
55
85
  #
56
- # _options_ must contain the following key:
57
- # <tt>:path</tt>:: The path of the overlay.
86
+ # @raise [ArgumentError]
87
+ # The +:path+ option was not specified.
58
88
  #
59
- # _options_ may contain the following key:
60
- # <tt>:media</tt>:: The media of the overlay.
61
- # <tt>:uri</tt>:: The URI of the overlay.
89
+ # @raise [OverlayNotFound]
90
+ # The +:path+ option did not represent a valid directory.
62
91
  #
63
92
  def Platform.add(options={},&block)
64
93
  path = options[:path]
@@ -78,24 +107,40 @@ module Ronin
78
107
 
79
108
  overlay = Overlay.new(path,media,uri)
80
109
 
81
- Platform.overlays.add(overlay) do
110
+ Platform.overlays.add(overlay) do |overlay|
82
111
  ObjectCache.cache(overlay.objects_dir)
83
112
  end
84
113
 
114
+ block.call(overlay) if block
85
115
  return overlay
86
116
  end
87
117
 
88
118
  #
89
- # Installs an Overlay specified by _options_ into the
90
- # OverlayCache::CACHE_DIR. If a _block_ is given, it will be
91
- # passed the newly created overlay after it has been added to
92
- # the overlay cache.
119
+ # Installs an overlay into the OverlayCache::CACHE_DIR and adds it
120
+ # to the overlay cache.
93
121
  #
94
- # _options_ must contain the following key:
95
- # <tt>:uri</tt>:: The URI of the overlay.
122
+ # @param [Hash] options
123
+ # Additional options.
96
124
  #
97
- # _options_ may contain the following key:
98
- # <tt>:media</tt>:: The media of the overlay.
125
+ # @option options [String, URI::HTTP, URI::HTTPS] :uri
126
+ # The URI to the overlay.
127
+ #
128
+ # @option options [Symbol] :media
129
+ # The media type of the overlay, may be either +:git+, +:hg+,
130
+ # +:svn+ or +:rsync+.
131
+ #
132
+ # @yield [overlay]
133
+ # If a block is given, it will be passed the overlay, after it has
134
+ # been installed.
135
+ #
136
+ # @yieldparam [Overlay] overlay
137
+ # The newly installed overlay.
138
+ #
139
+ # @return [Overlay]
140
+ # The newly installed overlay.
141
+ #
142
+ # @raise [ArgumentError]
143
+ # The +:uri+ option must be specified.
99
144
  #
100
145
  def Platform.install(options={},&block)
101
146
  unless options[:uri]
@@ -111,14 +156,18 @@ module Ronin
111
156
  return Platform.add(
112
157
  :path => repo.path,
113
158
  :media => repo.media_name,
114
- :uri => uri
159
+ :uri => uri,
160
+ &block
115
161
  )
116
162
  end
117
163
  end
118
164
 
119
165
  #
120
- # Updates all previously installed overlays. If a _block_ is given
121
- # it will be called after the overlays have been updated.
166
+ # Updates all previously installed overlays within the overlay cache.
167
+ #
168
+ # @yield []
169
+ # If a block is given, it will be called after all overlays have been
170
+ # updated within the cache.
122
171
  #
123
172
  def Platform.update(&block)
124
173
  Platform.overlays.update do |overlay|
@@ -130,10 +179,22 @@ module Ronin
130
179
  end
131
180
 
132
181
  #
133
- # Removes the overlay with the specified _name_. If no overlay
134
- # has the specified _name_, an OverlayNotFound exception will be
135
- # raised. If a _block_ is given, it will be called after the overlay
136
- # has been removed.
182
+ # Removes an overlay from the overlay cache, but leaves the contents
183
+ # of the overlay intact.
184
+ #
185
+ # @param [String] name
186
+ # The name of the overlay to remove.
187
+ #
188
+ # @yield [overlay]
189
+ # If a block is given, it will be passed the overlay after it has
190
+ # been removed.
191
+ #
192
+ # @yieldparam [Overlay] overlay
193
+ # The removed overlay.
194
+ #
195
+ # @raise [OverlayNotFound]
196
+ # The overlay with the specified _name_ could not be found in the
197
+ # overlay cache.
137
198
  #
138
199
  def Platform.remove(name,&block)
139
200
  Platform.overlays.remove(name,&block)
@@ -141,10 +202,19 @@ module Ronin
141
202
  end
142
203
 
143
204
  #
144
- # Uninstalls the overlay with the specified _name_. If no overlay
145
- # has the specified _name_, an OverlayNotFound exception will be
146
- # raised. If a _block_ is given, it will be called after the overlay
147
- # has been uninstalled.
205
+ # Uninstalls an overlay from the overlay cache, and deletes the
206
+ # contents of the overlay.
207
+ #
208
+ # @param [String] name
209
+ # The name of the overlay to uninstall.
210
+ #
211
+ # @yield []
212
+ # If a block is given, it will be called after the overlay has been
213
+ # uninstalled.
214
+ #
215
+ # @raise [OverlayNotFound]
216
+ # The overlay with the specified _name_ could not be found in the
217
+ # overlay cache.
148
218
  #
149
219
  def Platform.uninstall(name,&block)
150
220
  Platform.overlays.uninstall(name) do |overlay|
@@ -156,36 +226,36 @@ module Ronin
156
226
  end
157
227
 
158
228
  #
159
- # Returns the names of all extensions within the overlay cache.
229
+ # @return [Array]
230
+ # The names of all extensions within the overlays in the overlay
231
+ # cache.
160
232
  #
161
233
  def Platform.extension_names
162
- names = []
163
-
164
- Platform.overlays.each_overlay do |overlay|
165
- overlay.extensions.each do |name|
166
- names << name unless names.include?(name)
167
- end
168
- end
169
-
170
- return names
234
+ Platform.overlays.extensions
171
235
  end
172
236
 
173
237
  #
174
- # Returns +true+ if the cache has the extension with the matching
175
- # _name_, returns +false+ otherwise.
238
+ # Searches for the extension with the specified _name_, in all
239
+ # overlays within the overlay cache.
240
+ #
241
+ # @param [String] name
242
+ # The name of the extension to search for.
243
+ #
244
+ # @return [Boolean]
245
+ # Specifies whether the overlay cache contains the extension with
246
+ # the matching _name_.
176
247
  #
177
248
  def Platform.has_extension?(name)
178
- Platform.overlays.each_overlay do |overlay|
179
- return true if overlay.has_extension?(name)
180
- end
181
-
182
- return false
249
+ Platform.overlays.has_extension?(name)
183
250
  end
184
251
 
185
252
  #
186
- # Returns a +Hash+ of all loaded extensions. Extensions can be loaded
187
- # on-the-fly by accessing the +Hash+.
253
+ # The extension cache.
254
+ #
255
+ # @return [ExtensionCache]
256
+ # The extension cache of all currently loaded extensions.
188
257
  #
258
+ # @example
189
259
  # Platform.extensions['shellcode']
190
260
  # # => #<Ronin::Platform::Extension: ...>
191
261
  #
@@ -194,9 +264,25 @@ module Ronin
194
264
  end
195
265
 
196
266
  #
197
- # Loads the extension with the specified _name_. If a _block_ is given
198
- # it will be passed the loaded extension. If the extension cannot be
199
- # loaded, an ExtensionNotFound exception will be raised.
267
+ # Loads an extension into the extension cache, if it has yet to be
268
+ # loaded.
269
+ #
270
+ # @param [String] name
271
+ # The name of the desired extension.
272
+ #
273
+ # @yield [ext]
274
+ # If a block is given, it will be passed the extension with the
275
+ # matching _name_.
276
+ #
277
+ # @yieldparam [Extension] ext
278
+ # The desired extension.
279
+ #
280
+ # @return [Extension]
281
+ # The desired extension.
282
+ #
283
+ # @raise [ExtensionNotFound]
284
+ # The extension with the specified _name_ could not be found in any
285
+ # of the overlays or in the extension cache.
200
286
  #
201
287
  def Platform.extension(name,&block)
202
288
  ext = Platform.extensions[name]
@@ -204,5 +290,15 @@ module Ronin
204
290
  block.call(ext) if block
205
291
  return ext
206
292
  end
293
+
294
+ #
295
+ # Reloads the overlay cache and the extension cache.
296
+ #
297
+ # @return [Boolean]
298
+ # Specifies whether the reload was successful or not.
299
+ #
300
+ def Platform.reload!
301
+ Platform.overlays.reload! && Platform.extensions.reload!
302
+ end
207
303
  end
208
304
  end