Class: Unified2::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/unified2/payload.rb

Overview

Payload

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, packet = {}) ⇒ Payload

Initialize payload object

Parameters:

  • raw (String)

    Raw binary payload

  • packet (Hash) (defaults to: {})

    Packet attributes

Options Hash (packet):

  • :packet (String)

    Packet

  • :packet_length (Integer)

    Packet length

  • :linktype (Integer)

    Packet linktype



21
22
23
24
25
# File 'lib/unified2/payload.rb', line 21

def initialize(raw, packet={})
  @packet = raw
  @length = packet[:packet_length].to_i
  @linktype = packet[:linktype]
end

Instance Attribute Details

#lengthObject

Returns the value of attribute length.



9
10
11
# File 'lib/unified2/payload.rb', line 9

def length
  @length
end

#linktypeObject

Returns the value of attribute linktype.



9
10
11
# File 'lib/unified2/payload.rb', line 9

def linktype
  @linktype
end

#packetObject

Returns the value of attribute packet.



9
10
11
# File 'lib/unified2/payload.rb', line 9

def packet
  @packet
end

Instance Method Details

#blank?true, false

Blank?

Returns:

  • (true, false)

    Check is payload is blank



32
33
34
35
# File 'lib/unified2/payload.rb', line 32

def blank?
  return true unless @packet
  false
end

#dump(options = {}) {|index, hex_segment, print_segment| ... } ⇒ nil

Note:

Please view the hexdump documentation for more information. Hexdump is a great lib by @postmodern. (github.com/postmodern/hexdump)

Dump

Parameters:

  • options (options) (defaults to: {})

    Hash of options for Hexdump#dump

Options Hash (options):

  • :width (Integer) — default: 16

    The number of bytes to dump for each line.

  • :base (Symbol, Integer) — default: :hexadecimal

    The base to print bytes in. Supported bases include, ‘:hexadecimal`, `:hex`, `16, `:decimal`, `:dec`, `10, `:octal`, `:oct`, `8`, `:binary`, `:bin` and `2`.

  • :ascii (Boolean) — default: false

    Print ascii characters when possible.

  • :output (#<<) — default: STDOUT

    The output to print the hexdump to.

Yields:

  • (index, hex_segment, print_segment)

    The given block will be passed the hexdump break-down of each segment.

Yield Parameters:

  • index (Integer)

    The index of the hexdumped segment.

  • hex_segment (Array<String>)

    The hexadecimal-byte representation of the segment.

  • print_segment (Array<String>)

    The print-character representation of the segment.

Returns:

  • (nil)

Raises:

  • (ArgumentError)

    The given data does not define the ‘#each_byte` method, or



98
99
100
# File 'lib/unified2/payload.rb', line 98

def dump(options={})
  Hexdump.dump(@packet, options)
end

#hexString

Hex

Returns:

  • (String)

    Convert payload to hex



51
52
53
54
55
# File 'lib/unified2/payload.rb', line 51

def hex
  @hex = @packet.to_s.unpack('H*')
  return @hex.first if @hex
  nil
end

#rawString

Raw

Returns:

  • (String)

    Raw binary payload



42
43
44
# File 'lib/unified2/payload.rb', line 42

def raw
  @packet
end