Esempio n. 1
0
        public override void DecompileMethod(ilspy::Mono.Cecil.MethodDefinition method, ITextOutput output, DecompilationOptions options)
        {
            var xMethod = GetXMethodDefinition(method);
            var ilMethod = xMethod as XBuilder.ILMethodDefinition;

            CompiledMethod cmethod;

            if (ilMethod == null || !ilMethod.OriginalMethod.HasBody)
            {
                output.Write("");
                output.WriteLine("// not an il method or method without body.");
                return;
            }
            
            var methodSource = new MethodSource(xMethod, ilMethod.OriginalMethod);
            var target = (DexTargetPackage) AssemblyCompiler.TargetPackage;
            var dMethod = (MethodDefinition)xMethod.GetReference(target);
            DexMethodBodyCompiler.TranslateToRL(AssemblyCompiler, target, methodSource, dMethod, GenerateSetNextInstructionCode, out cmethod);

            var rlBody = cmethod.RLBody;

            // Optimize RL code
            string lastApplied = RLTransformations.Transform(target.DexFile, rlBody, StopOptimizationAfter == -1?int.MaxValue:StopOptimizationAfter);
            if(lastApplied != null)
                output.WriteLine("// Stop after " + lastApplied);

            PrintMethod(cmethod, output, options);
        }
Esempio n. 2
0
        private void DecompileMethod(XMethodDefinition xMethod, ITextOutput output, int indentation=0)
        {
            var indent = new string(Enumerable.Repeat('\t', indentation).ToArray());

            var ilMethod = xMethod as XBuilder.ILMethodDefinition;
            if (ilMethod == null || !ilMethod.OriginalMethod.HasBody)
            {
                output.Write(indent);
                output.WriteLine("// not an il method or method without body.");
                return;
            }

            var methodSource = new MethodSource(xMethod, ilMethod.OriginalMethod);
            var node = MethodBodyCompiler.CreateOptimizedAst(AssemblyCompiler, methodSource, GenerateSetNextInstructionCode, StopConversion);

            if (StopConversion != StopAstConversion.None)
            {
                output.Write(indent);
                output.Write("// Stop " + StopConversion);
                output.WriteLine();
                output.WriteLine();
            }

            var bridge = new TextOutputBridge(output);
            
            for(int i = 0; i < indentation; ++i)
                bridge.Indent();

            FormattingOptions formattingOptions;
            if (StopConversion == StopAstConversion.AfterILConversion || !BreakExpressionLines)
                formattingOptions = FormattingOptions.Default;
            else
                formattingOptions = FormattingOptions.BreakExpressions;
            
            if(!ShowFullNames)
                formattingOptions |= FormattingOptions.SimpleNames;
            if(ShowHasSeqPoint)
                formattingOptions |= FormattingOptions.ShowHasSeqPoint;

            node.WriteTo(bridge, formattingOptions);

            for (int i = 0; i < indentation; ++i)
                bridge.Unindent();

        }