Skip to content

Commit 2ff4e6f

Browse files
committed
Fixed defaults for elm327 realy.
Array2Hex in the automotive extension how supports passing an array or integers or string hexes Added some extra error handling for UDS calls to non-supported pids
1 parent 53dbd03 commit 2ff4e6f

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ def get_vin(bus, srcId, dstId)
496496
packets = get_vehicle_info(bus, srcId, dstId, 0x02)
497497
return "UDS ERR: #{packets["error"]}" if packets.has_key? "error"
498498
data = response_hash_to_data_array(dstId.to_s(16), packets)
499+
return "" if data == nil
499500
data.map! { |d| d.hex.chr }
500501
data.join
501502
end
@@ -511,6 +512,7 @@ def get_calibration_id(bus, srcId, dstId)
511512
packets = get_vehicle_info(bus, srcId, dstId, 0x04)
512513
return "UDS ERR: #{packets["error"]}" if packets.has_key? "error"
513514
data = response_hash_to_data_array(dstId.to_s(16), packets)
515+
return "" if data == nil
514516
data.map! { |d| d.hex.chr }
515517
data.join
516518
end
@@ -526,6 +528,7 @@ def get_ecu_name(bus, srcId, dstId)
526528
packets = get_vehicle_info(bus, srcId, dstId, 0x0A)
527529
return "UDS ERR: #{packets["error"]}" if packets.has_key? "error"
528530
data = response_hash_to_data_array(dstId.to_s(16), packets)
531+
return "" if data == nil
529532
data.map! { |d| d.hex.chr }
530533
data.join
531534
end

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def check_for_errors(data)
7777
#
7878
# @return [Array] Array of Hex string equivalents
7979
def array2hex(arr)
80-
arr.map { |b| "%02x" % b.hex }
80+
# We give the flexibility of sending Integers or string hexes in the array
81+
arr.map { |b| "%02x" % (b.respond_to?("hex") ? b.hex : b )}
8182
end
8283

8384
def set_active_bus(bus)

tools/hardware/elm327_relay.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class ELM327Relay < Msf::Auxiliary
7171
attr_accessor :serial_stop_bits
7272

7373
def initialize(info={})
74+
# Set some defaults
75+
self.serial_port = "/dev/ttyUSB0"
76+
self.serial_baud = 115200
7477
begin
7578
@opts = OptsConsole.parse(ARGV)
7679
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
@@ -99,8 +102,8 @@ def initialize(info={})
99102
{
100103
'URIPATH' => "/"
101104
}))
102-
self.serial_port = @opts[:serial]
103-
self.serial_baud = @opts[:baud].to_i
105+
self.serial_port = @opts[:serial] if @opts.has_key? :serial
106+
self.serial_baud = @opts[:baud].to_i if @opts.has_key? :baud
104107
self.serial_bits = 8
105108
self.serial_stop_bits = 1
106109
@operational_status = 0

0 commit comments

Comments
 (0)