Пример #1
0
 public override void Read(BamlBinaryReader reader)
 {
     base.Read(reader);
     _position = reader.ReadUInt32();
     Shared    = reader.ReadBoolean();
     SharedSet = reader.ReadBoolean();
 }
Пример #2
0
 protected override void ReadData(BamlBinaryReader reader, int size)
 {
     ValueId   = reader.ReadUInt16();
     _position = reader.ReadUInt32();
     Shared    = reader.ReadBoolean();
     SharedSet = reader.ReadBoolean();
 }
Пример #3
0
 public override void Read(BamlBinaryReader reader)
 {
     LoadAsync       = reader.ReadBoolean();
     MaxAsyncRecords = reader.ReadUInt32();
     DebugBaml       = reader.ReadBoolean();
 }
		public BamlTranslator(Stream stream):base(null, stream)
		{
			BamlBinaryReader reader = new BamlBinaryReader(stream);
	
			int length = reader.ReadInt32();
			string format = new string(new BinaryReader(stream, Encoding.Unicode).ReadChars(length >> 1));
			if (format != "MSBAML")
			{
                throw new NotSupportedException(String.Format("Not supported file format: {0}", format));
			}
	
			int readerVersion = reader.ReadInt32();
			int updateVersion = reader.ReadInt32();
			int writerVersion = reader.ReadInt32();
			if ((readerVersion != 0x00600000) || (updateVersion != 0x00600000) || (writerVersion != 0x00600000))
			{
                throw new NotSupportedException(String.Format("Not supported baml version: {0:x}", readerVersion));
			}
	
			while (reader.BaseStream.Position < reader.BaseStream.Length)
			{
				BamlRecordType recordType = (BamlRecordType) reader.ReadByte();
	
				long position = reader.BaseStream.Position;
				int size = 0;
	
				switch (recordType)
				{
					case BamlRecordType.XmlnsProperty:
					case BamlRecordType.PresentationOptionsAttribute:
					case BamlRecordType.PIMapping:
					case BamlRecordType.AssemblyInfo:
					case BamlRecordType.Property:
					case BamlRecordType.PropertyWithConverter:
					case BamlRecordType.PropertyCustom:
					case BamlRecordType.DefAttribute:
					case BamlRecordType.DefAttributeKeyString:
					case BamlRecordType.TypeInfo:
					case BamlRecordType.AttributeInfo:
					case BamlRecordType.StringInfo:
					case BamlRecordType.Text:
					case BamlRecordType.TextWithConverter:
					case BamlRecordType.TextWithId:
						size = reader.ReadCompressedInt32();
						break;
				}
	
				// Console.WriteLine(recordType.ToString());
	
				switch (recordType)
				{
					case BamlRecordType.DocumentStart:
						bool loadAsync = reader.ReadBoolean();
						int maxAsyncRecords = reader.ReadInt32();
						bool debugBaml = reader.ReadBoolean();
						break;
	
					case BamlRecordType.DocumentEnd:
						break;
	
					case BamlRecordType.ElementStart:
						this.namespaceManager.OnElementStart();
						this.ReadElementStart(reader);
						break;
	
					case BamlRecordType.ElementEnd:
						this.ReadElementEnd();
						this.namespaceManager.OnElementEnd();
						break;
	
					case BamlRecordType.KeyElementStart:
						this.ReadKeyElementStart(reader);
						break;
	
					case BamlRecordType.KeyElementEnd:
						this.ReadKeyElementEnd();
						break;
	
					case BamlRecordType.XmlnsProperty:
						this.ReadXmlnsProperty(reader);
						break;
	
					case BamlRecordType.PIMapping:
						this.ReadNamespaceMapping(reader);
						break;
	
					case BamlRecordType.PresentationOptionsAttribute:
						this.ReadPresentationOptionsAttribute(reader);
						break;
	
					case BamlRecordType.AssemblyInfo:
						this.ReadAssemblyInfo(reader);
						break;
	
					case BamlRecordType.StringInfo:
						this.ReadStringInfo(reader);
						break;
	
					case BamlRecordType.ConnectionId:
						reader.ReadInt32(); // ConnectionId
						break;
	
					case BamlRecordType.Property:
						this.ReadPropertyRecord(reader);
						break;
	
					case BamlRecordType.PropertyWithConverter:
						this.ReadPropertyWithConverter(reader);
						break;
	
					case BamlRecordType.PropertyWithExtension:
						this.ReadPropertyWithExtension(reader);
						break;
	
					case BamlRecordType.PropertyTypeReference:
						this.ReadPropertyTypeReference(reader);
						break;
	
					case BamlRecordType.PropertyWithStaticResourceId:
						this.ReadPropertyWithStaticResourceIdentifier(reader);
						break;
	
					case BamlRecordType.ContentProperty:
						this.ReadContentProperty(reader);
						break;
	
					case BamlRecordType.TypeInfo:
						this.ReadTypeInfo(reader);
						break;
	
					case BamlRecordType.AttributeInfo:
						this.ReadAttributeInfo(reader);
						break;
	
					case BamlRecordType.DefAttribute:
						this.ReadDefAttribute(reader);
						break;
	
					case BamlRecordType.DefAttributeKeyString:
						this.ReadDefAttributeKeyString(reader);
						break;
	
					case BamlRecordType.DefAttributeKeyType:
						this.ReadDefAttributeKeyType(reader);
						break;
	
					case BamlRecordType.Text:
						this.ReadText(reader);
						break;
	
					case BamlRecordType.TextWithConverter:
						this.ReadTextWithConverter(reader);
						break;
	
					case BamlRecordType.PropertyCustom:
						this.ReadPropertyCustom(reader);
						break;
	
					case BamlRecordType.PropertyListStart:
						this.ReadPropertyListStart(reader);
						break;
	
					case BamlRecordType.PropertyListEnd:
						this.ReadPropertyListEnd();
						break;
	
					case BamlRecordType.PropertyDictionaryStart:
						this.ReadPropertyDictionaryStart(reader);
						break;
	
					case BamlRecordType.PropertyDictionaryEnd:
						this.ReadPropertyDictionaryEnd();
						break;
	
					case BamlRecordType.PropertyComplexStart:
						this.ReadPropertyComplexStart(reader);
						break;
	
					case BamlRecordType.PropertyComplexEnd:
						this.ReadPropertyComplexEnd();
						break;
	
					case BamlRecordType.ConstructorParametersStart:
						this.ReadConstructorParametersStart();
						break;
	
					case BamlRecordType.ConstructorParametersEnd:
						this.ReadConstructorParametersEnd();
						break;
	
					case BamlRecordType.ConstructorParameterType:
						this.ReadConstructorParameterType(reader);
						break;
	
					case BamlRecordType.DeferableContentStart:
						int contentSize = reader.ReadInt32();
						break;
	
					case BamlRecordType.StaticResourceStart:
						this.ReadStaticResourceStart(reader);
						break;

					case BamlRecordType.StaticResourceEnd:
						this.ReadStaticResourceEnd(reader);
						break;

					case BamlRecordType.StaticResourceId:
						this.ReadStaticResourceIdentifier(reader);
						break;

					case BamlRecordType.OptimizedStaticResource:
						this.ReadOptimizedStaticResource(reader);
						break;
	
					case BamlRecordType.LineNumberAndPosition:
						this.lineNumber = reader.ReadInt32(); // LineNumber
						this.linePosition = reader.ReadInt32(); // Position
						// Console.WriteLine(lineNumber.ToString() + "," + linePosition.ToString());
						break;
	
					case BamlRecordType.LinePosition:
						this.linePosition = reader.ReadInt32(); // Position
						break;

					case BamlRecordType.TextWithId:
						this.ReadTextWithId(reader);
						break;

					default:
						throw new NotSupportedException(recordType.ToString());
				}
	
				if (size > 0)
				{
					reader.BaseStream.Position = position + size;
				}
			}
		}
		private void ReadKeyElementStart(BamlBinaryReader reader)
		{
			short typeIdentifier = reader.ReadInt16();

			byte flags = reader.ReadByte();
			bool createUsingTypeConverter = ((flags & 1) != 0);
			bool injected = ((flags & 2) != 0);

			int position = reader.ReadInt32();
			bool shared = reader.ReadBoolean();
			bool sharedSet = reader.ReadBoolean();
	
			Property keyProperty = new Property(PropertyType.Complex);
			keyProperty.PropertyDeclaration = new PropertyDeclaration("x:Key");
			// At least for the case where we are processing the key of a dictionary,
			// we should not assume that the key is a type. This is particularly true
			// when the type is a ComponentResourceKey.
			//
			//keyProperty.Value = this.CreateTypeExtension(typeIdentifier);
			keyProperty.Value = this.CreateTypeExtension(typeIdentifier, false);

			Element dictionary = (Element)this.elementStack.Peek();
			this.AddDictionaryEntry(dictionary, position, keyProperty);
			this.elementStack.Push(keyProperty.Value);
		}
		private void ReadDefAttributeKeyType(BamlBinaryReader reader)
		{
			short typeIdentifier = reader.ReadInt16();
			reader.ReadByte();
			int position = reader.ReadInt32();
			bool shared = reader.ReadBoolean();
			bool sharedSet = reader.ReadBoolean();
	
			Property keyProperty = new Property(PropertyType.Complex);
			keyProperty.PropertyDeclaration = new PropertyDeclaration("x:Key");
			keyProperty.Value = this.CreateTypeExtension(typeIdentifier);
	
			Element dictionary = (Element)this.elementStack.Peek();

			this.AddDictionaryEntry(dictionary, position, keyProperty);
		}
		private void ReadDefAttributeKeyString(BamlBinaryReader reader)
		{
			short valueIdentifier = reader.ReadInt16();
			int position = reader.ReadInt32();
			bool shared = reader.ReadBoolean();
			bool sharedSet = reader.ReadBoolean();
			
			string key = (string) this.stringTable[valueIdentifier];
			if (key == null)
			{
				throw new NotSupportedException();
			}
	
			Property keyProperty = new Property(PropertyType.Value);
			keyProperty.PropertyDeclaration = new PropertyDeclaration("x:Key");
			keyProperty.Value = key;
	
			Element dictionary = (Element)this.elementStack.Peek();

			this.AddDictionaryEntry(dictionary, position, keyProperty);
		}
Пример #8
0
        // Methods
        public BamlTranslator(Stream stream)
        {
            BamlRecordType type;
            long position;
            int num6;
            this.assemblyTable = new Hashtable();
            this.stringTable = new Hashtable();
            this.typeTable = new Hashtable();
            this.propertyTable = new Hashtable();
            this.staticResourceTable = new ArrayList();
            this.namespaceManager = new NamespaceManager();
            this.rootElement = null;
            this.elementStack = new Stack();
            this.constructorParameterTable = new ArrayList();
            knownTypeTable = null;
            knownPropertyTable = null;
            this.knownResourceTable = new Hashtable();
            this.dictionaryKeyStartTable = new Hashtable();
            this.dictionaryKeyPositionTable = new Hashtable();
            this.lineNumber = 0;
            this.linePosition = 0;
            BamlBinaryReader reader = new BamlBinaryReader(stream);
            int num = reader.ReadInt32();
            string str = new string(new BinaryReader(stream, Encoding.Unicode).ReadChars(num >> 1));
            if (str != "MSBAML")
            {
                throw new NotSupportedException();
            }
            int num2 = reader.ReadInt32();
            int num3 = reader.ReadInt32();
            int num4 = reader.ReadInt32();
            if (((num2 == 0x600000) && (num3 == 0x600000)) && (num4 == 0x600000))
            {
                goto Label_04F2;
            }
            throw new NotSupportedException();
            Label_01CB:
            switch (type)
            {
                case BamlRecordType.DocumentStart:
                    reader.ReadBoolean();
                    reader.ReadInt32();
                    reader.ReadBoolean();
                    break;

                case BamlRecordType.DocumentEnd:
                    break;

                case BamlRecordType.ElementStart:
                    this.namespaceManager.OnElementStart();
                    this.ReadElementStart(reader);
                    break;

                case BamlRecordType.ElementEnd:
                    this.ReadElementEnd();
                    this.namespaceManager.OnElementEnd();
                    break;

                case BamlRecordType.Property:
                    this.ReadPropertyRecord(reader);
                    break;

                case BamlRecordType.PropertyCustom:
                    this.ReadPropertyCustom(reader);
                    break;

                case BamlRecordType.PropertyComplexStart:
                    this.ReadPropertyComplexStart(reader);
                    break;

                case BamlRecordType.PropertyComplexEnd:
                    this.ReadPropertyComplexEnd();
                    break;

                case BamlRecordType.PropertyListStart:
                    this.ReadPropertyListStart(reader);
                    break;

                case BamlRecordType.PropertyListEnd:
                    this.ReadPropertyListEnd();
                    break;

                case BamlRecordType.PropertyDictionaryStart:
                    this.ReadPropertyDictionaryStart(reader);
                    break;

                case BamlRecordType.PropertyDictionaryEnd:
                    this.ReadPropertyDictionaryEnd();
                    break;

                case BamlRecordType.Text:
                    this.ReadText(reader);
                    break;

                case BamlRecordType.TextWithConverter:
                    this.ReadTextWithConverter(reader);
                    break;

                case BamlRecordType.XmlnsProperty:
                    this.ReadXmlnsProperty(reader);
                    break;

                case BamlRecordType.DefAttribute:
                    this.ReadDefAttribute(reader);
                    break;

                case BamlRecordType.PIMapping:
                    this.ReadNamespaceMapping(reader);
                    break;

                case BamlRecordType.AssemblyInfo:
                    this.ReadAssemblyInfo(reader);
                    break;

                case BamlRecordType.TypeInfo:
                    this.ReadTypeInfo(reader);
                    break;

                case BamlRecordType.AttributeInfo:
                    this.ReadAttributeInfo(reader);
                    break;

                case BamlRecordType.StringInfo:
                    this.ReadStringInfo(reader);
                    break;

                case BamlRecordType.PropertyTypeReference:
                    this.ReadPropertyTypeReference(reader);
                    break;

                case BamlRecordType.PropertyWithExtension:
                    this.ReadPropertyWithExtension(reader);
                    break;

                case BamlRecordType.PropertyWithConverter:
                    this.ReadPropertyWithConverter(reader);
                    break;

                case BamlRecordType.DeferableContentStart:
                    reader.ReadInt32();
                    break;

                case BamlRecordType.DefAttributeKeyString:
                    this.ReadDefAttributeKeyString(reader);
                    break;

                case BamlRecordType.DefAttributeKeyType:
                    this.ReadDefAttributeKeyType(reader);
                    break;

                case BamlRecordType.KeyElementStart:
                    this.ReadKeyElementStart(reader);
                    break;

                case BamlRecordType.KeyElementEnd:
                    this.ReadKeyElementEnd();
                    break;

                case BamlRecordType.ConstructorParametersStart:
                    this.ReadConstructorParametersStart();
                    break;

                case BamlRecordType.ConstructorParametersEnd:
                    this.ReadConstructorParametersEnd();
                    break;

                case BamlRecordType.ConstructorParameterType:
                    this.ReadConstructorParameterType(reader);
                    break;

                case BamlRecordType.ConnectionId:
                    reader.ReadInt32();
                    break;

                case BamlRecordType.ContentProperty:
                    this.ReadContentProperty(reader);
                    break;

                case BamlRecordType.StaticResourceStart:
                    this.ReadStaticResourceStart(reader);
                    break;

                case BamlRecordType.StaticResourceEnd:
                    this.ReadStaticResourceEnd(reader);
                    break;

                case BamlRecordType.StaticResourceId:
                    this.ReadStaticResourceIdentifier(reader);
                    break;

                case BamlRecordType.TextWithId:
                    this.ReadTextWithId(reader);
                    break;

                case BamlRecordType.PresentationOptionsAttribute:
                    this.ReadPresentationOptionsAttribute(reader);
                    break;

                case BamlRecordType.LineNumberAndPosition:
                    this.lineNumber = reader.ReadInt32();
                    this.linePosition = reader.ReadInt32();
                    break;

                case BamlRecordType.LinePosition:
                    this.linePosition = reader.ReadInt32();
                    break;

                case BamlRecordType.OptimizedStaticResource:
                    this.ReadOptimizedStaticResource(reader);
                    break;

                case BamlRecordType.PropertyWithStaticResourceId:
                    this.ReadPropertyWithStaticResourceIdentifier(reader);
                    break;

                default:
                    throw new NotSupportedException(type.ToString());
            }
            if (num6 > 0)
            {
                reader.BaseStream.Position = position + num6;
            }
            Label_04F2:
            if (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                type = (BamlRecordType)reader.ReadByte();
                position = reader.BaseStream.Position;
                num6 = 0;
                switch (type)
                {
                    case BamlRecordType.Property:
                    case BamlRecordType.PropertyCustom:
                    case BamlRecordType.Text:
                    case BamlRecordType.TextWithConverter:
                    case BamlRecordType.XmlnsProperty:
                    case BamlRecordType.DefAttribute:
                    case BamlRecordType.PIMapping:
                    case BamlRecordType.AssemblyInfo:
                    case BamlRecordType.TypeInfo:
                    case BamlRecordType.AttributeInfo:
                    case BamlRecordType.StringInfo:
                    case BamlRecordType.PropertyWithConverter:
                    case BamlRecordType.DefAttributeKeyString:
                    case BamlRecordType.TextWithId:
                    case BamlRecordType.PresentationOptionsAttribute:
                        num6 = reader.ReadCompressedInt32();
                        goto Label_01CB;

                    case BamlRecordType.RoutedEvent:
                    case BamlRecordType.ClrEvent:
                    case BamlRecordType.XmlAttribute:
                    case BamlRecordType.ProcessingInstruction:
                    case BamlRecordType.Comment:
                    case BamlRecordType.DefTag:
                    case BamlRecordType.EndAttributes:
                    case BamlRecordType.TypeSerializerInfo:
                    case BamlRecordType.DeferableContentStart:
                        goto Label_01CB;
                }
                goto Label_01CB;
            }
        }
Пример #9
0
 private void ReadKeyElementStart(BamlBinaryReader reader)
 {
     short typeIdentifier = reader.ReadInt16();
     byte num2 = reader.ReadByte();
     int position = reader.ReadInt32();
     reader.ReadBoolean();
     reader.ReadBoolean();
     Property keyProperty = new Property(PropertyType.Complex);
     keyProperty.PropertyDeclaration = new PropertyDeclaration("x:Key");
     keyProperty.Value = this.CreateTypeExtension(typeIdentifier, false);
     Element dictionary = (Element)this.elementStack.Peek();
     this.AddDictionaryEntry(dictionary, position, keyProperty);
     this.elementStack.Push(keyProperty.Value);
 }
Пример #10
0
 private void ReadDefAttributeKeyString(BamlBinaryReader reader)
 {
     short num = reader.ReadInt16();
     int position = reader.ReadInt32();
     reader.ReadBoolean();
     reader.ReadBoolean();
     string str = (string)stringTable[num];
     if (str == null)
     {
         throw new NotSupportedException();
     }
     Property keyProperty = new Property(PropertyType.Value);
     keyProperty.PropertyDeclaration = new PropertyDeclaration("x:Key");
     keyProperty.Value = str;
     Element dictionary = (Element)elementStack.Peek();
     AddDictionaryEntry(dictionary, position, keyProperty);
 }