Skip to content
This repository
Browse code

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

… the include path
  • Loading branch information...
commit 25c10d2e6562fb1411733756f4fad368415799ca 1 parent 2ddef11
HD Moore authored
131  lib/fastlib.rb
@@ -31,68 +31,6 @@
31 31
 # 	>> rubyzip is free software; you can redistribute it and/or
32 32
 # 	>> modify it under the terms of the ruby license.
33 33
 
34  
-module Kernel #:nodoc:all
35  
-	alias :fastlib_original_require :require
36  
-
37  
-	#
38  
-	# This method hooks the original Kernel.require to support
39  
-	# loading files within FASTLIB archives
40  
-	#	
41  
-	def require(name)
42  
-		fastlib_require(name) || fastlib_original_require(name)
43  
-	end
44  
-	
45  
-	#
46  
-	# This method handles the loading of FASTLIB archives
47  
-	#
48  
-	def fastlib_require(name)
49  
-		name = name + ".rb" if not name =~ /\.rb$/
50  
-		return false if fastlib_already_loaded?(name)
51  
-		return false if fastlib_already_tried?(name)
52  
-
53  
-		# TODO: Implement relative path $: checks and adjust the
54  
-		#       search path within archives to match.
55  
-			
56  
-		$:.grep( /^(.*)\.fastlib$/ ).each do |lib|
57  
-			data = FastLib.load(lib, name)
58  
-			next if not data
59  
-			$" << name
60  
-			
61  
-			# TODO: Implement a better stack trace that represents
62  
-			#       the original filename and line number.
63  
-			Object.class_eval(data)
64  
-			return true
65  
-		end
66  
-		
67  
-		$fastlib_miss << name 	
68  
-
69  
-		false
70  
-	end
71  
-	
72  
-	#
73  
-	# This method determines whether the specific file name
74  
-	# has already been loaded ($LOADED_FEATURES aka $")
75  
-	#
76  
-	def fastlib_already_loaded?(name)
77  
-		re = Regexp.new("^" + Regexp.escape(name) + "$")
78  
-		$".detect { |e| e =~ re } != nil
79  
-	end
80  
-
81  
-	#
82  
-	# This method determines whether the specific file name
83  
-	# has already been attempted with the included FASTLIB
84  
-	# archives.
85  
-	#
86  
-	# TODO: Ensure that this only applies to known FASTLIB
87  
-	#       archives and that newly included archives will
88  
-	#       be searched appropriately.
89  
-	#	
90  
-	def fastlib_already_tried?(name)
91  
-		$fastlib_miss ||= []
92  
-		$fastlib_miss.include?(name)
93  
-	end	
94  
-end
95  
-
96 34
 
97 35
 #
98 36
 # The FastLib class implements the meat of the FASTLIB archive format
@@ -403,4 +341,73 @@ def self.cache
403 341
 =end
404 342
 
405 343
 
  344
+module Kernel #:nodoc:all
  345
+	alias :fastlib_original_require :require
  346
+
  347
+	#
  348
+	# This method hooks the original Kernel.require to support
  349
+	# loading files within FASTLIB archives
  350
+	#	
  351
+	def require(name)
  352
+		fastlib_require(name) || fastlib_original_require(name)
  353
+	end
  354
+	
  355
+	#
  356
+	# This method handles the loading of FASTLIB archives
  357
+	#
  358
+	def fastlib_require(name)
  359
+		name = name + ".rb" if not name =~ /\.rb$/
  360
+		return false if fastlib_already_loaded?(name)
  361
+		return false if fastlib_already_tried?(name)
  362
+
  363
+		# TODO: Implement relative path $: checks and adjust the
  364
+		#       search path within archives to match.
  365
+		
  366
+		$:.map{ |path| ::Dir["#{path}/*.fastlib"] }.flatten.uniq.each do |lib|
  367
+			data = FastLib.load(lib, name)
  368
+			next if not data
  369
+			$" << name
  370
+			
  371
+			begin
  372
+				Object.class_eval(data)
  373
+			rescue ::Exception => e
  374
+				opath,oerror = e.backtrace.shift.split(':', 2)
  375
+				e.backtrace.unshift("#{lib}::#{name}:#{oerror}")
  376
+				raise e
  377
+			end
  378
+			
  379
+			return true
  380
+		end
  381
+		
  382
+		$fastlib_miss << name 	
  383
+
  384
+		false
  385
+	end
  386
+	
  387
+	#
  388
+	# This method determines whether the specific file name
  389
+	# has already been loaded ($LOADED_FEATURES aka $")
  390
+	#
  391
+	def fastlib_already_loaded?(name)
  392
+		re = Regexp.new("^" + Regexp.escape(name) + "$")
  393
+		$".detect { |e| e =~ re } != nil
  394
+	end
  395
+
  396
+	#
  397
+	# This method determines whether the specific file name
  398
+	# has already been attempted with the included FASTLIB
  399
+	# archives.
  400
+	#
  401
+	# TODO: Ensure that this only applies to known FASTLIB
  402
+	#       archives and that newly included archives will
  403
+	#       be searched appropriately.
  404
+	#	
  405
+	def fastlib_already_tried?(name)
  406
+		$fastlib_miss ||= []
  407
+		$fastlib_miss.include?(name)
  408
+	end	
  409
+end
  410
+
  411
+
  412
+
406 413
 
2  msfbinscan
@@ -12,7 +12,7 @@ end
12 12
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
13 13
 require 'fastlib'
14 14
 
15  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  15
+'))
16 16
 
17 17
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
18 18
 
2  msfcli
@@ -17,7 +17,7 @@ end
17 17
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
18 18
 require 'fastlib'
19 19
 
20  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  20
+'))
21 21
 
22 22
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
23 23
 
2  msfconsole
@@ -16,7 +16,7 @@ end
16 16
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
17 17
 require 'fastlib'
18 18
 
19  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  19
+'))
20 20
 
21 21
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
22 22
 
2  msfd
@@ -18,7 +18,7 @@ end
18 18
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
19 19
 require 'fastlib'
20 20
 
21  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  21
+'))
22 22
 
23 23
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
24 24
 
2  msfelfscan
@@ -12,7 +12,7 @@ end
12 12
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
13 13
 require 'fastlib'
14 14
 
15  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  15
+'))
16 16
 
17 17
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
18 18
 
2  msfencode
@@ -12,7 +12,7 @@ end
12 12
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
13 13
 require 'fastlib'
14 14
 
15  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  15
+'))
16 16
 
17 17
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
18 18
 
2  msfmachscan
@@ -12,7 +12,7 @@ end
12 12
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
13 13
 require 'fastlib'
14 14
 
15  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  15
+'))
16 16
 
17 17
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
18 18
 
2  msfopcode
@@ -17,7 +17,7 @@ end
17 17
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
18 18
 require 'fastlib'
19 19
 
20  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  20
+'))
21 21
 
22 22
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
23 23
 
2  msfpayload
@@ -12,7 +12,7 @@ end
12 12
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
13 13
 require 'fastlib'
14 14
 
15  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  15
+'))
16 16
 
17 17
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
18 18
 
2  msfpescan
@@ -12,7 +12,7 @@ end
12 12
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
13 13
 require 'fastlib'
14 14
 
15  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  15
+'))
16 16
 
17 17
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
18 18
 
2  msfrop
@@ -15,7 +15,7 @@ end
15 15
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
16 16
 require 'fastlib'
17 17
 
18  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  18
+'))
19 19
 
20 20
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
21 21
 
2  msfrpc
@@ -16,7 +16,7 @@ end
16 16
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
17 17
 require 'fastlib'
18 18
 
19  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  19
+'))
20 20
 
21 21
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
22 22
 
2  msfrpcd
@@ -16,7 +16,7 @@ end
16 16
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
17 17
 require 'fastlib'
18 18
 
19  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  19
+'))
20 20
 
21 21
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
22 22
 
2  msfvenom
@@ -11,7 +11,7 @@ end
11 11
 $:.unshift(File.join(File.dirname(msfbase), 'lib'))
12 12
 require 'fastlib'
13 13
 
14  
-$:.unshift(File.join(File.dirname(msfbase), 'lib', 'metasploit.fastlib'))
  14
+'))
15 15
 
16 16
 $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
17 17
 

0 notes on commit 25c10d2

Please sign in to comment.
Something went wrong with that request. Please try again.