Added test for the new DexFileModule constructor that supports specific .dex files.
This commit is contained in:
parent
2ab002df3e
commit
819e7e1a7f
|
@ -21,4 +21,5 @@ Export-Package: com.ibm.wala.dalvik.drivers,
|
||||||
com.ibm.wala.dalvik.test.callGraph,
|
com.ibm.wala.dalvik.test.callGraph,
|
||||||
com.ibm.wala.dalvik.test.callGraph.droidbench,
|
com.ibm.wala.dalvik.test.callGraph.droidbench,
|
||||||
com.ibm.wala.dalvik.test.ir,
|
com.ibm.wala.dalvik.test.ir,
|
||||||
|
com.ibm.wala.dalvik.test.cha,
|
||||||
com.ibm.wala.dalvik.test.util
|
com.ibm.wala.dalvik.test.util
|
||||||
|
|
|
@ -144,15 +144,20 @@ public abstract class DroidBenchCGTest extends DalvikCallGraphTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<Object[]> generateData(final URI[] androidLibs, final File androidJavaJar, final String filter) {
|
public static Collection<Object[]> generateData(final URI[] androidLibs, final File androidJavaJar, final String filter) {
|
||||||
String f = walaProperties.getProperty("droidbench.root");
|
|
||||||
if (f == null || !new File(f).exists()) {
|
return generateData(getDroidBenchRoot(), androidLibs, androidJavaJar, filter);
|
||||||
f = "/tmp/DroidBench";
|
}
|
||||||
}
|
|
||||||
|
public static String getDroidBenchRoot(){
|
||||||
System.err.println("Use " + f + " as droid bench root");
|
String f = walaProperties.getProperty("droidbench.root");
|
||||||
assert new File(f).exists() : "Use " + f + " as droid bench root";
|
if (f == null || !new File(f).exists()) {
|
||||||
assert new File(f + "/apk/").exists() : "Use " + f + " as droid bench root";
|
f = "/tmp/DroidBench";
|
||||||
return generateData(f, androidLibs, androidJavaJar, filter);
|
}
|
||||||
|
|
||||||
|
System.err.println("Use " + f + " as droid bench root");
|
||||||
|
assert new File(f).exists() : "Use " + f + " as droid bench root";
|
||||||
|
assert new File(f + "/apk/").exists() : "Use " + f + " as droid bench root";
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<Object[]> generateData(String droidBenchRoot, final URI[] androidLibs, final File androidJavaJar, final String filter) {
|
public static Collection<Object[]> generateData(String droidBenchRoot, final URI[] androidLibs, final File androidJavaJar, final String filter) {
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
package com.ibm.wala.dalvik.test.cha;
|
||||||
|
|
||||||
|
import com.ibm.wala.classLoader.IClass;
|
||||||
|
import com.ibm.wala.dalvik.classLoader.DexFileModule;
|
||||||
|
import com.ibm.wala.dalvik.test.callGraph.DroidBenchCGTest;
|
||||||
|
import com.ibm.wala.dalvik.test.util.Util;
|
||||||
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
|
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||||
|
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||||
|
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
|
||||||
|
import com.ibm.wala.types.ClassLoaderReference;
|
||||||
|
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||||
|
import org.jf.dexlib2.DexFileFactory;
|
||||||
|
import org.jf.dexlib2.Opcodes;
|
||||||
|
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
|
||||||
|
import org.jf.dexlib2.iface.MultiDexContainer;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public class MultiDexScopeTest {
|
||||||
|
|
||||||
|
private static void addAPKtoScope(ClassLoaderReference loader, AnalysisScope scope, String fileName){
|
||||||
|
File apkFile = new File(fileName);
|
||||||
|
MultiDexContainer<? extends DexBackedDexFile> multiDex = null;
|
||||||
|
try {
|
||||||
|
multiDex = DexFileFactory.loadDexContainer(apkFile, Opcodes.forApi(24));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
for (String dexEntry : multiDex.getDexEntryNames()) {
|
||||||
|
System.out.println("Adding dex file: " +dexEntry + " of file:" + fileName);
|
||||||
|
scope.addToScope(loader, new DexFileModule(apkFile, dexEntry,24));
|
||||||
|
}
|
||||||
|
}catch (IOException e){
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AnalysisScope setUpTestScope(String apkName, String exclusions, ClassLoader loader) throws IOException {
|
||||||
|
AnalysisScope scope;
|
||||||
|
scope = AnalysisScopeReader.readJavaScope("primordial.txt", new File(exclusions), loader);
|
||||||
|
scope.setLoaderImpl(ClassLoaderReference.Application,
|
||||||
|
"com.ibm.wala.dalvik.classLoader.WDexClassLoaderImpl");
|
||||||
|
|
||||||
|
addAPKtoScope(ClassLoaderReference.Application, scope, apkName);
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getNumberOfAppClasses(ClassHierarchy cha){
|
||||||
|
Iterator<IClass> classes = cha.iterator();
|
||||||
|
int numberOfClasses = 0;
|
||||||
|
while(classes.hasNext()){
|
||||||
|
if(classes.next().getClassLoader().getName().toString().equals("Application"))
|
||||||
|
numberOfClasses++;
|
||||||
|
}
|
||||||
|
return numberOfClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAPK() throws ClassHierarchyException, IOException {
|
||||||
|
AnalysisScope scope, scope2;
|
||||||
|
ClassHierarchy cha, cha2;
|
||||||
|
String testAPK = DroidBenchCGTest.getDroidBenchRoot() + "/apk/Aliasing/Merge1.apk";
|
||||||
|
|
||||||
|
scope = setUpTestScope(testAPK,"", MultiDexScopeTest.class.getClassLoader());
|
||||||
|
cha = ClassHierarchyFactory.make(scope);
|
||||||
|
|
||||||
|
scope2 = Util.makeDalvikScope(null,null, testAPK);
|
||||||
|
cha2 = ClassHierarchyFactory.make(scope2);
|
||||||
|
|
||||||
|
Assert.assertEquals(Integer.valueOf(getNumberOfAppClasses(cha)), Integer.valueOf(getNumberOfAppClasses(cha2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue