private void ReadCommonHeader(NdrBinaryReader pacStream)
        {
            Version = pacStream.Read(1)[0];

            if (Version != NdrConstants.PROTOCOL_VERSION)
            {
                throw new InvalidDataException($"Unknown Protocol version {Version}");
            }

            var headerBits = pacStream.Read(1)[0];

            var endian = headerBits >> 4 & 0x0F;

            if (endian != 0 && endian != 1)
            {
                throw new InvalidDataException($"Unknown endianness {endian}");
            }

            Endian = Convert.ToBoolean(endian);

            Encoding = (byte)(headerBits & 0x0F);

            if (Encoding != 0 && Encoding != 1)
            {
                throw new InvalidDataException($"Unknown encoding {Encoding}");
            }

            Length = pacStream.ReadShort();

            if (Length != NdrConstants.COMMON_HEADER_BYTES)
            {
                throw new InvalidDataException($"Unknown common header length {Length}");
            }
        }
Example #2
0
        private static IEnumerable <SecurityIdentifier> ParseAttributes(NdrBinaryReader Stream, int count, int pointer)
        {
            var attributes = new List <SecurityIdentifier>();

            if (pointer == 0)
            {
                return(attributes);
            }

            int realCount = Stream.ReadInt();

            if (realCount != count)
            {
                throw new InvalidDataException($"Expected count {count} doesn't match actual count {realCount}");
            }

            for (int i = 0; i < count; i++)
            {
                Stream.Align(4);

                var sid = Stream.ReadRid();

                attributes.Add(new SecurityIdentifier(sid, (SidAttributes)Stream.ReadInt()));
            }

            return(attributes);
        }
        public RpcHeader(NdrBinaryReader pacStream)
        {
            ReadCommonHeader(pacStream);

            pacStream.Read(4);
            pacStream.Read(8);
            pacStream.Read(4);
        }
Example #4
0
        public string ReadString(NdrBinaryReader reader)
        {
            if (pointer == 0)
            {
                return(null);
            }

            var result   = reader.ReadString(maxLength);
            var expected = length / 2;

            if (result.Length != expected)
            {
                throw new InvalidDataException($"Read length {result.Length} doesn't match expected length {expected}");
            }

            return(result);
        }
Example #5
0
        private static SecurityIdentifier[] ParseExtraSids(NdrBinaryReader Stream, int extraSidCount, int extraSidPointer)
        {
            if (extraSidPointer == 0)
            {
                return(new SecurityIdentifier[0]);
            }

            int realExtraSidCount = Stream.ReadInt();

            if (realExtraSidCount != extraSidCount)
            {
                throw new InvalidDataException($"Expected Sid count {extraSidCount} doesn't match actual sid count {realExtraSidCount}");
            }

            var extraSidAtts = new SecurityIdentifier[extraSidCount];

            var pointers   = new int[extraSidCount];
            var attributes = new SidAttributes[extraSidCount];

            for (int i = 0; i < extraSidCount; i++)
            {
                pointers[i]   = Stream.ReadInt();
                attributes[i] = (SidAttributes)Stream.ReadUnsignedInt();
            }

            for (int i = 0; i < extraSidCount; i++)
            {
                SecurityIdentifier sid = null;

                if (pointers[i] != 0)
                {
                    sid = new SecurityIdentifier(Stream.ReadSid(), attributes[i]);
                }

                extraSidAtts[i] = sid;
            }

            return(extraSidAtts);
        }