public static IDecompilerTypeSystem GetSpecializingTypeSystem(this IDecompilerTypeSystem typeSystem, ITypeResolveContext decompilationContext) { IReadOnlyList <IType> classTypeParameters = null; IReadOnlyList <IType> methodTypeParameters = null; if (decompilationContext.CurrentTypeDefinition != null && decompilationContext.CurrentTypeDefinition.TypeParameterCount > 0) { classTypeParameters = decompilationContext.CurrentTypeDefinition.TypeArguments; } IMethod method = decompilationContext.CurrentMember as IMethod; if (method != null && method.TypeParameters.Count > 0) { methodTypeParameters = method.TypeArguments; } if (typeSystem is SpecializingDecompilerTypeSystem) { typeSystem = ((SpecializingDecompilerTypeSystem)typeSystem).Context; } if ((classTypeParameters != null && classTypeParameters.Count > 0) || (methodTypeParameters != null && methodTypeParameters.Count > 0)) { return(new SpecializingDecompilerTypeSystem(typeSystem, new TypeParameterSubstitution(classTypeParameters, methodTypeParameters))); } else { return(typeSystem); } }
public CallBuilder(ExpressionBuilder expressionBuilder, IDecompilerTypeSystem typeSystem, DecompilerSettings settings) { this.expressionBuilder = expressionBuilder; this.resolver = expressionBuilder.resolver; this.settings = settings; this.typeSystem = typeSystem; }
public ILTransformContext(ILFunction function, IDecompilerTypeSystem typeSystem, DecompilerSettings settings = null) { this.Function = function ?? throw new ArgumentNullException(nameof(function)); this.TypeSystem = typeSystem ?? throw new ArgumentNullException(nameof(typeSystem)); this.Settings = settings ?? new DecompilerSettings(); Stepper = new Stepper(); }
XamlContext(IDecompilerTypeSystem typeSystem) { TypeSystem = typeSystem; NodeMap = new Dictionary <BamlRecord, BamlBlockNode>(); XmlNs = new XmlnsDictionary(); GeneratedMembers = new List <EntityHandle>(); XClassNames = new List <string>(); }
internal TransformContext(IDecompilerTypeSystem typeSystem, DecompileRun decompileRun, ITypeResolveContext decompilationContext, TypeSystemAstBuilder typeSystemAstBuilder) { this.TypeSystem = typeSystem; this.DecompileRun = decompileRun; this.decompilationContext = decompilationContext; this.TypeSystemAstBuilder = typeSystemAstBuilder; this.CancellationToken = decompileRun.CancellationToken; this.Settings = decompileRun.Settings; }
public StatementBuilder(IDecompilerTypeSystem typeSystem, ITypeResolveContext decompilationContext, IMethod currentMethod, ILFunction currentFunction, DecompilerSettings settings, CancellationToken cancellationToken) { Debug.Assert(typeSystem != null && decompilationContext != null && currentMethod != null); this.exprBuilder = new ExpressionBuilder(typeSystem, decompilationContext, settings, cancellationToken); this.currentFunction = currentFunction; this.currentMethod = currentMethod; this.settings = settings; this.cancellationToken = cancellationToken; }
BamlContext(IDecompilerTypeSystem typeSystem) { this.TypeSystem = typeSystem; KnownThings = new KnownThings(typeSystem); AssemblyIdMap = new Dictionary <ushort, AssemblyInfoRecord>(); AttributeIdMap = new Dictionary <ushort, AttributeInfoRecord>(); StringIdMap = new Dictionary <ushort, StringInfoRecord>(); TypeIdMap = new Dictionary <ushort, TypeInfoRecord>(); }
internal BlockBuilder(Mono.Cecil.Cil.MethodBody body, IDecompilerTypeSystem typeSystem, Dictionary <Mono.Cecil.Cil.ExceptionHandler, ILVariable> variableByExceptionHandler) { Debug.Assert(body != null); Debug.Assert(typeSystem != null); Debug.Assert(variableByExceptionHandler != null); this.body = body; this.typeSystem = typeSystem; this.variableByExceptionHandler = variableByExceptionHandler; }
public RecordDecompiler(IDecompilerTypeSystem dts, ITypeDefinition recordTypeDef, CancellationToken cancellationToken) { this.typeSystem = dts; this.recordTypeDef = recordTypeDef; this.cancellationToken = cancellationToken; this.baseClass = recordTypeDef.DirectBaseTypes.FirstOrDefault(b => b.Kind == TypeKind.Class); this.isInheritedRecord = !baseClass.IsKnownType(KnownTypeCode.Object); DetectAutomaticProperties(); this.orderedMembers = DetectMemberOrder(recordTypeDef, backingFieldToAutoProperty); }
public SpecializingDecompilerTypeSystem(IDecompilerTypeSystem context, TypeParameterSubstitution substitution) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (substitution == null) { throw new ArgumentNullException(nameof(substitution)); } this.context = context; this.substitution = substitution; }
public static XamlContext Construct(IDecompilerTypeSystem typeSystem, BamlDocument document, CancellationToken token, BamlDecompilerOptions bamlDecompilerOptions) { var ctx = new XamlContext(typeSystem); ctx.CancellationToken = token; ctx.BamlDecompilerOptions = bamlDecompilerOptions ?? new BamlDecompilerOptions(); ctx.Baml = BamlContext.ConstructContext(typeSystem, document, token); ctx.RootNode = BamlNode.Parse(document, token); ctx.BuildPIMappings(document); ctx.BuildNodeMap(ctx.RootNode as BamlBlockNode); return(ctx); }
public TextTokenWriter(ITextOutput output, DecompilerSettings settings, IDecompilerTypeSystem typeSystem) { if (output == null) { throw new ArgumentNullException(nameof(output)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (typeSystem == null) { throw new ArgumentNullException(nameof(typeSystem)); } this.output = output; this.settings = settings; this.typeSystem = typeSystem; }
public static BamlContext ConstructContext(IDecompilerTypeSystem typeSystem, BamlDocument document, CancellationToken token) { var ctx = new BamlContext(typeSystem); foreach (var record in document) { token.ThrowIfCancellationRequested(); if (record is AssemblyInfoRecord assemblyInfo) { if (assemblyInfo.AssemblyId == ctx.AssemblyIdMap.Count) { ctx.AssemblyIdMap.Add(assemblyInfo.AssemblyId, assemblyInfo); } } else if (record is AttributeInfoRecord attrInfo) { if (attrInfo.AttributeId == ctx.AttributeIdMap.Count) { ctx.AttributeIdMap.Add(attrInfo.AttributeId, attrInfo); } } else if (record is StringInfoRecord strInfo) { if (strInfo.StringId == ctx.StringIdMap.Count) { ctx.StringIdMap.Add(strInfo.StringId, strInfo); } } else if (record is TypeInfoRecord typeInfo) { if (typeInfo.TypeId == ctx.TypeIdMap.Count) { ctx.TypeIdMap.Add(typeInfo.TypeId, typeInfo); } } } return(ctx); }
//private static EcsFile GenerateFile(TypeDefinition t, CSharpDecompiler codeDomBuilder, string attributeString, OutputMode mode, string ext) //{ // var sourceRes = t.CustomAttributes.SingleOrDefault(x => x.AttributeType.Name == "Custom" + attributeString + "File"); // var sourceAtt = t.CustomAttributes.SingleOrDefault(x => x.AttributeType.Name == "Custom" + attributeString); // if (sourceRes != null) { // var sourceName = t.Name + ext; // sourceName = (string)sourceRes.ConstructorArguments[0].Value; // var sourceContent = EmbeddedFileLoader.GetResourceFile(sourceName, t.Module); // return new EcsFile(sourceName, sourceContent); // } // if (sourceAtt != null) { // var sourceContent = (string)sourceAtt.ConstructorArguments[0].Value; // return new EcsFile(t.Name + ext, sourceContent); // } // return new EcsFile(t.Name + ext, WriteType(codeDomBuilder, mode)); //} string WriteCode(DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem, OutputMode mode) { //syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); var ms = new MemoryStream(); using (StreamWriter w = new StreamWriter(ms)) { //codeDomBuilder.GenerateCode(new PlainTextOutput(w), mode); TokenWriter tokenWriter = new TextTokenWriter(new PlainTextOutput(w), settings, typeSystem) { FoldBraces = settings.FoldBraces, ExpandMemberDefinitions = settings.ExpandMemberDefinitions }; //syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, settings.CSharpFormattingOptions)); syntaxTree.AcceptVisitor(new COutputVisitor(tokenWriter, settings.CSharpFormattingOptions, mode)); w.Flush(); ms.Position = 0; var sr = new StreamReader(ms); var myStr = sr.ReadToEnd(); return(myStr); } }
public XDocument Decompile(IDecompilerTypeSystem typeSystem, BamlDocument document, CancellationToken token, BamlDecompilerOptions bamlDecompilerOptions, List <string> assemblyReferences) { var ctx = XamlContext.Construct(typeSystem, 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); }
void WriteCode(ITextOutput output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) { syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); output.IndentationString = settings.CSharpFormattingOptions.IndentationString; TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem); if (output is ISmartTextOutput highlightingOutput) { tokenWriter = new CSharpHighlightingTokenWriter(tokenWriter, highlightingOutput); } syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, settings.CSharpFormattingOptions)); }
void WriteCode(ITextOutput output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) { syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem) { FoldBraces = settings.FoldBraces, ExpandMemberDefinitions = settings.ExpandMemberDefinitions }; if (output is ISmartTextOutput highlightingOutput) { tokenWriter = new CSharpHighlightingTokenWriter(tokenWriter, highlightingOutput); } syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, settings.CSharpFormattingOptions)); }
static void WriteCode(TextWriter output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) { syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); TokenWriter tokenWriter = new TextWriterTokenWriter(output); tokenWriter = TokenWriter.WrapInWriterThatSetsLocationsInAST(tokenWriter); syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, settings.CSharpFormattingOptions)); }
void WriteCode(ITextOutput output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) { syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); var outputFormatter = new TextTokenWriter(output, settings, typeSystem) { FoldBraces = settings.FoldBraces }; var formattingPolicy = settings.CSharpFormattingOptions; syntaxTree.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy)); }
XamlContext(IDecompilerTypeSystem typeSystem) { TypeSystem = typeSystem; NodeMap = new Dictionary <BamlRecord, BamlBlockNode>(); XmlNs = new XmlnsDictionary(); }