예제 #1
0
		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;
		}
예제 #2
0
		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;
		}
예제 #3
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 != null)
				assemblyReferences.AddRange(ctx.Baml.AssemblyIdMap.Select(a => a.Value.AssemblyFullName));

			return xaml;
		}