Skip to content

Commit 43ac8fa

Browse files
committed
Add option to keep intermediate files
1 parent 920e2d3 commit 43ac8fa

File tree

8 files changed

+27
-7
lines changed

8 files changed

+27
-7
lines changed

app/src/androidTest/kotlin/com/njlabs/showjava/test/DecompilerTestBase.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ abstract class DecompilerTestBase {
8888
fun testDecompiler() {
8989
val data = BaseDecompiler.formData(hashMapOf(
9090
"shouldIgnoreLibs" to true,
91+
"keepIntermediateFiles" to true,
9192
"chunkSize" to 2000,
9293
"maxAttempts" to 1,
9394
"memoryThreshold" to 80,

app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class DecompilerActivity : BaseActivity() {
189189
"maxAttempts" to userPreferences.maxAttempts,
190190
"chunkSize" to userPreferences.chunkSize,
191191
"memoryThreshold" to userPreferences.memoryThreshold,
192+
"keepIntermediateFiles" to userPreferences.keepIntermediateFiles,
192193
"decompiler" to decompiler,
193194
"name" to packageInfo.name,
194195
"label" to packageInfo.label,

app/src/main/kotlin/com/njlabs/showjava/decompilers/BaseDecompiler.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ abstract class BaseDecompiler(val context: Context, val data: Data) {
5151
private var id = data.getString("id")
5252
private var processNotifier: ProcessNotifier? = null
5353
private var runAttemptCount: Int = 0
54-
protected var outOfMemory: Boolean = false
54+
protected var outOfMemory = false
5555

5656
protected val decompiler = data.getString("decompiler")
5757
protected val type = PackageInfo.Type.values()[data.getInt("type", 0)]
5858
private val maxAttempts = data.getInt("maxAttempts", UserPreferences.DEFAULTS.MAX_ATTEMPTS)
5959
private val memoryThreshold = data.getInt("memoryThreshold", 80)
6060

61-
protected val packageName: String = data.getString("name").toString()
62-
protected val packageLabel: String = data.getString("label").toString()
61+
protected val packageName = data.getString("name").toString()
62+
protected val packageLabel = data.getString("label").toString()
63+
64+
protected val keepIntermediateFiles = data.getBoolean("keepIntermediateFiles", UserPreferences.DEFAULTS.KEEP_INTERMEDIATE_FILES)
6365

6466
protected val workingDirectory: File = appStorage.resolve("sources/$packageName/")
6567
protected val cacheDirectory: File = appStorage.resolve("sources/.cache/")

app/src/main/kotlin/com/njlabs/showjava/decompilers/JarExtractionWorker.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ class JarExtractionWorker(context: Context, data: Data) : BaseDecompiler(context
220220
.verbose(verbose)
221221
dex2jar.exceptionHandler = dexExceptionHandlerMod
222222
dex2jar.to(outputJarFiles.resolve("$index.jar"))
223-
outputDexFile.delete()
223+
224+
if (!keepIntermediateFiles) {
225+
outputDexFile.delete()
226+
}
224227
}
225228
}
226229
}

app/src/main/kotlin/com/njlabs/showjava/decompilers/JavaExtractionWorker.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class JavaExtractionWorker(context: Context, data: Data) : BaseDecompiler(contex
7979
val jadx = JadxDecompiler(args)
8080
jadx.load()
8181
jadx.saveSources()
82-
if (dexInputFiles.exists() && dexInputFiles.isDirectory) {
82+
if (dexInputFiles.exists() && dexInputFiles.isDirectory && !keepIntermediateFiles) {
8383
dexInputFiles.deleteRecursively()
8484
}
8585
}
@@ -134,11 +134,11 @@ class JavaExtractionWorker(context: Context, data: Data) : BaseDecompiler(contex
134134
return exit(e)
135135
}
136136

137-
if (outputDexFiles.exists() && outputDexFiles.isDirectory) {
137+
if (outputDexFiles.exists() && outputDexFiles.isDirectory && !keepIntermediateFiles) {
138138
outputDexFiles.deleteRecursively()
139139
}
140140

141-
if (outputJarFiles.exists() && outputJarFiles.isDirectory) {
141+
if (outputJarFiles.exists() && outputJarFiles.isDirectory && !keepIntermediateFiles) {
142142
outputJarFiles.deleteRecursively()
143143
}
144144

app/src/main/kotlin/com/njlabs/showjava/utils/UserPreferences.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class UserPreferences(private val prefs: SharedPreferences) {
3838
const val SHOW_SYSTEM_APPS = false
3939
const val MEMORY_THRESHOLD = 80
4040
const val IGNORE_LIBRARIES = true
41+
const val KEEP_INTERMEDIATE_FILES = false
4142
const val CHUNK_SIZE = 500
4243
const val MAX_ATTEMPTS = 2
4344
}
@@ -46,6 +47,9 @@ class UserPreferences(private val prefs: SharedPreferences) {
4647
val ignoreLibraries: Boolean
4748
get() = prefs.getBoolean("ignoreLibraries", DEFAULTS.IGNORE_LIBRARIES)
4849

50+
val keepIntermediateFiles: Boolean
51+
get() = prefs.getBoolean("keepIntermediateFiles", DEFAULTS.KEEP_INTERMEDIATE_FILES)
52+
4953
val customFont: Boolean
5054
get() = prefs.getBoolean("customFont", DEFAULTS.CUSTOM_FONT)
5155

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,6 @@
177177
<string name="genericError">An unexpected error occurred</string>
178178
<string name="errorLoadingFiles">An error occurred while loading files</string>
179179
<string name="decompilersUnavailable">JaDX and Fernflower decompilers are available only on android devices running Android 7.0 and above.</string>
180+
<string name="keepIntermediateFiles">Keep intermediate files</string>
181+
<string name="keepIntermediateFilesSummary">Do not delete dex &amp; jar files created during the decompilation</string>
180182
</resources>

app/src/main/res/xml/preferences.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
android:summary="@string/ignoreLibrariesPreferenceSummary"
3232
android:title="@string/speedUpDecompile" />
3333

34+
<SwitchPreference
35+
app:iconSpaceReserved="false"
36+
android:key="keepIntermediateFiles"
37+
android:defaultValue="false"
38+
android:summary="@string/keepIntermediateFilesSummary"
39+
android:title="@string/keepIntermediateFiles" />
40+
3441
</PreferenceCategory>
3542

3643
<PreferenceCategory

0 commit comments

Comments
 (0)