2011-11-21 20:12:01 +00:00
|
|
|
#!/usr/bin/env ruby
|
2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2011-11-21 20:12:01 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# FASTLIB is a mechanism for loading large sets of libraries in a way that is
|
|
|
|
# faster and much more flexible than typical disk structures. FASTLIB includes
|
|
|
|
# hooks that can be used for both compression and encoding of Ruby libraries.
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
2012-11-21 01:29:12 +00:00
|
|
|
# This format was specifically created to improve the performance and
|
2011-11-21 20:12:01 +00:00
|
|
|
# AV-resistance of the Metasploit Framework and Rex libraries.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# This library is still in its early form; a large number of performance and
|
|
|
|
# compatiblity improvements are not yet included. Do not depend on the FASTLIB
|
|
|
|
# file format at this time.
|
|
|
|
#
|
|
|
|
|
|
|
|
require "find"
|
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011 Rapid7. You can redistribute it and/or
|
|
|
|
# modify it under the terms of the ruby license.
|
|
|
|
#
|
2012-11-21 01:29:12 +00:00
|
|
|
#
|
2011-11-21 20:12:01 +00:00
|
|
|
# Roughly based on the rubyzip zip/ziprequire library:
|
|
|
|
# >> Copyright (C) 2002 Thomas Sondergaard
|
|
|
|
# >> rubyzip is free software; you can redistribute it and/or
|
|
|
|
# >> modify it under the terms of the ruby license.
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# The FastLib class implements the meat of the FASTLIB archive format
|
|
|
|
#
|
|
|
|
class FastLib
|
|
|
|
|
2012-02-04 06:02:53 +00:00
|
|
|
VERSION = "0.0.8"
|
2011-11-21 20:12:01 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
FLAG_COMPRESS = 0x01
|
|
|
|
FLAG_ENCRYPT = 0x02
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
@@cache = {}
|
2011-11-24 04:05:25 +00:00
|
|
|
@@has_zlib = false
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
#
|
|
|
|
# Load zlib support if possible
|
|
|
|
#
|
|
|
|
begin
|
|
|
|
require 'zlib'
|
|
|
|
@@has_zlib = true
|
|
|
|
rescue ::LoadError
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
#
|
|
|
|
# This method returns the version of the fastlib library
|
|
|
|
#
|
|
|
|
def self.version
|
|
|
|
VERSION
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
#
|
2012-11-21 01:29:12 +00:00
|
|
|
# This method loads content from a specific archive file by name. If the
|
2011-11-21 20:12:01 +00:00
|
|
|
# noprocess argument is set to true, the contents will not be expanded to
|
|
|
|
# include workarounds for things such as __FILE__. This is useful when
|
|
|
|
# loading raw binary data where these strings may occur
|
|
|
|
#
|
|
|
|
def self.load(lib, name, noprocess=false)
|
|
|
|
data = ""
|
|
|
|
load_cache(lib)
|
|
|
|
|
2012-11-21 01:29:12 +00:00
|
|
|
return unless ( @@cache[lib] and @@cache[lib][name] )
|
|
|
|
|
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
::File.open(lib, "rb") do |fd|
|
|
|
|
fd.seek(
|
|
|
|
@@cache[lib][:fastlib_header][0] +
|
2012-11-21 01:29:12 +00:00
|
|
|
@@cache[lib][:fastlib_header][1] +
|
2011-11-21 20:12:01 +00:00
|
|
|
@@cache[lib][name][0]
|
|
|
|
)
|
2011-11-24 04:33:32 +00:00
|
|
|
data = fastlib_filter_decode( lib, fd.read(@@cache[lib][name][1] ))
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
# Return the contents in raw or processed form
|
|
|
|
noprocess ? data : post_process(lib, name, data)
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
#
|
|
|
|
# This method caches the file list and offsets within the archive
|
|
|
|
#
|
|
|
|
def self.load_cache(lib)
|
|
|
|
return if @@cache[lib]
|
2011-11-24 04:05:25 +00:00
|
|
|
@@cache[lib] = {}
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:21:27 +00:00
|
|
|
return if not ::File.exists?(lib)
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
::File.open(lib, 'rb') do |fd|
|
2011-11-24 04:05:25 +00:00
|
|
|
dict = {}
|
2011-11-21 20:12:01 +00:00
|
|
|
head = fd.read(4)
|
|
|
|
return if head != "FAST"
|
|
|
|
hlen = fd.read(4).unpack("N")[0]
|
2012-11-21 01:29:12 +00:00
|
|
|
flag = fd.read(4).unpack("N")[0]
|
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
@@cache[lib][:fastlib_header] = [12, hlen, fd.stat.mtime.utc.to_i ]
|
|
|
|
@@cache[lib][:fastlib_flags] = flag
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
nlen, doff, dlen, tims = fd.read(16).unpack("N*")
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
while nlen > 0
|
2011-11-24 04:05:25 +00:00
|
|
|
name = fastlib_filter_decode( lib, fd.read(nlen) )
|
|
|
|
dict[name] = [doff, dlen, tims]
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
nlen, doff, dlen, tims = fd.read(16).unpack("N*")
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
@@cache[lib].merge!(dict)
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
#
|
2011-11-24 04:05:25 +00:00
|
|
|
# This method provides compression and encryption capabilities
|
|
|
|
# for the fastlib archive format.
|
2011-11-21 20:12:01 +00:00
|
|
|
#
|
2011-11-24 04:05:25 +00:00
|
|
|
def self.fastlib_filter_decode(lib, buff)
|
|
|
|
|
|
|
|
if (@@cache[lib][:fastlib_flags] & FLAG_ENCRYPT) != 0
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
@@cache[lib][:fastlib_decrypt] ||= ::Proc.new do |data|
|
|
|
|
stub = "decrypt_%.8x" % ( @@cache[lib][:fastlib_flags] & 0xfffffff0 )
|
|
|
|
FastLib.send(stub, data)
|
|
|
|
end
|
|
|
|
|
|
|
|
buff = @@cache[lib][:fastlib_decrypt].call( buff )
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
if (@@cache[lib][:fastlib_flags] & FLAG_COMPRESS) != 0
|
|
|
|
if not @@has_zlib
|
|
|
|
raise ::RuntimeError, "zlib is required to open this archive"
|
|
|
|
end
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
buff = z.inflate(buff)
|
|
|
|
buff << z.finish
|
2012-11-21 01:29:12 +00:00
|
|
|
z.close
|
2011-11-24 04:05:25 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
buff
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2011-11-24 04:05:25 +00:00
|
|
|
# This method provides compression and encryption capabilities
|
|
|
|
# for the fastlib archive format.
|
|
|
|
#
|
|
|
|
def self.fastlib_filter_encode(lib, buff)
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
if (@@cache[lib][:fastlib_flags] & FLAG_COMPRESS) != 0
|
|
|
|
if not @@has_zlib
|
|
|
|
raise ::RuntimeError, "zlib is required to open this archive"
|
|
|
|
end
|
|
|
|
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
buff = z.deflate(buff)
|
|
|
|
buff << z.finish
|
2012-11-21 01:29:12 +00:00
|
|
|
z.close
|
2011-11-24 04:05:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if (@@cache[lib][:fastlib_flags] & FLAG_ENCRYPT) != 0
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
@@cache[lib][:fastlib_encrypt] ||= ::Proc.new do |data|
|
|
|
|
stub = "encrypt_%.8x" % ( @@cache[lib][:fastlib_flags] & 0xfffffff0 )
|
|
|
|
FastLib.send(stub, data)
|
|
|
|
end
|
|
|
|
|
|
|
|
buff = @@cache[lib][:fastlib_encrypt].call( buff )
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
buff
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
|
2012-10-31 16:43:28 +00:00
|
|
|
# This method provides a way to create a FASTLIB archive programatically.
|
2011-11-21 20:12:01 +00:00
|
|
|
#
|
2012-10-31 16:43:28 +00:00
|
|
|
# @param [String] lib the output path for the archive
|
2012-11-21 01:29:12 +00:00
|
|
|
# @param [String] flag a string containing the hex values for the
|
|
|
|
# flags ({FLAG_COMPRESS} and {FLAG_ENCRYPT}).
|
|
|
|
# @param [String] bdir the path to the base directory which will be
|
|
|
|
# stripped from all paths included in the archive
|
|
|
|
# @param [Array<String>] dirs list of directories/files to pack into
|
|
|
|
# the archive. All dirs should be under bdir so that the paths are
|
|
|
|
# stripped correctly.
|
2012-10-31 16:43:28 +00:00
|
|
|
# @return [void]
|
2011-11-24 04:05:25 +00:00
|
|
|
def self.dump(lib, flag, bdir, *dirs)
|
2011-11-21 20:12:01 +00:00
|
|
|
head = ""
|
|
|
|
data = ""
|
|
|
|
hidx = 0
|
|
|
|
didx = 0
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
bdir = bdir.gsub(/\/$/, '')
|
|
|
|
brex = /^#{Regexp.escape(bdir)}\//
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
@@cache[lib] = {
|
|
|
|
:fastlib_flags => flag.to_i(16)
|
|
|
|
}
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
dirs.each do |dir|
|
2012-11-21 01:21:26 +00:00
|
|
|
::Find.find(dir) do |path|
|
2011-11-21 20:12:01 +00:00
|
|
|
next if not ::File.file?(path)
|
2011-11-24 04:05:25 +00:00
|
|
|
name = fastlib_filter_encode( lib, path.sub( brex, "" ) )
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
buff = ""
|
|
|
|
::File.open(path, "rb") do |fd|
|
2011-11-24 04:05:25 +00:00
|
|
|
buff = fastlib_filter_encode(lib, fd.read(fd.stat.size))
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
|
|
|
|
head << [ name.length, didx, buff.length, ::File.stat(path).mtime.utc.to_i ].pack("NNNN")
|
2011-11-21 20:12:01 +00:00
|
|
|
head << name
|
2011-11-24 04:05:25 +00:00
|
|
|
hidx = hidx + 16 + name.length
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
data << buff
|
2011-11-21 20:12:01 +00:00
|
|
|
didx = didx + buff.length
|
|
|
|
end
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
head << [0,0,0].pack("NNN")
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
::File.open(lib, "wb") do |fd|
|
|
|
|
fd.write("FAST")
|
2011-11-24 04:05:25 +00:00
|
|
|
fd.write( [ head.length, flag.to_i(16) ].pack("NN") )
|
2011-11-21 20:12:01 +00:00
|
|
|
fd.write( head )
|
|
|
|
fd.write( data )
|
2012-11-21 01:29:12 +00:00
|
|
|
end
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
#
|
|
|
|
# This archive provides a way to list the contents of an archive
|
|
|
|
# file, returning the names only in sorted order.
|
|
|
|
#
|
|
|
|
def self.list(lib)
|
|
|
|
load_cache(lib)
|
2011-11-24 04:05:25 +00:00
|
|
|
( @@cache[lib] || {} ).keys.map{|x| x.to_s }.sort.select{ |x| @@cache[lib][x] }
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
#
|
|
|
|
# This method is called on the loaded is required to expand __FILE__
|
|
|
|
# and other inline dynamic constants to map to the correct location.
|
|
|
|
#
|
|
|
|
def self.post_process(lib, name, data)
|
|
|
|
data.gsub('__FILE__', "'#{ ::File.expand_path(::File.join(::File.dirname(lib), name)) }'")
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
#
|
|
|
|
# This is a stub crypto handler that performs a basic XOR
|
2012-02-04 06:02:53 +00:00
|
|
|
# operation against a fixed one byte key. The two usable IDs
|
|
|
|
# are 12345600 and 00000000
|
2011-11-24 04:05:25 +00:00
|
|
|
#
|
|
|
|
def self.encrypt_12345600(data)
|
2012-02-04 06:02:53 +00:00
|
|
|
encrypt_00000000(data)
|
2011-11-24 04:05:25 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 04:05:25 +00:00
|
|
|
def self.decrypt_12345600(data)
|
2012-02-04 06:02:53 +00:00
|
|
|
encrypt_00000000(data)
|
2011-11-24 04:05:25 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2012-02-04 06:02:53 +00:00
|
|
|
def self.encrypt_00000000(data)
|
|
|
|
data.unpack("C*").map{ |c| c ^ 0x90 }.pack("C*")
|
2011-11-24 04:05:25 +00:00
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2012-02-04 06:02:53 +00:00
|
|
|
def self.decrypt_00000000(data)
|
|
|
|
encrypt_00000000(data)
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2012-02-04 06:02:53 +00:00
|
|
|
#
|
|
|
|
# Expose the cache to callers
|
|
|
|
#
|
|
|
|
def self.cache
|
|
|
|
@@cache
|
2012-11-21 01:29:12 +00:00
|
|
|
end
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Allow this library to be used as an executable to create and list
|
|
|
|
# FASTLIB archives
|
|
|
|
#
|
|
|
|
if __FILE__ == $0
|
|
|
|
cmd = ARGV.shift
|
2011-11-24 04:05:25 +00:00
|
|
|
unless ["store", "list", "version"].include?(cmd)
|
2011-11-21 20:12:01 +00:00
|
|
|
$stderr.puts "Usage: #{$0} [dump|list|version] <arguments>"
|
|
|
|
exit(0)
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
case cmd
|
2011-11-24 04:05:25 +00:00
|
|
|
when "store"
|
2011-11-21 20:12:01 +00:00
|
|
|
dst = ARGV.shift
|
2011-11-24 04:05:25 +00:00
|
|
|
flg = ARGV.shift
|
2011-11-21 20:12:01 +00:00
|
|
|
dir = ARGV.shift
|
|
|
|
src = ARGV
|
|
|
|
unless dst and dir and src.length > 0
|
2011-11-24 04:05:25 +00:00
|
|
|
$stderr.puts "Usage: #{$0} store destination.fastlib flags base_dir src1 src2 ... src99"
|
2011-11-21 20:12:01 +00:00
|
|
|
exit(0)
|
|
|
|
end
|
2011-11-24 04:05:25 +00:00
|
|
|
FastLib.dump(dst, flg, dir, *src)
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
when "list"
|
|
|
|
src = ARGV.shift
|
|
|
|
unless src
|
2011-11-24 04:05:25 +00:00
|
|
|
$stderr.puts "Usage: #{$0} list"
|
2011-11-21 20:12:01 +00:00
|
|
|
exit(0)
|
|
|
|
end
|
|
|
|
$stdout.puts "Library: #{src}"
|
|
|
|
$stdout.puts "====================================================="
|
|
|
|
FastLib.list(src).each do |name|
|
2011-11-24 04:05:25 +00:00
|
|
|
fsize = FastLib.cache[src][name][1]
|
|
|
|
ftime = ::Time.at(FastLib.cache[src][name][2]).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
$stdout.puts sprintf("%9d\t%20s\t%s\n", fsize, ftime, name)
|
2011-11-21 20:12:01 +00:00
|
|
|
end
|
|
|
|
$stdout.puts ""
|
|
|
|
|
|
|
|
when "version"
|
|
|
|
$stdout.puts "FastLib Version #{FastLib.version}"
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
exit(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# FASTLIB archive format (subject to change without notice)
|
|
|
|
#
|
|
|
|
=begin
|
|
|
|
|
|
|
|
* All integers are 32-bit and in network byte order (big endian / BE)
|
|
|
|
* The file signature is 0x46415354 (big endian, use htonl() if necessary)
|
2011-11-24 04:05:25 +00:00
|
|
|
* The header is always 12 bytes into the archive (magic + header length)
|
|
|
|
* The data section is always 12 + header length into the archive
|
2011-11-21 20:12:01 +00:00
|
|
|
* The header entries always start with 'fastlib_header'
|
2011-11-24 04:05:25 +00:00
|
|
|
* The header entries always consist of 16 bytes + name length (no alignment)
|
2011-11-21 20:12:01 +00:00
|
|
|
* The header name data may be encoded, compressed, or transformed
|
|
|
|
* The data entries may be encoded, compressed, or transformed too
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
|
|
|
|
4 bytes: "FAST"
|
|
|
|
4 bytes: NBO header length
|
2012-02-04 06:02:53 +00:00
|
|
|
4 bytes: NBO flags (24-bit crypto ID, 8 bit modes)
|
2011-11-21 20:12:01 +00:00
|
|
|
[
|
|
|
|
4 bytes: name length (0 = End of Names)
|
|
|
|
4 bytes: data offset
|
|
|
|
4 bytes: data length
|
2011-11-24 04:05:25 +00:00
|
|
|
4 bytes: timestamp
|
2011-11-21 20:12:01 +00:00
|
|
|
]
|
|
|
|
[ Raw Data ]
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
|
2011-11-24 05:02:43 +00:00
|
|
|
module Kernel #:nodoc:all
|
|
|
|
alias :fastlib_original_require :require
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2012-02-04 06:02:53 +00:00
|
|
|
#
|
|
|
|
# Store the CWD when were initially loaded
|
|
|
|
# required for resolving relative paths
|
|
|
|
#
|
|
|
|
@@fastlib_base_cwd = ::Dir.pwd
|
2011-11-24 05:02:43 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# This method hooks the original Kernel.require to support
|
|
|
|
# loading files within FASTLIB archives
|
2012-11-21 01:29:12 +00:00
|
|
|
#
|
2011-11-24 05:02:43 +00:00
|
|
|
def require(name)
|
|
|
|
fastlib_require(name) || fastlib_original_require(name)
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 05:02:43 +00:00
|
|
|
#
|
|
|
|
# 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)
|
|
|
|
|
2012-11-21 01:29:12 +00:00
|
|
|
# XXX Implement relative search paths within archives
|
|
|
|
$:.map{ |path|
|
2012-02-04 06:02:53 +00:00
|
|
|
(path =~ /^([A-Za-z]\:|\/)/ ) ? path : ::File.expand_path( ::File.join(@@fastlib_base_cwd, path) )
|
|
|
|
}.map{ |path| ::Dir["#{path}/*.fastlib"] }.flatten.uniq.each do |lib|
|
2011-11-24 05:02:43 +00:00
|
|
|
data = FastLib.load(lib, name)
|
|
|
|
next if not data
|
|
|
|
$" << name
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2012-02-04 06:02:53 +00:00
|
|
|
Object.class_eval(data, lib + "::" + name)
|
|
|
|
|
2011-11-24 05:02:43 +00:00
|
|
|
return true
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
|
|
|
$fastlib_miss << name
|
2011-11-24 05:02:43 +00:00
|
|
|
|
|
|
|
false
|
|
|
|
end
|
2012-11-21 01:29:12 +00:00
|
|
|
|
2011-11-24 05:02:43 +00:00
|
|
|
#
|
|
|
|
# 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.
|
2012-11-21 01:29:12 +00:00
|
|
|
#
|
2011-11-24 05:02:43 +00:00
|
|
|
def fastlib_already_tried?(name)
|
|
|
|
$fastlib_miss ||= []
|
|
|
|
$fastlib_miss.include?(name)
|
2012-11-21 01:29:12 +00:00
|
|
|
end
|
2011-11-24 05:02:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-21 20:12:01 +00:00
|
|
|
|