Skip to content

Commit

Permalink
Fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
sdaubert committed May 4, 2024
1 parent 56925f0 commit 294c35f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/packetgen/plugin/smb/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.protocol_name
# @return [Browser] may return a subclass object if a more specific class
# may be determined
def read(str)
if self.class == Browser
if self.instance_of?(Browser)
return self if str.nil?

PacketGen.force_binary str
Expand All @@ -71,7 +71,7 @@ def read(str)
def added_to_packet(packet)
return if packet.respond_to? :smb_browser

packet.instance_eval("def smb_browser(arg=nil); header(#{self.class}, arg); end")
packet.instance_eval("def smb_browser(arg=nil); header(#{self.class}, arg); end") # def smb_browser(arg=nil); header(Browser, arg); end
end

private
Expand Down
4 changes: 1 addition & 3 deletions lib/packetgen/plugin/smb/filetime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def self.now
# @option options [Time] :time
# @raise [ArgumentError] if +:time+ and +:filetime+ are both given.
def initialize(options={})
if (options.keys & %i[time filetime]).size == 2
raise ArgumentError, ':time and :filetime options are both given'
end
raise ArgumentError, ':time and :filetime options are both given' if options.key?(:time) && options.key?(:filetime)

@int = PacketGen::Types::SInt64le.new(options[:filetime])
if options[:time]
Expand Down
2 changes: 1 addition & 1 deletion lib/packetgen/plugin/smb2/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def self.define_smb2_pad_field(name)
(8 - (hdr.offset_of(prev_field) + hdr[prev_field].sz) % 8) % 8
end
define_field name, PacketGen::Types::String, default: SMB2::MAX_PADDING,
builder: ->(h, t) { t.new(length_from: -> { lf[h] }) }
builder: ->(h, t) { t.new(length_from: -> { lf[h] }) }
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/packetgen/plugin/smb2/guid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GUID < PacketGen::Types::Fields
def to_human
data4p1 = data4 >> 48
data4p2 = data4 & 0xffff_ffff_ffff
"%08x-%04x-%04x-%04x-%012x" % [data1, data2, data3, data4p1, data4p2]
'%08x-%04x-%04x-%04x-%012x' % [data1, data2, data3, data4p1, data4p2] # rubocop:disable Style/FormatStringToken
end

# Set GUID from a human-readable string
Expand All @@ -56,13 +56,13 @@ def to_human
def from_human(guid)
return self if guid.nil? || guid.empty?

values = guid.split('-')
values = guid.split('-').map { |v| v.to_i(16) }
return self if values.size != 5

self.data1 = values[0].to_i(16)
self.data2 = values[1].to_i(16)
self.data3 = values[2].to_i(16)
self.data4 = values[3].to_i(16) << 48 | values[4].to_i(16)
self.data1 = values[0]
self.data2 = values[1]
self.data3 = values[2]
self.data4 = values[3] << 48 | values[4]
self
end
end
Expand Down

0 comments on commit 294c35f

Please sign in to comment.