public IList<string> Decompile(ModuleDef module, byte[] data, CancellationToken token, BamlDecompilerOptions bamlDecompilerOptions, Stream output, XamlOutputOptions outputOptions) { var doc = BamlReader.ReadDocument(new MemoryStream(data), token); var asmRefs = new List<string>(); var xaml = new XamlDecompiler().Decompile(module, doc, token, bamlDecompilerOptions, asmRefs); var resData = Encoding.UTF8.GetBytes(new XamlOutputCreator(outputOptions).CreateText(xaml)); output.Write(resData, 0, resData.Length); return asmRefs; }
public static XamlContext Construct(ModuleDef module, BamlDocument document, CancellationToken token, BamlDecompilerOptions bamlDecompilerOptions) { var ctx = new XamlContext(module); ctx.CancellationToken = token; ctx.BamlDecompilerOptions = bamlDecompilerOptions ?? BamlDecompilerOptions.CreateCSharp(); 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; }
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 != null) assemblyReferences.AddRange(ctx.Baml.AssemblyIdMap.Select(a => a.Value.AssemblyFullName)); return xaml; }