Class: PWN::SDR::Decoder::ZigBee::Octets
- Inherits:
-
Object
- Object
- PWN::SDR::Decoder::ZigBee::Octets
- 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
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
Instance Method Summary collapse
- #address(count) ⇒ Object
-
#initialize(bytes) ⇒ Octets
constructor
A new instance of Octets.
- #number(count = 1) ⇒ Object
- #rest ⇒ Object
- #take(count) ⇒ Object
Constructor Details
#initialize(bytes) ⇒ Octets
Returns a new instance of Octets.
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
#offset ⇒ Object (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 |
#rest ⇒ Object
234 235 236 |
# File 'lib/pwn/sdr/decoder/zigbee.rb', line 234 def rest take(@bytes.length - @offset) end |
#take(count) ⇒ Object
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 |