Permalink
Browse files

Bump fastlib to 0.0.6, no longer need to push metasploit.fastlib into…

… the include path
  • Loading branch information...
1 parent 2ddef11 commit 25c10d2e6562fb1411733756f4fad368415799ca HD Moore committed Nov 24, 2011
Showing with 83 additions and 76 deletions.
  1. +69 −62 lib/fastlib.rb
  2. +1 −1 msfbinscan
  3. +1 −1 msfcli
  4. +1 −1 msfconsole
  5. +1 −1 msfd
  6. +1 −1 msfelfscan
  7. +1 −1 msfencode
  8. +1 −1 msfmachscan
  9. +1 −1 msfopcode
  10. +1 −1 msfpayload
  11. +1 −1 msfpescan
  12. +1 −1 msfrop
  13. +1 −1 msfrpc
  14. +1 −1 msfrpcd
  15. +1 −1 msfvenom
View
131 lib/fastlib.rb
@@ -31,68 +31,6 @@
# >> rubyzip is free software; you can redistribute it and/or
# >> modify it under the terms of the ruby license.
-module Kernel #:nodoc:all
- alias :fastlib_original_require :require
-
- #
- # This method hooks the original Kernel.require to support
- # loading files within FASTLIB archives
- #
- def require(name)
- fastlib_require(name) || fastlib_original_require(name)
- end
-
- #
- # This method handles the loading of FASTLIB archives
- #
- def fastlib_require(name)
- name = name + ".rb" if not name =~ /\.rb$/
- return false if fastlib_already_loaded?(name)
- return false if fastlib_already_tried?(name)
-
- # TODO: Implement relative path $: checks and adjust the
- # search path within archives to match.
-
- $:.grep( /^(.*)\.fastlib$/ ).each do |lib|
- data = FastLib.load(lib, name)
- next if not data
- $" << name
-
- # TODO: Implement a better stack trace that represents
- # the original filename and line number.
- Object.class_eval(data)
- return true
- end
-
- $fastlib_miss << name
-
- false
- end
-
- #
- # This method determines whether the specific file name
- # has already been loaded ($LOADED_FEATURES aka $")
- #
- def fastlib_already_loaded?(name)
- re = Regexp.new("^" + Regexp.escape(name) + "$")
- $".detect { |e| e =~ re } != nil
- end
-
- #
- # This method determines whether the specific file name
- # has already been attempted with the included FASTLIB
- # archives.
- #
- # TODO: Ensure that this only applies to known FASTLIB
- # archives and that newly included archives will
- # be searched appropriately.
- #
- def fastlib_already_tried?(name)
- $fastlib_miss ||= []
- $fastlib_miss.include?(name)
- end
-end
-
#
# The FastLib class implements the meat of the FASTLIB archive format
@@ -403,4 +341,73 @@ def self.cache
=end
+module Kernel #:nodoc:all
+ alias :fastlib_original_require :require
+
+ #
+ # This method hooks the original Kernel.require to support
+ # loading files within FASTLIB archives
+ #
+ def require(name)
+ fastlib_require(name) || fastlib_original_require(name)
+ end
+
+ #
+ # This method handles the loading of FASTLIB archives
+ #
+ def fastlib_require(name)
+ name = name + ".rb" if not name =~ /\.rb$/
+ return false if fastlib_already_loaded?(name)
+ return false if fastlib_already_tried?(name)
+
+ # TODO: Implement relative path $: checks and adjust the
+ # search path within archives to match.
+
+ $:.map{ |path| ::Dir["#{path}/*.fastlib"] }.flatten.uniq.each do |lib|
+ data = FastLib.load(lib, name)
+ next if not data
+ $" << name
+
+ begin
+ Object.class_eval(data)
+ rescue ::Exception => e
+ opath,oerror = e.backtrace.shift.split(':', 2)
+ e.backtrace.unshift("#{lib}::#{name}:#{oerror}")
+ raise e
+ end
+
+ return true
+ end
+
+ $fastlib_miss << name
+
+ false
+ end
+
+ #
+ # This method determines whether the specific file name
+ # has already been loaded ($LOADED_FEATURES aka $")
+ #
+ def fastlib_already_loaded?(name)
+ re = Regexp.new("^" + Regexp.escape(name) + "$")
+ $".detect { |e| e =~ re } != nil
+ end
+
+ #
+ # This method determines whether the specific file name
+ # has already been attempted with the included FASTLIB
+ # archives.
+ #
+ # TODO: Ensure that this only applies to known FASTLIB
+ # archives and that newly included archives will
+ # be searched appropriately.
+ #
+ def fastlib_already_tried?(name)
+ $fastlib_miss ||= []
+ $fastlib_miss.include?(name)
+ end
+end
+
+
+
View
2 msfbinscan
@@ -12,7 +12,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfcli
@@ -17,7 +17,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfconsole
@@ -16,7 +16,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfd
@@ -18,7 +18,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfelfscan
@@ -12,7 +12,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfencode
@@ -12,7 +12,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfmachscan
@@ -12,7 +12,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfopcode
@@ -17,7 +17,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfpayload
@@ -12,7 +12,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfpescan
@@ -12,7 +12,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfrop
@@ -15,7 +15,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfrpc
@@ -16,7 +16,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfrpcd
@@ -16,7 +16,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
View
2 msfvenom
@@ -11,7 +11,7 @@ end
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
require 'fastlib'
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
+'))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']

0 comments on commit 25c10d2

Please sign in to comment.