void RunDecompiler(string assemblyFile, string fullTypeName, DebuggerTextOutput textOutput, CancellationToken cancellationToken)
        {
            ReaderParameters readerParameters = new ReaderParameters();

            // Use new assembly resolver instance so that the AssemblyDefinitions can be garbage-collected
            // once the code is decompiled.
            readerParameters.AssemblyResolver = new ILSpyAssemblyResolver(Path.GetDirectoryName(assemblyFile));

            ModuleDefinition module         = ModuleDefinition.ReadModule(assemblyFile, readerParameters);
            TypeDefinition   typeDefinition = module.GetType(fullTypeName);

            if (typeDefinition == null)
            {
                throw new InvalidOperationException("Could not find type");
            }
            DecompilerContext context = new DecompilerContext(module);

            context.CancellationToken = cancellationToken;
            AstBuilder astBuilder = new AstBuilder(context);

            astBuilder.AddType(typeDefinition);
            astBuilder.GenerateCode(textOutput);

            // save decompilation data
            decompiledType  = typeDefinition;
            memberLocations = textOutput.MemberLocations;
        }
Exemplo n.º 2
0
        public void DecompileOnDemand(TypeDefinition type)
        {
            if (type == null)
            {
                return;
            }

            if (CheckMappings(type.MetadataToken.ToInt32()))
            {
                return;
            }

            try {
                DecompilerContext context    = new DecompilerContext(type.Module);
                AstBuilder        astBuilder = new AstBuilder(context);
                astBuilder.AddType(type);
                DebuggerTextOutput output = new DebuggerTextOutput(new PlainTextOutput());
                astBuilder.GenerateCode(output);

                /*int token = type.MetadataToken.ToInt32();
                 * var info = new DecompileInformation {
                 *      CodeMappings = astBuilder.CodeMappings,
                 *      LocalVariables = astBuilder.LocalVariables,
                 *      DecompiledMemberReferences = astBuilder.DecompiledMemberReferences
                 * };
                 *
                 * // save the data
                 * DebugInformation.AddOrUpdate(token, info, (k, v) => info);*/
            } catch {
                return;
            }
        }
		public void DecompileOnDemand(TypeDefinition type)
		{
			if (type == null)
				return;
			
			if (CheckMappings(type.MetadataToken.ToInt32()))
				return;
			
			try {
				DecompilerContext context = new DecompilerContext(type.Module);
				AstBuilder astBuilder = new AstBuilder(context);
				astBuilder.AddType(type);
				DebuggerTextOutput output = new DebuggerTextOutput(new PlainTextOutput());
				astBuilder.GenerateCode(output);
				
				/*int token = type.MetadataToken.ToInt32();
				var info = new DecompileInformation {
					CodeMappings = astBuilder.CodeMappings,
					LocalVariables = astBuilder.LocalVariables,
					DecompiledMemberReferences = astBuilder.DecompiledMemberReferences
				};
				
				// save the data
				DebugInformation.AddOrUpdate(token, info, (k, v) => info);*/
			} catch {
				return;
			}
		}
Exemplo n.º 4
0
		void RunDecompiler(string assemblyFile, string fullTypeName, DebuggerTextOutput textOutput, CancellationToken cancellationToken)
		{
			ReaderParameters readerParameters = new ReaderParameters();
			// Use new assembly resolver instance so that the AssemblyDefinitions can be garbage-collected
			// once the code is decompiled.
			readerParameters.AssemblyResolver = new ILSpyAssemblyResolver(Path.GetDirectoryName(assemblyFile));
			
			ModuleDefinition module = ModuleDefinition.ReadModule(assemblyFile, readerParameters);
			TypeDefinition typeDefinition = module.GetType(fullTypeName);
			if (typeDefinition == null)
				throw new InvalidOperationException("Could not find type");
			DecompilerContext context = new DecompilerContext(module);
			context.CancellationToken = cancellationToken;
			AstBuilder astBuilder = new AstBuilder(context);
			astBuilder.AddType(typeDefinition);
			astBuilder.GenerateCode(textOutput);
			
			// save decompilation data
			decompiledType = typeDefinition;
			memberLocations = textOutput.MemberLocations;
		}