How to get rid of the unrelated classes when using WALA to analyze Java bytecode?

bytecode, java

Solution

In your loop of IClass, add the following line to check scope first by using `isApplicationLoader()`.

if (!scope.isApplicationLoader(c.getClassLoader())) continue;

Problem

I read the aricle about WALA on http://www.programcreek.com/2012/10/wala-tutorial/ and try to execute the example. I want to know how to get rid of the classes except my test code within test.jar. Thank you! ``` import java.io.File; import java.io.IOException; import java.util.jar.JarFile; import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IMethod; 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.IClassHierarchy; import com.ibm.wala.util.config.AnalysisScopeReader; import com.ibm.wala.util.io.FileProvider; public class WalaTest { public static void main(String args[]) throws IOException, ClassHierarchyException { File exFile=new FileProvider().getFile("Java60RegressionExclusions.txt"); System.out.println(exFile.getAbsolutePath()); AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope("test.jar",exFile); IClassHierarchy cha = ClassHierarchy.make(scope); for (IClass c : cha) { String cname = c.getName().toString(); System.out.println("Class:" + cname); for (IMethod m : c.getAllMethods()) { String mname = m.getName().toString(); System.out.println(" method:" + mname); } System.out.println(); } } } ```

Original source