Skip to content

Commit

Permalink
Add option to keep intermediate files
Browse files Browse the repository at this point in the history
  • Loading branch information
niranjan94 committed Dec 27, 2018
1 parent 920e2d3 commit 43ac8fa
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7 deletions.
Expand Up @@ -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,
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -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/")
Expand Down
Expand Up @@ -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()
}
}
}
}
Expand Down
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}

Expand Down
Expand Up @@ -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
}
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -177,4 +177,6 @@
<string name="genericError">An unexpected error occurred</string>
<string name="errorLoadingFiles">An error occurred while loading files</string>
<string name="decompilersUnavailable">JaDX and Fernflower decompilers are available only on android devices running Android 7.0 and above.</string>
<string name="keepIntermediateFiles">Keep intermediate files</string>
<string name="keepIntermediateFilesSummary">Do not delete dex &amp; jar files created during the decompilation</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/xml/preferences.xml
Expand Up @@ -31,6 +31,13 @@
android:summary="@string/ignoreLibrariesPreferenceSummary"
android:title="@string/speedUpDecompile" />

<SwitchPreference
app:iconSpaceReserved="false"
android:key="keepIntermediateFiles"
android:defaultValue="false"
android:summary="@string/keepIntermediateFilesSummary"
android:title="@string/keepIntermediateFiles" />

</PreferenceCategory>

<PreferenceCategory
Expand Down

0 comments on commit 43ac8fa

Please sign in to comment.