public void ProcessFile(object fileObject, Func<bool> isCanceled)
        {
            if (fileObject == null) throw new ArgumentNullException("fileObject");
            var file = fileObject as ApkFile;
            if (file == null)
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));

            var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));

            string arguments = string.Format("-c 4 \"{0}\"", file.FileSystemPath);

            if (ep.Execute(_zipAlignFile, arguments, Path.GetDirectoryName(_zipAlignFile)) == 0) return;

            MessageEngine.AddInformation(this, string.Format("Zipaligning {0}", file.Name));

            arguments = string.Format("-f 4 \"{0}\" \"{1}.tmpzipalign\"", file.FileSystemPath, file.FileSystemPath);

            if (ep.Execute(_zipAlignFile, arguments, Path.GetDirectoryName(_zipAlignFile)) == 0)
            {
                FileUtility.MoveFile(file.FileSystemPath + ".tmpzipalign", file.FileSystemPath);
            }
            else
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_zipAlignFile)));
            }
        }
Esempio n. 2
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));
            }
        }
        public void ProcessFile(object fileObject, Func<bool> isCanceled)
        {
            if (fileObject == null) throw new ArgumentNullException("fileObject");
            var file = fileObject as CompositFile;
            if (file == null)
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));

            foreach (ModPlugIn modPlugIn in CrcsSettings.Current.GetModPlugIns(file.Name))
            {
                if (modPlugIn.ModifyClasses && !file.IsDeCompiled) continue;
                var arguments = new StringBuilder();
                arguments.Append("\"").Append(file.ClassesFolder).Append("\"");
                var apkFile = file as ApkFile;
                if (apkFile != null)
                {
                    if (modPlugIn.ModifyResource && !apkFile.IsDeCoded) continue;
                    arguments.Append(" \"").Append(apkFile.ResourceFolder).Append("\"");
                }

                var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));
                if (
                    ep.Execute(modPlugIn.ProgramFile, arguments.ToString(), Path.GetDirectoryName(modPlugIn.ProgramFile)) !=
                    0)
                {
                    throw new Exception(string.Format("Program {0} failed", Path.GetFileName(modPlugIn.ProgramFile)));
                }
            }
        }
        public void ProcessFile(object fileObject, Func<bool> isCanceled)
        {
            if (fileObject == null) throw new ArgumentNullException("fileObject");
            var file = fileObject as ApkFile;
            if (file == null)
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            if (!file.Project.Properties.ReSignApkFiles) return;

            MessageEngine.AddInformation(this, string.Format("Createing a new signature for {0}", file.Name));

            var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));

            var arguments = new StringBuilder();

            arguments.Append("-jar \"").Append(_signApkFile).Append("\"");
            arguments.Append(" \"").Append(_certificateFile).Append("\"");
            arguments.Append(" \"").Append(_certificateKeyFile).Append("\"");
            arguments.Append(" \"").Append(file.FileSystemPath).Append("\"");
            arguments.Append(" \"").Append(file.FileSystemPath + ".tmpsign").Append("\"");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(file.FileSystemPath)) == 0)
            {
                FileUtility.MoveFile(file.FileSystemPath + ".tmpsign", file.FileSystemPath);
            }
            else
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_signApkFile)));
            }
        }
        public static void InstallFrameworkIfMissing(ApkFile apkFile)
        {
            IEnumerable<string> frameworkFiles = apkFile.Project.Properties.FrameWorkFiles;
            if (frameworkFiles.Count() == 0) return;
            string apkToolFrameWorkTag = apkFile.Project.Properties.ApkToolFrameWorkTag;
            apkToolFrameWorkTag = string.IsNullOrWhiteSpace(apkToolFrameWorkTag)
                                      ? apkFile.Project.Name
                                      : apkToolFrameWorkTag;
            string[] installedFrameworkFiles = Directory.GetFiles(CrcsSettings.Current.ApkToolFrameWorkFolder,
                                                                  "*" + apkToolFrameWorkTag + "*.apk",
                                                                  SearchOption.TopDirectoryOnly);
            if (frameworkFiles.Count() == installedFrameworkFiles.Length) return;

            var ep = new ExecuteProgram((message) => MessageEngine.AddError(null, message));

            foreach (string file in frameworkFiles)
            {
                var arguments = new StringBuilder();
                string apkToolFile = apkFile.Project.Solution.Properties.ApkToolFile;
                arguments.Append("-jar \"").Append(apkToolFile).Append("\"");
                arguments.Append(" if \"").Append(file).Append("\"");
                if (!string.IsNullOrWhiteSpace(apkToolFrameWorkTag))
                {
                    arguments.Append(" ").Append(apkToolFrameWorkTag);
                }

                if (
                    ep.Execute(CrcsSettings.Current.JavaFile, arguments.ToString(), Path.GetDirectoryName(apkToolFile)) !=                    0)
                {
                    throw new Exception(string.Format("Program {0} failed", Path.GetFileName(apkToolFile)));
                }
            }
        }
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as ApkFile;

            if (file == null)
            {
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            }

            if (FolderUtility.Empty(file.ResourceFolder))
            {
                return;
            }
            MessageEngine.AddInformation(this, string.Format("Optimizing png files for {0}", file.Name));
            int allFiles       = 0;
            int optimizedFiles = 0;

            foreach (string pngFile in file.GetPngFilesToOptimize())
            {
                if (isCanceled())
                {
                    return;
                }
                var arguments = new StringBuilder();
                arguments.Append(" -o7 -quiet");
                arguments.Append(" -out \"").Append(pngFile + ".oz").Append("\"");
                arguments.Append(" \"").Append(pngFile).Append("\"");

                var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));

                if (ep.Execute(_optiPngFile, arguments.ToString(), Path.GetDirectoryName(pngFile)) != 0)
                {
                    throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_optiPngFile)));
                }
                if (File.Exists(pngFile + ".oz"))
                {
                    FileUtility.MoveFile(pngFile + ".oz", pngFile);
                    optimizedFiles++;
                }
                allFiles++;
            }
            file.SetPngOptimized();
            MessageEngine.AddInformation(this,
                                         string.Format("\t {0} of {1} png files optimized", optimizedFiles, allFiles));
        }
Esempio n. 7
0
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as ApkFile;

            if (file == null)
            {
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            }

            if (!file.IsDeCoded)
            {
                return;
            }
            MessageEngine.AddInformation(this, string.Format("Encoding resources for {0}", file.Name));

            DecodeHandler.InstallFrameworkIfMissing(file);

            FileUtility.DeleteFile(file.UnsignedFile);
            var ep        = new ExecuteProgram((message) => MessageEngine.AddInformation(this, message));
            var arguments = new StringBuilder();

            arguments.Append("-jar \"").Append(_apkToolFile).Append("\"");
            if (_verbose)
            {
                arguments.Append(" -v");
            }
            arguments.Append(" b -f \"").Append(file.ResourceFolder).Append("\"");
            arguments.Append(" \"").Append(file.UnsignedFile).Append("\"");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(_apkToolFile)) != 0)
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_apkToolFile)));
            }
            //ZipFile.ExtractAll(file.UnsignedFile, file.UnsignedFolder, true);
            using (var zf = new AndroidArchive(file.FileSystemPath, CrcsSettings.Current.OnlyStoreFileTypes))
            {
                zf.MergeZipFile(file.UnsignedFile, true);
                //foreach (string resFile in Directory.GetFiles(file.UnsignedFolder, "*.*", SearchOption.AllDirectories))
                //{
                //    if (resFile.IndexOf(@"\META-INF\", StringComparison.Ordinal) >= 0) continue;
                //    if (resFile.EndsWith("AndroidManifest.xml", StringComparison.OrdinalIgnoreCase)) continue;
                //    zf.Add(resFile, FolderUtility.GetRelativePath(file.UnsignedFolder, resFile));
                //}
            }
        }
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as ApkFile;

            if (file == null)
            {
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            }

            var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));

            string arguments = string.Format("-c 4 \"{0}\"", file.FileSystemPath);

            if (ep.Execute(_zipAlignFile, arguments, Path.GetDirectoryName(_zipAlignFile)) == 0)
            {
                return;
            }

            MessageEngine.AddInformation(this, string.Format("Zipaligning {0}", file.Name));

            arguments = string.Format("-f 4 \"{0}\" \"{1}.tmpzipalign\"", file.FileSystemPath, file.FileSystemPath);

            if (ep.Execute(_zipAlignFile, arguments, Path.GetDirectoryName(_zipAlignFile)) == 0)
            {
                FileUtility.MoveFile(file.FileSystemPath + ".tmpzipalign", file.FileSystemPath);
            }
            else
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_zipAlignFile)));
            }
        }
Esempio n. 9
0
        private string GetVersion(string jarFile)
        {
            var ep = new ExecuteProgram();

            var arguments = new StringBuilder();

            arguments.Append("-jar");
            arguments.Append(" ").Append(jarFile).Append(" -v");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(_smaliFile)) == 0)
            {
                return(ep.Output.Split(' ')[1]);
            }
            return("");
        }
Esempio n. 10
0
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as CompositFile;

            if (file == null)
            {
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            }

            foreach (ModPlugIn modPlugIn in CrcsSettings.Current.GetModPlugIns(file.Name))
            {
                if (modPlugIn.ModifyClasses && !file.IsDeCompiled)
                {
                    continue;
                }
                var arguments = new StringBuilder();
                arguments.Append("\"").Append(file.ClassesFolder).Append("\"");
                var apkFile = file as ApkFile;
                if (apkFile != null)
                {
                    if (modPlugIn.ModifyResource && !apkFile.IsDeCoded)
                    {
                        continue;
                    }
                    arguments.Append(" \"").Append(apkFile.ResourceFolder).Append("\"");
                }


                var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));
                if (
                    ep.Execute(modPlugIn.ProgramFile, arguments.ToString(), Path.GetDirectoryName(modPlugIn.ProgramFile)) !=
                    0)
                {
                    throw new Exception(string.Format("Program {0} failed", Path.GetFileName(modPlugIn.ProgramFile)));
                }
            }
        }
        public static void InstallFrameworkIfMissing(ApkFile apkFile)
        {
            IEnumerable <string> frameworkFiles = apkFile.Project.Properties.FrameWorkFiles;

            if (frameworkFiles.Count() == 0)
            {
                return;
            }
            string apkToolFrameWorkTag = apkFile.Project.Properties.ApkToolFrameWorkTag;

            apkToolFrameWorkTag = string.IsNullOrWhiteSpace(apkToolFrameWorkTag)
                                      ? apkFile.Project.Name
                                      : apkToolFrameWorkTag;
            string[] installedFrameworkFiles = Directory.GetFiles(CrcsSettings.Current.ApkToolFrameWorkFolder,
                                                                  "*" + apkToolFrameWorkTag + "*.apk",
                                                                  SearchOption.TopDirectoryOnly);
            if (frameworkFiles.Count() == installedFrameworkFiles.Length)
            {
                return;
            }

            var ep = new ExecuteProgram((message) => MessageEngine.AddError(null, message));

            foreach (string file in frameworkFiles)
            {
                var    arguments   = new StringBuilder();
                string apkToolFile = apkFile.Project.Solution.Properties.ApkToolFile;
                arguments.Append("-jar \"").Append(apkToolFile).Append("\"");
                arguments.Append(" if \"").Append(file).Append("\"");
                if (!string.IsNullOrWhiteSpace(apkToolFrameWorkTag))
                {
                    arguments.Append(" ").Append(apkToolFrameWorkTag);
                }

                if (
                    ep.Execute(CrcsSettings.Current.JavaFile, arguments.ToString(), Path.GetDirectoryName(apkToolFile)) != 0)
                {
                    throw new Exception(string.Format("Program {0} failed", Path.GetFileName(apkToolFile)));
                }
            }
        }
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as ApkFile;

            if (file == null)
            {
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            }
            if (!file.Project.Properties.ReSignApkFiles)
            {
                return;
            }

            MessageEngine.AddInformation(this, string.Format("Createing a new signature for {0}", file.Name));

            var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));

            var arguments = new StringBuilder();

            arguments.Append("-jar \"").Append(_signApkFile).Append("\"");
            arguments.Append(" \"").Append(_certificateFile).Append("\"");
            arguments.Append(" \"").Append(_certificateKeyFile).Append("\"");
            arguments.Append(" \"").Append(file.FileSystemPath).Append("\"");
            arguments.Append(" \"").Append(file.FileSystemPath + ".tmpsign").Append("\"");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(file.FileSystemPath)) == 0)
            {
                FileUtility.MoveFile(file.FileSystemPath + ".tmpsign", file.FileSystemPath);
            }
            else
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_signApkFile)));
            }
        }
        public void ProcessFile(object fileObject, Func <bool> isCanceled)
        {
            if (fileObject == null)
            {
                throw new ArgumentNullException("fileObject");
            }
            var file = fileObject as ApkFile;

            if (file == null)
            {
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));
            }

            if (file.IsDeCoded)
            {
                return;
            }
            MessageEngine.AddInformation(this, string.Format("Decoding resources for {0}", file.Name));

            InstallFrameworkIfMissing(file);

            var ep        = new ExecuteProgram((message) => MessageEngine.AddInformation(this, message));
            var arguments = new StringBuilder();

            arguments.Append("-jar \"").Append(_apkToolFile).Append("\"");
            if (_verbose)
            {
                arguments.Append(" -v");
            }
            arguments.Append(" d -s -f -t ").Append(file.Project.Properties.ApkToolFrameWorkTag);
            arguments.Append(" \"").Append(file.FileSystemPath).Append("\"");
            arguments.Append(" \"").Append(file.ResourceFolder).Append("\"");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(_apkToolFile)) != 0)
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_apkToolFile)));
            }
        }
        public void ProcessFile(object fileObject, Func<bool> isCanceled)
        {
            if (fileObject == null) throw new ArgumentNullException("fileObject");
            var file = fileObject as ApkFile;
            if (file == null)
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));

            if (FolderUtility.Empty(file.ResourceFolder)) return;
            MessageEngine.AddInformation(this, string.Format("Optimizing png files for {0}", file.Name));
            int allFiles = 0;
            int optimizedFiles = 0;
            foreach (string pngFile in file.GetPngFilesToOptimize())
            {
                if (isCanceled()) return;
                var arguments = new StringBuilder();
                arguments.Append(" -o7 -quiet");
                arguments.Append(" -out \"").Append(pngFile + ".oz").Append("\"");
                arguments.Append(" \"").Append(pngFile).Append("\"");

                var ep = new ExecuteProgram((message) => MessageEngine.AddError(this, message));

                if (ep.Execute(_optiPngFile, arguments.ToString(), Path.GetDirectoryName(pngFile)) != 0)
                {
                    throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_optiPngFile)));
                }
                if (File.Exists(pngFile + ".oz"))
                {
                    FileUtility.MoveFile(pngFile + ".oz", pngFile);
                    optimizedFiles++;
                }
                allFiles++;
            }
            file.SetPngOptimized();
            MessageEngine.AddInformation(this,
                                         string.Format("\t {0} of {1} png files optimized", optimizedFiles, allFiles));
        }
        public void ProcessFile(object fileObject, Func<bool> isCanceled)
        {
            if (fileObject == null) throw new ArgumentNullException("fileObject");
            var file = fileObject as ApkFile;
            if (file == null)
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));

            if (!file.IsDeCoded) return;
            MessageEngine.AddInformation(this, string.Format("Encoding resources for {0}", file.Name));

            DecodeHandler.InstallFrameworkIfMissing(file);

            FileUtility.DeleteFile(file.UnsignedFile);
            var ep = new ExecuteProgram((message) => MessageEngine.AddInformation(this, message));
            var arguments = new StringBuilder();
            arguments.Append("-jar \"").Append(_apkToolFile).Append("\"");
            if (_verbose) arguments.Append(" -v");
            arguments.Append(" b -f \"").Append(file.ResourceFolder).Append("\"");
            arguments.Append(" \"").Append(file.UnsignedFile).Append("\"");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(_apkToolFile)) != 0)
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_apkToolFile)));
            }
            //ZipFile.ExtractAll(file.UnsignedFile, file.UnsignedFolder, true);
            using (var zf = new AndroidArchive(file.FileSystemPath, CrcsSettings.Current.OnlyStoreFileTypes))
            {
                zf.MergeZipFile(file.UnsignedFile, true);
                //foreach (string resFile in Directory.GetFiles(file.UnsignedFolder, "*.*", SearchOption.AllDirectories))
                //{
                //    if (resFile.IndexOf(@"\META-INF\", StringComparison.Ordinal) >= 0) continue;
                //    if (resFile.EndsWith("AndroidManifest.xml", StringComparison.OrdinalIgnoreCase)) continue;
                //    zf.Add(resFile, FolderUtility.GetRelativePath(file.UnsignedFolder, resFile));
                //}
            }
        }
        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));
                        }
                    }
                }
            }
        }
        private string GetVersion(string jarFile)
        {
            var ep = new ExecuteProgram();

            var arguments = new StringBuilder();
            arguments.Append("-jar");
            arguments.Append(" ").Append(jarFile).Append(" -v");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(_smaliFile)) == 0)
            {
                return ep.Output.Split(' ')[1];
            }
            return "";
        }
        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));
            }
        }
        public void ProcessFile(object fileObject, Func<bool> isCanceled)
        {
            if (fileObject == null) throw new ArgumentNullException("fileObject");
            var file = fileObject as ApkFile;
            if (file == null)
                throw new Exception(string.Format("{0} can not handle object of type {1}", GetType().Name,
                                                  fileObject.GetType().Name));

            if (file.IsDeCoded) return;
            MessageEngine.AddInformation(this, string.Format("Decoding resources for {0}", file.Name));

            InstallFrameworkIfMissing(file);

            var ep = new ExecuteProgram((message) => MessageEngine.AddInformation(this, message));
            var arguments = new StringBuilder();
            arguments.Append("-jar \"").Append(_apkToolFile).Append("\"");
            if (_verbose) arguments.Append(" -v");
            arguments.Append(" d -s -f -t ").Append(file.Project.Properties.ApkToolFrameWorkTag);
            arguments.Append(" \"").Append(file.FileSystemPath).Append("\"");
            arguments.Append(" \"").Append(file.ResourceFolder).Append("\"");

            if (ep.Execute(_javaFile, arguments.ToString(), Path.GetDirectoryName(_apkToolFile)) != 0)
            {
                throw new Exception(string.Format("Program {0} failed", Path.GetFileName(_apkToolFile)));
            }
        }
Esempio n. 20
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));
                        }
                    }
                }
            }
        }