|
3 | 3 |
|
4 | 4 | ###
|
5 | 5 | #
|
6 |
| -# This data type represents an author of a piece of code in either |
7 |
| -# the framework, a module, a script, or something entirely unrelated. |
| 6 | +# An author of a piece of code in either the framework, a module, a script, |
| 7 | +# or something entirely unrelated. |
8 | 8 | #
|
9 | 9 | ###
|
10 | 10 | class Msf::Author
|
11 | 11 |
|
12 |
| - # A hash of known author names |
13 |
| - Known = |
14 |
| - { |
15 |
| - 'amaloteaux' => 'alex_maloteaux' + 0x40.chr + 'metasploit.com', |
16 |
| - 'anonymous' => 'Unknown', |
17 |
| - 'bannedit' => 'bannedit' + 0x40.chr + 'metasploit.com', |
18 |
| - 'Carlos Perez' => 'carlos_perez' + 0x40.chr + 'darkoperator.com', |
19 |
| - 'cazz' => 'bmc' + 0x40.chr + 'shmoo.com', |
20 |
| - 'CG' => 'cg' + 0x40.chr + 'carnal0wnage.com', |
21 |
| - 'ddz' => 'ddz' + 0x40.chr + 'theta44.org', |
22 |
| - 'egypt' => 'egypt' + 0x40.chr + 'metasploit.com', |
23 |
| - 'et' => 'et' + 0x40.chr + 'metasploit.com', |
24 |
| - 'Christian Mehlmauer' => 'FireFart' + 0x40.chr + 'gmail.com', |
25 |
| - 'hdm' => 'hdm' + 0x40.chr + 'metasploit.com', |
26 |
| - 'I)ruid' => 'druid' + 0x40.chr + 'caughq.org', |
27 |
| - 'jcran' => 'jcran' + 0x40.chr + 'metasploit.com', |
28 |
| - 'jduck' => 'jduck' + 0x40.chr + 'metasploit.com', |
29 |
| - 'joev' => 'joev' + 0x40.chr + 'metasploit.com', |
30 |
| - 'juan vazquez' => 'juan.vazquez' + 0x40.chr + 'metasploit.com', |
31 |
| - 'kf' => 'kf_list' + 0x40.chr + 'digitalmunition.com', |
32 |
| - 'kris katterjohn' => 'katterjohn' + 0x40.chr + 'gmail.com', |
33 |
| - 'MC' => 'mc' + 0x40.chr + 'metasploit.com', |
34 |
| - 'Ben Campbell' => 'eat_meatballs' + 0x40.chr + 'hotmail.co.uk', |
35 |
| - 'msmith' => 'msmith' + 0x40.chr + 'metasploit.com', |
36 |
| - 'mubix' => 'mubix' + 0x40.chr + 'hak5.org', |
37 |
| - 'natron' => 'natron' + 0x40.chr + 'metasploit.com', |
38 |
| - 'optyx' => 'optyx' + 0x40.chr + 'no$email.com', |
39 |
| - 'patrick' => 'patrick' + 0x40.chr + 'osisecurity.com.au', |
40 |
| - 'pusscat' => 'pusscat' + 0x40.chr + 'metasploit.com', |
41 |
| - 'Ramon de C Valle' => 'rcvalle' + 0x40.chr + 'metasploit.com', |
42 |
| - 'sf' => 'stephen_fewer' + 0x40.chr + 'harmonysecurity.com', |
43 |
| - 'sinn3r' => 'sinn3r' + 0x40.chr + 'metasploit.com', |
44 |
| - 'skape' => 'mmiller' + 0x40.chr + 'hick.org', |
45 |
| - 'skylined' => 'skylined' + 0x40.chr + 'edup.tudelft.nl', |
46 |
| - 'spoonm' => 'spoonm' + 0x40.chr + 'no$email.com', |
47 |
| - 'stinko' => 'vinnie' + 0x40.chr + 'metasploit.com', |
48 |
| - 'theLightCosine' => 'theLightCosine' + 0x40.chr + 'metasploit.com', |
49 |
| - 'todb' => 'todb' + 0x40.chr + 'metasploit.com', |
50 |
| - 'vlad902' => 'vlad902' + 0x40.chr + 'gmail.com', |
51 |
| - 'wvu' => 'wvu' + 0x40.chr + 'metasploit.com' |
52 |
| - } |
| 12 | + # |
| 13 | + # Constants |
| 14 | + # |
| 15 | + |
| 16 | + # A hash that maps known author names to email addresses |
| 17 | + KNOWN = { |
| 18 | + 'amaloteaux' => 'alex_maloteaux' + 0x40.chr + 'metasploit.com', |
| 19 | + 'anonymous' => 'Unknown', |
| 20 | + 'bannedit' => 'bannedit' + 0x40.chr + 'metasploit.com', |
| 21 | + 'Carlos Perez' => 'carlos_perez' + 0x40.chr + 'darkoperator.com', |
| 22 | + 'cazz' => 'bmc' + 0x40.chr + 'shmoo.com', |
| 23 | + 'CG' => 'cg' + 0x40.chr + 'carnal0wnage.com', |
| 24 | + 'ddz' => 'ddz' + 0x40.chr + 'theta44.org', |
| 25 | + 'egypt' => 'egypt' + 0x40.chr + 'metasploit.com', |
| 26 | + 'et' => 'et' + 0x40.chr + 'metasploit.com', |
| 27 | + 'Christian Mehlmauer' => 'FireFart' + 0x40.chr + 'gmail.com', |
| 28 | + 'hdm' => 'hdm' + 0x40.chr + 'metasploit.com', |
| 29 | + 'I)ruid' => 'druid' + 0x40.chr + 'caughq.org', |
| 30 | + 'jcran' => 'jcran' + 0x40.chr + 'metasploit.com', |
| 31 | + 'jduck' => 'jduck' + 0x40.chr + 'metasploit.com', |
| 32 | + 'joev' => 'joev' + 0x40.chr + 'metasploit.com', |
| 33 | + 'juan vazquez' => 'juan.vazquez' + 0x40.chr + 'metasploit.com', |
| 34 | + 'kf' => 'kf_list' + 0x40.chr + 'digitalmunition.com', |
| 35 | + 'kris katterjohn' => 'katterjohn' + 0x40.chr + 'gmail.com', |
| 36 | + 'MC' => 'mc' + 0x40.chr + 'metasploit.com', |
| 37 | + 'Ben Campbell' => 'eat_meatballs' + 0x40.chr + 'hotmail.co.uk', |
| 38 | + 'msmith' => 'msmith' + 0x40.chr + 'metasploit.com', |
| 39 | + 'mubix' => 'mubix' + 0x40.chr + 'hak5.org', |
| 40 | + 'natron' => 'natron' + 0x40.chr + 'metasploit.com', |
| 41 | + 'optyx' => 'optyx' + 0x40.chr + 'no$email.com', |
| 42 | + 'patrick' => 'patrick' + 0x40.chr + 'osisecurity.com.au', |
| 43 | + 'pusscat' => 'pusscat' + 0x40.chr + 'metasploit.com', |
| 44 | + 'Ramon de C Valle' => 'rcvalle' + 0x40.chr + 'metasploit.com', |
| 45 | + 'sf' => 'stephen_fewer' + 0x40.chr + 'harmonysecurity.com', |
| 46 | + 'sinn3r' => 'sinn3r' + 0x40.chr + 'metasploit.com', |
| 47 | + 'skape' => 'mmiller' + 0x40.chr + 'hick.org', |
| 48 | + 'skylined' => 'skylined' + 0x40.chr + 'edup.tudelft.nl', |
| 49 | + 'spoonm' => 'spoonm' + 0x40.chr + 'no$email.com', |
| 50 | + 'stinko' => 'vinnie' + 0x40.chr + 'metasploit.com', |
| 51 | + 'theLightCosine' => 'theLightCosine' + 0x40.chr + 'metasploit.com', |
| 52 | + 'todb' => 'todb' + 0x40.chr + 'metasploit.com', |
| 53 | + 'vlad902' => 'vlad902' + 0x40.chr + 'gmail.com', |
| 54 | + 'wvu' => 'wvu' + 0x40.chr + 'metasploit.com' |
| 55 | + } |
53 | 56 |
|
54 | 57 | #
|
55 |
| - # Class method that translates a string to an instance of the Author class, |
56 |
| - # if it's of the right format, and returns the Author class instance |
| 58 | + # Class Methods |
| 59 | + # |
| 60 | + |
| 61 | + # Parses an {Author} instance from the specified string. |
57 | 62 | #
|
| 63 | + # @param str [String] the String to parse an Author instance from |
| 64 | + # @return [Author] a valid {Author} instance |
| 65 | + # @return nil if `str` is not the correct format |
58 | 66 | def self.from_s(str)
|
59 | 67 | instance = self.new
|
60 | 68 |
|
61 | 69 | # If the serialization fails...
|
62 |
| - if (instance.from_s(str) == false) |
63 |
| - return nil |
| 70 | + if instance.from_s(str) == true |
| 71 | + instance |
| 72 | + else |
| 73 | + nil |
64 | 74 | end
|
65 |
| - |
66 |
| - return instance |
67 | 75 | end
|
68 | 76 |
|
| 77 | + # Normalizes a single {Author} reference or an Array of {Author} references |
| 78 | + # to an Array of {Author} references. |
69 | 79 | #
|
70 |
| - # Transforms the supplied source into an array of authors |
71 |
| - # |
| 80 | + # @param src [Author, Array<Author>] a single {Author} or an Array of {Author} instances |
| 81 | + # @return [Array<Author>] an Array of {Author} instances |
72 | 82 | def self.transform(src)
|
73 | 83 | Rex::Transformer.transform(src, Array, [ self ], 'Author')
|
74 | 84 | end
|
75 | 85 |
|
| 86 | + # Constructs an {Author} from a given `name` and `email` |
| 87 | + # |
| 88 | + # @param name [String] the author's name |
| 89 | + # @param email [String] the author's email |
76 | 90 | def initialize(name = nil, email = nil)
|
77 | 91 | self.name = name
|
78 |
| - self.email = email || Known[name] |
| 92 | + self.email = email || KNOWN[name] |
79 | 93 | end
|
80 | 94 |
|
81 | 95 | #
|
82 |
| - # Compares authors |
| 96 | + # Instance Attributes |
83 | 97 | #
|
84 |
| - def ==(tgt) |
85 |
| - return (tgt.to_s == to_s) |
86 |
| - end |
87 | 98 |
|
| 99 | + # @!attribute email |
| 100 | + # An optional email associated with this {Author}. |
| 101 | + # |
| 102 | + # @return [String, nil] |
| 103 | + attr_accessor :email |
| 104 | + |
| 105 | + # @!attribute name |
| 106 | + # The name associated with this {Author}. |
88 | 107 | #
|
89 |
| - # Serialize the author object to a string in form: |
| 108 | + # @return [String] |
| 109 | + attr_reader :name |
| 110 | + |
90 | 111 | #
|
91 |
| - # name <email> |
| 112 | + # Instance Methods |
92 | 113 | #
|
| 114 | + |
| 115 | + # @return [Boolean] whether the {Author} instances are equal |
| 116 | + def ==(tgt) |
| 117 | + tgt.to_s == to_s |
| 118 | + end |
| 119 | + |
| 120 | + # Serialize the {Author} instance to a string of the form `name` or `name <[email protected]>` |
| 121 | + # |
| 122 | + # @return [String] serialized {Author} |
93 | 123 | def to_s
|
94 | 124 | str = "#{name}"
|
95 |
| - |
96 | 125 | if (email and not email.empty?)
|
97 | 126 | str += " <#{email}>"
|
98 | 127 | end
|
99 |
| - |
100 |
| - return str |
| 128 | + str |
101 | 129 | end
|
102 | 130 |
|
| 131 | + |
| 132 | + # Parses {Author} details from the supplied string which may |
| 133 | + # be of the form `name` or `name <[email protected]>` |
103 | 134 | #
|
104 |
| - # Translate the author from the supplied string which may |
105 |
| - # have either just a name or also an email address |
106 |
| - # |
| 135 | + # @param str [String] the String to parse from |
| 136 | + # @return [Boolean] the translation succeeded |
107 | 137 | def from_s(str)
|
108 | 138 |
|
109 |
| - |
110 | 139 | # Supported formats:
|
111 | 140 | # known_name
|
112 | 141 | # user [at/@] host [dot/.] tld
|
113 | 142 | # Name <user [at/@] host [dot/.] tld>
|
114 | 143 |
|
115 |
| - |
116 |
| - if ((m = str.match(/^\s*([^<]+)<([^>]+)>\s*$/))) |
117 |
| - self.name = m[1].sub(/<.*/, '') |
118 |
| - self.email = m[2].sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.') |
119 |
| - else |
120 |
| - if (Known[str]) |
121 |
| - self.email = Known[str] |
122 |
| - self.name = str |
| 144 | + if str.present? |
| 145 | + if ((m = str.match(/^\s*([^<]+)<([^>]+)>\s*$/))) |
| 146 | + self.name = m[1].sub(/<.*/, '') |
| 147 | + self.email = m[2].sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.') |
123 | 148 | else
|
124 |
| - self.email = str.sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.').gsub(/^<|>$/, '') |
125 |
| - m = self.email.match(/([^@]+)@/) |
126 |
| - self.name = m ? m[1] : nil |
127 |
| - if !(self.email and self.email.index('@')) |
128 |
| - self.name = self.email |
129 |
| - self.email = '' |
| 149 | + if (KNOWN[str]) |
| 150 | + self.email = KNOWN[str] |
| 151 | + self.name = str |
| 152 | + else |
| 153 | + self.email = str.sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.').gsub(/^<|>$/, '') |
| 154 | + m = self.email.match(/([^@]+)@/) |
| 155 | + self.name = m ? m[1] : nil |
| 156 | + if !(self.email and self.email.index('@')) |
| 157 | + self.name = self.email |
| 158 | + self.email = '' |
| 159 | + end |
130 | 160 | end
|
131 | 161 | end
|
132 | 162 | end
|
133 | 163 |
|
134 |
| - self.name.strip! if self.name |
| 164 | + self.name.strip! if self.name.present? |
135 | 165 |
|
136 |
| - return true |
| 166 | + # The parse succeeds only when a name is found |
| 167 | + self.name.present? |
137 | 168 | end
|
138 | 169 |
|
139 |
| - # |
140 | 170 | # Sets the name of the author and updates the email if it's a known author.
|
141 |
| - # |
| 171 | + # @param name [String] the name to set |
142 | 172 | def name=(name)
|
143 |
| - self.email = Known[name] if (Known[name]) |
| 173 | + if KNOWN.has_key?(name) |
| 174 | + self.email = KNOWN[name] |
| 175 | + end |
144 | 176 | @name = name
|
145 | 177 | end
|
146 | 178 |
|
147 |
| - attr_accessor :email |
148 |
| - attr_reader :name |
149 | 179 | end
|
0 commit comments