Class: Metasploit::Aggregator::Tlv::GroupTlv
- Defined in:
- lib/metasploit/aggregator/tlv/packet.rb
Overview
Group TLVs contain zero or more TLVs
Direct Known Subclasses
Instance Attribute Summary collapse
-
#tlvs ⇒ Object
Returns the value of attribute tlvs.
Attributes inherited from Tlv
Instance Method Summary collapse
-
#add_tlv(type, value = nil, replace = false, compress = false) ⇒ Object
Adds a TLV of a given type and value.
-
#add_tlvs(tlvs) ⇒ Object
Adds zero or more TLVs to the packet.
-
#each(type = TLV_TYPE_ANY, &block) ⇒ Object
Enumerates TLVs of the supplied type.
-
#each_tlv(type = TLV_TYPE_ANY, &block) ⇒ Object
Synonym for each.
-
#each_tlv_with_index(type = TLV_TYPE_ANY, &block) ⇒ Object
Synonym for each_with_index.
-
#each_with_index(type = TLV_TYPE_ANY, &block) ⇒ Object
Enumerates TLVs of a supplied type with indexes.
-
#from_r(raw) ⇒ Object
Converts the TLV group container from raw to all of the individual TLVs.
-
#get_tlv(type, index = 0) ⇒ Object
Gets the first TLV of a given type.
-
#get_tlv_value(type, index = 0) ⇒ Object
Returns the value of a TLV if it exists, otherwise nil.
-
#get_tlv_values(type) ⇒ Object
Returns an array of values for all tlvs of type type.
-
#get_tlvs(type) ⇒ Object
Returns an array of TLVs for the given type.
-
#has_tlv?(type) ⇒ Boolean
Checks to see if the container has a TLV of a given type.
-
#initialize(type) ⇒ GroupTlv
constructor
Initializes the group TLV container to the supplied type and creates an empty TLV array.
-
#reset ⇒ Object
Zeros out the array of TLVs.
-
#to_r ⇒ Object
Converts all of the TLVs in the TLV array to raw and prefixes them with a container TLV of this instance’s TLV type.
Methods inherited from Tlv
#inspect, #meta_type?, #type?, #value?
Constructor Details
#initialize(type) ⇒ GroupTlv
Initializes the group TLV container to the supplied type and creates an empty TLV array.
358 359 360 361 362 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 358 def initialize(type) super(type) self.tlvs = [ ] end |
Instance Attribute Details
#tlvs ⇒ Object
Returns the value of attribute tlvs.
346 347 348 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 346 def tlvs @tlvs end |
Instance Method Details
#add_tlv(type, value = nil, replace = false, compress = false) ⇒ Object
Adds a TLV of a given type and value.
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 426 def add_tlv(type, value = nil, replace = false, compress=false) # If we should replace any TLVs with the same type...remove them first if (replace) each(type) { |tlv| if (tlv.type == type) self.tlvs.delete(tlv) end } end if (type & TLV_META_TYPE_GROUP == TLV_META_TYPE_GROUP) tlv = GroupTlv.new(type) else tlv = Tlv.new(type, value, compress) end self.tlvs << tlv return tlv end |
#add_tlvs(tlvs) ⇒ Object
Adds zero or more TLVs to the packet.
451 452 453 454 455 456 457 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 451 def add_tlvs(tlvs) if (tlvs != nil) tlvs.each { |tlv| add_tlv(tlv['type'], tlv['value']) } end end |
#each(type = TLV_TYPE_ANY, &block) ⇒ Object
Enumerates TLVs of the supplied type.
373 374 375 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 373 def each(type = TLV_TYPE_ANY, &block) get_tlvs(type).each(&block) end |
#each_tlv(type = TLV_TYPE_ANY, &block) ⇒ Object
Synonym for each.
380 381 382 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 380 def each_tlv(type = TLV_TYPE_ANY, &block) each(type, &block) end |
#each_tlv_with_index(type = TLV_TYPE_ANY, &block) ⇒ Object
Synonym for each_with_index.
394 395 396 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 394 def each_tlv_with_index(type = TLV_TYPE_ANY, &block) each_with_index(type, block) end |
#each_with_index(type = TLV_TYPE_ANY, &block) ⇒ Object
Enumerates TLVs of a supplied type with indexes.
387 388 389 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 387 def each_with_index(type = TLV_TYPE_ANY, &block) get_tlvs(type).each_with_index(&block) end |
#from_r(raw) ⇒ Object
Converts the TLV group container from raw to all of the individual TLVs.
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 526 def from_r(raw) offset = 8 # Reset the TLVs array self.tlvs = [] self.type = raw.unpack("NN")[1] # Enumerate all of the TLVs while (offset < raw.length-1) tlv = nil # Get the length and type length, type = raw[offset..offset+8].unpack("NN") if (type & TLV_META_TYPE_GROUP == TLV_META_TYPE_GROUP) tlv = GroupTlv.new(type) else tlv = Tlv.new(type) end tlv.from_r(raw[offset..offset+length]) # Insert it into the list of TLVs tlvs << tlv # Move up offset += length end end |
#get_tlv(type, index = 0) ⇒ Object
Gets the first TLV of a given type.
462 463 464 465 466 467 468 469 470 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 462 def get_tlv(type, index = 0) type_tlvs = get_tlvs(type) if (type_tlvs.length > index) return type_tlvs[index] end return nil end |
#get_tlv_value(type, index = 0) ⇒ Object
Returns the value of a TLV if it exists, otherwise nil.
475 476 477 478 479 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 475 def get_tlv_value(type, index = 0) tlv = get_tlv(type, index) return (tlv != nil) ? tlv.value : nil end |
#get_tlv_values(type) ⇒ Object
Returns an array of values for all tlvs of type type.
484 485 486 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 484 def get_tlv_values(type) get_tlvs(type).collect { |a| a.value } end |
#get_tlvs(type) ⇒ Object
Returns an array of TLVs for the given type.
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 401 def get_tlvs(type) if (type == TLV_TYPE_ANY) return self.tlvs else type_tlvs = [] self.tlvs.each() { |tlv| if (tlv.type?(type)) type_tlvs << tlv end } return type_tlvs end end |
#has_tlv?(type) ⇒ Boolean
Checks to see if the container has a TLV of a given type.
491 492 493 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 491 def has_tlv?(type) return get_tlv(type) != nil end |
#reset ⇒ Object
Zeros out the array of TLVs.
498 499 500 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 498 def reset self.tlvs = [] end |
#to_r ⇒ Object
Converts all of the TLVs in the TLV array to raw and prefixes them with a container TLV of this instance’s TLV type.
512 513 514 515 516 517 518 519 520 |
# File 'lib/metasploit/aggregator/tlv/packet.rb', line 512 def to_r raw = '' self.each() { |tlv| raw << tlv.to_r } return [raw.length + 8, self.type].pack("NN") + raw end |