fastlib 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +15 -0
  2. data/README.markdown +10 -11
  3. data/bin/fastlib +122 -0
  4. data/fastlib.gemspec +22 -0
  5. data/lib/fastlib.rb +17 -62
  6. metadata +29 -49
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjVjMmZmODA5NzE3NmM4ZGY3NDZlZmZmZTQ2MDE0NzdjZmIxM2I0Mg==
5
+ data.tar.gz: !binary |-
6
+ YjIxMGY0NWYyZTRiZWRlOTJlMzg3MGMzMmRjMmM4YzI4NjgyZjkzNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MWQwYzczYzQ1ZmM5ZTJkZmZkOWI0NzQ0ZWU5MDU1ZDY5MjgwMGQwYzcxNzA5
10
+ YmM0MmVkYmNkMjBhYjI3MTI2ZTdlY2I5NzhjOWI2OWYwOTBmZWY5M2FiYTc0
11
+ NzFjMTNjZmM5YzgwZmM0YzVkZGYwNTcyZTJhYmE3YjQ4MDg1YjA=
12
+ data.tar.gz: !binary |-
13
+ OGQ3ZGNiMDRlNmNiNDlkMjVlZmNlMGQ0MWE5MGE3MzdlMjAzNjZiOTE3NDNh
14
+ ZmZkYmU2MDI5YjY3NDNkNjQ1NWY4ODQ5YjViYjIzODBlOWQ4ZmU4ZTU5NWUx
15
+ ZTVhMDQzMTM2YmZiYTEyMTI0ODE0OWUyNjZkMzRmZWRkOTBiM2Y=
@@ -6,26 +6,25 @@ This is similar to capabilities like zip/ziprequire, except that it provides wor
6
6
 
7
7
  # Usage
8
8
 
9
- $ apt-get install fastlib
9
+ $ gem install fastlib
10
10
 
11
11
  ## Store a library structure into FASTLIB archive
12
- $ \`gem env gemdir\`/gems/fastlib-\*/lib/fastlib.rb store 00000000 myarchive.fastlib lib/ lib/\*
13
- $ rm -rf lib
12
+ $ fastlib create mylib.fastlib /path/to/mylib
14
13
 
15
14
  ## Use that archive just by including the containing directory
16
- $ ruby -r rubygems -r fastlib -I. ./app.rb
15
+ $ ruby -r fastlib -I . ./myapp.rb
17
16
 
18
17
  ## Store a library structure into a FASTLIB archive with compression
19
- $ \`gem env gemdir\`/gems/fastlib-\*/lib/fastlib.rb store 00000001 myarchive.fastlib lib/ lib/\*
18
+ $ fastlib create -c mylib.fastlib /path/to/mylib
20
19
 
21
20
  ## Store a library structure into a FASTLIB archive with default "encryption"
22
- $ \`gem env gemdir\`/gems/fastlib-\*/lib/fastlib.rb store 00000002 myarchive.fastlib lib/ lib/\*
21
+ $ fastlib create -e 0 mylib.fastlib /path/to/mylib
23
22
 
24
23
  ## Store a library structure into a FASTLIB archive with default "encryption" and compression
25
- $ \`gem env gemdir\`/gems/fastlib-\*/lib/fastlib.rb store 00000003 myarchive.fastlib lib/ lib/\*
24
+ $ fastlib create -c -e 0 mylib.fastlib /path/to/mylib
26
25
 
27
26
  ## Store a library structure into a FASTLIB archive with custom encryption and compression
28
- $ ruby -I . -r mycrypto.rb \`gem env gemdir\`/gems/fastlib-\*/lib/fastlib.rb store 13370003 myarchive.fastlib lib/ lib/\*
27
+ $ fastlib create -I . -r mycrypto -c 0 -e 0x1337 mylib.fastlib /path/to/mylib
29
28
 
30
29
  $ cat mycrypto.rb
31
30
 
@@ -33,11 +32,11 @@ $ cat mycrypto.rb
33
32
 
34
33
  class FastLib
35
34
 
36
- def self.encrypt_13370000(data)
35
+ def self.encrypt_00133700(data)
37
36
  # Encrypt
38
37
  end
39
38
 
40
- def self.decrypt_13370000(data)
39
+ def self.decrypt_00133700(data)
41
40
  # Decrypt
42
41
  end
43
42
 
@@ -45,4 +44,4 @@ $ cat mycrypto.rb
45
44
 
46
45
 
47
46
  # Credits
48
- Rapid7 LLC
47
+ Rapid7, Inc.
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
4
+
5
+ require 'fastlib'
6
+ require 'optparse'
7
+ require 'ostruct'
8
+
9
+ options = OpenStruct.new(action: nil, archive: nil, required: nil, included: nil, compress: nil, encrypt: nil, verbose: nil)
10
+
11
+ option_parser = OptionParser.new do |opts|
12
+ opts.banner = "Usage: #{$0} <action> [options] <arguments>"
13
+ opts.separator "Create or list the contents of a fastlib archive"
14
+ opts.separator ""
15
+ opts.separator "Examples"
16
+ opts.separator " fastlib create mylib.fastlib mylib/"
17
+ opts.separator " fastlib create -c mylib_compressed.fastlib mylib/"
18
+ opts.separator " fastlib create -c -e 0 mylib_compressed_encrypted.fastlib mylib/"
19
+ opts.separator " fastlib create -c -e 0x4444 -I /my/crypto/lib -r mycrypto mylib_compressed_encrypted_custom.fastlib mylib/"
20
+ opts.separator " fastlib list mycompressed.fastlib"
21
+ opts.separator ""
22
+ opts.separator "Options"
23
+
24
+ opts.on("-c", "--compress", "Compresses the archive with Zlib ") do
25
+ options.compress = true
26
+ end
27
+
28
+ opts.on("-e", "--encrypt 0x<Algorithm ID>", "Encrypt the archive with the specified algorithm ID (0x00 for XOR)") do |opt_encrypt|
29
+ if opt_encrypt =~ /^0x/
30
+ options.encrypt = opt_encrypt.to_i(16)
31
+ else
32
+ options.encrypt = opt_encrypt.to_i
33
+ end
34
+
35
+ if options.encrypt > 0xffffff
36
+ $stderr.puts "Error: Algorithm IDs must be between 0 and 0xffffff"
37
+ exit(1)
38
+ end
39
+ end
40
+
41
+ opts.on("-r", "--require library", "Require the specified library to support custom encryption methods") do |opt_require|
42
+ options.required ||= []
43
+ options.required << opt_require
44
+ end
45
+
46
+ opts.on("-I", "--include library_path", "Search the specified path for required libraries") do |opt_include|
47
+ $:.append opt_include
48
+ end
49
+
50
+ opts.on("-V", "--version", "Show the FastLib version") do
51
+ $stderr.puts "FastLib v#{FastLib::VERSION}"
52
+ exit(0)
53
+ end
54
+
55
+ opts.on("-h", "--help", "Show this message.") do
56
+ $stderr.puts opts
57
+ exit(1)
58
+ end
59
+ end
60
+ option_parser.parse!(ARGV)
61
+
62
+ # Load any libraries required to support custom encryption providers
63
+ if options.required
64
+ options.required.each {|lname| require(lname) }
65
+ end
66
+
67
+ if options.encrypt
68
+ # Verify that our 24-bit algorithm ID maps to a FastLib namespace method
69
+ # The user may need to specify -r provider to load the right library first
70
+ unless FastLib.respond_to?(sprintf("encrypt_%.8x", (options.encrypt<<8) ))
71
+ $stderr.puts "Error: Unknown algorithm ID, you may need to specify the provider library with -r"
72
+ exit(1)
73
+ end
74
+ end
75
+
76
+ options.action = ARGV.shift
77
+ options.archive = ARGV.shift
78
+
79
+ unless options.archive
80
+ $stderr.puts "Error: No archive file has been specified"
81
+ exit(1)
82
+ end
83
+
84
+ case options.action
85
+ when 'create'
86
+
87
+ source_path = ARGV.shift
88
+
89
+ unless source_path
90
+ $stderr.puts "Error: No source directory has been specified"
91
+ exit(1)
92
+ end
93
+
94
+ source_path = File.expand_path(source_path)
95
+ source_files = Dir["#{source_path}/*"]
96
+
97
+ create_flags = 0
98
+
99
+ if options.compress
100
+ create_flags |= FastLib::FLAG_COMPRESS
101
+ end
102
+
103
+ if options.encrypt
104
+ create_flags |= (options.encrypt<<8)
105
+ create_flags |= FastLib::FLAG_ENCRYPT
106
+ end
107
+
108
+ FastLib.create(options.archive, create_flags, source_path, *source_files)
109
+
110
+ when 'list'
111
+ $stdout.puts "Library: #{options.archive}"
112
+ $stdout.puts "====================================================="
113
+ FastLib.list(options.archive).each do |name|
114
+ fsize = FastLib.cache[options.archive][name][1]
115
+ ftime = ::Time.at(FastLib.cache[options.archive][name][2]).strftime("%Y-%m-%d %H:%M:%S")
116
+ $stdout.puts sprintf("%9d\t%20s\t%s\n", fsize, ftime, name)
117
+ end
118
+ $stdout.puts ""
119
+ else
120
+ $stderr.puts "Error: Unknown action '#{options.action}'"
121
+ exit(1)
122
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ APP_NAME = "fastlib"
4
+ VERSION = "0.0.8"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = APP_NAME
8
+ s.version = VERSION
9
+ s.homepage = "https://github.com/rapid7/fastlib"
10
+ s.summary = "FASTLIB archive library"
11
+ s.description = "This gem provides a way to load libraries from an archive"
12
+ s.license = "BSD"
13
+ s.authors = ["HD Moore"]
14
+ s.email = ["hdm@rapid7.com"]
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
+ s.extra_rdoc_files = ["README.markdown"]
20
+ s.required_ruby_version = ">= 1.9.3"
21
+ s.platform = "ruby"
22
+ end
@@ -11,18 +11,10 @@
11
11
  # AV-resistance of the Metasploit Framework and Rex libraries.
12
12
  #
13
13
 
14
-
15
- #
16
- # This library is still in its early form; a large number of performance and
17
- # compatiblity improvements are not yet included. Do not depend on the FASTLIB
18
- # file format at this time.
19
- #
20
-
21
14
  require "find"
22
15
 
23
-
24
16
  #
25
- # Copyright (C) 2011 Rapid7. You can redistribute it and/or
17
+ # Copyright (C) 2011-2014 Rapid7, Inc. You can redistribute it and/or
26
18
  # modify it under the terms of the ruby license.
27
19
  #
28
20
  #
@@ -37,7 +29,7 @@ require "find"
37
29
  #
38
30
  class FastLib
39
31
 
40
- VERSION = "0.0.7"
32
+ VERSION = "0.0.8"
41
33
 
42
34
  FLAG_COMPRESS = 0x01
43
35
  FLAG_ENCRYPT = 0x02
@@ -187,7 +179,7 @@ class FastLib
187
179
  # directory that should be excluded from the archived path, and finally
188
180
  # the list of specific files and directories to include in the archive.
189
181
  #
190
- def self.dump(lib, flag, bdir, *dirs)
182
+ def self.create(lib, flags, bdir, *dirs)
191
183
  head = ""
192
184
  data = ""
193
185
  hidx = 0
@@ -196,8 +188,16 @@ class FastLib
196
188
  bdir = bdir.gsub(/\/$/, '')
197
189
  brex = /^#{Regexp.escape(bdir)}\//
198
190
 
191
+ if flags.kind_of?(::String)
192
+ if flags =~ /^0x/
193
+ flags = flags.to_i(16)
194
+ else
195
+ flags = flags.to_i
196
+ end
197
+ end
198
+
199
199
  @@cache[lib] = {
200
- :fastlib_flags => flag.to_i(16)
200
+ :fastlib_flags => flags
201
201
  }
202
202
 
203
203
  dirs.each do |dir|
@@ -210,7 +210,6 @@ class FastLib
210
210
  buff = fastlib_filter_encode(lib, fd.read(fd.stat.size))
211
211
  end
212
212
 
213
-
214
213
  head << [ name.length, didx, buff.length, ::File.stat(path).mtime.utc.to_i ].pack("NNNN")
215
214
  head << name
216
215
  hidx = hidx + 16 + name.length
@@ -224,14 +223,14 @@ class FastLib
224
223
 
225
224
  ::File.open(lib, "wb") do |fd|
226
225
  fd.write("FAST")
227
- fd.write( [ head.length, flag.to_i(16) ].pack("NN") )
226
+ fd.write( [ head.length, flags ].pack("NN") )
228
227
  fd.write( head )
229
228
  fd.write( data )
230
229
  end
231
230
  end
232
231
 
233
232
  #
234
- # This archive provides a way to list the contents of an archive
233
+ # This method provides a way to list the contents of an archive
235
234
  # file, returning the names only in sorted order.
236
235
  #
237
236
  def self.list(lib)
@@ -240,8 +239,8 @@ class FastLib
240
239
  end
241
240
 
242
241
  #
243
- # This method is called on the loaded is required to expand __FILE__
244
- # and other inline dynamic constants to map to the correct location.
242
+ # This method is expands __FILE__ sequences and other inline dynamic constants
243
+ # to map to the correct location.
245
244
  #
246
245
  def self.post_process(lib, name, data)
247
246
  data.gsub('__FILE__', "'#{ ::File.expand_path(::File.join(::File.dirname(lib), name)) }'")
@@ -277,51 +276,6 @@ class FastLib
277
276
  end
278
277
 
279
278
 
280
- #
281
- # Allow this library to be used as an executable to create and list
282
- # FASTLIB archives
283
- #
284
- if __FILE__ == $0
285
- cmd = ARGV.shift
286
- unless ["store", "list", "version"].include?(cmd)
287
- $stderr.puts "Usage: #{$0} [dump|list|version] <arguments>"
288
- exit(0)
289
- end
290
-
291
- case cmd
292
- when "store"
293
- dst = ARGV.shift
294
- flg = ARGV.shift
295
- dir = ARGV.shift
296
- src = ARGV
297
- unless dst and dir and src.length > 0
298
- $stderr.puts "Usage: #{$0} store destination.fastlib flags base_dir src1 src2 ... src99"
299
- exit(0)
300
- end
301
- FastLib.dump(dst, flg, dir, *src)
302
-
303
- when "list"
304
- src = ARGV.shift
305
- unless src
306
- $stderr.puts "Usage: #{$0} list"
307
- exit(0)
308
- end
309
- $stdout.puts "Library: #{src}"
310
- $stdout.puts "====================================================="
311
- FastLib.list(src).each do |name|
312
- fsize = FastLib.cache[src][name][1]
313
- ftime = ::Time.at(FastLib.cache[src][name][2]).strftime("%Y-%m-%d %H:%M:%S")
314
- $stdout.puts sprintf("%9d\t%20s\t%s\n", fsize, ftime, name)
315
- end
316
- $stdout.puts ""
317
-
318
- when "version"
319
- $stdout.puts "FastLib Version #{FastLib.version}"
320
- end
321
-
322
- exit(0)
323
- end
324
-
325
279
  #
326
280
  # FASTLIB archive format (subject to change without notice)
327
281
  #
@@ -339,6 +293,7 @@ end
339
293
 
340
294
  4 bytes: "FAST"
341
295
  4 bytes: NBO header length
296
+ 4 bytes: NBO flags (24-bit crypto ID, 8 bit modes)
342
297
  [
343
298
  4 bytes: name length (0 = End of Names)
344
299
  4 bytes: data offset
metadata CHANGED
@@ -1,72 +1,52 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fastlib
3
- version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 7
10
- version: 0.0.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - HD Moore
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-11-23 00:00:00 -06:00
19
- default_executable:
11
+ date: 2014-09-07 00:00:00.000000000 Z
20
12
  dependencies: []
21
-
22
13
  description: This gem provides a way to load libraries from an archive
23
- email:
24
- - hdm@metasploit.com
25
- executables: []
26
-
14
+ email:
15
+ - hdm@rapid7.com
16
+ executables:
17
+ - fastlib
27
18
  extensions: []
28
-
29
- extra_rdoc_files:
19
+ extra_rdoc_files:
30
20
  - README.markdown
31
- files:
21
+ files:
32
22
  - README.markdown
33
23
  - Rakefile
24
+ - bin/fastlib
25
+ - fastlib.gemspec
34
26
  - lib/fastlib.rb
35
- has_rdoc: true
36
27
  homepage: https://github.com/rapid7/fastlib
37
- licenses:
28
+ licenses:
38
29
  - BSD
30
+ metadata: {}
39
31
  post_install_message:
40
32
  rdoc_options: []
41
-
42
- require_paths:
33
+ require_paths:
43
34
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
45
- none: false
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- hash: 57
50
- segments:
51
- - 1
52
- - 8
53
- - 7
54
- version: 1.8.7
55
- required_rubygems_version: !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: 1.9.3
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
64
45
  requirements: []
65
-
66
46
  rubyforge_project:
67
- rubygems_version: 1.4.2
47
+ rubygems_version: 2.2.2
68
48
  signing_key:
69
- specification_version: 3
49
+ specification_version: 4
70
50
  summary: FASTLIB archive library
71
51
  test_files: []
72
-
52
+ has_rdoc: