From 25c10d2e6562fb1411733756f4fad368415799ca Mon Sep 17 00:00:00 2001 From: HD Moore Date: Wed, 23 Nov 2011 23:02:43 -0600 Subject: [PATCH] Bump fastlib to 0.0.6, no longer need to push metasploit.fastlib into the include path --- lib/fastlib.rb | 131 ++++++++++++++++++++++++++----------------------- msfbinscan | 2 +- msfcli | 2 +- msfconsole | 2 +- msfd | 2 +- msfelfscan | 2 +- msfencode | 2 +- msfmachscan | 2 +- msfopcode | 2 +- msfpayload | 2 +- msfpescan | 2 +- msfrop | 2 +- msfrpc | 2 +- msfrpcd | 2 +- msfvenom | 2 +- 15 files changed, 83 insertions(+), 76 deletions(-) diff --git a/lib/fastlib.rb b/lib/fastlib.rb index 390b74158e..8062b4d5dd 100755 --- a/lib/fastlib.rb +++ b/lib/fastlib.rb @@ -31,68 +31,6 @@ require "find" # >> 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 @@ end =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 + + + diff --git a/msfbinscan b/msfbinscan index b31edc972a..93a718cbb2 100755 --- a/msfbinscan +++ b/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'] diff --git a/msfcli b/msfcli index 75f47459f1..cdfb68cf66 100755 --- a/msfcli +++ b/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'] diff --git a/msfconsole b/msfconsole index beae22e163..a4470a28a3 100755 --- a/msfconsole +++ b/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'] diff --git a/msfd b/msfd index ccd4d2cd79..3e33c8d957 100755 --- a/msfd +++ b/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'] diff --git a/msfelfscan b/msfelfscan index f098a494be..7944dbb167 100755 --- a/msfelfscan +++ b/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'] diff --git a/msfencode b/msfencode index dc300ee402..1de951c36b 100755 --- a/msfencode +++ b/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'] diff --git a/msfmachscan b/msfmachscan index 5f7f29988e..1a1fe4d821 100755 --- a/msfmachscan +++ b/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'] diff --git a/msfopcode b/msfopcode index e7939adb4c..0309362eb5 100755 --- a/msfopcode +++ b/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'] diff --git a/msfpayload b/msfpayload index 5601e7f91b..f8cfee879b 100755 --- a/msfpayload +++ b/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'] diff --git a/msfpescan b/msfpescan index e1f4b2ffcb..eb81955e74 100755 --- a/msfpescan +++ b/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'] diff --git a/msfrop b/msfrop index 79bb0b1469..caa4b8dfc3 100755 --- a/msfrop +++ b/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'] diff --git a/msfrpc b/msfrpc index ff308226f2..06535db6f4 100755 --- a/msfrpc +++ b/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'] diff --git a/msfrpcd b/msfrpcd index 0086660c0f..3f5db9a484 100755 --- a/msfrpcd +++ b/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'] diff --git a/msfvenom b/msfvenom index 9624ffb372..4946ad1dea 100755 --- a/msfvenom +++ b/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']