public static new DataElement PitParser(PitParser context, XmlNode node, DataElementContainer parent)
        {
            var ret = Generate <HPACKInteger>(node, parent);


            ret.prefixBits = node.getAttrInt("prefixBits");

            context.handleCommonDataElementAttributes(node, ret);
            context.handleCommonDataElementChildren(node, ret);
            context.handleCommonDataElementValue(node, ret);

            return(ret);
        }
예제 #2
0
        public static DataElement PitParser(PitParser context, XmlNode node, DataElementContainer parent)
        {
            if (node.Name != "Blob")
            {
                return(null);
            }

            var blob = DataElement.Generate <Blob>(node);

            context.handleCommonDataElementAttributes(node, blob);
            context.handleCommonDataElementChildren(node, blob);
            context.handleCommonDataElementValue(node, blob);

            if (blob.DefaultValue == null)
            {
                blob.DefaultValue = new Variant(new BitStream());
            }

            BitwiseStream bs;

            if (blob.DefaultValue.GetVariantType() == Variant.VariantType.String)
            {
                bs = new BitStream();
                new BitWriter(bs).WriteString((string)blob.DefaultValue);
            }
            else
            {
                System.Diagnostics.Debug.Assert(blob.DefaultValue.GetVariantType() == Variant.VariantType.BitStream);
                bs = (BitwiseStream)blob.DefaultValue;
            }

            bs.Seek(0, SeekOrigin.Begin);
            blob.DefaultValue = new Variant(bs);

            if (blob.hasLength)
            {
                if (bs.LengthBits > blob.lengthAsBits)
                {
                    throw new PeachException("Error, value of " + blob.debugName + " is longer than specified length.");
                }

                if (bs.LengthBits < blob.lengthAsBits)
                {
                    bs.SetLengthBits(blob.lengthAsBits);
                }
            }

            return(blob);
        }
예제 #3
0
파일: Flag.cs 프로젝트: 751620780/Peach
        public static DataElement PitParser(PitParser context, XmlNode node, Flags parent)
        {
            if (node.Name == "Flags")
            {
                return(null);
            }

            var flag = DataElement.Generate <Flag>(node);

            int position = node.getAttrInt("position");
            int size     = node.getAttrInt("size");

            if (position < 0 || size < 0 || (position + size) > parent.lengthAsBits)
            {
                throw new PeachException("Error, " + flag.debugName + " is placed outside its parent.");
            }

            if (parent.LittleEndian)
            {
                position = (int)parent.lengthAsBits - size - position;
            }

            foreach (Flag other in parent)
            {
                if (other.Overlapps(position, size))
                {
                    throw new PeachException("Error, " + flag.debugName + " overlapps with " + other.debugName + ".");
                }
            }

            flag.position   = position;
            flag.lengthType = LengthType.Bits;
            flag.length     = size;

            // The individual flag is always big endian, it is up to the flags container
            // to change the order after all the flags are packed.
            flag.LittleEndian = false;

            context.handleCommonDataElementAttributes(node, flag);
            context.handleCommonDataElementChildren(node, flag);
            context.handleCommonDataElementValue(node, flag);

            return(flag);
        }
예제 #4
0
        public static DataElement PitParser(PitParser context, XmlNode node, DataElementContainer parent)
        {
            if (node.Name != "Blob")
            {
                return(null);
            }

            var blob = DataElement.Generate <Blob>(node);

            context.handleCommonDataElementAttributes(node, blob);
            context.handleCommonDataElementChildren(node, blob);
            context.handleCommonDataElementValue(node, blob);

            if (blob.DefaultValue == null)
            {
                blob.DefaultValue = new Variant(new byte[0]);
            }

            if (blob.DefaultValue.GetVariantType() == Variant.VariantType.String)
            {
                blob.DefaultValue = new Variant(ASCIIEncoding.ASCII.GetBytes((string)blob.DefaultValue));
            }

            if (blob.hasLength)
            {
                BitStream bs = (BitStream)blob.DefaultValue;
                if (bs.LengthBits > blob.lengthAsBits)
                {
                    throw new PeachException("Error, value of " + blob.debugName + " is longer than specified length.");
                }
                else if (bs.LengthBits < blob.lengthAsBits)
                {
                    ExpandDefaultValue(blob, bs);
                }
            }

            return(blob);
        }
예제 #5
0
파일: String.cs 프로젝트: 751620780/Peach
        public static DataElement PitParser(PitParser context, XmlNode node, DataElementContainer parent)
        {
            if (node.Name != "String")
            {
                return(null);
            }

            var str = DataElement.Generate <String>(node);

            if (node.hasAttr("nullTerminated"))
            {
                str.nullTerminated = node.getAttrBool("nullTerminated");
            }
            else
            {
                str.nullTerminated = context.getDefaultAttr(typeof(String), "nullTerminated", str.nullTerminated);
            }

            string type = "ascii";

            if (node.hasAttr("type"))
            {
                type = node.getAttrString("type");
            }
            else
            {
                type = context.getDefaultAttr(typeof(String), "type", type);
            }

            StringType stringType;

            if (!Enum.TryParse <StringType>(type, true, out stringType))
            {
                throw new PeachException("Error, unknown String type '" + type + "' on element '" + str.name + "'.");
            }

            str.stringType = stringType;

            if (node.hasAttr("padCharacter"))
            {
                str.padCharacter = node.getAttrChar("padCharacter");
            }
            else
            {
                str.padCharacter = context.getDefaultAttr(typeof(String), "padCharacter", str.padCharacter);
            }

            if (node.hasAttr("tokens"))             // This item has a default!
            {
                throw new NotSupportedException("Tokens attribute is depricated in Peach 3.  Use parameter to StringToken analyzer isntead.");
            }

            if (node.hasAttr("analyzer"))             // this should be passed via a child element me things!
            {
                throw new NotSupportedException("Analyzer attribute is depricated in Peach 3.  Use a child element instead.");
            }

            context.handleCommonDataElementAttributes(node, str);
            context.handleCommonDataElementChildren(node, str);
            context.handleCommonDataElementValue(node, str);

            if (!node.hasAttr("value"))
            {
                str.DefaultValue = new Variant("");
            }

            return(str);
        }
예제 #6
0
        public static DataElement PitParser(PitParser context, XmlNode node, DataElementContainer parent)
        {
            if (node.Name != "Number")
            {
                return(null);
            }

            var num = DataElement.Generate <Number>(node);

            if (node.hasAttr("signed"))
            {
                num.Signed = node.getAttrBool("signed");
            }
            else
            {
                num.Signed = context.getDefaultAttr(typeof(Number), "signed", num.Signed);
            }

            if (node.hasAttr("size"))
            {
                int size = node.getAttrInt("size");

                if (size < 1 || size > 64)
                {
                    throw new PeachException(string.Format("Error, unsupported size '{0}' for {1}.", size, num.debugName));
                }

                num.lengthType = LengthType.Bits;
                num.length     = size;
            }

            string strEndian = null;

            if (node.hasAttr("endian"))
            {
                strEndian = node.getAttrString("endian");
            }
            if (strEndian == null)
            {
                strEndian = context.getDefaultAttr(typeof(Number), "endian", null);
            }

            if (strEndian != null)
            {
                switch (strEndian.ToLower())
                {
                case "little":
                    num.LittleEndian = true;
                    break;

                case "big":
                    num.LittleEndian = false;
                    break;

                case "network":
                    num.LittleEndian = false;
                    break;

                default:
                    throw new PeachException(
                              string.Format("Error, unsupported value '{0}' for 'endian' attribute on {1}.", strEndian, num.debugName));
                }
            }

            context.handleCommonDataElementAttributes(node, num);
            context.handleCommonDataElementChildren(node, num);
            context.handleCommonDataElementValue(node, num);

            return(num);
        }