void RewriteClass(XamlContext ctx, XElement elem) { var type = elem.Annotation<XamlType>(); if (type == null || type.ResolvedType == null) return; var typeDef = type.ResolvedType.ResolveTypeDef(); var comparer = new AssemblyNameComparer(AssemblyNameComparerFlags.All); if (typeDef == null || !comparer.Equals(typeDef.DefinitionAssembly, ctx.Module.Assembly)) return; var newType = typeDef.BaseType; var xamlType = new XamlType(newType.DefinitionAssembly, newType.ReflectionNamespace, newType.Name); xamlType.ResolveNamespace(elem, ctx); elem.Name = xamlType.ToXName(ctx); var attrName = ctx.GetXamlNsName("Class", elem); var attrs = elem.Attributes().ToList(); if (typeDef.IsNotPublic) { var classModifierName = ctx.GetXamlNsName("ClassModifier", elem); attrs.Insert(0, new XAttribute(classModifierName, ctx.BamlDecompilerOptions.InternalClassModifier)); } attrs.Insert(0, new XAttribute(attrName, type.ResolvedType.ReflectionFullName)); elem.ReplaceAttributes(attrs); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyRecord)((BamlRecordNode)node).Record; var elemType = parent.Xaml.Element.Annotation <XamlType>(); var xamlProp = ctx.ResolveProperty(record.AttributeId); var value = XamlUtils.Escape(record.Value); parent.Xaml.Element.Add(ConstructXAttribute()); return(null); XAttribute ConstructXAttribute() { if (xamlProp.IsAttachedTo(elemType)) { return(new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, true), value)); } if (xamlProp.PropertyName == "Name" && elemType.ResolvedType.GetDefinition()?.ParentModule.IsMainModule == true) { return(new XAttribute(ctx.GetXamlNsName("Name"), value)); } return(new XAttribute(xamlProp.ToXName(ctx, parent.Xaml, false), value)); } }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyTypeReferenceRecord)((BamlRecordNode)node).Record; var attr = ctx.ResolveProperty(record.AttributeId); var type = ctx.ResolveType(record.TypeId); var typeName = ctx.ToString(parent.Xaml, type); var elem = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); elem.Xaml = new XElement(elemAttr.ToXName(ctx, null)); elem.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(elem.Xaml.Element); var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName)); elem.Xaml.Element.Add(typeElem); elemAttr.DeclaringType.ResolveNamespace(elem.Xaml, ctx); elem.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return(elem); }
void RewriteClass(XamlContext ctx, XElement elem) { var type = elem.Annotation <XamlType>(); if (type == null || type.ResolvedType == null) { return; } var typeDef = type.ResolvedType.ResolveTypeDef(); var comparer = new AssemblyNameComparer(AssemblyNameComparerFlags.All); if (typeDef == null || !comparer.Equals(typeDef.DefinitionAssembly, ctx.Module.Assembly)) { return; } var newType = typeDef.BaseType; var xamlType = new XamlType(newType.DefinitionAssembly, newType.ReflectionNamespace, newType.Name); xamlType.ResolveNamespace(elem, ctx); elem.Name = xamlType.ToXName(ctx); var attrName = ctx.GetXamlNsName("Class", elem); var attrs = elem.Attributes().ToList(); attrs.Insert(0, new XAttribute(attrName, type.ResolvedType.ReflectionFullName)); elem.ReplaceAttributes(attrs); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (DefAttributeRecord)((BamlRecordNode)node).Record; var attrName = ctx.ResolveString(record.NameId); parent.Xaml.Element.Add(new XAttribute(ctx.GetXamlNsName(attrName), record.Value)); return null; }
public void Run(XamlContext ctx, XDocument document) { var xClass = document.Root.Elements().First().Attribute(ctx.GetXamlNsName("Class")); if (xClass == null) { return; } var type = ctx.Module.Find(xClass.Value, true); if (type == null) { return; } var wbAsm = ctx.Module.CorLibTypes.AssemblyRef.Version == new Version(2, 0, 0, 0) ? new AssemblyNameInfo("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35").ToAssemblyRef() : new AssemblyNameInfo("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35").ToAssemblyRef(); var ifaceRef = new TypeRefUser(ctx.Module, "System.Windows.Markup", "IComponentConnector", wbAsm); var iface = ctx.Module.Context.Resolver.ResolveThrow(ifaceRef); var connect = iface.FindMethod("Connect"); foreach (MethodDef method in type.Methods) { if (Impl(method, connect)) { connect = method; iface = null; break; } } if (iface != null) { return; } Dictionary <int, Action <XamlContext, XElement> > connIds = null; try { connIds = ExtractConnectionId(ctx, connect); } catch { } if (connIds == null) { var msg = dnSpy_BamlDecompiler_Resources.Error_IComponentConnectorConnetCannotBeParsed; document.Root.AddBeforeSelf(new XComment(string.Format(msg, type.ReflectionFullName))); return; } foreach (var elem in document.Elements()) { ProcessElement(ctx, elem, connIds); } }
public void Callback(XamlContext ctx, XElement elem) { var xName = ctx.GetXamlNsName("Name"); if (elem.Attribute("Name") == null && elem.Attribute(xName) == null) { elem.Add(new XAttribute(xName, FieldName)); } }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (DefAttributeKeyTypeRecord)((BamlRecordNode)node).Record; var type = ctx.ResolveType(record.TypeId); var typeName = ctx.ToString(parent.Xaml, type); var key = (XamlResourceKey)node.Annotation; var bamlElem = new BamlElement(node); bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml)); parent.Xaml.Element.Add(bamlElem.Xaml.Element); var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName)); bamlElem.Xaml.Element.Add(typeElem); key.KeyElement = bamlElem; return bamlElem; }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (DefAttributeRecord)((BamlRecordNode)node).Record; var attrName = ctx.ResolveString(record.NameId); parent.Xaml.Element.Add(new XAttribute(ctx.GetXamlNsName(attrName), record.Value)); return(null); }
public void Run(XamlContext ctx, XDocument document) { key = ctx.GetXamlNsName("Key"); bool doWork; do { doWork = false; foreach (var elem in document.Elements()) { doWork |= ProcessElement(ctx, elem); } } while (doWork); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (LiteralContentRecord)((BamlRecordNode)node).Record; var elem = new XElement(ctx.GetXamlNsName("XData", parent.Xaml)); var content = XElement.Parse(record.Value); elem.Add(content); parent.Xaml.Element.Add(elem); return null; }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (DefAttributeKeyStringRecord)((BamlRecordNode)node).Record; var key = (XamlResourceKey)node.Annotation; var bamlElem = new BamlElement(node); bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml)); parent.Xaml.Element.Add(bamlElem.Xaml.Element); bamlElem.Xaml.Element.Value = ctx.ResolveString(record.ValueId); key.KeyElement = bamlElem; return bamlElem; }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (KeyElementStartRecord)((BamlBlockNode)node).Header; var key = (XamlResourceKey)node.Annotation; var bamlElem = new BamlElement(node); bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml)); parent.Xaml.Element.Add(bamlElem.Xaml.Element); key.KeyElement = bamlElem; base.Translate(ctx, node, bamlElem); return bamlElem; }
void RewriteClass(XamlContext ctx, XElement elem) { var type = elem.Annotation <XamlType>(); if (type == null || type.ResolvedType == null) { return; } var typeDef = type.ResolvedType.GetDefinition(); if (typeDef == null || !typeDef.ParentModule.IsMainModule) { return; } var newType = typeDef.DirectBaseTypes.First().GetDefinition(); if (newType == null) { return; } var xamlType = new XamlType(newType.ParentModule, newType.ParentModule.FullAssemblyName, newType.Namespace, newType.Name); xamlType.ResolveNamespace(elem, ctx); elem.Name = xamlType.ToXName(ctx); var attrName = ctx.GetXamlNsName("Class", elem); var attrs = elem.Attributes().ToList(); if (typeDef.Accessibility != ICSharpCode.Decompiler.TypeSystem.Accessibility.Public) { var classModifierName = ctx.GetXamlNsName("ClassModifier", elem); attrs.Insert(0, new XAttribute(classModifierName, "internal")); } attrs.Insert(0, new XAttribute(attrName, type.ResolvedType.FullName)); elem.ReplaceAttributes(attrs); }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (DefAttributeKeyTypeRecord)((BamlRecordNode)node).Record; var type = ctx.ResolveType(record.TypeId); var typeName = ctx.ToString(parent.Xaml, type); var key = (XamlResourceKey)node.Annotation; var bamlElem = new BamlElement(node); bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml)); parent.Xaml.Element.Add(bamlElem.Xaml.Element); var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName)); bamlElem.Xaml.Element.Add(typeElem); key.KeyElement = bamlElem; return(bamlElem); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (LiteralContentRecord)((BamlRecordNode)node).Record; var elem = new XElement(ctx.GetXamlNsName("XData", parent.Xaml)); var content = XElement.Parse(record.Value); elem.Add(content); parent.Xaml.Element.Add(elem); return(null); }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (KeyElementStartRecord)((BamlBlockNode)node).Header; var key = (XamlResourceKey)node.Annotation; var bamlElem = new BamlElement(node); bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml)); parent.Xaml.Element.Add(bamlElem.Xaml.Element); key.KeyElement = bamlElem; base.Translate(ctx, node, bamlElem); return(bamlElem); }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (DefAttributeKeyStringRecord)((BamlRecordNode)node).Record; var key = (XamlResourceKey)node.Annotation; var bamlElem = new BamlElement(node); bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml)); parent.Xaml.Element.Add(bamlElem.Xaml.Element); bamlElem.Xaml.Element.Value = ctx.ResolveString(record.ValueId); key.KeyElement = bamlElem; return(bamlElem); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (ConstructorParameterTypeRecord)((BamlRecordNode)node).Record; var elem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); elem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension var bamlElem = new BamlElement(node); bamlElem.Xaml = elem; parent.Xaml.Element.Add(elem); var type = ctx.ResolveType(record.TypeId); var typeName = ctx.ToString(parent.Xaml, type); elem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName)); return bamlElem; }
public void Run(XamlContext ctx, XDocument document) { var xClass = document.Root.Elements().First().Attribute(ctx.GetXamlNsName("Class")); if (xClass == null) return; var type = ctx.Module.Find(xClass.Value, true); if (type == null) return; var wbAsm = new AssemblyNameInfo("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35").ToAssemblyRef(); var ifaceRef = new TypeRefUser(ctx.Module, "System.Windows.Markup", "IComponentConnector", wbAsm); var iface = ctx.Module.Context.Resolver.ResolveThrow(ifaceRef); var connect = iface.FindMethod("Connect"); foreach (MethodDef method in type.Methods) { if (Impl(method, connect)) { connect = method; iface = null; break; } } if (iface != null) return; Dictionary<int, Action<XamlContext, XElement>> connIds = null; try { connIds = ExtractConnectionId(ctx, connect); } catch { } if (connIds == null) { var msg = dnSpy_BamlDecompiler_Resources.Error_IComponentConnectorConnetCannotBeParsed; document.Root.AddBeforeSelf(new XComment(string.Format(msg, type.ReflectionFullName))); return; } foreach (var elem in document.Elements()) { ProcessElement(ctx, elem, connIds); } }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (ConstructorParameterTypeRecord)((BamlRecordNode)node).Record; var elem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); elem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension var bamlElem = new BamlElement(node); bamlElem.Xaml = elem; parent.Xaml.Element.Add(elem); var type = ctx.ResolveType(record.TypeId); var typeName = ctx.ToString(parent.Xaml, type); elem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName)); return(bamlElem); }
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (PropertyTypeReferenceRecord)((BamlRecordNode)node).Record; var attr = ctx.ResolveProperty(record.AttributeId); var type = ctx.ResolveType(record.TypeId); var typeName = ctx.ToString(parent.Xaml, type); var elem = new BamlElement(node); var elemAttr = ctx.ResolveProperty(record.AttributeId); elem.Xaml = new XElement(elemAttr.ToXName(ctx, null)); elem.Xaml.Element.AddAnnotation(elemAttr); parent.Xaml.Element.Add(elem.Xaml.Element); var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName)); elem.Xaml.Element.Add(typeElem); elemAttr.DeclaringType.ResolveNamespace(elem.Xaml, ctx); elem.Xaml.Element.Name = elemAttr.ToXName(ctx, null); return elem; }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (OptimizedStaticResourceRecord)((BamlRecordNode)node).Record; var bamlElem = new BamlElement(node); object key; if (record.IsType) { var value = ctx.ResolveType(record.ValueId); var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), ctx.ToString(parent.Xaml, value))); key = typeElem; } else if (record.IsStatic) { string attrName; if (record.ValueId > 0x7fff) { bool isKey = true; short bamlId = (short)-record.ValueId; if (bamlId > 232 && bamlId < 464) { bamlId -= 232; isKey = false; } else if (bamlId > 464 && bamlId < 467) { bamlId -= 231; } else if (bamlId > 467 && bamlId < 470) { bamlId -= 234; isKey = false; } var res = ctx.Baml.KnownThings.Resources(bamlId); string name; if (isKey) name = res.Item1 + "." + res.Item2; else name = res.Item1 + "." + res.Item3; var xmlns = ctx.GetXmlNamespace("http://schemas.microsoft.com/winfx/2006/xaml/presentation"); attrName = ctx.ToString(parent.Xaml, xmlns.GetName(name)); } else { var value = ctx.ResolveProperty(record.ValueId); value.DeclaringType.ResolveNamespace(parent.Xaml, ctx); var xName = value.ToXName(ctx, parent.Xaml); attrName = ctx.ToString(parent.Xaml, xName); } var staticElem = new XElement(ctx.GetXamlNsName("StaticExtension", parent.Xaml)); staticElem.AddAnnotation(ctx.ResolveType(0xfda6)); // Known type - StaticExtension staticElem.Add(new XElement(ctx.GetPseudoName("Ctor"), attrName)); key = staticElem; } else key = ctx.ResolveString(record.ValueId); var extType = ctx.ResolveType(0xfda5); var resElem = new XElement(extType.ToXName(ctx)); resElem.AddAnnotation(extType); // Known type - StaticResourceExtension bamlElem.Xaml = resElem; parent.Xaml.Element.Add(resElem); var attrElem = new XElement(ctx.GetPseudoName("Ctor")); attrElem.Add(key); resElem.Add(attrElem); return bamlElem; }
public void Callback(XamlContext ctx, XElement elem) { var xName = ctx.GetXamlNsName("Name"); if (elem.Attribute("Name") == null && elem.Attribute(xName) == null) elem.Add(new XAttribute(xName, FieldName)); }
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) { var record = (OptimizedStaticResourceRecord)((BamlRecordNode)node).Record; var bamlElem = new BamlElement(node); object key; if (record.IsType) { var value = ctx.ResolveType(record.ValueId); var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml)); typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), ctx.ToString(parent.Xaml, value))); key = typeElem; } else if (record.IsStatic) { string attrName; if (record.ValueId > 0x7fff) { bool isKey = true; short bamlId = (short)-record.ValueId; if (bamlId > 232 && bamlId < 464) { bamlId -= 232; isKey = false; } else if (bamlId > 464 && bamlId < 467) { bamlId -= 231; } else if (bamlId > 467 && bamlId < 470) { bamlId -= 234; isKey = false; } var res = ctx.Baml.KnownThings.Resources(bamlId); string name; if (isKey) { name = res.Item1 + "." + res.Item2; } else { name = res.Item1 + "." + res.Item3; } var xmlns = ctx.GetXmlNamespace("http://schemas.microsoft.com/winfx/2006/xaml/presentation"); attrName = ctx.ToString(parent.Xaml, xmlns.GetName(name)); } else { var value = ctx.ResolveProperty(record.ValueId); value.DeclaringType.ResolveNamespace(parent.Xaml, ctx); var xName = value.ToXName(ctx, parent.Xaml); attrName = ctx.ToString(parent.Xaml, xName); } var staticElem = new XElement(ctx.GetXamlNsName("StaticExtension", parent.Xaml)); staticElem.AddAnnotation(ctx.ResolveType(0xfda6)); // Known type - StaticExtension staticElem.Add(new XElement(ctx.GetPseudoName("Ctor"), attrName)); key = staticElem; } else { key = ctx.ResolveString(record.ValueId); } var extType = ctx.ResolveType(0xfda5); var resElem = new XElement(extType.ToXName(ctx)); resElem.AddAnnotation(extType); // Known type - StaticResourceExtension bamlElem.Xaml = resElem; parent.Xaml.Element.Add(resElem); var attrElem = new XElement(ctx.GetPseudoName("Ctor")); attrElem.Add(key); resElem.Add(attrElem); return(bamlElem); }