Skip to content

Commit aeed81d

Browse files
committed
Code cleanup from Rubocop output
Signed-off-by: Craig Smith <[email protected]>
1 parent c2296dc commit aeed81d

File tree

8 files changed

+339
-339
lines changed

8 files changed

+339
-339
lines changed

lib/msf/core/post/hardware/automotive/dtc.rb

Lines changed: 298 additions & 298 deletions
Large diffs are not rendered by default.

lib/msf/core/post/hardware/zigbee/utils.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,26 +220,26 @@ def dot154_packet_decode(packet)
220220
daddr_mask = (fcf & DOT154_FCF_DADDR_MASK) >> 10
221221
if daddr_mask == DOT154_FCF_ADDR_EXT
222222
pktchop[3] = packet[offset,8]
223-
offset+=8
223+
offset += 8
224224
elsif daddr_mask == DOT154_FCF_ADDR_SHORT
225225
pktchop[3] = packet[offset,2]
226-
offset+=2
226+
offset += 2
227227
end
228228

229229
# Examine the Intra-PAN flag
230230
if (fcf & DOT154_FCF_INTRA_PAN) == 0
231231
pktchop[4] = packet[offset,2]
232-
offset+=2
232+
offset += 2
233233
end
234234

235235
# Examine the source addressing mode
236236
saddr_mask = (fcf & DOT154_FCF_SADDR_MASK) >> 14
237237
if daddr_mask == DOT154_FCF_ADDR_EXT
238238
pktchop[5] = packet[offset,8]
239-
offset+=8
239+
offset += 8
240240
elsif daddr_mask == DOT154_FCF_ADDR_SHORT
241241
pktchop[5] = packet[offset,2]
242-
offset+=2
242+
offset += 2
243243
end
244244
end
245245
# Append remaining payload

lib/rex/post/hwbridge/extensions/automotive/uds_errors.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module UDSErrors
117117
"SLNIP" => "Shifter Lever Not In Park",
118118
"TCCL" => "Torque Converter Clutch Locked",
119119
"VTH" => "Voltage Too High",
120-
"VTL" => "Voltage Too Low"
120+
"VTL" => "Voltage Too Low"
121121
}
122122

123123
end

lib/rex/post/hwbridge/ui/console/command_dispatcher/automotive.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ def cmd_isotpsend(*args)
222222
return result
223223
end
224224
opt = {}
225-
opt['TIMEOUT'] = timeout if not timeout.nil?
226-
opt['MAXPKTS'] = maxpackets if not maxpackets.nil?
225+
opt['TIMEOUT'] = timeout unless timeout.nil?
226+
opt['MAXPKTS'] = maxpackets unless maxpackets.nil?
227227
result = client.automotive.send_isotp_and_wait_for_response(bus, id, ret, bytes, opt)
228228
if result.key? 'Packets'
229229
result['Packets'].each do |pkt|
@@ -269,7 +269,7 @@ def cmd_testerpresent(*args)
269269
return
270270
end
271271
if id.blank? && !stop
272-
if self.tpjobs.size > 0
272+
if self.tpjobs.size.positive?
273273
print_line("TesterPresent is currently active")
274274
self.tpjobs.each_index do |jid|
275275
if self.tpjobs[jid]

lib/rex/post/hwbridge/ui/console/command_dispatcher/core.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def cmd_sessions_help
8484
end
8585

8686
def cmd_sessions(*args)
87-
if args.length == 0 || args[0].to_i == 0
87+
if args.length.zero? || args[0].to_i.zero?
8888
cmd_sessions_help
8989
elsif args[0].to_s == client.name.to_s
9090
print_status("Session #{client.name} is already interactive.")
@@ -185,7 +185,7 @@ def cmd_info(*args)
185185
if mod
186186
print_line(::Msf::Serializer::ReadableText.dump_module(mod))
187187
mod_opt = ::Msf::Serializer::ReadableText.dump_options(mod, ' ')
188-
print_line("\nModule options (#{mod.fullname}):\n\n#{mod_opt}") if mod_opt && mod_opt.length > 0
188+
print_line("\nModule options (#{mod.fullname}):\n\n#{mod_opt}") if mod_opt && mod_opt.length.positive?
189189
end
190190
end
191191

@@ -204,7 +204,7 @@ def cmd_status_help
204204
# Get the HW bridge devices status
205205
#
206206
def cmd_status(*args)
207-
if args.length > 0
207+
if args.length.positive?
208208
cmd_status_help
209209
return true
210210
end
@@ -235,7 +235,7 @@ def cmd_specialty_help
235235
# Get the Hardware specialty
236236
#
237237
def cmd_specialty(*args)
238-
if args.length > 0
238+
if args.length.positive?
239239
cmd_specialty_help
240240
return true
241241
end
@@ -251,7 +251,7 @@ def cmd_reset_help
251251
# Performs a device reset or factory reset
252252
#
253253
def cmd_reset(*args)
254-
if args.length > 0
254+
if args.length.positive?
255255
cmd_reset_help
256256
return
257257
end
@@ -268,7 +268,7 @@ def cmd_reboot_help
268268
# Perform a device reboot
269269
#
270270
def cmd_reboot(*args)
271-
if args.length > 0
271+
if args.length.positive?
272272
cmd_reboot_help
273273
return
274274
end
@@ -286,15 +286,15 @@ def cmd_load_custom_methods_help
286286
# Loads custom methods if any exist
287287
#
288288
def cmd_load_custom_methods(*args)
289-
if args.length > 0
289+
if args.length.positive?
290290
cmd_load_custom_methods_help
291291
return true
292292
end
293293
res = client.get_custom_methods
294294
if res.has_key? 'Methods'
295295
cmd_load("custom_methods")
296296
self.shell.dispatcher_stack.each do |dispatcher|
297-
if dispatcher.name =~/custom methods/i
297+
if dispatcher.name =~ /custom methods/i
298298
dispatcher.load_methods(res['Methods'])
299299
end
300300
end
@@ -315,7 +315,7 @@ def cmd_load_help
315315
# Loads one or more meterpreter extensions.
316316
#
317317
def cmd_load(*args)
318-
if args.length == 0
318+
if args.length.zero?
319319
args.unshift("-h")
320320
end
321321

@@ -369,7 +369,7 @@ def cmd_run_help
369369
# Executes a script in the context of the hwbridge session.
370370
#
371371
def cmd_run(*args)
372-
if args.length == 0
372+
if args.length.zero?
373373
cmd_run_help
374374
return true
375375
end
@@ -423,7 +423,7 @@ def cmd_run_tabs(str, words)
423423
next unless ::File.exist? dir
424424
tabs += ::Dir.new(dir).find_all { |e|
425425
path = dir + ::File::SEPARATOR + e
426-
::File.file?(path) and ::File.readable?(path)
426+
::File.file?(path) && ::File.readable?(path)
427427
}
428428
end
429429
rescue Exception
@@ -436,7 +436,7 @@ def cmd_run_tabs(str, words)
436436
# Executes a script in the context of the hardware bridge session in the background
437437
#
438438
def cmd_bgrun(*args)
439-
if args.length == 0
439+
if args.length.zero?
440440
print_line(
441441
"Usage: bgrun <script> [arguments]\n\n" +
442442
"Executes a ruby script in the context of the hardware bridge session.")
@@ -475,7 +475,7 @@ def cmd_bgrun_tabs(*args)
475475
# Kill a background job
476476
#
477477
def cmd_bgkill(*args)
478-
if args.length == 0
478+
if args.length.zero?
479479
print_line("Usage: bgkill [id]")
480480
return
481481
end
@@ -574,7 +574,7 @@ def add_extension_client(mod)
574574
end
575575

576576
def tab_complete_postmods
577-
tabs = client.framework.modules.post.map { |name,klass|
577+
tabs = client.framework.modules.post.map { |name, klass|
578578
mod = client.framework.modules.post.create(name)
579579
if mod && mod.session_compatible?(client)
580580
mod.fullname.dup

lib/rex/post/hwbridge/ui/console/command_dispatcher/custom_methods.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def name
4040
def load_methods(m)
4141
@custom_methods = m
4242
m.each do |method|
43-
if method.has_key? "method_name"
43+
if method.key? "method_name"
4444
desc = "See HW manual for command description"
45-
desc = method["method_desc"] if method.has_key? "method_desc"
45+
desc = method["method_desc"] if method.key? "method_desc"
4646
cmd = method["method_name"]
47-
cmd = $1 if cmd=~/\/(\S+)$/
47+
cmd = /\/(\S+)$/.match(cmd)
4848
@cmds[cmd] = method["method_desc"]
4949
eval("alias cmd_#{cmd} cmd_generic_handler")
5050
end
@@ -56,14 +56,14 @@ def load_methods(m)
5656
#
5757
def cmd_generic_handler_help(cmd)
5858
@custom_methods.each do |meth|
59-
if meth["method_name"] =~ /#{cmd}$/
59+
next unless meth["method_name"] =~ /#{cmd}$/
6060
args = ""
6161
args = "<args>" if meth["args"].size > 0
6262
print_line("Usage: #{cmd} #{args}")
6363
print_line
6464
meth["args"].each do |arg|
6565
req = ""
66-
req = " *required*" if arg.has_key? "required" and arg["required"] == true
66+
req = " *required*" if arg.key? "required" and arg["required"] == true
6767
print_line(" #{arg["arg_name"]}=<#{arg["arg_type"]}> #{req}")
6868
end
6969
end
@@ -87,8 +87,8 @@ def cmd_generic_handler(*args)
8787
return true
8888
end
8989
res = client.custom_methods.send_request(cmd, args, @custom_methods)
90-
print_status(res["status"]) if res.has_key? "status"
91-
print_status(res["value"]) if res.has_key? "value"
90+
print_status(res["status"]) if res.key? "status"
91+
print_status(res["value"]) if res.key? "value"
9292
end
9393

9494
#
@@ -104,8 +104,8 @@ def has_required_args(cmd, args)
104104
@custom_methods.each do |meth|
105105
if meth["method_name"] =~ /#{cmd}$/
106106
meth["args"].each do |arg|
107-
if arg.has_key? "required" and arg["required"] == true
108-
all_found = false if not arguments.has_key? arg["arg_name"]
107+
if arg.key? "required" and arg["required"] == true
108+
all_found = false if not arguments.key? arg["arg_name"]
109109
end
110110
end
111111
end

lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ def commands
4343

4444
def cmd_supported_idx
4545
indexes = client.rftransceiver.supported_idx
46-
if !indexes || !indexes.has_key?('indexes')
46+
if !indexes || !indexes.key?('indexes')
4747
print_line("error retrieving index list")
4848
return
4949
end
5050
indexes = indexes['indexes']
51-
unless indexes.size > 0
51+
unless indexes.size.positive?
5252
print_line('none')
5353
return
5454
end
55-
self.idx = indexes[0].to_i if indexes.size == 0
55+
self.idx = indexes[0].to_i if indexes.size.zero?
5656
str = "Supported Indexes: "
5757
str << indexes.join(', ')
5858
str << "\nUse idx to set your desired bus, default is 0"
@@ -91,7 +91,7 @@ def cmd_freq_help
9191
# Takes the results of a client request and prints Ok on success
9292
#
9393
def print_success(r)
94-
if r.has_key?('success') && r['success'] == true
94+
if r.key?('success') && r['success'] == true
9595
print_line("Ok")
9696
else
9797
print_line("Error")
@@ -290,7 +290,7 @@ def cmd_recv(*args)
290290
arg['blocksize'] = blocksize unless blocksize == -1
291291
arg['timeout'] = timeout unless timeout == -1
292292
r = client.rftransceiver.rfrecv(idx, arg)
293-
if r.has_key?('data') && r.has_key?('timestamp')
293+
if r.key?('data') && r.has_key?('timestamp')
294294
print_line(" #{r['timestamp']}: #{r['data'].inspect}")
295295
else
296296
print_line("Error")
@@ -305,7 +305,7 @@ def cmd_enable_crc(*args)
305305
opts = Rex::Parser::Arguments.new(
306306
'-h' => [ false, 'Help Banner' ]
307307
)
308-
opts.parse(args) do |opt, _idx, val|
308+
opts.parse(args) do |opt, _idx, _val|
309309
case opt
310310
when '-h'
311311
print_line("Usage: enable_crc\n")
@@ -537,7 +537,7 @@ def cmd_maxpower_help
537537
#
538538
def cmd_maxpower(*args)
539539
self.idx ||= 0
540-
if args.length > 0
540+
if args.length.positive?
541541
cmd_maxpower_help
542542
return
543543
end

lib/rex/post/hwbridge/ui/console/command_dispatcher/zigbee.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def cmd_supported_devices
4444
return
4545
end
4646
devices = devices["devices"]
47-
unless devices.size > 0
47+
unless devices.size.positive?
4848
print_line("none")
4949
return
5050
end
@@ -100,7 +100,7 @@ def cmd_channel(*args)
100100
chan = val.to_i
101101
end
102102
end
103-
if !dev
103+
unless dev
104104
print_line("You must specify or set a target device")
105105
return
106106
end

0 commit comments

Comments
 (0)