diff --git a/app/src/androidTest/kotlin/com/njlabs/showjava/test/DecompilerTestBase.kt b/app/src/androidTest/kotlin/com/njlabs/showjava/test/DecompilerTestBase.kt index 21f4a5e4..cff2210e 100644 --- a/app/src/androidTest/kotlin/com/njlabs/showjava/test/DecompilerTestBase.kt +++ b/app/src/androidTest/kotlin/com/njlabs/showjava/test/DecompilerTestBase.kt @@ -88,6 +88,7 @@ abstract class DecompilerTestBase { fun testDecompiler() { val data = BaseDecompiler.formData(hashMapOf( "shouldIgnoreLibs" to true, + "keepIntermediateFiles" to true, "chunkSize" to 2000, "maxAttempts" to 1, "memoryThreshold" to 80, diff --git a/app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt b/app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt index 747eb722..6e568967 100644 --- a/app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt +++ b/app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt @@ -189,6 +189,7 @@ class DecompilerActivity : BaseActivity() { "maxAttempts" to userPreferences.maxAttempts, "chunkSize" to userPreferences.chunkSize, "memoryThreshold" to userPreferences.memoryThreshold, + "keepIntermediateFiles" to userPreferences.keepIntermediateFiles, "decompiler" to decompiler, "name" to packageInfo.name, "label" to packageInfo.label, diff --git a/app/src/main/kotlin/com/njlabs/showjava/decompilers/BaseDecompiler.kt b/app/src/main/kotlin/com/njlabs/showjava/decompilers/BaseDecompiler.kt index 14b1b639..f7b16f80 100644 --- a/app/src/main/kotlin/com/njlabs/showjava/decompilers/BaseDecompiler.kt +++ b/app/src/main/kotlin/com/njlabs/showjava/decompilers/BaseDecompiler.kt @@ -51,15 +51,17 @@ abstract class BaseDecompiler(val context: Context, val data: Data) { private var id = data.getString("id") private var processNotifier: ProcessNotifier? = null private var runAttemptCount: Int = 0 - protected var outOfMemory: Boolean = false + protected var outOfMemory = false protected val decompiler = data.getString("decompiler") protected val type = PackageInfo.Type.values()[data.getInt("type", 0)] private val maxAttempts = data.getInt("maxAttempts", UserPreferences.DEFAULTS.MAX_ATTEMPTS) private val memoryThreshold = data.getInt("memoryThreshold", 80) - protected val packageName: String = data.getString("name").toString() - protected val packageLabel: String = data.getString("label").toString() + protected val packageName = data.getString("name").toString() + protected val packageLabel = data.getString("label").toString() + + protected val keepIntermediateFiles = data.getBoolean("keepIntermediateFiles", UserPreferences.DEFAULTS.KEEP_INTERMEDIATE_FILES) protected val workingDirectory: File = appStorage.resolve("sources/$packageName/") protected val cacheDirectory: File = appStorage.resolve("sources/.cache/") diff --git a/app/src/main/kotlin/com/njlabs/showjava/decompilers/JarExtractionWorker.kt b/app/src/main/kotlin/com/njlabs/showjava/decompilers/JarExtractionWorker.kt index b4a7e914..bce6a171 100644 --- a/app/src/main/kotlin/com/njlabs/showjava/decompilers/JarExtractionWorker.kt +++ b/app/src/main/kotlin/com/njlabs/showjava/decompilers/JarExtractionWorker.kt @@ -220,7 +220,10 @@ class JarExtractionWorker(context: Context, data: Data) : BaseDecompiler(context .verbose(verbose) dex2jar.exceptionHandler = dexExceptionHandlerMod dex2jar.to(outputJarFiles.resolve("$index.jar")) - outputDexFile.delete() + + if (!keepIntermediateFiles) { + outputDexFile.delete() + } } } } diff --git a/app/src/main/kotlin/com/njlabs/showjava/decompilers/JavaExtractionWorker.kt b/app/src/main/kotlin/com/njlabs/showjava/decompilers/JavaExtractionWorker.kt index 2c729792..92cbfd27 100644 --- a/app/src/main/kotlin/com/njlabs/showjava/decompilers/JavaExtractionWorker.kt +++ b/app/src/main/kotlin/com/njlabs/showjava/decompilers/JavaExtractionWorker.kt @@ -79,7 +79,7 @@ class JavaExtractionWorker(context: Context, data: Data) : BaseDecompiler(contex val jadx = JadxDecompiler(args) jadx.load() jadx.saveSources() - if (dexInputFiles.exists() && dexInputFiles.isDirectory) { + if (dexInputFiles.exists() && dexInputFiles.isDirectory && !keepIntermediateFiles) { dexInputFiles.deleteRecursively() } } @@ -134,11 +134,11 @@ class JavaExtractionWorker(context: Context, data: Data) : BaseDecompiler(contex return exit(e) } - if (outputDexFiles.exists() && outputDexFiles.isDirectory) { + if (outputDexFiles.exists() && outputDexFiles.isDirectory && !keepIntermediateFiles) { outputDexFiles.deleteRecursively() } - if (outputJarFiles.exists() && outputJarFiles.isDirectory) { + if (outputJarFiles.exists() && outputJarFiles.isDirectory && !keepIntermediateFiles) { outputJarFiles.deleteRecursively() } diff --git a/app/src/main/kotlin/com/njlabs/showjava/utils/UserPreferences.kt b/app/src/main/kotlin/com/njlabs/showjava/utils/UserPreferences.kt index 05bd16bc..5cb83573 100644 --- a/app/src/main/kotlin/com/njlabs/showjava/utils/UserPreferences.kt +++ b/app/src/main/kotlin/com/njlabs/showjava/utils/UserPreferences.kt @@ -38,6 +38,7 @@ class UserPreferences(private val prefs: SharedPreferences) { const val SHOW_SYSTEM_APPS = false const val MEMORY_THRESHOLD = 80 const val IGNORE_LIBRARIES = true + const val KEEP_INTERMEDIATE_FILES = false const val CHUNK_SIZE = 500 const val MAX_ATTEMPTS = 2 } @@ -46,6 +47,9 @@ class UserPreferences(private val prefs: SharedPreferences) { val ignoreLibraries: Boolean get() = prefs.getBoolean("ignoreLibraries", DEFAULTS.IGNORE_LIBRARIES) + val keepIntermediateFiles: Boolean + get() = prefs.getBoolean("keepIntermediateFiles", DEFAULTS.KEEP_INTERMEDIATE_FILES) + val customFont: Boolean get() = prefs.getBoolean("customFont", DEFAULTS.CUSTOM_FONT) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c000180..1c37d85f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -177,4 +177,6 @@ An unexpected error occurred An error occurred while loading files JaDX and Fernflower decompilers are available only on android devices running Android 7.0 and above. + Keep intermediate files + Do not delete dex & jar files created during the decompilation diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 055657be..3fd359a0 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -31,6 +31,13 @@ android:summary="@string/ignoreLibrariesPreferenceSummary" android:title="@string/speedUpDecompile" /> + +