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

随声附和 提交于 2019-12-06 04:34:08

问题


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();
            }


    }
}

回答1:


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

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


来源:https://stackoverflow.com/questions/15842245/how-to-get-rid-of-the-unrelated-classes-when-using-wala-to-analyze-java-bytecode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!