Compare commits

...

23 Commits

Author SHA1 Message Date
Michael Herzberg 39b3cad56a For some reason, using the precise JS call graph builder, the analysis crashes here.... Temporary workaround. 2015-08-17 19:18:26 +02:00
Michael Herzberg 345acb559f Changed visibility of getCol function. 2015-08-03 16:18:15 +02:00
Michael Herzberg 1e78b289e1 Cleaned up. 2015-07-19 22:21:37 +02:00
Michael Herzberg bc50020c61 Readded column information. 2015-07-19 20:43:08 +02:00
Michael Herzberg fdb25cb7ed Added catching of StringIndexOutOfBoundExceptions. 2015-07-19 15:43:36 +02:00
Michael Herzberg 5c061b7462 Added missing jars back to build.properties and removed sample cup download which is not available anymore. 2015-07-19 13:57:38 +02:00
Michael Herzberg 2996a704e3 Changed some pom.xmls and build.properties to use maven dependencies for some and put the class files not in nested jars but on the top level. 2015-07-08 13:03:03 +02:00
Michael Herzberg ab33d777fc Removed @Override to support older eclipse versions. 2015-07-08 12:56:39 +02:00
Michael Herzberg 69a671680d Fixed quotifying of JavaScript elements. 2015-07-08 12:56:04 +02:00
Michael Herzberg 6a8bcdacfb Added possibility to add dex line number information manually. 2015-07-02 20:37:51 +02:00
Michael Herzberg 8f247b7fa6 Added missing method when using Eclipse Mars. 2015-07-01 13:30:09 +02:00
Michael Herzberg d1010ff939 Changed visibility of getScriptFromUrl in order to be able to override it. 2015-07-01 13:29:27 +02:00
Michael Herzberg b620ae4c1d Muted logging of timings. 2015-06-24 15:00:28 +02:00
Michael Herzberg 50dbbba070 Close input streams properly. 2015-06-24 14:07:55 +02:00
Michael Herzberg 6961dd9a08 Made call graph builder less noisy. 2015-06-24 14:07:29 +02:00
Michael Herzberg 842ce920e7 Use IOUtils instead of FileUtils to allow reading of files from jars. 2015-06-24 02:27:56 +02:00
Michael Herzberg 2e592889c8 Added corner case when line = 1. 2015-06-24 01:44:07 +02:00
Michael Herzberg 6d20fc80cd Implemented line and column information for JavaScript code. 2015-06-21 15:34:55 +02:00
Michael Herzberg 4767929b66 (Hopefully) Fixed construction of dalvik goto instructions. 2015-06-21 15:25:32 +02:00
Michael Herzberg 42e5ec14e6 Ignore script tags in HTML files which are not JavaScript. 2015-06-21 15:22:39 +02:00
Michael Herzberg dbe76a5145 Moved event listener models from prototype into function. 2015-06-21 14:26:21 +02:00
Michael Herzberg 2cec69074c Changed buildCG method to be static. 2015-06-21 14:15:06 +02:00
Michael Herzberg 3db294742e Changed build.xml to copy dx.jar from ANDROID_HOME. 2015-06-21 13:05:57 +02:00
27 changed files with 179 additions and 145 deletions

5
.gitignore vendored
View File

@ -6,6 +6,7 @@
*/bin/*
*~
.metadata/
com.ibm.wala.cast/lib/
com.ibm.wala.cast.java.jdt.test/
com.ibm.wala.cast.java.polyglot/lib/
com.ibm.wala.cast.java.test.data/src/JLex/
@ -22,10 +23,12 @@ com.ibm.wala.cast.js.rhino.test/xxxx
com.ibm.wala.cast.js.rhino/lib/
com.ibm.wala.cast.js.test.data/examples-src/ajaxslt/
com.ibm.wala.cast.js.test/examples-src/ajaxslt/
com.ibm.wala.cast.js.test/test.jar
com.ibm.wala.cast.js/lib/
com.ibm.wala.core.testdata/*.jar
com.ibm.wala.core.testdata/@dot/
com.ibm.wala.core.testdata/lib/
com.ibm.wala.core.testdata/ocaml
com.ibm.wala.core.tests/dat/wala.examples.properties
com.ibm.wala.core.tests/report
com.ibm.wala.core/@dot
@ -35,3 +38,5 @@ com.ibm.wala.dalvik/src/logback.xml
com.ibm.wala.ide.jdt.test/testdata/
edu.kit.wala.smali.test/out/
target/
.classpath
.project

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.ibm.wala-feature</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.FeatureBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.FeatureNature</nature>
</natures>
</projectDescription>

View File

@ -10,6 +10,13 @@
</parent>
<artifactId>com.ibm.wala.cast.js.rhino</artifactId>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>1.7R3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -1,4 +1,7 @@
source.. = harness-src/
output.. = bin/
source.test.jar = harness-src/
output.test.jar = bin/
bin.includes = test.jar,\
bin.includes = .,\
test.jar,\
META-INF/

View File

@ -91,7 +91,7 @@ public class FieldBasedCGUtil {
return buildCG(loaders, scripts, builderType, monitor, supportFullPointerAnalysis);
}
public Pair<JSCallGraph, PointerAnalysis<ObjectVertex>> buildCG(JavaScriptLoaderFactory loaders, SourceModule[] scripts, BuilderType builderType, IProgressMonitor monitor, boolean supportFullPointerAnalysis) throws IOException, WalaException, CancelException {
public static Pair<JSCallGraph, PointerAnalysis<ObjectVertex>> buildCG(JavaScriptLoaderFactory loaders, SourceModule[] scripts, BuilderType builderType, IProgressMonitor monitor, boolean supportFullPointerAnalysis) throws IOException, WalaException, CancelException {
CAstAnalysisScope scope = new CAstAnalysisScope(scripts, loaders, Collections.singleton(JavaScriptLoader.JS));
IClassHierarchy cha = ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS);
Util.checkForFrontEndErrors(cha);

View File

@ -133,12 +133,12 @@ DOMNode = function DOMNode() { // An impostor for the Node class
this.selectNodes = function(a) {
}
this.addEventListener = function Node_prototype_addEventListener(name, fn) { fn(); };
this.removeEventListener = function Node_prototype_removeEventListener(name) {};
};
DOMNode.prototype.addEventListener = function Node_prototype_addEventListener(name, fn) { fn(); };
DOMNode.prototype.removeEventListener = function Node_prototype_removeEventListener(name) {};
DOMNode.prototype.cloneNode = function Node_prototype_cloneNode() {
// TODO: model me
};

View File

@ -11,6 +11,13 @@
<groupId>com.ibm.wala</groupId>
<artifactId>com.ibm.wala.cast.js</artifactId>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>net.htmlparser.jericho</groupId>
<artifactId>jericho-html</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -75,7 +75,7 @@ public abstract class FieldBasedCallGraphBuilder {
protected final MethodTargetSelector targetSelector;
protected final boolean supportFullPointerAnalysis;
private static final boolean LOG_TIMINGS = true;
private static final boolean LOG_TIMINGS = false;
public FieldBasedCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache, boolean supportFullPointerAnalysis) {
this.cha = cha;
@ -218,7 +218,7 @@ public abstract class FieldBasedCallGraphBuilder {
// need to create nodes for reflective targets of call, and then add them
// as callees of the synthetic method
OrdinalSet<FuncVertex> reflectiveTargets = getReflectiveTargets(flowgraph, callVertex, monitor);
System.err.println("adding callees " + reflectiveTargets + " for " + caller);
// System.err.println("adding callees " + reflectiveTargets + " for " + caller);
// there should only be one call site in the synthetic method
CallSiteReference reflectiveCallSite = functionPrototypeCallNode.getIR().iterateCallSites().next();
for (FuncVertex f : reflectiveTargets) {

View File

@ -126,7 +126,7 @@ public class OptimisticCallgraphBuilder extends FieldBasedCallGraphBuilder {
VarVertex receiverVertex = factory.makeVarVertex(caller, invk.getUse(1));
OrdinalSet<FuncVertex> realCallees = flowgraph.getReachingSet(receiverVertex, monitor);
System.err.println("callees " + realCallees + " for " + caller);
// System.err.println("callees " + realCallees + " for " + caller);
for(FuncVertex realCallee: realCallees) {
// flow from arguments to parameters
for(int i=2;i<invk.getNumberOfParameters();++i)

View File

@ -218,7 +218,7 @@ public class FlowGraph implements Iterable<Vertex> {
if (! dataflow.containsNode(prototype)) {
dataflow.addNode(prototype);
}
System.err.println("adding " + p + " --> " + prototype);
// System.err.println("adding " + p + " --> " + prototype);
dataflow.addEdge(p, prototype);
}
}

View File

@ -87,7 +87,9 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
@Override
public void handleEndTag(ITag tag) {
if (tag.getName().equalsIgnoreCase("script")) {
if (tag.getName().equalsIgnoreCase("script")
&& (tag.getAttributeByName("type") == null
|| tag.getAttributeByName("type").fst.equals("text/javascript"))) {
assert currentScriptTag != null;
currentScriptTag = null;
} else if (currentScriptTag != null && tag.getName().equals("!--")) {
@ -118,7 +120,9 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
@Override
public void handleStartTag(ITag tag) {
if (tag.getName().equalsIgnoreCase("script")) {
if (tag.getName().equalsIgnoreCase("script")
&& (tag.getAttributeByName("type") == null
|| tag.getAttributeByName("type").fst.equals("text/javascript"))) {
handleScript(tag);
assert currentScriptTag == null;
currentScriptTag = tag;
@ -189,7 +193,7 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
if (value.indexOf('"') < 0) {
quote= '"';
} else if (value.indexOf("'") < 0) {
quote= '"';
quote= '\'';
} else {
quote= '"';
value = value.replaceAll("\"", "\\\"");
@ -234,7 +238,7 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
}
}
private void getScriptFromUrl(String urlAsString, ITag scriptTag) throws IOException, MalformedURLException {
protected void getScriptFromUrl(String urlAsString, ITag scriptTag) throws IOException, MalformedURLException {
URL scriptSrc = new URL(entrypointUrl, urlAsString);
Reader scriptInputStream;
try {
@ -243,7 +247,7 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE,
ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
if (bs.hasBOM()) {
System.err.println("removing BOM " + bs.getBOM());
// System.err.println("removing BOM " + bs.getBOM());
}
scriptInputStream = new InputStreamReader(bs);
} catch (Exception e) {

View File

@ -57,14 +57,14 @@ public class JerichoTag implements ITag {
@Override
public int getFirstCol() {
return -1;
// return e.getSource().getRowColumnVector(e.getBegin()).getColumn();
// return -1;
return e.getSource().getRowColumnVector(e.getBegin()).getColumn();
}
@Override
public int getLastCol() {
return -1;
//return e.getSource().getRowColumnVector(e.getEnd()).getColumn();
// return -1;
return e.getSource().getRowColumnVector(e.getEnd()).getColumn();
}
@Override

View File

@ -34,6 +34,7 @@ import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.debug.UnimplementedError;
import com.ibm.wala.util.intset.OrdinalSet;
public class LoadFileTargetSelector implements MethodTargetSelector {
@ -55,7 +56,13 @@ public class LoadFileTargetSelector implements MethodTargetSelector {
Set<String> names = new HashSet<String>();
SSAInstruction call = caller.getIR().getInstructions()[caller.getIR().getCallInstructionIndices(site).intIterator().next()];
LocalPointerKey fileNameV = new LocalPointerKey(caller, call.getUse(1));
LocalPointerKey fileNameV = null;
try {
fileNameV = new LocalPointerKey(caller, call.getUse(1));
} catch (UnsupportedOperationException e) {
e.printStackTrace();
return target;
}
OrdinalSet<InstanceKey> ptrs = builder.getPointerAnalysis().getPointsToSet(fileNameV);
for(InstanceKey k : ptrs) {
if (k instanceof ConstantKey) {

View File

@ -15,16 +15,22 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import org.apache.commons.io.IOUtils;
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
import com.ibm.wala.cast.tree.impl.AbstractSourcePosition;
public class RangePosition extends AbstractSourcePosition implements Position {
private final static int NUMBER_OF_CHARS_IN_TAB = 4;
private final URL url;
private final int line;
private final int startOffset;
private final int endOffset;
private int col = -1;
private int lastLine = -1;
private int lastCol = -1;
public RangePosition(URL url, int line, int startOffset, int endOffset) {
super();
this.url = url;
@ -50,17 +56,85 @@ public class RangePosition extends AbstractSourcePosition implements Position {
@Override
public int getLastLine() {
return -1;
if (lastLine == -1) {
String content;
Reader reader = null;
try {
reader = getReader();
content = IOUtils.toString(reader).substring(startOffset, endOffset);
} catch (IOException e) {
e.printStackTrace();
return -1;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
return -1;
}
}
}
int nrOfNewlines = content.length() - content.replace("\n", "").length();
lastLine = line + nrOfNewlines;
}
return lastLine;
}
@Override
public int getFirstCol() {
return -1;
if (col == -1) {
col = getCol(getFirstLine(), startOffset);
}
return col;
}
@Override
public int getLastCol() {
return -1;
if (lastCol == -1) {
lastCol = getCol(getLastLine(), endOffset);
}
return lastCol;
}
private int getCol(int line, int offset) {
int col = -1;
Reader reader = null;
try {
reader = getReader();
col = getCol(IOUtils.toString(reader), line, offset);
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(reader);
}
return col;
}
public static int getCol(String content, int line, int offset) {
if (line == 1) {
return offset + 1;
}
int pos = -1;
for (int i = 0; i < line - 1; i++) {
pos = content.indexOf('\n', pos + 1);
}
try {
String lineBeginning = content.substring(pos, offset);
int nrOfTabs = lineBeginning.length() - lineBeginning.replace("\t", "").length();
return offset - pos + (NUMBER_OF_CHARS_IN_TAB - 1) * nrOfTabs;
} catch (StringIndexOutOfBoundsException e) {
System.err.println("Could not determine column!");
return -1;
}
}
@Override

View File

@ -68,7 +68,7 @@ public class CAstCallGraphUtil {
ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
try {
if (bs.hasBOM()) {
System.err.println("removing BOM " + bs.getBOM());
// System.err.println("removing BOM " + bs.getBOM());
}
return bs;
} catch (IOException e) {

View File

@ -1,7 +1,8 @@
source.. = source/,\
data/
output.. = bin/
bin.includes = META-INF/,\
bin.includes = .,\
META-INF/,\
lib/dx.jar
jars.extra.classpath = lib/dx.jar
jre.compilation.profile = JavaSE-1.7

View File

@ -35,6 +35,8 @@
<property name="bundleJavacTarget" value="${javacTarget}"/>
<property name="bundleBootClasspath" value="${bootclasspath}"/>
<property environment="env"/>
<target name="sampleLexPresent" depends="init">
<available file="${plugin.destination}/data/sample.lex" property="sample.lex.present"/>
</target>
@ -42,14 +44,6 @@
<target name="fetchSampleLex" depends="sampleLexPresent" unless="sample.lex.present">
<get src="https://www.cs.princeton.edu/~appel/modern/java/JLex/current/sample.lex" dest="${plugin.destination}/data/sample.lex" />
</target>
<target name="fetchSampleCup" depends="sampleCupPresent" unless="sample.cup.present">
<get src="http://casper.cii.saxion.nl:8083/~vanleeuw/pse/spanje/troff2html.cup" dest="${plugin.destination}/data/troff2html.cup" />
</target>
<target name="sampleCupPresent" depends="init">
<available file="${plugin.destination}/data/troff2html.cup" property="sample.cup.present"/>
</target>
<target name="fetchAndroidJar" depends="androidJarPresent" unless="android.jar.present">
<get src="http://central.maven.org/maven2/com/google/android/android/4.1.1.4/android-4.1.1.4.jar" dest="${plugin.destination}/data/android.jar" />
@ -59,7 +53,15 @@
<available file="${plugin.destination}/data/android.jar" property="android.jar.present"/>
</target>
<target name="getJars" depends="fetchSampleLex,fetchSampleCup,fetchAndroidJar" />
<target name="copyDxJar" depends="dxJarPresent" unless="dx.jar.present">
<copy file="${env.ANDROID_HOME}/build-tools/20.0.0/lib/dx.jar" tofile="${basedir}/lib/dx.jar" />
</target>
<target name="dxJarPresent" depends="init">
<available file="${basedir}/lib/dx.jar" property="dx.jar.present"/>
</target>
<target name="getJars" depends="fetchSampleLex,fetchAndroidJar,copyDxJar" />
<target name="init" depends="properties">
<condition property="pluginTemp" value="${buildTempFolder}/plugins">

View File

@ -1,3 +1,5 @@
source.. = src/
output.. = bin/
source.dalvik.jar = src/
bin.includes = META-INF/,\
.,\
@ -8,4 +10,4 @@ bin.includes = META-INF/,\
lib/logback-classic-1.0.9.jar,\
lib/logback-core-1.0.9.jar,\
lib/slf4j-api-1.7.2.jar,\
dalvik.jar
dalvik.jar

View File

@ -11,6 +11,19 @@
<artifactId>com.ibm.wala.dalvik</artifactId>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>dexlib</groupId>
<artifactId>dexlib</artifactId>
<version>1.3.4</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -61,6 +61,7 @@ import static org.jf.dexlib.Util.AccessFlags.VOLATILE;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -180,9 +181,11 @@ public class DexIMethod implements IBytecodeMethod {
private TypeReference typeReference;
private ExceptionHandler[][] handlers;
protected InstructionArray instructions;
private Map<Integer, Integer> lineNumbers = new HashMap<Integer, Integer>();
private static int totalInsts = 0;
@ -537,7 +540,12 @@ public class DexIMethod implements IBytecodeMethod {
}
public int getLineNumber(int bcIndex) {
return getInstructionIndex(bcIndex);
// return getInstructionIndex(bcIndex);
return lineNumbers.getOrDefault(bcIndex, -1);
}
public void setLineNumber(int bcIndex, int lineNumber) {
lineNumbers.put(bcIndex, lineNumber);
}
/*

View File

@ -766,7 +766,7 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
*/
@Override
public void visitGoto(Goto instruction) {
emitInstruction(insts.GotoInstruction(getCurrentInstructionIndex(), -1));
emitInstruction(insts.GotoInstruction(getCurrentInstructionIndex(), method.getInstructionIndex(instruction.pc + instruction.destination)));
}
/**

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.ibm.wala.ide-feature</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.FeatureBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.FeatureNature</nature>
</natures>
</projectDescription>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="source"/>
<classpathentry kind="src" path="data"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.ibm.wala.ide.jdt.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -452,4 +452,10 @@ public class FakeExceptionTypeBinding implements ITypeBinding {
return null;
}
// I guess the comments above apply here as well...
public IBinding getDeclaringMember() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.ibm.wala.ide.jsdt.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>