public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); PEFile module = property.ParentModule.PEFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleProperty(module, (PropertyDefinitionHandle)property.MetadataToken); var pd = module.Metadata.GetPropertyDefinition((PropertyDefinitionHandle)property.MetadataToken); var accessors = pd.GetAccessors(); if (!accessors.Getter.IsNil) { output.WriteLine(); dis.DisassembleMethod(module, accessors.Getter); } if (!accessors.Setter.IsNil) { output.WriteLine(); dis.DisassembleMethod(module, accessors.Setter); } /*foreach (var m in property.OtherMethods) { * output.WriteLine(); * dis.DisassembleMethod(m); * }*/ }
public override void DecompileEvent(IEvent ev, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); PEFile module = ev.ParentModule.PEFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleEvent(module, (EventDefinitionHandle)ev.MetadataToken); var ed = ((MetadataReader)module.Metadata).GetEventDefinition((EventDefinitionHandle)ev.MetadataToken); var accessors = ed.GetAccessors(); if (!accessors.Adder.IsNil) { output.WriteLine(); dis.DisassembleMethod(module, accessors.Adder); } if (!accessors.Remover.IsNil) { output.WriteLine(); dis.DisassembleMethod(module, accessors.Remover); } if (!accessors.Raiser.IsNil) { output.WriteLine(); dis.DisassembleMethod(module, accessors.Raiser); } /*foreach (var m in ev.OtherMethods) { * output.WriteLine(); * dis.DisassembleMethod(m); * }*/ }
static CSharpDecompiler CreateDecompiler(PEFile module, DecompilationOptions options) { CSharpDecompiler decompiler = new CSharpDecompiler(module, module.GetAssemblyResolver(), options.DecompilerSettings); decompiler.CancellationToken = options.CancellationToken; return(decompiler); }
public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); PEFile module = field.ParentModule.PEFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleField(module, (FieldDefinitionHandle)field.MetadataToken); }
public override void DecompileNamespace(string nameSpace, IEnumerable <ITypeDefinition> types, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); PEFile module = types.FirstOrDefault()?.ParentModule.PEFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleNamespace(nameSpace, module, types.Select(t => (TypeDefinitionHandle)t.MetadataToken)); }
public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); PEFile module = type.ParentModule.PEFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DebugInfo = module.GetDebugInfoOrNull(); dis.DisassembleType(module, (TypeDefinitionHandle)type.MetadataToken); }
CSharpDecompiler CreateDecompiler(PEFile module, DecompilationOptions options) { CSharpDecompiler decompiler = new CSharpDecompiler(module, module.GetAssemblyResolver(), options.DecompilerSettings); decompiler.CancellationToken = options.CancellationToken; while (decompiler.AstTransforms.Count > transformCount) { decompiler.AstTransforms.RemoveAt(decompiler.AstTransforms.Count - 1); } return(decompiler); }
internal static void AddBaseTypes(SharpTreeNodeCollection children, PEFile module, ITypeDefinition typeDefinition) { TypeDefinitionHandle handle = (TypeDefinitionHandle)typeDefinition.MetadataToken; DecompilerTypeSystem typeSystem = new DecompilerTypeSystem(module, module.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached); var t = typeSystem.MainModule.ResolveEntity(handle) as ITypeDefinition; foreach (var td in t.GetAllBaseTypeDefinitions().Reverse().Skip(1)) { if (t.Kind != TypeKind.Interface || t.Kind == td.Kind) { children.Add(new BaseTypesEntryNode(td)); } } }
CSharpDecompiler CreateDecompiler(PEFile module, DecompilationOptions options) { CSharpDecompiler decompiler = new CSharpDecompiler(module, module.GetAssemblyResolver(), options.DecompilerSettings); decompiler.CancellationToken = options.CancellationToken; decompiler.DebugInfoProvider = module.GetDebugInfoOrNull(); while (decompiler.AstTransforms.Count > transformCount) { decompiler.AstTransforms.RemoveAt(decompiler.AstTransforms.Count - 1); } if (options.EscapeInvalidIdentifiers) { decompiler.AstTransforms.Add(new EscapeInvalidIdentifiers()); } return(decompiler); }
ITypeDefinition TryResolve(PEFile module, EntityHandle handle, IType type, bool mayRetry = true) { DecompilerTypeSystem typeSystem = new DecompilerTypeSystem(module, module.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached); var t = typeSystem.MainModule.ResolveEntity(handle) as ITypeDefinition; if (t != null) { showExpander = t.DirectBaseTypes.Any(); var other = t.ParentModule.PEFile.GetTypeSystemWithCurrentOptionsOrNull(); Debug.Assert(other != null); t = other.FindType(t.FullTypeName).GetDefinition(); } else { showExpander = mayRetry; } RaisePropertyChanged(nameof(Text)); RaisePropertyChanged(nameof(ShowExpander)); return(t); }
public DecompilerTypeSystem ConstructTypeSystem(PEFile module) { return(new DecompilerTypeSystem(module, module.GetAssemblyResolver(assemblyListSnapshot, loadOnDemand: false))); }