Пример #1
0
		public static XamlContext Construct(ModuleDef module, BamlDocument document, CancellationToken token) {
			var ctx = new XamlContext(module);
			ctx.CancellationToken = token;

			ctx.Baml = BamlContext.ConstructContext(module, document, token);
			ctx.RootNode = BamlNode.Parse(document, token);

			ctx.BuildPIMappings(document);
			ctx.BuildNodeMap(ctx.RootNode as BamlBlockNode, new RecursionCounter());

			return ctx;
		}
Пример #2
0
        public XDocument Decompile(ModuleDef module, BamlDocument document, CancellationToken token)
        {
            var ctx = XamlContext.Construct(module, document, token);

            var handler = HandlerMap.LookupHandler(ctx.RootNode.Type);
            var elem    = handler.Translate(ctx, ctx.RootNode, null);

            var xaml = new XDocument();

            xaml.Add(elem.Xaml.Element);

            foreach (var pass in rewritePasses)
            {
                token.ThrowIfCancellationRequested();
                pass.Run(ctx, xaml);
            }

            return(xaml);
        }
Пример #3
0
		public static void ProcessChildren(XamlContext ctx, BamlBlockNode node, BamlElement nodeElem) {
			ctx.XmlNs.PushScope(nodeElem);
			if (nodeElem.Xaml.Element != null)
				nodeElem.Xaml.Element.AddAnnotation(ctx.XmlNs.CurrentScope);
			foreach (var child in node.Children) {
				var handler = LookupHandler(child.Type);
				if (handler == null) {
					Debug.WriteLine("BAML Handler {0} not implemented.", child.Type);
					continue;
				}
				var elem = handler.Translate(ctx, (BamlNode)child, nodeElem);
				if (elem != null) {
					nodeElem.Children.Add(elem);
					elem.Parent = nodeElem;
				}

				ctx.CancellationToken.ThrowIfCancellationRequested();
			}
			ctx.XmlNs.PopScope();
		}
Пример #4
0
        public XDocument Decompile(ModuleDef module, BamlDocument document, CancellationToken token, BamlDecompilerOptions bamlDecompilerOptions, List <string> assemblyReferences)
        {
            var ctx = XamlContext.Construct(module, document, token, bamlDecompilerOptions);

            var handler = HandlerMap.LookupHandler(ctx.RootNode.Type);
            var elem    = handler.Translate(ctx, ctx.RootNode, null);

            var xaml = new XDocument();

            xaml.Add(elem.Xaml.Element);

            foreach (var pass in rewritePasses)
            {
                token.ThrowIfCancellationRequested();
                pass.Run(ctx, xaml);
            }

            if (assemblyReferences is not null)
            {
                assemblyReferences.AddRange(ctx.Baml.AssemblyIdMap.Select(a => a.Value.AssemblyFullName));
            }

            return(xaml);
        }