Ejemplo n.º 1
0
        public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options)
        {
            var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken);

            dis.DisassembleType(type);
            NotifyDecompilationFinished(dis);
        }
Ejemplo n.º 2
0
 void DoDisassemble(IDnlibDef item, ITextOutput output, ReflectionDisassembler disassembler)
 {
     if (item is ModuleDef)
     {
         var module = (ModuleDef)item;
         disassembler.WriteAssemblyReferences(module);
         if (module.Assembly != null)
         {
             disassembler.WriteAssemblyHeader(module.Assembly);
         }
         output.WriteLine();
         disassembler.WriteModuleHeader(module);
     }
     else if (item is TypeDef)
     {
         disassembler.DisassembleType((TypeDef)item);
     }
     else if (item is MethodDef)
     {
         disassembler.DisassembleMethod((MethodDef)item);
     }
     else if (item is FieldDef)
     {
         disassembler.DisassembleField((FieldDef)item);
     }
     else if (item is PropertyDef)
     {
         disassembler.DisassembleProperty((PropertyDef)item);
     }
     else if (item is EventDef)
     {
         disassembler.DisassembleEvent((EventDef)item);
     }
 }
Ejemplo n.º 3
0
        public static string Disassemble <T>(this T member)
            where T : class, IMemberDefinition
        {
            var writer = new PlainTextOutput();
            var dasm   = new ReflectionDisassembler(writer);

            if (typeof(T) == typeof(EventDefinition))
            {
                dasm.DisassembleEvent(member as EventDefinition);
            }
            else if (typeof(T) == typeof(FieldDefinition))
            {
                dasm.DisassembleField(member as FieldDefinition);
            }
            else if (typeof(T) == typeof(PropertyDefinition))
            {
                dasm.DisassembleProperty(member as PropertyDefinition);
            }
            else if (typeof(T) == typeof(MethodDefinition))
            {
                dasm.DisassembleMethod(member as MethodDefinition);
            }
            else if (typeof(T) == typeof(TypeDefinition))
            {
                dasm.DisassembleType(member as TypeDefinition);
            }
            else
            {
                throw new NotImplementedException($"the type {typeof(T).FullName} cannot be disassembled.");
            }

            return(writer.ToString());
        }
Ejemplo n.º 4
0
        public void Decompile(Stream assemblyStream, TextWriter codeWriter)
        {
            var assembly = AssemblyDefinition.ReadAssembly(assemblyStream);
            //#if DEBUG
            //assembly.Write(@"d:\Temp\assembly\" + System.DateTime.Now.Ticks + "-il.dll");
            //#endif

            var output = new CustomizableIndentPlainTextOutput(codeWriter)
            {
                IndentationString = "    "
            };
            var disassembler = new ReflectionDisassembler(output, false, CancellationToken.None);

            foreach (TypeDefinition td in assembly.MainModule.Types)
            {
                // Skip a large helper class generated by Peachpie
                if (td.Name == Pchp.Core.Context.ScriptInfo.ScriptTypeName)
                {
                    continue;
                }

                disassembler.DisassembleType(td);
                output.WriteLine();
            }
        }
Ejemplo n.º 5
0
		void DoDisassemble(IDnlibDef item, ITextOutput output, ReflectionDisassembler disassembler) {
			if (item is ModuleDef) {
				var module = (ModuleDef)item;
				disassembler.WriteAssemblyReferences(module);
				if (module.Assembly != null)
					disassembler.WriteAssemblyHeader(module.Assembly);
				output.WriteLine();
				disassembler.WriteModuleHeader(module);
			}
			else if (item is TypeDef) {
				disassembler.DisassembleType((TypeDef)item);
			}
			else if (item is MethodDef) {
				disassembler.DisassembleMethod((MethodDef)item);
			}
			else if (item is FieldDef) {
				disassembler.DisassembleField((FieldDef)item);
			}
			else if (item is PropertyDef) {
				disassembler.DisassembleProperty((PropertyDef)item);
			}
			else if (item is EventDef) {
				disassembler.DisassembleEvent((EventDef)item);
			}
		}
Ejemplo n.º 6
0
        public static string ToMSIL(TypeDefinition typeDefinition)
        {
            var output       = new StringWriter();
            var disassembler = new ReflectionDisassembler(new PlainTextOutput(output), false, new CancellationToken());

            disassembler.DisassembleType(typeDefinition);
            return(output.ToString());
        }
Ejemplo n.º 7
0
		public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options)
		{
			var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken);
			dis.DisassembleType(type);
		}