Skip to content

Commit

Permalink
Code cleanup from Rubocop output
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Smith <agent.craig@gmail.com>
  • Loading branch information
zombieCraig committed Apr 25, 2017
1 parent c2296dc commit aeed81d
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 339 deletions.
596 changes: 298 additions & 298 deletions lib/msf/core/post/hardware/automotive/dtc.rb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions lib/msf/core/post/hardware/zigbee/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,26 +220,26 @@ def dot154_packet_decode(packet)
daddr_mask = (fcf & DOT154_FCF_DADDR_MASK) >> 10
if daddr_mask == DOT154_FCF_ADDR_EXT
pktchop[3] = packet[offset,8]
offset+=8
offset += 8
elsif daddr_mask == DOT154_FCF_ADDR_SHORT
pktchop[3] = packet[offset,2]
offset+=2
offset += 2
end

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

# Examine the source addressing mode
saddr_mask = (fcf & DOT154_FCF_SADDR_MASK) >> 14
if daddr_mask == DOT154_FCF_ADDR_EXT
pktchop[5] = packet[offset,8]
offset+=8
offset += 8
elsif daddr_mask == DOT154_FCF_ADDR_SHORT
pktchop[5] = packet[offset,2]
offset+=2
offset += 2
end
end
# Append remaining payload
Expand Down
2 changes: 1 addition & 1 deletion lib/rex/post/hwbridge/extensions/automotive/uds_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module UDSErrors
"SLNIP" => "Shifter Lever Not In Park",
"TCCL" => "Torque Converter Clutch Locked",
"VTH" => "Voltage Too High",
"VTL" => "Voltage Too Low"
"VTL" => "Voltage Too Low"
}

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def cmd_isotpsend(*args)
return result
end
opt = {}
opt['TIMEOUT'] = timeout if not timeout.nil?
opt['MAXPKTS'] = maxpackets if not maxpackets.nil?
opt['TIMEOUT'] = timeout unless timeout.nil?
opt['MAXPKTS'] = maxpackets unless maxpackets.nil?
result = client.automotive.send_isotp_and_wait_for_response(bus, id, ret, bytes, opt)
if result.key? 'Packets'
result['Packets'].each do |pkt|
Expand Down Expand Up @@ -269,7 +269,7 @@ def cmd_testerpresent(*args)
return
end
if id.blank? && !stop
if self.tpjobs.size > 0
if self.tpjobs.size.positive?
print_line("TesterPresent is currently active")
self.tpjobs.each_index do |jid|
if self.tpjobs[jid]
Expand Down
28 changes: 14 additions & 14 deletions lib/rex/post/hwbridge/ui/console/command_dispatcher/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def cmd_sessions_help
end

def cmd_sessions(*args)
if args.length == 0 || args[0].to_i == 0
if args.length.zero? || args[0].to_i.zero?
cmd_sessions_help
elsif args[0].to_s == client.name.to_s
print_status("Session #{client.name} is already interactive.")
Expand Down Expand Up @@ -185,7 +185,7 @@ def cmd_info(*args)
if mod
print_line(::Msf::Serializer::ReadableText.dump_module(mod))
mod_opt = ::Msf::Serializer::ReadableText.dump_options(mod, ' ')
print_line("\nModule options (#{mod.fullname}):\n\n#{mod_opt}") if mod_opt && mod_opt.length > 0
print_line("\nModule options (#{mod.fullname}):\n\n#{mod_opt}") if mod_opt && mod_opt.length.positive?
end
end

Expand All @@ -204,7 +204,7 @@ def cmd_status_help
# Get the HW bridge devices status
#
def cmd_status(*args)
if args.length > 0
if args.length.positive?
cmd_status_help
return true
end
Expand Down Expand Up @@ -235,7 +235,7 @@ def cmd_specialty_help
# Get the Hardware specialty
#
def cmd_specialty(*args)
if args.length > 0
if args.length.positive?
cmd_specialty_help
return true
end
Expand All @@ -251,7 +251,7 @@ def cmd_reset_help
# Performs a device reset or factory reset
#
def cmd_reset(*args)
if args.length > 0
if args.length.positive?
cmd_reset_help
return
end
Expand All @@ -268,7 +268,7 @@ def cmd_reboot_help
# Perform a device reboot
#
def cmd_reboot(*args)
if args.length > 0
if args.length.positive?
cmd_reboot_help
return
end
Expand All @@ -286,15 +286,15 @@ def cmd_load_custom_methods_help
# Loads custom methods if any exist
#
def cmd_load_custom_methods(*args)
if args.length > 0
if args.length.positive?
cmd_load_custom_methods_help
return true
end
res = client.get_custom_methods
if res.has_key? 'Methods'
cmd_load("custom_methods")
self.shell.dispatcher_stack.each do |dispatcher|
if dispatcher.name =~/custom methods/i
if dispatcher.name =~ /custom methods/i
dispatcher.load_methods(res['Methods'])
end
end
Expand All @@ -315,7 +315,7 @@ def cmd_load_help
# Loads one or more meterpreter extensions.
#
def cmd_load(*args)
if args.length == 0
if args.length.zero?
args.unshift("-h")
end

Expand Down Expand Up @@ -369,7 +369,7 @@ def cmd_run_help
# Executes a script in the context of the hwbridge session.
#
def cmd_run(*args)
if args.length == 0
if args.length.zero?
cmd_run_help
return true
end
Expand Down Expand Up @@ -423,7 +423,7 @@ def cmd_run_tabs(str, words)
next unless ::File.exist? dir
tabs += ::Dir.new(dir).find_all { |e|
path = dir + ::File::SEPARATOR + e
::File.file?(path) and ::File.readable?(path)
::File.file?(path) && ::File.readable?(path)
}
end
rescue Exception
Expand All @@ -436,7 +436,7 @@ def cmd_run_tabs(str, words)
# Executes a script in the context of the hardware bridge session in the background
#
def cmd_bgrun(*args)
if args.length == 0
if args.length.zero?
print_line(
"Usage: bgrun <script> [arguments]\n\n" +
"Executes a ruby script in the context of the hardware bridge session.")
Expand Down Expand Up @@ -475,7 +475,7 @@ def cmd_bgrun_tabs(*args)
# Kill a background job
#
def cmd_bgkill(*args)
if args.length == 0
if args.length.zero?
print_line("Usage: bgkill [id]")
return
end
Expand Down Expand Up @@ -574,7 +574,7 @@ def add_extension_client(mod)
end

def tab_complete_postmods
tabs = client.framework.modules.post.map { |name,klass|
tabs = client.framework.modules.post.map { |name, klass|
mod = client.framework.modules.post.create(name)
if mod && mod.session_compatible?(client)
mod.fullname.dup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def name
def load_methods(m)
@custom_methods = m
m.each do |method|
if method.has_key? "method_name"
if method.key? "method_name"
desc = "See HW manual for command description"
desc = method["method_desc"] if method.has_key? "method_desc"
desc = method["method_desc"] if method.key? "method_desc"
cmd = method["method_name"]
cmd = $1 if cmd=~/\/(\S+)$/
cmd = /\/(\S+)$/.match(cmd)
@cmds[cmd] = method["method_desc"]
eval("alias cmd_#{cmd} cmd_generic_handler")
end
Expand All @@ -56,14 +56,14 @@ def load_methods(m)
#
def cmd_generic_handler_help(cmd)
@custom_methods.each do |meth|
if meth["method_name"] =~ /#{cmd}$/
next unless meth["method_name"] =~ /#{cmd}$/
args = ""
args = "<args>" if meth["args"].size > 0
print_line("Usage: #{cmd} #{args}")
print_line
meth["args"].each do |arg|
req = ""
req = " *required*" if arg.has_key? "required" and arg["required"] == true
req = " *required*" if arg.key? "required" and arg["required"] == true
print_line(" #{arg["arg_name"]}=<#{arg["arg_type"]}> #{req}")
end
end
Expand All @@ -87,8 +87,8 @@ def cmd_generic_handler(*args)
return true
end
res = client.custom_methods.send_request(cmd, args, @custom_methods)
print_status(res["status"]) if res.has_key? "status"
print_status(res["value"]) if res.has_key? "value"
print_status(res["status"]) if res.key? "status"
print_status(res["value"]) if res.key? "value"
end

#
Expand All @@ -104,8 +104,8 @@ def has_required_args(cmd, args)
@custom_methods.each do |meth|
if meth["method_name"] =~ /#{cmd}$/
meth["args"].each do |arg|
if arg.has_key? "required" and arg["required"] == true
all_found = false if not arguments.has_key? arg["arg_name"]
if arg.key? "required" and arg["required"] == true
all_found = false if not arguments.key? arg["arg_name"]
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ def commands

def cmd_supported_idx
indexes = client.rftransceiver.supported_idx
if !indexes || !indexes.has_key?('indexes')
if !indexes || !indexes.key?('indexes')
print_line("error retrieving index list")
return
end
indexes = indexes['indexes']
unless indexes.size > 0
unless indexes.size.positive?
print_line('none')
return
end
self.idx = indexes[0].to_i if indexes.size == 0
self.idx = indexes[0].to_i if indexes.size.zero?
str = "Supported Indexes: "
str << indexes.join(', ')
str << "\nUse idx to set your desired bus, default is 0"
Expand Down Expand Up @@ -91,7 +91,7 @@ def cmd_freq_help
# Takes the results of a client request and prints Ok on success
#
def print_success(r)
if r.has_key?('success') && r['success'] == true
if r.key?('success') && r['success'] == true
print_line("Ok")
else
print_line("Error")
Expand Down Expand Up @@ -290,7 +290,7 @@ def cmd_recv(*args)
arg['blocksize'] = blocksize unless blocksize == -1
arg['timeout'] = timeout unless timeout == -1
r = client.rftransceiver.rfrecv(idx, arg)
if r.has_key?('data') && r.has_key?('timestamp')
if r.key?('data') && r.has_key?('timestamp')
print_line(" #{r['timestamp']}: #{r['data'].inspect}")
else
print_line("Error")
Expand All @@ -305,7 +305,7 @@ def cmd_enable_crc(*args)
opts = Rex::Parser::Arguments.new(
'-h' => [ false, 'Help Banner' ]
)
opts.parse(args) do |opt, _idx, val|
opts.parse(args) do |opt, _idx, _val|
case opt
when '-h'
print_line("Usage: enable_crc\n")
Expand Down Expand Up @@ -537,7 +537,7 @@ def cmd_maxpower_help
#
def cmd_maxpower(*args)
self.idx ||= 0
if args.length > 0
if args.length.positive?
cmd_maxpower_help
return
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rex/post/hwbridge/ui/console/command_dispatcher/zigbee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def cmd_supported_devices
return
end
devices = devices["devices"]
unless devices.size > 0
unless devices.size.positive?
print_line("none")
return
end
Expand Down Expand Up @@ -100,7 +100,7 @@ def cmd_channel(*args)
chan = val.to_i
end
end
if !dev
unless dev
print_line("You must specify or set a target device")
return
end
Expand Down

0 comments on commit aeed81d

Please sign in to comment.