Skip to content

Commit

Permalink
Bump fastlib to 0.0.6, no longer need to push metasploit.fastlib into…
Browse files Browse the repository at this point in the history
… the include path
  • Loading branch information
HD Moore committed Nov 24, 2011
1 parent 2ddef11 commit 25c10d2
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 76 deletions.
131 changes: 69 additions & 62 deletions lib/fastlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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




2 changes: 1 addition & 1 deletion msfbinscan
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfcli
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfconsole
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfd
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfelfscan
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfencode
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfmachscan
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfopcode
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfpayload
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfpescan
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfrop
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfrpc
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfrpcd
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion msfvenom
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 25c10d2

Please sign in to comment.