IBM WALA tutorial

Below is a tutorial for showing how to use Wala to do static program analysis. It is done under windows.

WALA is a bundle of java libraries for software analysis which is initially developed by IBM T.J. Watson Research Center. It has capacities to analyze the code of several programming languages. In this simple tutorial, I will show you how to use its Java analysis function. What I will analyze is Java bytecode.

1. Download Wala Source Code

The source code of WALA is available in the subversion repository. You can checkout source code from below URL:
https://github.com/wala/WALA

The trunk branch and early 1.3.4 or 1.3.3 version could work for analysis of Java code. If you want check out the WALA source code to your eclipse, you need install a SubClipse for your eclipse firstly. This eclipse plugin’s update stie URL is:
http://subclipse.tigris.org/update_1.8.x

When you installed this plugin in your eclipse, you can import source code to your eclipse workspace from SVN repository. For basic analysis work of java code, you just need checkout several basic packages of WALA. They are listed below:

  • com.ibm.wala.core
  • com.ibm.wala.shrike
  • com.ibm.wala.util

You can find more details about WALA packages on this webpage:
http://wala.sourceforge.net/wiki/index.php/UserGuide:Technical_Overview
For running wala properly, you need to modify wala.properties to reflect your environment. If there is no such file in com/ibm/wala/core/dat dictionary, you need copy wala.properties.sample to wala.properties and modify the java_runtime_dir property according to your operating system. For example, I use following set when I running wala on windows system.
java_runtime_dir =C:/Program Files/Java/jre6/lib
When you finish all above steps, you can program your own analysis tool upon WALA.

2. Example

In this section, we introduce a very simple program to analyze JAVA bytecode by using wala.

 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();
			}
 
 
	}
}
Category >> Static Analysis  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
<pre><code> 
String foo = "bar";
</code></pre>