Esempio n. 1
0
        void Decode(byte[] buffer, int startIndex, int length, bool unicode)
        {
            int index = startIndex;

            do
            {
                var type = BitConverterLE.ToInt16(buffer, index);

                index += 2;

                switch (type)
                {
                case 1: ServerName = DecodeString(buffer, ref index, unicode); break;

                case 2: DomainName = DecodeString(buffer, ref index, unicode); break;

                case 3: DnsServerName = DecodeString(buffer, ref index, unicode); break;

                case 4: DnsDomainName = DecodeString(buffer, ref index, unicode); break;

                case 5: DnsTreeName = DecodeString(buffer, ref index, unicode); break;

                case 6: Flags = DecodeFlags(buffer, ref index); break;

                case 7: Timestamp = DecodeTimestamp(buffer, ref index); break;

                case 9: TargetName = DecodeString(buffer, ref index, unicode); break;

                default: index += 2 + BitConverterLE.ToInt16(buffer, index); break;
                }
            } while (index < startIndex + length);
        }
Esempio n. 2
0
        static long DecodeTimestamp(byte[] buffer, ref int index, out short size)
        {
            size = BitConverterLE.ToInt16(buffer, index);
            long value;

            index += 2;

            switch (size)
            {
            case 8:
                long lo = BitConverterLE.ToUInt32(buffer, index);
                long hi = BitConverterLE.ToUInt32(buffer, index + 4);
                value = (hi << 32) | lo;
                break;

            case 4: value = BitConverterLE.ToUInt32(buffer, index); break;

            case 2: value = BitConverterLE.ToUInt16(buffer, index); break;

            default: value = 0; break;
            }

            index += size;

            return(value);
        }
Esempio n. 3
0
        static long DecodeTimestamp(byte[] buffer, ref int index)
        {
            short nbytes = BitConverterLE.ToInt16(buffer, index);
            long  lo, hi;

            index += 2;

            switch (nbytes)
            {
            case 8:
                lo     = BitConverterLE.ToUInt32(buffer, index);
                index += 4;
                hi     = BitConverterLE.ToUInt32(buffer, index);
                index += 4;
                return((hi << 32) | lo);

            case 4:
                lo     = BitConverterLE.ToUInt32(buffer, index);
                index += 4;
                return(lo);

            case 2:
                lo     = BitConverterLE.ToUInt16(buffer, index);
                index += 2;
                return(lo);

            default:
                index += nbytes;
                return(0);
            }
        }
Esempio n. 4
0
        static int DecodeFlags(byte[] buffer, ref int index)
        {
            short nbytes = BitConverterLE.ToInt16(buffer, index);
            int   value  = BitConverterLE.ToInt32(buffer, index + 2);

            index += 6;

            return(value);
        }
Esempio n. 5
0
        static string DecodeString(byte[] buffer, ref int index, bool unicode)
        {
            var encoding = unicode ? Encoding.Unicode : Encoding.UTF8;
            var length   = BitConverterLE.ToInt16(buffer, index);
            var value    = encoding.GetString(buffer, index + 2, length);

            index += 2 + length;

            return(value);
        }
Esempio n. 6
0
        void Decode(byte[] buffer, int startIndex, int length, bool unicode)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (startIndex < 0 || startIndex > buffer.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(startIndex));
            }

            if (length < 12 || length > (buffer.Length - startIndex))
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            int index = startIndex;

            do
            {
                var   attr = (NtlmAttribute)BitConverterLE.ToInt16(buffer, index);
                short size;

                index += 2;

                switch (attr)
                {
                case NtlmAttribute.EOL:
                    index = startIndex + length;
                    break;

                case NtlmAttribute.ServerName:
                case NtlmAttribute.DomainName:
                case NtlmAttribute.DnsServerName:
                case NtlmAttribute.DnsDomainName:
                case NtlmAttribute.DnsTreeName:
                case NtlmAttribute.TargetName:
                    attributes.Add(new NtlmAttributeStringValuePair(attr, DecodeString(buffer, ref index, unicode)));
                    break;

                case NtlmAttribute.Flags:
                    attributes.Add(new NtlmAttributeFlagsValuePair(attr, DecodeFlags(buffer, ref index, out size), size));
                    break;

                case NtlmAttribute.Timestamp:
                    attributes.Add(new NtlmAttributeTimestampValuePair(attr, DecodeTimestamp(buffer, ref index, out size), size));
                    break;

                default:
                    attributes.Add(new NtlmAttributeByteArrayValuePair(attr, DecodeByteArray(buffer, ref index)));
                    break;
                }
            } while (index < startIndex + length);
        }
Esempio n. 7
0
        static byte[] DecodeByteArray(byte[] buffer, ref int index)
        {
            var length = BitConverterLE.ToInt16(buffer, index);
            var value  = new byte[length];

            Buffer.BlockCopy(buffer, index + 2, value, 0, length);

            index += 2 + length;

            return(value);
        }
Esempio n. 8
0
        static string DecodeString(byte[] buffer, ref int index, bool unicode)
        {
            short  length = BitConverterLE.ToInt16(buffer, index);
            string value;

            if (unicode)
            {
                value = Encoding.Unicode.GetString(buffer, index + 2, length);
            }
            else
            {
                value = Encoding.ASCII.GetString(buffer, index + 2, length);
            }

            index += 2 + length;

            return(value);
        }
Esempio n. 9
0
        static int DecodeFlags(byte[] buffer, ref int index)
        {
            short nbytes = BitConverterLE.ToInt16(buffer, index);
            int   flags;

            index += 2;

            switch (nbytes)
            {
            case 4:  flags = BitConverterLE.ToInt32(buffer, index); break;

            case 2:  flags = BitConverterLE.ToInt16(buffer, index); break;

            default: flags = 0; break;
            }

            index += nbytes;

            return(flags);
        }
Esempio n. 10
0
        static int DecodeFlags(byte[] buffer, ref int index, out short size)
        {
            size = BitConverterLE.ToInt16(buffer, index);
            int flags;

            index += 2;

            switch (size)
            {
            case 4:  flags = BitConverterLE.ToInt32(buffer, index); break;

            case 2:  flags = BitConverterLE.ToInt16(buffer, index); break;

            default: flags = 0; break;
            }

            index += size;

            return(flags);
        }