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 ReadOptimizedStaticResource(BamlBinaryReader reader)
		{
			byte extension = reader.ReadByte(); // num1
			short valueIdentifier = reader.ReadInt16();

			bool typeExtension = ((extension & 1) == 1);
			bool staticExtension = ((extension & 2) == 2);

			object element = null;

			if (typeExtension)
			{
				Element innerElement = this.CreateTypeExtension(valueIdentifier);
				element = innerElement;
			}
			else if (staticExtension)
			{
				Element innerElement = new Element();
				innerElement.TypeDeclaration = new TypeDeclaration("x:Static");
				// innerElement.TypeDeclaration = new TypeDeclaration("StaticExtension", "System.Windows.Markup);

				ResourceName resourceName = (ResourceName) this.GetResourceName(valueIdentifier);
				innerElement.Arguments.Add(resourceName);

				element = innerElement;
			}
			else
			{
				string value = (string)this.stringTable[valueIdentifier];
				element = value;
			}

			this.staticResourceTable.Add(element);
		}
		private void ReadAttributeInfo(BamlBinaryReader reader)
		{
			short attributeIdentifier = reader.ReadInt16();
			short ownerTypeIdentifier = reader.ReadInt16();
			BamlAttributeUsage attributeUsage = (BamlAttributeUsage) reader.ReadByte();
			string attributeName = reader.ReadString();

			TypeDeclaration declaringType = this.GetTypeDeclaration(ownerTypeIdentifier);
			PropertyDeclaration propertyName = new PropertyDeclaration(attributeName, declaringType);
			this.propertyTable.Add(attributeIdentifier, propertyName);
		}
		private void ReadStaticResourceStart(BamlBinaryReader reader)
		{
			short typeIdentifier = reader.ReadInt16();
			byte flags = reader.ReadByte(); // 1 = CreateUsingTypeConverter, 2 = Injected

			Element element = new Element();
			element.TypeDeclaration = this.GetTypeDeclaration(typeIdentifier);

			this.elementStack.Push(element);

			this.staticResourceTable.Add(element);
		}
		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;
				}
			}
		}
			internal static object ParseStreamGeometry(BamlBinaryReader reader)
			{
				StringBuilder sb = new StringBuilder();
				bool shouldClose = false;
				char lastChar = '\0';

				while (true)
				{
					byte b = reader.ReadByte();
					bool bit1 = (b & 0x10) == 0x10;
					bool bit2 = (b & 0x20) == 0x20;
					bool bit3 = (b & 0x40) == 0x40;
					bool bit4 = (b & 0x80) == 0x80;

					switch (b & 0xF)
					{
						case 0x0: //Begin
							{
								shouldClose = bit2;

								AddPathCommand('M', ref lastChar, sb);
								AddPathPoint(reader, sb, bit3, bit4);
								break;
							}
						case 0x1: //LineTo
							{
								AddPathCommand('L', ref lastChar, sb);
								AddPathPoint(reader, sb, bit3, bit4);
								break;
							}
						case 0x2: //QuadraticBezierTo
							{
								AddPathCommand('Q', ref lastChar, sb);
								AddPathPoint(reader, sb, bit3, bit4);
								AddPathPoint(reader, sb);
								break;
							}
						case 0x3: //BezierTo
							{
								AddPathCommand('C', ref lastChar, sb);
								AddPathPoint(reader, sb, bit3, bit4);
								AddPathPoint(reader, sb);
								AddPathPoint(reader, sb);
								break;
							}
						case 0x4: //PolyLineTo
							{
								bool isStroked = bit1;
								bool isSmooth = bit2;
								AddPathCommand('L', ref lastChar, sb);
								int count = reader.ReadInt32();

								for (int i = 0; i < count; i++)
									AddPathPoint(reader, sb);
								break;
							}
						case 0x5: //PolyQuadraticBezierTo
							{
								AddPathCommand('Q', ref lastChar, sb);
								int count = reader.ReadInt32();
								//System.Diagnostics.Debug.Assert(count % 2 == 0);
								for (int i = 0; i < count; i++)
									AddPathPoint(reader, sb);
								break;
							}
						case 0x6: //PolyBezierTo
							{
								AddPathCommand('C', ref lastChar, sb);
								int count = reader.ReadInt32();
								//System.Diagnostics.Debug.Assert(count % 3 == 0);
								for (int i = 0; i < count; i++)
									AddPathPoint(reader, sb);
								break;
							}
						case 0x7: //ArcTo
							{
								double endPtX = ReadPathDouble(reader, bit3);
								double endPtY = ReadPathDouble(reader, bit4);
								byte arcInfo = reader.ReadByte();
								bool isLarge = (arcInfo & 0xF) != 0;
								bool clockWise = (arcInfo & 0xF0) != 0;
								double sizeX = reader.ReadCompressedDouble();
								double sizeY = reader.ReadCompressedDouble();
								double angle = reader.ReadCompressedDouble();
								sb.AppendFormat("A {0},{1} {2} {3} {4} {5},{6} ", sizeX, sizeY, angle, isLarge ? 1 : 0, clockWise ? 1 : 0, endPtX, endPtY);
								lastChar = 'A';
								break;
							}
						case 0x8: //Closed
							{
								if (shouldClose)
								{
									sb.Append("Z");
								}
								else if (sb.Length > 0)
								{
									// trim off the ending space
									sb.Remove(sb.Length - 1, 0);
								}

								return sb.ToString();
							}
						case 0x9: //FillRule
							{
								sb.Insert(0, bit1 ? "F1 " : "F0 ");
								lastChar = 'F';
								break;
							}
						default:
							throw new InvalidOperationException();
					}
				}
			}
		private void ReadPropertyCustom(BamlBinaryReader reader)
		{
			short attributeIdentifier = reader.ReadInt16();
			short serializerTypeIdentifierOriginal = reader.ReadInt16();
            bool typeIdentifier = (serializerTypeIdentifierOriginal & 0x4000) == 0x4000;
            short serializerTypeIdentifier = (short)(serializerTypeIdentifierOriginal & ~0x4000);

			Property property = new Property(PropertyType.Value);
			property.PropertyDeclaration = this.GetPropertyDeclaration(attributeIdentifier);
	
			switch (serializerTypeIdentifier)
			{
				// PropertyReference
				case 0x0089:
					short identifier = reader.ReadInt16();
					if (typeIdentifier)
					{
						TypeDeclaration declaringType = this.GetTypeDeclaration(identifier);
						string propertyName = reader.ReadString();
						property.Value = new PropertyDeclaration(propertyName, declaringType);
					}
					else
					{
						property.Value = this.GetPropertyDeclaration(identifier);
					}
					break;
	
				case 0x002e: // Boolean
					int value = reader.ReadByte();
					property.Value = (value == 0x01) ? "true" : "false";
					break;
	
				case 0x02e8: // SolidColorBrush
					switch (reader.ReadByte())
					{
						case 0x01: // KnownSolidColor
							uint color = reader.ReadUInt32();
							switch (color)
							{
								case 0x00ffffff:
									property.Value = "Transparent";
									break;
	
								default:
									property.Value = KnownColors.KnownColorFromUInt(color);
									break;
							}
							break;
	
						case 0x02: // OtherColor
							property.Value = reader.ReadString();
							break;
	
						default:
							throw new NotSupportedException();
					}
					break;
	
				case 0x02e9: // IntCollection
					using (StringWriter writer = new StringWriter())
					{
						byte format = reader.ReadByte();
						int count = reader.ReadInt32();
	
						switch (format)
						{
							case 0x01: // Consecutive
								for (int i = 0; i < count; i++)
								{
									if (i != 0)
									{
										writer.Write(",");
									}
	
									int number = reader.ReadInt32();
									writer.Write(number.ToString());
									if (number > count)
									{
										break;
									}
								}
								break;
	
							case 0x02: // Byte
								for (int i = 0; i < count; i++)
								{
									if (i != 0)
									{
										writer.Write(",");
									}

									int number = reader.ReadByte();
									writer.Write(number.ToString());
								}
								break;
	
							case 0x03: // UInt16
								for (int i = 0; i < count; i++)
								{
									if (i != 0)
									{
										writer.Write(",");
									}

									int number = reader.ReadUInt16();
									writer.Write(number.ToString());
								}
								break;
	
							case 0x04: // UInt32
								throw new NotSupportedException();
	
							default:
								throw new NotSupportedException();
						}
	
						property.Value = writer.ToString();
					}
					break;
	
				case 0x02ea: // PathData
					property.Value = PathDataParser.ParseStreamGeometry(reader);
					break;
	
				case 0x02ec: // Point
					using (StringWriter writer = new StringWriter())
					{
						int count = reader.ReadInt32();
						for (int i = 0; i < count; i++)
						{
							if (i != 0)
							{
								writer.Write(" ");
							}
	
							for (int j = 0; j < 2; j++)
							{
								if (j != 0)
								{
									writer.Write(",");
								}
	
								double number = reader.ReadCompressedDouble();
								writer.Write(number.ToString());
							}
						}
	
						property.Value = writer.ToString();
					}
					break;
	
				case 0x02eb: // Point3D
				case 0x02f0: // Vector3D
					using (StringWriter writer = new StringWriter())
					{
						int count = reader.ReadInt32();
						for (int i = 0; i < count; i++)
						{
							if (i != 0)
							{
								writer.Write(" ");
							}
	
							for (int j = 0; j < 3; j++)
							{
								if (j != 0)
								{
									writer.Write(",");
								}
	
								double number = reader.ReadCompressedDouble();
								writer.Write(number.ToString());
							}
						}
	
						property.Value = writer.ToString();
					}
					break;
	
				default:
                    property.Value = String.Format("Not supported serializer type identifier: 0x{0:x}", serializerTypeIdentifier);
                    break;
                    //throw new NotSupportedException();
			}
	
			Element element = (Element)this.elementStack.Peek();
			element.Properties.Add(property);
		}
		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);
		}
Пример #9
0
 private void ReadStaticResourceStart(BamlBinaryReader reader)
 {
     short identifier = reader.ReadInt16();
     reader.ReadByte();
     Element element = new Element();
     element.TypeDeclaration = this.GetTypeDeclaration(identifier);
     this.elementStack.Push(element);
     this.staticResourceTable.Add(element);
 }
Пример #10
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;
            }
        }
Пример #11
0
        private void ReadPropertyCustom(BamlBinaryReader reader)
        {
            Element element;
            short identifier = reader.ReadInt16();
            short num2 = reader.ReadInt16();
            bool flag = (num2 & 0x4000) == 0x4000;
            num2 = (short)(num2 & -16385);
            Property property = new Property(PropertyType.Value);
            property.PropertyDeclaration = this.GetPropertyDeclaration(identifier);
            switch (num2)
            {
                case 0x2e8:
                    switch (reader.ReadByte())
                    {
                        case 1:
                            {
                                uint argb = reader.ReadUInt32();
                                if (argb == 0xffffff)
                                {
                                    property.Value = "Transparent";
                                }
                                else
                                {
                                    property.Value = KnownColors.KnownColorFromUInt(argb);
                                }
                                goto Label_038A;
                            }
                        case 2:
                            property.Value = reader.ReadString();
                            goto Label_038A;
                    }
                    throw new NotSupportedException();

                case 0x2e9:
                    {
                        using (StringWriter writer = new StringWriter())
                        {
                            int num8;
                            int num10;
                            int num12;
                            byte num6 = reader.ReadByte();
                            int num7 = reader.ReadInt32();
                            switch (num6)
                            {
                                case 1:
                                    num8 = 0;
                                    goto Label_01C9;

                                case 2:
                                    num10 = 0;
                                    goto Label_0202;

                                case 3:
                                    num12 = 0;
                                    goto Label_023C;

                                case 4:
                                    throw new NotSupportedException();

                                default:
                                    throw new NotSupportedException();
                            }
                        Label_0194:
                            if (num8 != 0)
                            {
                                writer.Write(",");
                            }
                            int num9 = reader.ReadInt32();
                            writer.Write(num9.ToString());
                            if (num9 > num7)
                            {
                                goto Label_0250;
                            }
                            num8++;
                        Label_01C9:
                            if (num8 < num7)
                            {
                                goto Label_0194;
                            }
                            goto Label_0250;
                        Label_01D6:
                            if (num10 != 0)
                            {
                                writer.Write(",");
                            }
                            writer.Write(((int)reader.ReadByte()).ToString());
                            num10++;
                        Label_0202:
                            if (num10 < num7)
                            {
                                goto Label_01D6;
                            }
                            goto Label_0250;
                        Label_020F:
                            if (num12 != 0)
                            {
                                writer.Write(",");
                            }
                            writer.Write(((int)reader.ReadUInt16()).ToString());
                            num12++;
                        Label_023C:
                            if (num12 < num7)
                            {
                                goto Label_020F;
                            }
                        Label_0250:
                            property.Value = writer.ToString();
                            goto Label_038A;
                        }
                    }
                case 0x2ea:
                    property.Value = PathDataParser.ParseStreamGeometry(reader);
                    goto Label_038A;

                case 0x2eb:
                case 0x2f0:
                    {
                        using (StringWriter writer3 = new StringWriter())
                        {
                            int num18 = reader.ReadInt32();
                            for (int i = 0; i < num18; i++)
                            {
                                if (i != 0)
                                {
                                    writer3.Write(" ");
                                }
                                for (int j = 0; j < 3; j++)
                                {
                                    if (j != 0)
                                    {
                                        writer3.Write(",");
                                    }
                                    writer3.Write(reader.ReadCompressedDouble().ToString());
                                }
                            }
                            property.Value = writer3.ToString();
                            goto Label_038A;
                        }
                    }
                case 0x2ec:
                    {
                        using (StringWriter writer2 = new StringWriter())
                        {
                            int num14 = reader.ReadInt32();
                            for (int k = 0; k < num14; k++)
                            {
                                if (k != 0)
                                {
                                    writer2.Write(" ");
                                }
                                for (int m = 0; m < 2; m++)
                                {
                                    if (m != 0)
                                    {
                                        writer2.Write(",");
                                    }
                                    writer2.Write(reader.ReadCompressedDouble().ToString());
                                }
                            }
                            property.Value = writer2.ToString();
                            goto Label_038A;
                        }
                    }
                case 0x2ed:
                case 750:
                case 0x2ef:
                    goto Label_0384;

                case 0x89:
                    {
                        short num3 = reader.ReadInt16();
                        if (flag)
                        {
                            TypeDeclaration typeDeclaration = this.GetTypeDeclaration(num3);
                            string name = reader.ReadString();
                            property.Value = new PropertyDeclaration(name, typeDeclaration);
                        }
                        else
                        {
                            property.Value = this.GetPropertyDeclaration(num3);
                        }
                        goto Label_038A;
                    }
                case 0x2e:
                    {
                        int num4 = reader.ReadByte();
                        property.Value = (num4 == 1) ? "true" : "false";
                        goto Label_038A;
                    }
            }
            Label_0384:
            throw new NotSupportedException();
            Label_038A:
            element = (Element)this.elementStack.Peek();
            element.Properties.Add(property);
        }
Пример #12
0
 private void ReadOptimizedStaticResource(BamlBinaryReader reader)
 {
     byte num = reader.ReadByte();
     short typeIdentifier = reader.ReadInt16();
     bool flag = (num & 1) == 1;
     bool flag2 = (num & 2) == 2;
     object obj2 = null;
     if (flag)
     {
         obj2 = this.CreateTypeExtension(typeIdentifier);
     }
     else if (flag2)
     {
         Element element2 = new Element();
         element2.TypeDeclaration = new TypeDeclaration("x:Static");
         ResourceName resourceName = (ResourceName)this.GetResourceName(typeIdentifier);
         element2.Arguments.Add(resourceName);
         obj2 = element2;
     }
     else
     {
         string str = (string)this.stringTable[typeIdentifier];
         obj2 = str;
     }
     this.staticResourceTable.Add(obj2);
 }
Пример #13
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);
 }
Пример #14
0
 private void ReadElementStart(BamlBinaryReader reader)
 {
     short identifier = reader.ReadInt16();
     reader.ReadByte();
     Element element = new Element();
     element.TypeDeclaration = this.GetTypeDeclaration(identifier);
     this.AddElementToTree(element, reader);
     this.elementStack.Push(element);
 }
Пример #15
0
 private void ReadAttributeInfo(BamlBinaryReader reader)
 {
     short key = reader.ReadInt16();
     short identifier = reader.ReadInt16();
     reader.ReadByte();
     string name = reader.ReadString();
     TypeDeclaration typeDeclaration = this.GetTypeDeclaration(identifier);
     PropertyDeclaration declaration2 = new PropertyDeclaration(name, typeDeclaration);
     this.propertyTable.Add(key, declaration2);
 }