Setting up and trying the TJ Watson Library for Analysis (WALA).
You will need the following for this exercise:
sudo update-alternatives --config java
(select version
11).java -version
. You should get something like:
openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu1, mixed mode, sharing)
javac -version
and getting something like this:
javac 11.0.16
git clone https://github.com/wala/WALA.git
. It might take a
while as it's a large project. As such, make sure that you are on a
strong network connection.cd
) to WALA
.git checkout e24abb10cc330cfcee0f741865e218d01e63a453
.JAVA_HOME
environmental variable. The
variable's value should hold the path of where your JDK is installed.
NOTE: The installation will not work correctly if this
variable is not set correctly. For example, on a Linux system, the JDK
might be installed at: /usr/lib/jvm/default-jdk
. To set the
environmental variable on such a system using bash, one may issue the
command: export JAVA_HOME=/usr/lib/jvm/default-jdk
../gradlew clean build -x test
.
This may also take a while as there are many dependencies to
download.WALA is not really a "program" but rather a framework to help create programs that do program analysis. Note that WALA is not a transformation framework per se and is focused on analysis. There are other source-to-source transformations frameworks we will explore, such as the Eclipse SDK.
WALA does come, however, with some example driver programs that show you how to use WALA for program analysis.
JavaViewerDriver
, which allows you to
view the "call graph", "class hierarchy", and "pointer analysis" of a
given class path:
java -cp com.ibm.wala.core/build/libs/com.ibm.wala.core-1.5.9-SNAPSHOT.jar:com.ibm.wala.util/build/libs/com.ibm.wala.util-1.5.9-SNAPSHOT.jar:com.ibm.wala.shrike/build/libs/com.ibm.wala.shrike-1.5.9-SNAPSHOT.jar com.ibm.wala.examples.drivers.JavaViewerDriver
-cp
option above but you can also set it using the
CLASSPATH
environmental variable for convenience.Exception in thread "main" java.lang.UnsupportedOperationException: expected command-line to include -appClassPath
at com.ibm.wala.examples.drivers.JavaViewerDriver.validateCommandLine(JavaViewerDriver.java:52)
at com.ibm.wala.examples.drivers.JavaViewerDriver.main(JavaViewerDriver.java:44)
It just means that we're missing a command-line option.mkdir test
test
directory (e.g., vim test/Test.java
) using a text editor:
class Test {
public static void main(String[] a) {
int x = 5;
int y = x + 6;
System.out.println(y);
}
}
Test.java
in the test
directory and compile it:
cd test
javac Test.java
cd -
That will produce Test.class
in the test
directory.JavaViewerDriver
using the option:
java -cp com.ibm.wala.core/build/libs/com.ibm.wala.core-1.5.9-SNAPSHOT.jar:com.ibm.wala.util/build/libs/com.ibm.wala.util-1.5.9-SNAPSHOT.jar:com.ibm.wala.shrike/build/libs/com.ibm.wala.shrike-1.5.9-SNAPSHOT.jar com.ibm.wala.examples.drivers.JavaViewerDriver -appClassPath test
main()
method
(invokestatic < Application, LTest, main([Ljava/lang/String;)V > @5
).
You'll see something that looks like assembly code on the right. This is
a pretty-print version of the intermediate representation (IR) for the
main()
method used by WALA. This representation is called
Shrike, and it is constructed from the bytecode of class
Test
(i.e., from file Test.class
). Have a look
inside to get some idea what is the IR for the input Java method
Test.main()
.invokestatic
node to the
node that reads
Node: < Application, LTest, main([Ljava/lang/String;)V > Context: Everywhere
.
Select it. Notice the instruction at program counter (PC) 4 (the first
number on the left) that corresponds to "line 4" in the original source.
Explain the following:
For illustration purposes, we will use a Java program called jlex; this program is similar to the classic 'lex' scanner generator. First, we will focus on static analysis of the Jimple for program's methods.
git clone https://github.com/CSc-71010-CSCI-77100-Fall-2022/wala-quick-start-khatchad
mvn clean install
java -jar target/CTA-0.0.1-SNAPSHOT.jar JLex.jar
JLex.jar
by analyzing the bytecode
for each class.vim src/main/java/cta/Main.java
com.ibm.wala.ssa.SSAGotoInstruction
,
com.ibm.wala.ssa.SSAConditionalBranchInstruction
, and
com.ibm.wala.ssa.SSASwitchInstruction
. Strictly speaking,
we also need to consider
com.ibm.wala.ssa.SSAThrowInstruction
(since it throws an
exception and the flow of control jumps to the exception handler), but
for now we will ignore exceptions and throw statements. The WALA API documentation may be
helpful.This is assignment is based on an assignment by Atanas Rountev.