Skip to content

Commit 0e7e3ab

Browse files
committed
Implement -no-cache for dex decoding
1 parent 80b3b9d commit 0e7e3ab

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/main/java/com/reandroid/apkeditor/decompile/DecompileOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public class DecompileOptions extends OptionsWithFramework {
6666
@OptionArg(name = "-dex", flag = true, description = "raw_dex")
6767
public boolean dex;
6868

69+
@OptionArg(name = "-no-cache", description = "decode_no_cache", flag = true)
70+
public boolean noCache;
71+
6972
@OptionArg(name = "-no-dex-debug", flag = true, description = "no_dex_debug")
7073
public boolean noDexDebug;
7174

src/main/java/com/reandroid/apkeditor/smali/SmaliDecompiler.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ public void decodeDex(ApkModule apkModule, File mainDirectory) throws IOExceptio
9797
setting.clearMethodComments();
9898
directory.close();
9999

100-
List<DexFileInputSource> dexList = apkModule.listDexFiles();
101-
for (DexFileInputSource inputSource : dexList) {
102-
writeDexCache(inputSource, mainDirectory);
100+
if (!decompileOptions.noCache) {
101+
List<DexFileInputSource> dexList = apkModule.listDexFiles();
102+
for (DexFileInputSource inputSource : dexList) {
103+
writeDexCache(inputSource, mainDirectory);
104+
}
103105
}
104106
}
105107

@@ -137,9 +139,11 @@ private void disassembleWithInternalDexLib(DexFileInputSource inputSource, File
137139
dexFile.close();
138140
}
139141
private void writeDexCache(DexFileInputSource inputSource, File mainDir) throws IOException {
140-
File cache = new File(mainDir, SmaliUtil.CACHE_DIR);
141-
cache = new File(cache, inputSource.getAlias());
142-
inputSource.write(cache);
142+
if (!decompileOptions.noCache) {
143+
File cache = new File(mainDir, SmaliUtil.CACHE_DIR);
144+
cache = new File(cache, inputSource.getAlias());
145+
inputSource.write(cache);
146+
}
143147
}
144148
private File toOutDir(DexFileInputSource inputSource, File mainDir) {
145149
String name = "classes";

src/main/resources/strings/strings.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ decode_example_2=[Specify output]\njava -jar APKEditor.jar d -i path/input.apk -
4242
decode_example_3=[Specify decode type]\njava -jar APKEditor.jar d -t xml -i path/input.apk
4343
decode_example_4=[Specify framework file(s)]\njava -jar APKEditor.jar d -i path/input.apk -framework framework-res.apk -framework platforms/android-32/android.jar
4444
decode_example_5=[Decode apk signature block]\njava -jar APKEditor.jar d -t sig -i path/input.apk -sig path/signatures_dir
45+
decode_no_cache=Do not create dex .cache files.
4546
decode_load_dex=Number of dex files to load at a time.\nIf the apk dex files count greater than this value, then the decoder loads one dex at a time.\n *Applies only when -dex-lib set to internal.\n *Default = 3\n *See<Notes> below.
4647
decode_note_1=[internal] Dex builder\:\n* Fully supports dex files up to 042.\n* Highest dex file compression.\n* Builds with similar dex-section order as r8/dx.\n* Convenient dex markers editing, see file smali/classes/dex-file.json \n* Additional helpful smali comments: e.g class/method hierarchy.\n* Supports whitespaces on class simple name as introduced on dex 040+
4748
decode_note_2=[-load-dex] To print correct class/method hierarchy, it is necessary to load all dex files at once. This may result high memory consumption and could fail with "OutOfMemoryError" thus you are required to limit the number of dex files to load at a time. You can overcome this problem with -Xmx memory arg e.g java -Xmx8g -jar APKEditor.jar ...

0 commit comments

Comments
 (0)