/// <summary>
        /// read struct from bytes. All sub class override this to unmarshal itself.
        /// </summary>
        /// <param name="start">the start to read bytes</param>
        /// <param name="packetBytes">the bytes of struct</param>
        /// <returns>the read result, if success, return true.</returns>
        protected override bool ReadStructFromBytes(
            byte[] packetBytes,
            int start
            )
        {
            CHALLENGE_MESSAGE challenge = new CHALLENGE_MESSAGE();

            challenge.TargetNameFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(packetBytes, ref start);
            challenge.NegotiateFlags   = (NegotiateTypes)NlmpUtility.BytesToStruct <uint>(packetBytes, ref start);
            challenge.ServerChallenge  = NlmpUtility.BytesToStruct <ulong>(packetBytes, ref start);
            challenge.Reserved         = NlmpUtility.BytesToStruct <ulong>(packetBytes, ref start);
            challenge.TargetInfoFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(packetBytes, ref start);

            // Unmarshal the Version field.
            // The Version field is NOT sent or accessed by Windows NT or Windows 2000. Windows NT and Windows 2000
            // assume that the Payload field started immediately after WorkstationNameBufferOffset.
            if (challenge.TargetInfoFields.BufferOffset != start &&
                challenge.TargetNameFields.BufferOffset != start)
            {
                challenge.Version = NlmpUtility.BytesToStruct <VERSION>(packetBytes, ref start);
            }

            int currentIndex = 0;

            while (currentIndex != start)
            {
                currentIndex = start;
                if (challenge.TargetNameFields.Len != 0 && challenge.TargetNameFields.BufferOffset == start)
                {
                    challenge.TargetName = NlmpUtility.ReadBytes(
                        packetBytes, ref start, challenge.TargetNameFields.Len);
                    continue;
                }
                else if (challenge.TargetInfoFields.Len != 0 && challenge.TargetInfoFields.BufferOffset == start)
                {
                    challenge.TargetInfo = NlmpUtility.ReadBytes(
                        packetBytes, ref start, challenge.TargetInfoFields.Len);
                    continue;
                }
                else
                {
                    break;
                }
            }

            this.payload = challenge;

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// read struct from bytes. All sub class override this to unmarshal itself.
        /// </summary>
        /// <param name="start">the start to read bytes</param>
        /// <param name="packetBytes">the bytes of struct</param>
        /// <returns>the read result, if success, return true.</returns>
        protected override bool ReadStructFromBytes(
            byte[] packetBytes,
            int start
            )
        {
            NEGOTIATE_MESSAGE negotiate = new NEGOTIATE_MESSAGE();

            negotiate.NegotiateFlags    = (NegotiateTypes)NlmpUtility.BytesToStruct <uint>(packetBytes, ref start);
            negotiate.DomainNameFields  = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(packetBytes, ref start);
            negotiate.WorkstationFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(packetBytes, ref start);
            negotiate.Version           = NlmpUtility.BytesToStruct <VERSION>(packetBytes, ref start);

            int currentIndex = 0;

            while (currentIndex != start)
            {
                currentIndex = start;
                if (negotiate.DomainNameFields.Len != 0 && negotiate.DomainNameFields.BufferOffset == start)
                {
                    negotiate.DomainName = NlmpUtility.ReadBytes(
                        packetBytes, ref start, negotiate.DomainNameFields.Len);
                    continue;
                }
                else if (negotiate.WorkstationFields.Len != 0 && negotiate.WorkstationFields.BufferOffset == start)
                {
                    negotiate.WorkstationName = NlmpUtility.ReadBytes(
                        packetBytes, ref start, negotiate.WorkstationFields.Len);
                    continue;
                }
                else
                {
                    break;
                }
            }

            this.payload = negotiate;

            return(true);
        }
        protected NlmpPacket(
            byte[] packetBytes
            )
        {
            if (packetBytes == null)
            {
                throw new ArgumentNullException("packetBytes");
            }

            if (packetBytes.Length < HeaderLength)
            {
                throw new InvalidOperationException("the bytes just contains NlmpHeader data!");
            }

            int start = 0;

            this.header.Signature = NlmpUtility.ReadBytes(
                packetBytes, ref start, NlmpUtility.NLMP_HEADER_SIGNATURE_SIZE);

            this.header.MessageType = (MessageType_Values)NlmpUtility.BytesToStruct <uint>(packetBytes, ref start);

            ReadStructFromBytes(packetBytes, start);
        }
        /// <summary>
        /// read struct from bytes. All sub class override this to unmarshal itself.
        /// </summary>
        /// <param name="start">the start to read bytes</param>
        /// <param name="packetBytes">the bytes of struct</param>
        /// <returns>the read result, if success, return true.</returns>
        protected override bool ReadStructFromBytes(
            byte[] packetBytes,
            int start
            )
        {
            AUTHENTICATE_MESSAGE authenticate = new AUTHENTICATE_MESSAGE();

            authenticate.LmChallengeResponseFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(
                packetBytes, ref start);

            authenticate.NtChallengeResponseFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(
                packetBytes, ref start);

            authenticate.DomainNameFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(
                packetBytes, ref start);

            authenticate.UserNameFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(
                packetBytes, ref start);

            authenticate.WorkstationFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(
                packetBytes, ref start);

            authenticate.EncryptedRandomSessionKeyFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(
                packetBytes, ref start);

            authenticate.NegotiateFlags = (NegotiateTypes)NlmpUtility.BytesToStruct <uint>(
                packetBytes, ref start);

            authenticate.Version = NlmpUtility.BytesToStruct <VERSION>(
                packetBytes, ref start);

            authenticate.MIC = NlmpUtility.ReadBytes(
                packetBytes, ref start, NlmpUtility.AUTHENTICATE_MESSAGE_MIC_CONST_SIZE);

            int currentIndex = 0;

            while (currentIndex != start)
            {
                currentIndex = start;
                if (authenticate.DomainNameFields.Len != 0 && authenticate.DomainNameFields.BufferOffset == start)
                {
                    authenticate.DomainName = NlmpUtility.ReadBytes(
                        packetBytes, ref start, authenticate.DomainNameFields.Len);
                    continue;
                }
                else if (authenticate.EncryptedRandomSessionKeyFields.Len != 0 &&
                         authenticate.EncryptedRandomSessionKeyFields.BufferOffset == start)
                {
                    authenticate.EncryptedRandomSessionKey = NlmpUtility.ReadBytes(
                        packetBytes, ref start, authenticate.EncryptedRandomSessionKeyFields.Len);
                    continue;
                }
                else if (authenticate.LmChallengeResponseFields.Len != 0 &&
                         authenticate.LmChallengeResponseFields.BufferOffset == start)
                {
                    authenticate.LmChallengeResponse = NlmpUtility.ReadBytes(
                        packetBytes, ref start, authenticate.LmChallengeResponseFields.Len);
                    continue;
                }
                else if (authenticate.NtChallengeResponseFields.Len != 0 &&
                         authenticate.NtChallengeResponseFields.BufferOffset == start)
                {
                    authenticate.NtChallengeResponse = NlmpUtility.ReadBytes(
                        packetBytes, ref start, authenticate.NtChallengeResponseFields.Len);
                    continue;
                }
                else if (authenticate.UserNameFields.Len != 0 && authenticate.UserNameFields.BufferOffset == start)
                {
                    authenticate.UserName = NlmpUtility.ReadBytes(
                        packetBytes, ref start, authenticate.UserNameFields.Len);
                    continue;
                }
                else if (authenticate.WorkstationFields.Len != 0 &&
                         authenticate.WorkstationFields.BufferOffset == start)
                {
                    authenticate.Workstation = NlmpUtility.ReadBytes(
                        packetBytes, ref start, authenticate.WorkstationFields.Len);
                    continue;
                }
                else
                {
                    break;
                }
            }

            this.payload = authenticate;

            return(true);
        }