private void DecompileFile(string file) { _globalVariables.CurrentProjectFile.Value = file; string logPath = Path.Combine(Path.GetDirectoryName(file) ?? string.Empty, $"{Path.GetFileNameWithoutExtension(file)}_log.txt"); if (!TryCreateNewLog(logPath)) { return; } if (Apk != null) { Apk.Logging -= VisLog; } Apk = new Apktools( file, GlobalVariables.PathToResources, GlobalVariables.CurrentApktoolPath ); Apk.Logging += VisLog; if (!Apk.HasJava()) { MessBox.ShowDial(StringResources.JavaNotFoundError, StringResources.ErrorLower); return; } ClearVisLog(); bool success = false; LoadingWindow.ShowWindow( beforeStarting: () => IsBusy = true, threadActions: source => success = GlobalVariables.AppSettings.OnlyResources ? Apk.Decompile(options: "-s") : Apk.Decompile(), finishActions: () => { IsBusy = false; VisLog(LogLine); VisLog(StringResources.Finished); VisLog(LogLine); if (GlobalVariables.AppSettings.ShowNotifications) { NotificationService.Instance.ShowMessage(StringResources.DecompilationFinished); } if (success) { Application.Current.Dispatcher.InvokeAction(() => LoadFolder(_globalVariables.CurrentProjectFolder.Value, true)); } }, cancelVisibility: Visibility.Collapsed, ownerWindow: _window ); }
private void BuildCommand_Execute() { if (Apk == null) { return; } if (!Apk.HasJava()) { MessBox.ShowDial(StringResources.JavaNotFoundError, StringResources.ErrorLower); return; } ClearVisLog(); bool success = false; var errors = new List <Error>(); LoadingWindow.ShowWindow( beforeStarting: () => IsBusy = true, threadActions: source => success = Apk.Compile(out errors), finishActions: () => { IsBusy = false; VisLog(LogLine); VisLog(success ? StringResources.Finished : StringResources.ErrorWhileCompiling); VisLog(LogLine); if (GlobalVariables.AppSettings.ShowNotifications) { NotificationService.Instance.ShowMessage(StringResources.CompilationFinished); } if (!success && errors.Any(error => error.Type != Error.ErrorType.None)) { if (MessBox.ShowDial("Обнаружены ошибки. Попробовать исправить?", "", MessBox.MessageButtons.Yes, MessBox.MessageButtons.No) == MessBox.MessageButtons.Yes) { Apktools.FixErrors(errors); BuildCommand_Execute(); } } else { VisLog(StringResources.FileIsSituatedIn + " " + Apk.NewApk); } RaiseCommandsCanExecute(); }, cancelVisibility: Visibility.Collapsed, ownerWindow: _window ); }
private void InstallFramework(string fileName) { using (BusyDisposable()) { var apktool = new Apktools(null, GlobalVariables.PathToResources, Path.Combine(GlobalVariables.PathToApktoolVersions, $"apktool_{GlobalVariables.AppSettings.ApktoolVersion}.jar")); if (!apktool.HasJava()) { MessBox.ShowDial(StringResources.JavaNotFoundError, StringResources.ErrorLower); return; } apktool.Logging += VisLog; apktool.InstallFramework(fileName); apktool.Logging -= VisLog; } }
private void CreateMoreFolderDictionaries(string sourceFolder, string modifiedFolder, string resultFolder) { if (IOUtils.FolderExists(resultFolder)) { IOUtils.DeleteFolder(resultFolder); } IOUtils.CreateFolder(resultFolder); List <Apktools> sourceApktools = Directory.EnumerateFiles(sourceFolder, "*.apk") .Select(file => new Apktools(file, GlobalVariables.PathToResources, GlobalVariables.CurrentApktoolPath)) .ToList(); List <Apktools> modifiedApktools = Directory.EnumerateFiles(modifiedFolder, "*.apk") .Select(file => new Apktools(file, GlobalVariables.PathToResources, GlobalVariables.CurrentApktoolPath)) .ToList(); Log("Decompiling files:"); ProgressValue.Value = 0; ProgressMax.Value = sourceApktools.Count + modifiedApktools.Count; for (int i = 0; i < sourceApktools.Count; i++) { ProgressValue.Value++; Log(" -- " + sourceApktools[i].FileName); if (!sourceApktools[i].Decompile(true, false)) { Log("Error while decompiling!"); sourceApktools.RemoveAt(i); i--; } } for (int i = 0; i < modifiedApktools.Count; i++) { ProgressValue.Value++; Log(" -- " + modifiedApktools[i].FileName); if (!modifiedApktools[i].Decompile(true, false)) { Log("Error while decompiling!"); modifiedApktools.RemoveAt(i); i--; } } Log(); Log("Creating dictionaries:"); int progressState = 1; int progressMax = sourceApktools.Count; foreach (var apktool in sourceApktools) { try { Log($" -- ({progressState++} из {progressMax}) {apktool.FileName}", false); Apktools modifiedApktool = modifiedApktools.Find(a => a.Manifest.Package == apktool.Manifest.Package); if (modifiedApktool == null) { Log(" - skipped"); continue; } CreateOneFolderDictionary(apktool.FolderOfProject, modifiedApktool.FolderOfProject, Path.Combine(resultFolder, apktool.Manifest.Package), false); Log(" - created"); } catch (Exception ex) { // ReSharper disable once LocalizableElement MessageBox.Show($"Message: {ex.Message}\nStackTrace: {ex.StackTrace}"); Log(" - error"); } } }
private void LoadFolder(string folderPath, bool haveLogger = false) { if (string.IsNullOrEmpty(folderPath)) { return; } if (!haveLogger) { string logPath = folderPath + "_log.txt"; if (!TryCreateNewLog(logPath)) { return; } } _globalVariables.CurrentProjectFile.Value = folderPath + ".apk"; if (Apk != null) { Apk.Logging -= VisLog; } Apk = new Apktools( _globalVariables.CurrentProjectFile.Value, GlobalVariables.PathToResources, GlobalVariables.CurrentApktoolPath ); Apk.Logging += VisLog; FilesFilesTreeViewModel.Children.Clear(); FilesFilesTreeViewModel.Children.Add( new FilesTreeViewNodeModel { Name = StringResources.AllXml, Options = new Options(fullPath: string.Empty, isFolder: false, isImageLoaded: true), DoubleClicked = LoadXmlFiles, Image = GlobalResources.IconUnknownFile } ); FilesFilesTreeViewModel.Children.Add( new FilesTreeViewNodeModel { Name = StringResources.AllSmali, Options = new Options(fullPath: string.Empty, isFolder: false, isImageLoaded: true), DoubleClicked = LoadSmaliFiles, Image = GlobalResources.IconUnknownFile } ); LoadingProcessWindow.ShowWindow( beforeStarting: () => IsBusy = true, threadActions: (cts, invoker) => { invoker.IsIndeterminate = true; invoker.ProcessMax = Directory.EnumerateFiles(folderPath, "*", SearchOption.AllDirectories).Count(); invoker.IsIndeterminate = false; CommonUtils.LoadFilesToTreeView(Application.Current.Dispatcher, folderPath, FilesFilesTreeViewModel, GlobalVariables.AppSettings.EmptyFolders, cts, () => invoker.ProcessValue++); }, finishActions: () => { IsBusy = false; FilesFilesTreeViewModel.Children.ForEach(ImageUtils.LoadIconForItem); RaiseCommandsCanExecute(); }, ownerWindow: _window ); }