Exemple #1
0
        public static ConditionalAceCompositeToken FromBytes(byte[] binaryForm, int offset)
        {
            var returnToken = new ConditionalAceCompositeToken();

            int compositeLength = BitConverter.ToInt32(binaryForm, offset);

            foreach (var currentToken in GetTokens(binaryForm, offset + 4, compositeLength))
            {
                returnToken.Tokens.Add(currentToken);
            }

            return(returnToken);
        }
Exemple #2
0
        public static List <ConditionalAceToken> GetTokens(byte[] binaryForm, int offset, int length)
        {
            int maxOffset = offset + length;
            List <ConditionalAceToken>  tokenList = new List <ConditionalAceToken>();
            ConditionalAceTokenByteCode tokenByteCode;

            while (offset < maxOffset)
            {
                tokenByteCode = (ConditionalAceTokenByteCode)binaryForm[offset++];
                //Console.WriteLine("offset = {0}; maxOffset = {1}: {2}", offset - 1, maxOffset, tokenByteCode);

                switch (tokenByteCode)
                {
                case ConditionalAceTokenByteCode.Padding:                          // Padding
                    tokenList.Add(new ConditionalAcePaddingToken());
                    break;

                case ConditionalAceTokenByteCode.UnicodeString:
                case ConditionalAceTokenByteCode.OctetString:
                    tokenList.Add(ConditionalAceStringToken.FromBytes(binaryForm, offset, tokenByteCode));
                    break;

                case ConditionalAceTokenByteCode.ResourceAttribute:
                case ConditionalAceTokenByteCode.LocalAttribute:
                case ConditionalAceTokenByteCode.DeviceAttribute:
                case ConditionalAceTokenByteCode.UserAttribute:
                    tokenList.Add(ConditionalAceAttributeToken.FromBytes(binaryForm, offset, tokenByteCode));
                    break;

                case ConditionalAceTokenByteCode.Composite:                          // Composite
                    tokenList.Add(ConditionalAceCompositeToken.FromBytes(binaryForm, offset));
                    break;

                case ConditionalAceTokenByteCode.Sid:                          // SID
                    tokenList.Add(ConditionalAceSecurityIdentifierToken.FromBytes(binaryForm, offset));
                    break;


                case ConditionalAceTokenByteCode.Exists:
                case ConditionalAceTokenByteCode.Member_of:
                case ConditionalAceTokenByteCode.Device_Member_of:
                case ConditionalAceTokenByteCode.Member_of_Any:
                case ConditionalAceTokenByteCode.Device_Member_of_Any:
                case ConditionalAceTokenByteCode.Not_Exists:
                case ConditionalAceTokenByteCode.Not_Member_of:
                case ConditionalAceTokenByteCode.Not_Device_Member_of:
                case ConditionalAceTokenByteCode.Not_Member_of_Any:
                case ConditionalAceTokenByteCode.Not_Device_Member_of_Any:
                case ConditionalAceTokenByteCode.Not:
                case ConditionalAceTokenByteCode.Equals:
                case ConditionalAceTokenByteCode.NotEquals:
                case ConditionalAceTokenByteCode.LessThan:
                case ConditionalAceTokenByteCode.LessThanOrEqualTo:
                case ConditionalAceTokenByteCode.GreaterThan:
                case ConditionalAceTokenByteCode.GreaterThanOrEqualTo:
                case ConditionalAceTokenByteCode.Contains:
                case ConditionalAceTokenByteCode.AnyOf:
                case ConditionalAceTokenByteCode.NotContains:
                case ConditionalAceTokenByteCode.NotAnyOf:
                case ConditionalAceTokenByteCode.And:
                case ConditionalAceTokenByteCode.Or:
                    tokenList.Add(new ConditionalAceOperatorToken(tokenByteCode));
                    break;

                default:
                    throw new Exception(string.Format("Unknown token byte code: 0x{0:x2}", (byte)tokenByteCode));
                }

                offset += tokenList.Last().BinaryLength - 1;                  // -1 b/c offset was already incremented
            }
            return(tokenList);
        }