lib/ruby_smb/dcerpc/uuid.rb in ruby_smb-0.0.21 vs lib/ruby_smb/dcerpc/uuid.rb in ruby_smb-0.0.22

- old
+ new

@@ -1,28 +1,46 @@ module RubySMB module Dcerpc - #https://msdn.microsoft.com/en-us/library/windows/desktop/aa379358(v=vs.85).aspx + # [Universal Unique Identifier](http://pubs.opengroup.org/onlinepubs/9629399/apdxa.htm) class Uuid < BinData::Primitive - uint32le :time_low - uint16le :time_mid - uint16le :time_hi_and_version + endian :little + uint32 :time_low, label: 'Low field of the timestamp' + uint16 :time_mid, label: 'Middle field of the timestamp' + uint16 :time_hi_and_version, label: 'High field of the timestamp multiplexed with the version number' - uint16be :clock_seq_hi_and_res - uint48be :node + uint8 :clock_seq_hi_and_reserved, label: 'High field of the clock sequence multiplexed with the variant' + uint8 :clock_seq_low, label: 'Low field of the clock sequence' + array :node, label: 'Spatially unique node identifier', :type => :uint8, initial_length: 6 def get - self.to_binary_s + "#{to_string_le(time_low.to_binary_s)}"\ + "-#{to_string_le(time_mid.to_binary_s)}"\ + "-#{to_string_le(time_hi_and_version.to_binary_s)}"\ + "-#{clock_seq_hi_and_reserved.to_hex}#{clock_seq_low.to_hex}"\ + "-#{node.to_hex}" end def set(uuid_string) components = uuid_string.split('-') - self.time_low = components[0].hex - self.time_mid = components[1].hex - self.time_hi_and_version = components[2].hex - self.clock_seq_hi_and_res = components[3].hex - self.node = components[4].hex + self.time_low.read(to_binary_le(components[0])) + self.time_mid.read(to_binary_le(components[1])) + self.time_hi_and_version.read(to_binary_le(components[2])) + self.clock_seq_hi_and_reserved.read(components[3][0,2].hex.chr) + self.clock_seq_low.read(components[3][2,2].hex.chr) + self.node.read(components[4].gsub(/../) {|e| e.hex.chr}) end + + + private + + def to_binary_le(str) + str.scan(/../).map {|char| char.hex.chr}.reverse.join + end + + def to_string_le(bin) + bin.each_byte.map {|byte| byte.to_s(16).rjust(2, '0')}.reverse.join + end end end -end \ No newline at end of file +end