-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathresplat.rb
executable file
·55 lines (46 loc) · 1.57 KB
/
resplat.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env ruby
# -*- coding: binary -*-
# Replace comment splat with something shorter and
# more sensible.
#
# Usage:
# metasploit-framework$ ./tools/dev/resplat.rb [path]
#
# Some cargo-culting of tools/dev/retab.rb
require 'fileutils'
require 'find'
dir = ARGV[0] || "."
raise ArgumentError, "Need a filename or directory" unless (dir and File.readable? dir)
def is_ruby?(fname)
return true if fname =~ /\.rb$/
end
def resplat(line)
if line =~ /This file is part of the Metasploit Framework/
# This module requires Metasploit: http://metasploit.com/download
elsif line =~ /# redistribution and commercial restrictions\./
return "# Current source: https://github.com/rapid7/metasploit-framework\n"
else
return nil
end
end
Find.find(dir) do |infile|
next if infile =~ /\.git[\x5c\x2f]/
next unless File.file? infile
next unless is_ruby? infile
outfile = infile
data = File.open(infile, "rb") {|f| f.read f.stat.size}
fixed = []
data.each_line do |line|
case line
when /^[\s]*#( ##)? This file is part of the Metasploit Framework and may be subject to/, /^[\s]*# redistribution and commercial restrictions\. Please see the Metasploit/, /^[\s]*# web site for more information on licensing and terms of use\./, /^[\s]*#[\s]{1,3}http:\/\/metasploit.com\/(framework\/)?/, /^# Framework web site for more information on licensing and terms of use./
new_line = resplat(line)
fixed << new_line if new_line
else
fixed << line
end
end
fh = File.open(outfile, "wb")
fh.write fixed.join
fh.close
puts "Resplatted #{fh.path}"
end