コード例 #1
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());
        }
コード例 #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);
     }
 }
コード例 #3
0
ファイル: CILLanguage.cs プロジェクト: mamingxiu/dnExplorer
		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);
			}
		}
コード例 #4
0
		public static bool Write(IDecompilerOutput output, IMemberRef member) {
			var method = member as IMethod;
			if (method != null && method.IsMethod) {
				method.WriteMethodTo(output);
				return true;
			}

			var field = member as IField;
			if (field != null && field.IsField) {
				field.WriteFieldTo(output);
				return true;
			}

			var prop = member as PropertyDef;
			if (prop != null) {
				var dis = new ReflectionDisassembler(output, false, new DisassemblerOptions(new System.Threading.CancellationToken(), null));
				dis.DisassembleProperty(prop, false);
				return true;
			}

			var evt = member as EventDef;
			if (evt != null) {
				var dis = new ReflectionDisassembler(output, false, new DisassemblerOptions(new System.Threading.CancellationToken(), null));
				dis.DisassembleEvent(evt, false);
				return true;
			}

			var type = member as ITypeDefOrRef;
			if (type != null) {
				type.WriteTo(output, ILNameSyntax.TypeName);
				return true;
			}

			return false;
		}
コード例 #5
0
ファイル: Illness.cs プロジェクト: nasser/illness
        public static string ToMSIL(PropertyDefinition propertyDefinition)
        {
            var output       = new StringWriter();
            var disassembler = new ReflectionDisassembler(new PlainTextOutput(output), false, new CancellationToken());

            disassembler.DisassembleProperty(propertyDefinition);
            return(output.ToString());
        }
コード例 #6
0
		public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options)
		{
			ReflectionDisassembler rd = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken);
			rd.DisassembleProperty(property);
			if (property.GetMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(property.GetMethod);
			}
			if (property.SetMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(property.SetMethod);
			}
			foreach (var m in property.OtherMethods) {
				output.WriteLine();
				rd.DisassembleMethod(m);
			}
		}
コード例 #7
0
ファイル: ILLanguage.cs プロジェクト: jorik041/dnSpy
        public static bool Write(ITextOutput output, IMemberRef member)
        {
            var method = member as IMethod;

            if (method != null && method.IsMethod)
            {
                method.WriteMethodTo(output);
                return(true);
            }

            var field = member as IField;

            if (field != null && field.IsField)
            {
                field.WriteFieldTo(output);
                return(true);
            }

            var prop = member as PropertyDef;

            if (prop != null)
            {
                var dis = new ReflectionDisassembler(output, false, new DisassemblerOptions(new System.Threading.CancellationToken(), null));
                dis.DisassembleProperty(prop, false);
                return(true);
            }

            var evt = member as EventDef;

            if (evt != null)
            {
                var dis = new ReflectionDisassembler(output, false, new DisassemblerOptions(new System.Threading.CancellationToken(), null));
                dis.DisassembleEvent(evt, false);
                return(true);
            }

            var type = member as ITypeDefOrRef;

            if (type != null)
            {
                type.WriteTo(output, ILNameSyntax.TypeName);
                return(true);
            }

            return(false);
        }
コード例 #8
0
		public override void DecompileProperty(PropertyDef property, ITextOutput output, DecompilationOptions options)
		{
			ReflectionDisassembler rd = CreateReflectionDisassembler(output, options, property);
			rd.DisassembleProperty(property);
			if (property.GetMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(property.GetMethod);
			}
			if (property.SetMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(property.SetMethod);
			}
			foreach (var m in property.OtherMethods) {
				output.WriteLine();
				rd.DisassembleMethod(m);
			}
		}
コード例 #9
0
        public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options)
        {
            ReflectionDisassembler rd = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken);

            rd.DisassembleProperty(property);
            if (property.GetMethod != null)
            {
                output.WriteLine();
                rd.DisassembleMethod(property.GetMethod);
            }
            if (property.SetMethod != null)
            {
                output.WriteLine();
                rd.DisassembleMethod(property.SetMethod);
            }
            foreach (var m in property.OtherMethods)
            {
                output.WriteLine();
                rd.DisassembleMethod(m);
            }
        }
コード例 #10
0
ファイル: ILDecompiler.cs プロジェクト: wagnerhsu/tools-dnSpy
        public override void Decompile(PropertyDef property, IDecompilerOutput output, DecompilationContext ctx)
        {
            ReflectionDisassembler rd = CreateReflectionDisassembler(output, ctx, property);

            rd.DisassembleProperty(property, addLineSep: true);
            if (property.GetMethod != null)
            {
                output.WriteLine();
                rd.DisassembleMethod(property.GetMethod, true);
            }
            if (property.SetMethod != null)
            {
                output.WriteLine();
                rd.DisassembleMethod(property.SetMethod, true);
            }
            foreach (var m in property.OtherMethods)
            {
                output.WriteLine();
                rd.DisassembleMethod(m, true);
            }
        }
コード例 #11
0
        public static bool Write(IDecompilerOutput output, IMemberRef member)
        {
            if (member is IMethod method && method.IsMethod)
            {
                method.WriteMethodTo(output);
                return(true);
            }

            if (member is IField field && field.IsField)
            {
                field.WriteFieldTo(output);
                return(true);
            }

            if (member is PropertyDef prop)
            {
                var dis = new ReflectionDisassembler(output, false, new DisassemblerOptions(0, new System.Threading.CancellationToken(), null));
                dis.DisassembleProperty(prop, false);
                return(true);
            }

            if (member is EventDef evt)
            {
                var dis = new ReflectionDisassembler(output, false, new DisassemblerOptions(0, new System.Threading.CancellationToken(), null));
                dis.DisassembleEvent(evt, false);
                return(true);
            }

            if (member is ITypeDefOrRef type)
            {
                type.WriteTo(output, ILNameSyntax.TypeName);
                return(true);
            }

            return(false);
        }