コード例 #1
0
ファイル: DexLanguage.cs プロジェクト: Xtremrules/dot42
        public override void DecompileMethod(ilspy::Mono.Cecil.MethodDefinition method, ICSharpCode.Decompiler.ITextOutput output, DecompilationOptions options)
        {
            var cmethod = GetCompiledMethod(method);

            if ((cmethod != null) && (cmethod.DexMethod != null))
            {
                try
                {
                    var f = new MethodBodyDisassemblyFormatter(cmethod.DexMethod, MapFile);
                    var formatOptions = FormatOptions.EmbedSourceCode | FormatOptions.ShowJumpTargets;
                    if(ShowFullNames) formatOptions |= FormatOptions.FullTypeNames;
                    if(DebugOperandTypes) formatOptions |= FormatOptions.DebugOperandTypes;
                    
                    var s = f.Format(formatOptions);
                    output.Write(s);
                }
                catch (Exception)
                {
                    output.Write("\n\n// Formatting error. Using Fallback.\n\n");
                    FallbackFormatting(output, cmethod);    
                }
                
            }
            else
            {
                output.Write("Method not found in dex");
                output.WriteLine();
            }
        }
コード例 #2
0
ファイル: RLLanguage.cs プロジェクト: Xtremrules/dot42
        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);
        }
コード例 #3
0
ファイル: CachedCompiler.cs プロジェクト: jakesays/dot42
        public void CompileIfRequired(ilspy::Mono.Cecil.AssemblyDefinition assembly, bool stopBeforeGeneratingCode = false)
        {
            if (_compiler != null && _previousAssembly == assembly
            && (_isFullyCompiled || stopBeforeGeneratingCode))
                return;

            CompilationErrors = null;
            _compiler = null;

#if DEBUG
            var framework = Frameworks.Instance.GetBySdkVersion(15);
#else
            var framework = Frameworks.Instance.GetNewestVersion();
#endif
            string frameworkFolder = framework.Folder;
            var refFolders = new List<string> { frameworkFolder };

            var module = new XModule();
            var classLoader = new AssemblyClassLoader(module.OnClassLoaded);
            var resolver = new AssemblyResolver(refFolders, classLoader, module.OnAssemblyLoaded);
            var parameter = new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = resolver,ReadSymbols = true};

            var assemblies = new[] { resolver.Load(assembly.MainModule.FullyQualifiedName, parameter) }.ToList();
            List<AssemblyDefinition> references = new List<AssemblyDefinition>();
            
            if(assembly.MainModule.Name != "dot42.dll")
                references = new[] { resolver.Load(AssemblyConstants.SdkAssemblyName, parameter) }.ToList();
            
            foreach (var a in assemblies)
                references.Remove(a);

            var c = new AssemblyCompiler(CompilationMode.All, assemblies, references, new Table("pkg.name"),
                                         new NameConverter("pkg.name", ""), true, 
                                         new AssemblyClassLoader(file => { }), definition => null,
                                         new DexMethodBodyCompilerCache(), new HashSet<string>(), 
                                         module, _generateSetNextInstructionCode);

            c.StopCompilationBeforeGeneratingCode = stopBeforeGeneratingCode;
            c.StopAtFirstError = false;
            
            try
            {
                c.Compile();
            }
            catch (AggregateException ex)
            {
                CompilationErrors = ex.Flatten().InnerExceptions.Select(e => e.Message.Replace(": ", "\n//      ").Replace("; ", "\n//      &  ")).ToList();
            }

            if (c.MapFile != null)
            {
                c.MapFile.Optimize();
                MapFile = new MapFileLookup(c.MapFile);
            }

            _compiler = c;
            _previousAssembly = assembly;
            _isFullyCompiled = !stopBeforeGeneratingCode;
        }
コード例 #4
0
ファイル: DexInputLanguage.cs プロジェクト: jakesays/dot42
 public override void DecompileMethod(ilspy::Mono.Cecil.MethodDefinition method, ICSharpCode.Decompiler.ITextOutput output, DecompilationOptions options)
 {
     var xMethod = GetXMethodDefinition(method);
     DecompileMethod(xMethod, output);
 }