Example #1
0
        protected void Recompile(string compositFilePath, string inputFolder, CrcsProject project)
        {
            var ep       = new ExecuteProgram();
            var apiLevel = project.Properties.ApiLevel;

            var arguments = new StringBuilder();

            arguments.Append("-jar \"").Append(_smaliFile).Append("\"");
            arguments.Append(" \"").Append(inputFolder).Append("\"");
            string classesDexFile = Path.Combine(FolderUtility.CreateTempFolder(), "classes.dex");

            arguments.Append(" -o \"").Append(classesDexFile).Append("\"");
            if (_useSmaliApiLevel)
            {
                arguments.Append(" -a ").Append(apiLevel);
            }
            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(classesDexFile)) != 0)
            {
                throw ep.CreateException(Path.GetFileName(_smaliFile));
            }

            // add to program file apk/jar...
            using (var zf = new AndroidArchive(compositFilePath))
            {
                zf.Add(classesDexFile, Path.GetFileName(classesDexFile));
            }
        }
        protected void Decompile(string name, string classesFile, string outputFolder, bool ignoreDecompileErrors, CrcsProject project)
        {
            var ep = new ExecuteProgram();

            string locationOfDependencies = GetLocationOfDependencies(project);
            var apiLevel = project.Properties.ApiLevel;

            bool decompiled = false;
            bool useIgnoreDecompileErrorsFlag = false;
            while (!decompiled)
            {
                string additionalDependencies = project.GetAdditionalDependencies(name).Aggregate("",
                                                                                                  (current, dependency)
                                                                                                  =>
                                                                                                  current +
                                                                                                  (":" + dependency));
                if (additionalDependencies.Length > 0) additionalDependencies = " -c " + additionalDependencies;

                var arguments = new StringBuilder();
                arguments.Append("-Xmx512m -jar \"").Append(_baksmaliFile).Append("\"");
                arguments.Append(locationOfDependencies);
                arguments.Append(" -o \"").Append(outputFolder).Append("\"");
                if (useIgnoreDecompileErrorsFlag) arguments.Append(" -I");
                arguments.Append(" -l -s");
                arguments.Append(additionalDependencies);
                if ((Path.GetExtension(classesFile) ?? "").ToUpperInvariant() == ".ODEX") arguments.Append(" -x");
                arguments.Append(" \"").Append(classesFile).Append("\"");
                if (_useBaksmaliApiLevel)
                {
                    arguments.Append(" -a ").Append(apiLevel);
                }
                if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(classesFile)) == 0)
                {
                    if (useIgnoreDecompileErrorsFlag)
                    {
                        MessageEngine.AddInformation(this, ep.Output);
                    }
                    decompiled = true;
                }
                else
                {
                    if (!FindMissingDependency(name, project, ep.Output))
                    {
                        if (ignoreDecompileErrors)
                        {
                            useIgnoreDecompileErrorsFlag = true;
                        }
                        else
                        {
                            throw ep.CreateException(Path.GetFileName(_baksmaliFile));
                        }
                    }
                }
            }
        }
        protected void Recompile(string compositFilePath, string inputFolder, CrcsProject project)
        {
            var ep = new ExecuteProgram();
            var apiLevel = project.Properties.ApiLevel;

            var arguments = new StringBuilder();
            arguments.Append("-jar \"").Append(_smaliFile).Append("\"");
            arguments.Append(" \"").Append(inputFolder).Append("\"");
            string classesDexFile = Path.Combine(FolderUtility.CreateTempFolder(), "classes.dex");
            arguments.Append(" -o \"").Append(classesDexFile).Append("\"");
            if (_useSmaliApiLevel)
            {
                arguments.Append(" -a ").Append(apiLevel);
            }
            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(classesDexFile)) != 0)
            {
                throw ep.CreateException(Path.GetFileName(_smaliFile));
            }

            // add to program file apk/jar...
            using (var zf = new AndroidArchive(compositFilePath))
            {
                zf.Add(classesDexFile, Path.GetFileName(classesDexFile));
            }
        }
Example #4
0
        protected void Decompile(string name, string classesFile, string outputFolder, bool ignoreDecompileErrors, CrcsProject project)
        {
            var ep = new ExecuteProgram();

            string locationOfDependencies = GetLocationOfDependencies(project);
            var    apiLevel = project.Properties.ApiLevel;

            bool decompiled = false;
            bool useIgnoreDecompileErrorsFlag = false;

            while (!decompiled)
            {
                string additionalDependencies = project.GetAdditionalDependencies(name).Aggregate("",
                                                                                                  (current, dependency)
                                                                                                  =>
                                                                                                  current +
                                                                                                  (":" + dependency));
                if (additionalDependencies.Length > 0)
                {
                    additionalDependencies = " -c " + additionalDependencies;
                }

                var arguments = new StringBuilder();
                arguments.Append("-Xmx512m -jar \"").Append(_baksmaliFile).Append("\"");
                arguments.Append(locationOfDependencies);
                arguments.Append(" -o \"").Append(outputFolder).Append("\"");
                if (useIgnoreDecompileErrorsFlag)
                {
                    arguments.Append(" -I");
                }
                arguments.Append(" -l -s");
                arguments.Append(additionalDependencies);
                if ((Path.GetExtension(classesFile) ?? "").ToUpperInvariant() == ".ODEX")
                {
                    arguments.Append(" -x");
                }
                arguments.Append(" \"").Append(classesFile).Append("\"");
                if (_useBaksmaliApiLevel)
                {
                    arguments.Append(" -a ").Append(apiLevel);
                }
                if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(classesFile)) == 0)
                {
                    if (useIgnoreDecompileErrorsFlag)
                    {
                        MessageEngine.AddInformation(this, ep.Output);
                    }
                    decompiled = true;
                }
                else
                {
                    if (!FindMissingDependency(name, project, ep.Output))
                    {
                        if (ignoreDecompileErrors)
                        {
                            useIgnoreDecompileErrorsFlag = true;
                        }
                        else
                        {
                            throw ep.CreateException(Path.GetFileName(_baksmaliFile));
                        }
                    }
                }
            }
        }