示例#1
0
        void tweakingPanel_TranslationTweaked(object sender, ExpressionTweakingPanel.TranslationTweakedEventArgs translationTweakedEventArgs)
        {
            ExpressionTweakingPanel p = (ExpressionTweakingPanel)sender;
            XDocument           document;
            ILog                log;
            TagClass            tag      = (TagClass)p.FilePresenterTab.Tag;
            TranslationSettings settings = tag.settings;

            settings.Retranslation = true;
            GenerateSchema(p.FilePresenterTab.SourcePSMSchema, settings, out document, out log);
            p.FilePresenterTab.ReDisplayFile(document, EDisplayedFileType.SCH,
                                             p.FilePresenterTab.SourcePSMSchema.Caption, log, p.FilePresenterTab.ValidationSchema, p.FilePresenterTab.SourcePSMSchema);
        }
示例#2
0
        public Asn1Tag(TagClass tagClass, int tagValue, bool isConstructed = false)
            : this((byte)((byte)tagClass | (isConstructed ? ConstructedMask : 0)), tagValue)
        {
            if (tagClass < TagClass.Universal || tagClass > TagClass.Private)
            {
                throw new ArgumentOutOfRangeException(nameof(tagClass));
            }

            if (tagValue < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(tagValue));
            }
        }
示例#3
0
        public static void ExpectedTag_IgnoresConstructed(
            AsnEncodingRules ruleSet,
            string inputHex,
            TagClass tagClass,
            int tagValue)
        {
            Asn1Tag primitiveTag   = new Asn1Tag(tagClass, tagValue, false);
            Asn1Tag constructedTag = new Asn1Tag(tagClass, tagValue, true);

            byte[] inputData = inputHex.HexToByteArray();

            AsnReader   reader = new AsnReader(inputData, ruleSet);
            ShortBacked val1   = reader.ReadEnumeratedValue <ShortBacked>(constructedTag);

            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);
            ShortBacked val2 = reader.ReadEnumeratedValue <ShortBacked>(primitiveTag);

            Assert.False(reader.HasData);

            Assert.Equal(val1, val2);

            reader = new AsnReader(inputData, ruleSet);
            ShortBacked val3 = (ShortBacked)reader.ReadEnumeratedValue(typeof(ShortBacked), constructedTag);

            Assert.False(reader.HasData);

            Assert.Equal(val1, val3);

            reader = new AsnReader(inputData, ruleSet);
            ShortBacked val4 = (ShortBacked)reader.ReadEnumeratedValue(typeof(ShortBacked), primitiveTag);

            Assert.False(reader.HasData);

            Assert.Equal(val1, val4);

            reader = new AsnReader(inputData, ruleSet);
            ReadOnlyMemory <byte> bytes1 = reader.ReadEnumeratedBytes(constructedTag);

            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);
            ReadOnlyMemory <byte> bytes2 = reader.ReadEnumeratedBytes(primitiveTag);

            Assert.False(reader.HasData);

            Assert.Equal(bytes1.ByteArrayToHex(), bytes2.ByteArrayToHex());
            Assert.Equal("FF", bytes1.ByteArrayToHex());
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var sourceTag = (ExtractedTag)value;

            TagClass tc = TagsSource.Classes.Where(c => c.RawClass.Magic == sourceTag.Class).FirstOrDefault();

            if (tc == null)
            {
                return(false);
            }

            var existingTag = tc.Children.Find(t => t.TagFileName == sourceTag.Name);

            return(existingTag != null);
        }
示例#5
0
        public static void ExpectedTag_IgnoresConstructed(
            AsnEncodingRules ruleSet,
            string inputHex,
            TagClass tagClass,
            int tagValue)
        {
            byte[]    inputData = inputHex.HexToByteArray();
            AsnReader reader    = new AsnReader(inputData, ruleSet);

            reader.ReadNull(new Asn1Tag(tagClass, tagValue, true));
            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);
            reader.ReadNull(new Asn1Tag(tagClass, tagValue, false));
            Assert.False(reader.HasData);
        }
示例#6
0
        /// <summary>
        /// Read tag. (only check the value type)
        /// </summary>
        /// <param name="tagClass">expected tag class</param>
        /// <param name="isConstructed">expected value of "constructed" flag</param>
        /// <param name="tagNumber">expected tag number</param>
        /// <param name="length">length of the value field will be stored</param>
        /// <returns>true if succeeded.</returns>
        public bool ReadTag(TagClass tagClass, bool isConstructed, int tagNumber, out int length)
        {
            BERTagInfo tagInfo = new BERTagInfo();

            if (ReadTagInfo(ref tagInfo) &&
                tagInfo.ClassBits == (int)tagClass &&
                tagInfo.IsConstructed == isConstructed &&
                tagInfo.TagNumber == tagNumber)
            {
                length = tagInfo.Length;
                return(true);
            }

            length = 0;
            return(false);
        }
示例#7
0
        public TagDatum Add(TagClass tagClass, string newPath, int length, int virtualAddress)
        {
            var last     = _data.Last();
            var newDatum = new TagDatum
            {
                Class          = tagClass,
                Identifier     = last.Identifier,
                Length         = length,
                Path           = newPath,
                VirtualAddress = virtualAddress
            };

            _data.Insert(IndexOf(last), newDatum);
            last.Identifier++;
            Update(last.Identifier, last);
            return(newDatum);
        }
 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
 {
     string[] tmp = openFileDialog1.FileNames;
     for (int i = 0; i < tmp.Length; i++)
     {
         TrackBase.Files.Add(tmp[i]);
         TagClass TM = new TagClass(tmp[i]);
         if (TM.title != "")
         {
             playlist.Items.Add(TM.artist + " - " + TM.title);
         }
         else
         {
             playlist.Items.Add(TM.artist);
         }
     }
 }
示例#9
0
        protected TagIndexBase(CacheStream cache)
        {
            var binaryReader = new BinaryReader(cache);

            classArrayAddress = binaryReader.ReadInt32();
            classArrayCount   = binaryReader.ReadInt32();
            datumArrayAddress = binaryReader.ReadInt32();
            ScenarioIdent     = binaryReader.ReadTagIdent();
            GlobalsIdent      = binaryReader.ReadTagIdent();
            _noodleValue      = binaryReader.ReadInt32();
            datumArrayCount   = binaryReader.ReadInt32();
            fourCC            = binaryReader.ReadTagClass();
            if (fourCC != new TagClass("tags"))
            {
                throw new InvalidDataException();
            }
        }
示例#10
0
        public void VisitTagRef(TagRefData field)
        {
            SeekToOffset(field.Offset);

            TagClass   tagClass = null;
            DatumIndex index;

            if (field.WithClass)
            {
                // Read the datum index based upon the layout
                StructureValueCollection values = StructureReader.ReadStructure(_reader, _tagRefLayout);
                index = new DatumIndex(values.GetInteger("datum index"));

                // Check the class, in case the datum index is null
                var magic = values.GetInteger("class magic");
                var str   = CharConstant.ToString((int)magic);
                tagClass = field.Tags.Classes.FirstOrDefault(c => c.TagClassMagic == str);
            }
            else
            {
                // Just read the datum index at the current position
                index = DatumIndex.ReadFrom(_reader);
            }

            TagEntry tag = null;

            if (index.IsValid && index.Index < field.Tags.Entries.Count)
            {
                tag = field.Tags.Entries[index.Index];
                if (tag == null || tag.RawTag == null || tag.RawTag.Index != index)
                {
                    tag = null;
                }
            }

            if (tag != null)
            {
                field.Class = field.Tags.Classes.FirstOrDefault(c => c.RawClass == tag.RawTag.Class);
                field.Value = tag;
            }
            else
            {
                field.Class = tagClass;
                field.Value = null;
            }
        }
        public LdapMessage TryParsePacket(byte[] input)
        {
            AsnReader  reader         = new AsnReader(input, AsnEncodingRules.BER);
            AsnReader  sequenceReader = reader.ReadSequence();
            BigInteger messageId      = sequenceReader.ReadInteger();

            TagClass tagClass = sequenceReader.PeekTag().TagClass;
            int      tagValue = sequenceReader.PeekTag().TagValue;

            if (tagClass != TagClass.Application)
            {
                throw new ArgumentException("Input type is expected to be " + TagClass.Application + " but was " + tagClass);
            }

            IProtocolOp message = DecodeApplicationData(tagValue, sequenceReader, input);

            return(new LdapMessage(messageId, message));
        }
        public static void ExpectedTag_IgnoresConstructed(
            AsnEncodingRules ruleSet,
            string inputHex,
            TagClass tagClass,
            int tagValue)
        {
            byte[]                inputData = inputHex.HexToByteArray();
            AsnReader             reader    = new AsnReader(inputData, ruleSet);
            ReadOnlyMemory <byte> val1      = reader.ReadIntegerBytes(new Asn1Tag(tagClass, tagValue, true));

            Assert.False(reader.HasData);
            reader = new AsnReader(inputData, ruleSet);
            ReadOnlyMemory <byte> val2 = reader.ReadIntegerBytes(new Asn1Tag(tagClass, tagValue, false));

            Assert.False(reader.HasData);

            Assert.Equal(val1.ByteArrayToHex(), val2.ByteArrayToHex());
        }
示例#13
0
        private bool ReadBinary(TagClass tagClass, bool isConstructed, int tagNumber, out byte[] data)
        {
            int valueLength;

            if (ReadTag(tagClass, isConstructed, tagNumber, out valueLength) &&
                valueLength != LENGTH_INDEFINITE && valueLength > 0)
            {
                byte[] buff = new byte[valueLength];
                int    len  = strm.Read(buff, 0, valueLength);
                if (len == valueLength)
                {
                    data = buff;
                    return(true);
                }
            }

            data = null;
            return(false);
        }
示例#14
0
        public override void Execute(object parameter = null)
        {
            if (Current.ActiveDiagram != null && Current.ActiveDiagram is PSMDiagram)
            {
                XDocument schematronSchemaDocument;
                ILog      log;

                TranslationSettings settings = new TranslationSettings();
                settings.Functional  = true;
                settings.SchemaAware = true;

                GenerateSchema((PSMSchema)Current.ActiveDiagram.Schema, settings, out schematronSchemaDocument, out log);

                FilePresenterButtonInfo[] additionalButtonsInfo = new[] {
                    new FilePresenterButtonInfo()
                    {
                        ButtonName = "SA", Text = "Schema aware", Icon = ExolutioResourceNames.GetResourceImageSource(ExolutioResourceNames.refresh), UpdateFileContentAction = RegenerateSchema, ToggleButton = true, IsToggled = true
                    },
                    new FilePresenterButtonInfo()
                    {
                        ButtonName = "F", Text = "Functional", Icon = ExolutioResourceNames.GetResourceImageSource(ExolutioResourceNames.refresh), UpdateFileContentAction = RegenerateSchema, ToggleButton = true, IsToggled = true
                    },
                };

                ExpressionTweakingPanel tweakingPanel = new ExpressionTweakingPanel();

                TagClass tag = new TagClass();
                tag.settings      = settings;
                tag.tweakingPanel = tweakingPanel;

                IFilePresenterTab filePresenterTab
                    = Current.MainWindow.FilePresenter.DisplayFile(schematronSchemaDocument, EDisplayedFileType.SCH, Current.ActiveDiagram.Caption + ".sch", log, sourcePSMSchema: (PSMSchema)Current.ActiveDiagram.Schema,
                                                                   additionalActions: additionalButtonsInfo, tag: tag);
                filePresenterTab.RefreshCallback += RegenerateSchema;
                if (settings.SubexpressionTranslations.TranslationOptionsWithMorePossibilities.Any())
                {
                    tweakingPanel.Bind(settings.SubexpressionTranslations);
                    tweakingPanel.FilePresenterTab = filePresenterTab;
                    filePresenterTab.DisplayAdditionalControl(tweakingPanel, "Expression Tweaking");
                    tweakingPanel.TranslationTweaked += tweakingPanel_TranslationTweaked;
                }
            }
        }
示例#15
0
        /// <summary>
        /// Decodes an identifier from the stream.
        /// </summary>
        /// <param name="Input">Input stream.</param>
        /// <param name="Constructed">If the identifier is constructed (true) or primitive (false)</param>
        /// <param name="Class">Class of tag.</param>
        /// <returns>TAG</returns>
        public static long DecodeIdentifier(Stream Input, out bool Constructed, out TagClass Class)
        {
            int i = Input.ReadByte();

            if (i < 0)
            {
                throw new EndOfStreamException();
            }

            Class       = (TagClass)((i >> 6) & 3);
            Constructed = (i & 32) != 0;

            i &= 31;
            if (i < 31)
            {
                return(i);
            }

            return(DecodeVarLenInt(Input));
        }
示例#16
0
        public static void EmptyData_Allows0UnusedBits(
            AsnEncodingRules ruleSet,
            TagClass tagClass,
            int tagValue,
            string expectedHex)
        {
            AsnWriter writer = new AsnWriter(ruleSet);

            if (tagClass == TagClass.Universal)
            {
                Debug.Assert(tagValue == (int)UniversalTagNumber.BitString);
                writer.WriteBitString(ReadOnlySpan <byte> .Empty, 0);
            }
            else
            {
                writer.WriteBitString(ReadOnlySpan <byte> .Empty, 0, new Asn1Tag(tagClass, tagValue));
            }

            Verify(writer, expectedHex);
        }
示例#17
0
        /// <summary>
        ///   Create an <see cref="Asn1Tag"/> for a specified value within a specified tag class.
        /// </summary>
        /// <param name="tagClass">
        ///   The tag class for this tag.
        /// </param>
        /// <param name="tagValue">
        ///   The numeric value for this tag.
        /// </param>
        /// <param name="isConstructed">
        ///   <see langword="true"/> for a constructed tag, <see langword="false"/> for a primitive tag.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///   <paramref name="tagClass"/> is not a known value.
        ///
        ///   -or-
        ///
        ///   <paramref name="tagValue" /> is negative.
        /// </exception>
        /// <remarks>
        ///   This constructor allows for the creation undefined UNIVERSAL class tags.
        /// </remarks>
        public Asn1Tag(TagClass tagClass, int tagValue, bool isConstructed = false)
            : this((byte)((byte)tagClass | (isConstructed ? ConstructedMask : 0)), tagValue)
        {
            switch (tagClass)
            {
            case TagClass.Universal:
            case TagClass.ContextSpecific:
            case TagClass.Application:
            case TagClass.Private:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(tagClass));
            }

            if (tagValue < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(tagValue));
            }
        }
        public static void ExpectedTag_IgnoresConstructed(
            AsnEncodingRules ruleSet,
            string inputHex,
            TagClass tagClass,
            int tagValue)
        {
            byte[]    inputData = inputHex.HexToByteArray();
            AsnReader reader    = new AsnReader(inputData, ruleSet);

            DateTimeOffset val1 = reader.ReadGeneralizedTime(new Asn1Tag(tagClass, tagValue, true));

            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);

            DateTimeOffset val2 = reader.ReadGeneralizedTime(new Asn1Tag(tagClass, tagValue, false));

            Assert.False(reader.HasData);

            Assert.Equal(val1, val2);
        }
示例#19
0
        public static void VerifyWriteNamedBitList_WithTag(
            AsnEncodingRules ruleSet,
            string expectedHex,
            Enum value)
        {
            int      ruleSetVal = (int)ruleSet;
            TagClass tagClass   = (TagClass)(byte)(ruleSetVal << 6);

            if (tagClass == TagClass.Universal)
            {
                tagClass = TagClass.Private;
            }

            Asn1Tag tag = new Asn1Tag(tagClass, ruleSetVal);

            AsnWriter writer = new AsnWriter(ruleSet);

            writer.WriteNamedBitList(value, tag);

            Verify(writer, expectedHex);
        }
示例#20
0
        protected void ParseIdentifier(byte[] bytes)
        {
            bool long_form = (bytes[0] & 0x1F) == 0x1F;

            identifier_class = (TagClass)(bytes[0] & 0xC0);
            is_constructed   = ((bytes[0] & 0x20) == 0x20);
            if (long_form)
            {
                int i = 1, temp_tag = 0;
                do
                {
                    temp_tag <<= 7;
                    tag       += bytes[i];
                } while ((bytes[i++] & 0x80) == 0x80);                 // Highest bit not set in final octet.
                tag = temp_tag;
            }
            else
            {
                tag = bytes[0] & 0x1F;
            }
        }
示例#21
0
        public static void ExpectedTag_IgnoresConstructed(
            AsnEncodingRules ruleSet,
            string inputHex,
            TagClass tagClass,
            int tagValue)
        {
            byte[]    inputData = inputHex.HexToByteArray();
            AsnReader reader    = new AsnReader(inputData, ruleSet);

            AsnReader val1 = reader.ReadSetOf(expectedTag: new Asn1Tag(tagClass, tagValue, true));

            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);

            AsnReader val2 = reader.ReadSetOf(expectedTag: new Asn1Tag(tagClass, tagValue, false));

            Assert.False(reader.HasData);

            Assert.Equal(val1.ReadEncodedValue().ByteArrayToHex(), val2.ReadEncodedValue().ByteArrayToHex());
        }
示例#22
0
        public static void VerifyEncode(TagClass tagClass, int tagValue, bool constructed, string expectedHex)
        {
            Asn1Tag     tag = new Asn1Tag(tagClass, tagValue, constructed);
            Span <byte> buf = stackalloc byte[10];

            Assert.False(tag.TryEncode(Span <byte> .Empty, out int written));
            Assert.Equal(0, written);

            int expectedSize = expectedHex.Length / 2;

            Assert.Equal(expectedSize, tag.CalculateEncodedSize());

            Assert.False(tag.TryEncode(buf.Slice(0, expectedSize - 1), out written));
            Assert.Equal(0, written);

            AssertExtensions.Throws <ArgumentException>(
                "destination",
                () =>
            {
                Span <byte> tmp = stackalloc byte[expectedSize - 1];
                return(tag.Encode(tmp));
            });

            Assert.True(tag.TryEncode(buf, out written));
            Assert.Equal(expectedSize, written);
            Assert.Equal(expectedHex, buf.Slice(0, written).ByteArrayToHex());

            written = tag.Encode(buf.Slice(1));
            Assert.Equal(expectedSize, written);
            Assert.Equal(expectedHex, buf.Slice(1, written).ByteArrayToHex());

            Assert.True(tag.TryEncode(buf.Slice(0, expectedSize), out written));
            Assert.Equal(expectedSize, written);
            Assert.Equal(expectedHex, buf.Slice(0, written).ByteArrayToHex());

            written = tag.Encode(buf.Slice(1, expectedSize));
            Assert.Equal(expectedSize, written);
            Assert.Equal(expectedHex, buf.Slice(1, written).ByteArrayToHex());
        }
        public static void ExpectedTag_IgnoresConstructed(
            AsnEncodingRules ruleSet,
            string inputHex,
            TagClass tagClass,
            int tagValue)
        {
            byte[]    inputData      = inputHex.HexToByteArray();
            Asn1Tag   constructedTag = new Asn1Tag(tagClass, tagValue, true);
            Asn1Tag   primitiveTag   = new Asn1Tag(tagClass, tagValue, false);
            AsnReader reader         = new AsnReader(inputData, ruleSet);

            string val1 = reader.ReadObjectIdentifier(constructedTag);

            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);

            string val2 = reader.ReadObjectIdentifier(primitiveTag);

            Assert.False(reader.HasData);

            Assert.Equal(val1, val2);
        }
示例#24
0
 public TagClassAttribute(string tagClass)
 {
     TagClass = (TagClass)tagClass;
 }
示例#25
0
 public static void NoNegativeTagNumbers(TagClass tagClass, int value)
 {
     AssertExtensions.Throws <ArgumentOutOfRangeException>(
         "tagValue",
         () => new Asn1Tag(tagClass, value));
 }
        public static void ExpectedTag_IgnoresConstructed(
            AsnEncodingRules ruleSet,
            string inputHex,
            TagClass tagClass,
            int tagValue)
        {
            byte[]    inputData          = inputHex.HexToByteArray();
            AsnReader reader             = new AsnReader(inputData, ruleSet);
            Asn1Tag   correctConstructed = new Asn1Tag(tagClass, tagValue, true);
            Asn1Tag   correctPrimitive   = new Asn1Tag(tagClass, tagValue, false);

            Assert.True(
                reader.TryReadPrimitiveBitString(
                    out int ubc1,
                    out ReadOnlyMemory <byte> val1,
                    correctConstructed));

            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);

            Assert.True(
                reader.TryReadPrimitiveBitString(
                    out int ubc2,
                    out ReadOnlyMemory <byte> val2,
                    correctPrimitive));

            Assert.False(reader.HasData);

            string val1Hex = val1.ByteArrayToHex();

            Assert.Equal(val1Hex, val2.ByteArrayToHex());
            Assert.Equal(ubc1, ubc2);

            reader = new AsnReader(inputData, ruleSet);
            byte[] output1 = new byte[inputData.Length];

            Assert.True(reader.TryReadBitString(output1.AsSpan(1), out ubc1, out int written, correctConstructed));
            Assert.Equal(ubc2, ubc1);
            Assert.Equal(val1Hex, output1.AsSpan(1, written).ByteArrayToHex());
            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);

            Assert.True(reader.TryReadBitString(output1.AsSpan(2), out ubc1, out written, correctPrimitive));
            Assert.Equal(ubc2, ubc1);
            Assert.Equal(val1Hex, output1.AsSpan(2, written).ByteArrayToHex());
            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);
            byte[] output2 = reader.ReadBitString(out ubc1, correctConstructed);

            Assert.Equal(ubc2, ubc1);
            Assert.Equal(val1Hex, output2.ByteArrayToHex());
            Assert.False(reader.HasData);

            reader = new AsnReader(inputData, ruleSet);
            byte[] output3 = reader.ReadBitString(out ubc1, correctPrimitive);

            Assert.Equal(ubc2, ubc1);
            Assert.Equal(val1Hex, output3.ByteArrayToHex());
            Assert.False(reader.HasData);
        }
示例#27
0
 //void PostProcessTag(TagBlockWrapper wrapper)
 //{
 //    //var items = wrapper.references.Select(x => x.Owner).Distinct().ToArray();
 //    //foreach (var item in items)
 //    //{
 //    //    TagBlockWrapper resource_owner = PreProcessTag(Tags[item.Index]);
 //    //    var resources = wrapper.references.Where(x => x.Owner == item).ToArray();
 //    //    for (int resource_index = 0; resource_index < resources.Length; ++resource_index)
 //    //    {
 //    //        resources[resource_index].TagblockID = resource_owner.tagblocks
 //    //            .Where(x => x.Offset == resources[resource_index].TagblockID)
 //    //            .Select(x => x.TagblockID).First();
 //    //    }
 //    //}
 //    //TagBlockWrapper resource_owner = PreProcessTag(Tags[wrapper.references[i].Owner.Index]);
 //    //{
 //    //}
 //    //wrapper.references[i].TagblockID = resource_owner.tagblocks.Select(x => x.).Single();//Select(x => x.Offset).Single();
 //}
 Tag FindFirst(TagClass tag_class, string path_fragment)
 {
     foreach (var tag in this.Tags)
     {
         if (tag.Type == tag_class && tag.Path.Contains(path_fragment))
             return tag;
     }
     return new Tag();
 }
示例#28
0
 internal static bool IsNull(TagDatum data)
 {
     return
         (TagClass.IsNullOrZero(data.Class) && data.Identifier == TagIdent.NullIdentifier && data.Length == 0 &&
          data.VirtualAddress == 0);
 }
示例#29
0
 public TagClassHeirarchy(TagClass @class, TagClass parent, TagClass root)
 {
     Root   = root;
     Parent = parent;
     Class  = @class;
 }
示例#30
0
 /// <summary>
 /// Decodes an identifier from the stream.
 /// </summary>
 /// <param name="Constructed">If the identifier is constructed (true) or primitive (false)</param>
 /// <param name="Class">Class of tag.</param>
 /// <returns>TAG</returns>
 public long DecodeIdentifier(out bool Constructed, out TagClass Class)
 {
     return(BER.DecodeIdentifier(this.input, out Constructed, out Class));
 }
 public Identifier(TagClass tagClass, bool constructed, int tag)
 {
     TagClass    = tagClass;
     Constructed = constructed;
     Tag         = tag;
 }
示例#32
0
 void IField.SetFieldData(byte[] field_data, IStructure caller)
 {
     tag_class = (TagClass)BitConverter.ToInt32(field_data, 0);
     tag_identifier = BitConverter.ToInt32(field_data, 4);
 }
 public StructureBspEnvironmentObjectBlock(BinaryReader binaryReader)
 {
     this.name = binaryReader.ReadString32();
     this.rotation = binaryReader.ReadQuaternion();
     this.translation = binaryReader.ReadVector3();
     this.paletteIndex = binaryReader.ReadShortBlockIndex1();
     this.padding = binaryReader.ReadBytes(2);
     this.uniqueID = binaryReader.ReadInt32();
     this.exportedObjectType = binaryReader.ReadTagClass();
     this.scenarioObjectName = binaryReader.ReadString32();
 }
示例#34
0
 internal static Type GetTypeOf(TagClass class_name)
 {
     return halo_2_classes[class_name];
 }
示例#35
0
 public DontUseMeScenarioEnvironmentObjectBlock(BinaryReader binaryReader)
 {
     this.bSP = binaryReader.ReadShortBlockIndex1();
     this.eMPTYSTRING = binaryReader.ReadInt16();
     this.uniqueID = binaryReader.ReadInt32();
     this.padding = binaryReader.ReadBytes(4);
     this.objectDefinitionTag = binaryReader.ReadTagClass();
     this.invalidName_object = binaryReader.ReadInt32();
     this.padding0 = binaryReader.ReadBytes(44);
 }
示例#36
0
 public static TagBlock CreateInstance(TagClass class_name)
 {
     Type tagblock_type = halo_2_classes[class_name];
     return Activator.CreateInstance(tagblock_type) as TagBlock;
 }
示例#37
0
        /// <summary>
        /// Read tag. (only check the value type)
        /// </summary>
        /// <param name="tagClass">expected tag class</param>
        /// <param name="isConstructed">expected value of "constructed" flag</param>
        /// <param name="tagNumber">expected tag number</param>
        /// <param name="length">length of the value field will be stored</param>
        /// <returns>true if succeeded.</returns>
        public bool ReadTag(TagClass tagClass, bool isConstructed, int tagNumber, out int length)
        {
            BERTagInfo tagInfo = new BERTagInfo();
            if (ReadTagInfo(ref tagInfo)
                && tagInfo.ClassBits == (int)tagClass
                && tagInfo.IsConstructed == isConstructed
                && tagInfo.TagNumber == tagNumber) {

                length = tagInfo.Length;
                return true;
            }

            length = 0;
            return false;
        }
示例#38
0
            public IndexTable(Base.CacheFile Cache)
            {
                cache = Cache;

                var IH = cache.IndexHeader;
                var CH = cache.Header;
                var Reader = cache.Reader;

                ClassList = new List<TagClass>();

                #region Read Class List

                Reader.SeekTo(IH.tagClassIndexOffset);
                for (int i = 0; i < IH.tagClassCount; i++)
                {
                    TagClass tc = new TagClass();
                    tc.ClassCode = Reader.ReadString(4);
                    tc.Parent = Reader.ReadString(4);
                    tc.Parent2 = Reader.ReadString(4);
                    tc.StringID = Reader.ReadInt32();
                    ClassList.Add(tc);
                }
                #endregion

                #region Read Tags' Info
                Reader.SeekTo(IH.tagInfoOffset);
                for (int i = 0; i < IH.tagCount; i++)
                {
                    IndexItem item = new IndexItem() { Cache = cache };
                    item.ClassIndex = Reader.ReadInt16();
                    item.ID = (Reader.ReadInt16() << 16) | i;
                    item.Offset = Reader.ReadInt32() - cache.Magic;
                    item.metaIndex = i;
                    this.Add(item);
                }
                #endregion

                #region Read Indices
                Reader.SeekTo(CH.fileTableIndexOffset);
                int[] indices = new int[IH.tagCount];
                for (int i = 0; i < IH.tagCount; i++)
                    indices[i] = Reader.ReadInt32();
                #endregion

                #region Read Names
                Reader.SeekTo(CH.fileTableOffset);
                EndianReader newReader = (cache.tagsKey == "" || cache.tagsKey == null)
                    ? new EndianReader(new MemoryStream(Reader.ReadBytes(CH.fileTableSize)), EndianFormat.Big)
                    : AES.DecryptSegment(Reader, CH.fileTableOffset, CH.fileTableSize, cache.tagsKey);

                for (int i = 0; i < indices.Length; i++)
                {
                    if (indices[i] == -1)
                    {
                        this[i].Filename = "<null>";
                        continue;
                    }

                    newReader.SeekTo(indices[i]);

                    int length;
                    if (i == indices.Length - 1)
                        length = CH.fileTableSize - indices[i];
                    else
                    {
                        if (indices[i + 1] == -1)
                        {
                            int index = -1;

                            for (int j = i + 1; j < indices.Length; j++)
                            {
                                if (indices[j] != -1)
                                {
                                    index = j;
                                    break;
                                }
                            }

                            length = (index == -1) ? CH.fileTableSize - indices[i] : indices[index] - indices[i];
                        }
                        else
                            length = indices[i + 1] - indices[i];
                    }

                    if (length == 1)
                    {
                        this[i].Filename = "<blank>";
                        continue;
                    }

                    if (length < 0)
                    {
                        int i0 = indices[i];
                        int i1 = indices[i + 1];
                        int i2 = indices[i + 2];
                        int i3 = indices[i + 3];
                    }

                    this[i].Filename = newReader.ReadString(length);
                }

                newReader.Close();
                newReader.Dispose();
                #endregion
            }
示例#39
0
 public static void Write(this BinaryWriter binary_writer, TagClass tclass)
 {
     binary_writer.Write((int)tclass);
 }
示例#40
0
        private bool ReadBinary(TagClass tagClass, bool isConstructed, int tagNumber, out byte[] data)
        {
            int valueLength;
            if (ReadTag(tagClass, isConstructed, tagNumber, out valueLength)
                    && valueLength != LENGTH_INDEFINITE && valueLength > 0) {

                byte[] buff = new byte[valueLength];
                int len = strm.Read(buff, 0, valueLength);
                if (len == valueLength) {
                    data = buff;
                    return true;
                }
            }

            data = null;
            return false;
        }