Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Multidex Support To Ensure All APK Classes are Scanned #9

Merged
merged 5 commits into from
Jun 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed main/libs/dexlib2-2.2.1.jar
Binary file not shown.
Binary file added main/libs/dexlib2-2.4.0-5339a81f.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions main/src/main/java/main/analyzer/ApkAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public static void analyzeSlices(String criteriaClass,
System.exit(1);
}


List<String> classNames = Utils.getClassNamesFromApkArchive(projectJarPath);

//enables multi-dex support for soot
Options.v().set_process_multiple_dex(true);
Options.v().set_keep_line_number(true);
Options.v().set_src_prec(Options.src_prec_apk);
Options.v().set_android_jars(androidHome + "/platforms");
Expand Down
18 changes: 13 additions & 5 deletions main/src/main/java/main/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import main.util.manifest.ProcessManifest;
import org.jf.dexlib2.DexFileFactory;
import org.jf.dexlib2.Opcodes;
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
import org.jf.dexlib2.dexbacked.ZipDexContainer;
import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib2.iface.DexFile;
import org.jf.dexlib2.iface.MultiDexContainer;
import soot.*;
import soot.jimple.Constant;
import soot.jimple.InvokeExpr;
Expand Down Expand Up @@ -134,12 +137,17 @@ public static List<String> getClassNamesFromApkArchive(String apkfile) throws IO

File zipFile = new File(apkfile);

DexFile dexFile = DexFileFactory.loadDexEntry(zipFile, "classes.dex", true, Opcodes.forApi(23));
ZipDexContainer zipContainer = (ZipDexContainer) DexFileFactory.loadDexContainer(zipFile,Opcodes.forApi(23));

for (ClassDef classDef : dexFile.getClasses()) {
String className = classDef.getType().replace('/', '.');
if (!className.contains("android."))
classNames.add(className.substring(1, className.length() - 1));
for(String dexEntryName: zipContainer.getDexEntryNames()){
DexFile dexFile = DexFileFactory.loadDexEntry(zipFile, dexEntryName, true, Opcodes.forApi(23));

for (ClassDef classDef : dexFile.getClasses()) {
String className = classDef.getType().replace('/', '.');
if (!className.contains("android.")){
classNames.add(className.substring(1, className.length() - 1));
}
}
}

return classNames;
Expand Down