internal static bool Parse(byte byte_code, BinaryReader reader, out ConditionalIntegerOperand operand)
        {
            operand = new ConditionalIntegerOperand();
            switch (byte_code)
            {
            case 0x01:
                operand.Size = ConditionalIntegerSize.Byte;
                break;

            case 0x02:
                operand.Size = ConditionalIntegerSize.Short;
                break;

            case 0x03:
                operand.Size = ConditionalIntegerSize.Dword;
                break;

            case 0x04:
                operand.Size = ConditionalIntegerSize.Qword;
                break;

            default:
                return(false);
            }
            operand.Value = reader.ReadInt64();

            switch (reader.ReadByte())
            {
            case 0x01:
                operand.Sign = ConditionalIntegerSign.Positive;
                break;

            case 0x02:
                operand.Sign = ConditionalIntegerSign.Negative;
                break;

            case 0x03:
                operand.Sign = ConditionalIntegerSign.None;
                break;

            default:
                return(false);
            }

            switch (reader.ReadByte())
            {
            case 0x01:
                operand.Base = ConditionalIntegerBase.Octal;
                break;

            case 0x02:
                operand.Base = ConditionalIntegerBase.Decimal;
                break;

            case 0x03:
                operand.Base = ConditionalIntegerBase.Hexadecimal;
                break;

            default:
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        private static bool Parse(byte[] data, bool expression, out List <ConditionalOperand> operands)
        {
            operands = new List <ConditionalOperand>();
            BinaryReader reader = new BinaryReader(new MemoryStream(data));

            if (expression && reader.ReadUInt32() != BINARY_MAGIC)
            {
                return(false);
            }

            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                byte token = reader.ReadByte();
                switch (token)
                {
                case 0x00:
                    break;

                case 0x01:
                case 0x02:
                case 0x03:
                case 0x04:
                    if (!ConditionalIntegerOperand.Parse(token, reader, out ConditionalIntegerOperand int_op))
                    {
                        return(false);
                    }
                    operands.Add(int_op);
                    break;

                case 0x10:
                    operands.Add(new ConditionalStringOperand(ReadString(reader)));
                    break;

                case 0x18:
                    operands.Add(new ConditionalOctetStringOperand(ReadBytes(reader)));
                    break;

                case 0x50:
                    if (!Parse(ReadBytes(reader), false, out List <ConditionalOperand> comp_ops))
                    {
                        return(false);
                    }
                    operands.Add(new ConditionalCompositeOperand(comp_ops));
                    break;

                case 0x51:
                    var sid = Sid.Parse(ReadBytes(reader), false);
                    if (!sid.IsSuccess)
                    {
                        return(false);
                    }
                    operands.Add(new ConditionalSidOperand(sid.Result));
                    break;

                default:
                    if (!expression || !Parse(token, reader, operands))
                    {
                        return(false);
                    }
                    break;
                }
            }
            return(true);
        }