Skip to content

Commit ed2d6cd

Browse files
authored
Merge pull request rapid7#20312 from bcoles/rubocop-lib-msf-module-platform_list
Msf::Module::PlatformList: Resolve RuboCop violations
2 parents b0ef381 + 682a4b4 commit ed2d6cd

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed
Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env ruby
21
# -*- coding: binary -*-
32

43
#
@@ -7,8 +6,6 @@
76
# of Msf::Module::Platform objects. It also supports ranges based on relative
87
# ranks...
98
#
10-
11-
129
class Msf::Module::PlatformList
1310
attr_accessor :platforms
1411

@@ -32,88 +29,85 @@ def self.transform(src)
3229
# Create an instance from an array
3330
#
3431
def self.from_a(ary)
35-
self.new(*ary)
32+
new(*ary)
3633
end
3734

3835
def index(needle)
39-
self.platforms.index(needle)
36+
platforms.index(needle)
4037
end
4138

4239
#
43-
# Constructor, takes the entries are arguments
40+
# Constructor, takes the entries as arguments
4441
#
4542
def initialize(*args)
46-
self.platforms = [ ]
43+
self.platforms = []
4744

48-
args.each { |a|
49-
if a.kind_of?(String)
45+
args.each do |a|
46+
if a.is_a?(String)
5047
platforms << Msf::Module::Platform.find_platform(a)
51-
elsif a.kind_of?(Range)
52-
b = Msf::Module::Platform.find_platform(a.begin)
53-
e = Msf::Module::Platform.find_platform(a.end)
48+
elsif a.is_a?(Range)
49+
a_begin = Msf::Module::Platform.find_platform(a.begin)
50+
a_end = Msf::Module::Platform.find_platform(a.end)
51+
range = (a_begin::Rank..a_end::Rank)
5452

55-
children = b.superclass.find_children
56-
r = (b::Rank .. e::Rank)
57-
children.each { |c|
58-
platforms << c if r.include?(c::Rank)
59-
}
53+
a_begin.superclass.find_children.each do |c|
54+
platforms << c if range.include?(c::Rank)
55+
end
6056
else
6157
platforms << a
6258
end
63-
64-
}
65-
59+
end
6660
end
6761

6862
#
6963
# Checks to see if the platform list is empty.
7064
#
7165
def empty?
72-
return platforms.empty?
66+
platforms.empty?
7367
end
7468

7569
#
7670
# Returns an array of names contained within this platform list.
7771
#
7872
def names
79-
platforms.map { |m| m.realname }
73+
platforms.map(&:realname)
8074
end
8175

8276
#
8377
# Symbolic check to see if this platform list represents 'all' platforms.
8478
#
8579
def all?
86-
names.include? ''
80+
names.include?('')
8781
end
8882

8983
#
90-
# Do I support plist (do I support all of they support?)
84+
# Do I support platform list (do I support all of they support?)
9185
# use for matching say, an exploit and a payload
9286
#
93-
def supports?(plist)
94-
plist.platforms.each { |pl|
87+
def supports?(platform_list)
88+
platform_list.platforms.each do |pl|
9589
supported = false
96-
platforms.each { |p|
90+
platforms.each do |p|
9791
if p >= pl
9892
supported = true
9993
break
10094
end
101-
}
102-
return false if !supported
103-
}
95+
end
96+
return false unless supported
97+
end
10498

105-
return true
99+
true
106100
end
107101

108102
#
109103
# used for say, building a payload from a stage and stager
110104
# finds common subarchitectures between the arguments
111105
#
112-
def &(plist)
106+
def &(other)
113107
l1 = platforms
114-
l2 = plist.platforms
108+
l2 = other.platforms
115109
total = l1.find_all { |m| l2.find { |mm| m <= mm } } |
116-
l2.find_all { |m| l1.find { |mm| m <= mm } }
110+
l2.find_all { |m| l1.find { |mm| m <= mm } }
117111
Msf::Module::PlatformList.from_a(total)
118112
end
119113
end

0 commit comments

Comments
 (0)