Class: PWN::SDR::Decoder::ZigBee::Octets

Inherits:
Object
  • Object
show all
Defined in:
lib/pwn/sdr/decoder/zigbee.rb

Overview

ZigBee PRO NWK version 2 and APS. Unsupported variants return nil. Layout cross-check: https://github.com/secdev/scapy/blob/master/scapy/layers/zigbee.py

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ Octets

Returns a new instance of Octets.

Raises:

  • (IndexError)


211
212
213
214
215
216
# File 'lib/pwn/sdr/decoder/zigbee.rb', line 211

def initialize(bytes)
  raise IndexError unless bytes.is_a?(Array) && bytes.all? { |b| b.is_a?(Integer) && (0..255).cover?(b) }

  @bytes = bytes
  @offset = 0
end

Instance Attribute Details

#offsetObject (readonly)

Returns the value of attribute offset.



209
210
211
# File 'lib/pwn/sdr/decoder/zigbee.rb', line 209

def offset
  @offset
end

Instance Method Details

#address(count) ⇒ Object



230
231
232
# File 'lib/pwn/sdr/decoder/zigbee.rb', line 230

def address(count)
  take(count).reverse.pack('C*').unpack1('H*').upcase
end

#number(count = 1) ⇒ Object



226
227
228
# File 'lib/pwn/sdr/decoder/zigbee.rb', line 226

def number(count = 1)
  take(count).each_with_index.sum { |b, i| b << (8 * i) }
end

#restObject



234
235
236
# File 'lib/pwn/sdr/decoder/zigbee.rb', line 234

def rest
  take(@bytes.length - @offset)
end

#take(count) ⇒ Object

Raises:

  • (IndexError)


218
219
220
221
222
223
224
# File 'lib/pwn/sdr/decoder/zigbee.rb', line 218

def take(count)
  raise IndexError if @offset + count > @bytes.length

  value = @bytes[@offset, count]
  @offset += count
  value
end