本文介绍了使用WALA分析Java字节码时如何摆脱不相关的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在并尝试执行该示例。我想知道如何摆脱除test.jar中的测试代码以外的类。谢谢!

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


    }
}


推荐答案

在IClass循环中,使用 isApplicationLoader()首先添加以下行以检查作用域。

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

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

这篇关于使用WALA分析Java字节码时如何摆脱不相关的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 16:52