This commit is contained in:
Julian Dolby 2017-08-05 21:09:34 -04:00
commit eaba8d59b7
48 changed files with 886 additions and 1055 deletions

View File

@ -4,21 +4,27 @@ addons:
apt: apt:
packages: packages:
- realpath - realpath
- xvfb
before_install: before_install:
- git clone --depth=1 https://github.com/secure-software-engineering/DroidBench.git - git clone --depth=1 https://github.com/secure-software-engineering/DroidBench.git /tmp/DroidBench
/tmp/DroidBench - export M2_HOME=$HOME/apache-maven-3.5.0
- if [ ! -d $M2_HOME/bin ]; then curl https://archive.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz | tar zxf - -C $HOME; fi
- export PATH=$M2_HOME/bin:$PATH
install: install:
- mvn clean verify -DskipTests=true -B -q - mvn clean verify -DskipTests=true -B -q
script: script:
- xvfb-run mvn clean verify -B -q - xvfb-run mvn clean install -B -q
- bash ./dependent-projects-trigger.sh $AUTH_TOKEN - bash ./dependent-projects-trigger.sh $AUTH_TOKEN
- mvn javadoc:aggregate -B -q
- bash ./upload-javascript.sh $GH_TOKEN - bash ./upload-javascript.sh $GH_TOKEN
- jdk_switcher use oraclejdk7
- ./build-maven-jars.py "install -Dgpg.skip" - ./build-maven-jars.py "install -Dgpg.skip"
sudo: false sudo: false
cache: cache:
directories: directories:
- "$HOME/.m2" - "$HOME/.m2"
- "$HOME/apache-maven-3.5.0"
- "$TRAVIS_BUILD_DIR/com.ibm.wala.core.testdata/ocaml/ocamljava-2.0-alpha1/lib" - "$TRAVIS_BUILD_DIR/com.ibm.wala.core.testdata/ocaml/ocamljava-2.0-alpha1/lib"
env: env:
secure: GTtE6dQXwex1+nZkA9fCrBl/nrl71nwSNrwH+KXEcTWRyLnxQPmGKeCey0kLX2bpVngGu7fi2CPZbGaOOm+0tm1kHZtNUUciVkt9qeA0cwdUHz7/EhfN6Xkj7wYZwQ4XUHMhxnHo9FtHK6IliArjUv84DNcDMHJbaiGcHPEmHGo= global:
- secure: KcugjQYnBqeZ7XenZD5QY7jhekVPO0QpQyjDUteLytaokhyRK2g6eNvr/pPerN2uWUvsPwO18P9F+oOupge1cpPZf4cEY8RzLIromyUoRWd6JA0SKciUYdN2kSqnC4uZSJGXeGLoroyEEL4Q2sqimpkbIGxgxYtVniWgJULOyR4=
- secure: jacvGPYX4ugG/HgwJEEpWnllWsS/ipX+qRJ7qM5mbDYryeqsz0eiaxBxQ6IpDyj0v6O4DUi74lSQs/UxCWcUxvOn/5AweCZfoF1U8vt1xivanR4MbC2kr6rJ6ohICuJ4PHDS4IffncgaP3Y8cfExHq6+d0tbibYkjRIiMUGpSik=

View File

@ -1 +0,0 @@
CAST_TEST_BIN = /Users/dolby/git/WALA/com.ibm.wala.cast.test/target/classes/

View File

@ -26,6 +26,7 @@ import com.ibm.wala.core.tests.util.TestAssertions;
import com.ibm.wala.core.tests.util.WalaTestCase; import com.ibm.wala.core.tests.util.WalaTestCase;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.shrikeBT.IInstruction;
import com.ibm.wala.shrikeCT.InvalidClassFileException; import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.FieldReference; import com.ibm.wala.types.FieldReference;
@ -96,9 +97,9 @@ public class AnnotationTest extends WalaTestCase {
BytecodeClass<?> bcClassUnderTest = (BytecodeClass<?>) classUnderTest; BytecodeClass<?> bcClassUnderTest = (BytecodeClass<?>) classUnderTest;
Collection<Annotation> runtimeInvisibleAnnotations = bcClassUnderTest.getAnnotations(true); Collection<Annotation> runtimeInvisibleAnnotations = bcClassUnderTest.getAnnotations(true);
harness.assertEqualCollections(expectedRuntimeInvisibleAnnotations, runtimeInvisibleAnnotations);
Collection<Annotation> runtimeVisibleAnnotations = bcClassUnderTest.getAnnotations(false); Collection<Annotation> runtimeVisibleAnnotations = bcClassUnderTest.getAnnotations(false);
harness.assertEqualCollections(expectedRuntimeInvisibleAnnotations, runtimeInvisibleAnnotations);
harness.assertEqualCollections(expectedRuntimeVisibleAnnotations, runtimeVisibleAnnotations); harness.assertEqualCollections(expectedRuntimeVisibleAnnotations, runtimeVisibleAnnotations);
} }
@ -120,7 +121,7 @@ public class AnnotationTest extends WalaTestCase {
IMethod methodUnderTest = cha.resolveMethod(methodRefUnderTest); IMethod methodUnderTest = cha.resolveMethod(methodRefUnderTest);
harness.assertNotNull(methodRefUnderTest.toString() + " not found", methodUnderTest); harness.assertNotNull(methodRefUnderTest.toString() + " not found", methodUnderTest);
harness.assertTrue(methodUnderTest + " must be IBytecodeMethod", methodUnderTest instanceof IBytecodeMethod); harness.assertTrue(methodUnderTest + " must be IBytecodeMethod", methodUnderTest instanceof IBytecodeMethod);
IBytecodeMethod bcMethodUnderTest = (IBytecodeMethod) methodUnderTest; IBytecodeMethod<IInstruction> bcMethodUnderTest = (IBytecodeMethod<IInstruction>) methodUnderTest;
Collection<Annotation> runtimeInvisibleAnnotations = bcMethodUnderTest.getAnnotations(true); Collection<Annotation> runtimeInvisibleAnnotations = bcMethodUnderTest.getAnnotations(true);
harness.assertEquals(1, runtimeInvisibleAnnotations.size()); harness.assertEquals(1, runtimeInvisibleAnnotations.size());
@ -182,7 +183,7 @@ public class AnnotationTest extends WalaTestCase {
IMethod methodUnderTest = cha.resolveMethod(methodRefUnderTest); IMethod methodUnderTest = cha.resolveMethod(methodRefUnderTest);
harness.assertTrue(methodRefUnderTest.toString() + " not found", methodUnderTest != null); harness.assertTrue(methodRefUnderTest.toString() + " not found", methodUnderTest != null);
harness.assertTrue(methodUnderTest + " must be bytecode method", methodUnderTest instanceof IBytecodeMethod); harness.assertTrue(methodUnderTest + " must be bytecode method", methodUnderTest instanceof IBytecodeMethod);
IBytecodeMethod IBytecodeMethodUnderTest = (IBytecodeMethod) methodUnderTest; IBytecodeMethod<IInstruction> IBytecodeMethodUnderTest = (IBytecodeMethod<IInstruction>) methodUnderTest;
Collection<Annotation>[] parameterAnnotations = IBytecodeMethodUnderTest.getParameterAnnotations(); Collection<Annotation>[] parameterAnnotations = IBytecodeMethodUnderTest.getParameterAnnotations();
harness.assertEquals(expected.length, parameterAnnotations.length); harness.assertEquals(expected.length, parameterAnnotations.length);

View File

@ -47,7 +47,7 @@ public class ShrikeCFG extends AbstractCFG<IInstruction, ShrikeCFG.BasicBlock> i
private int[] instruction2Block; private int[] instruction2Block;
private final IBytecodeMethod method; private final IBytecodeMethod<IInstruction> method;
/** /**
* Cache this here for efficiency * Cache this here for efficiency
@ -59,11 +59,11 @@ public class ShrikeCFG extends AbstractCFG<IInstruction, ShrikeCFG.BasicBlock> i
*/ */
final private Set<ExceptionHandler> exceptionHandlers = HashSetFactory.make(10); final private Set<ExceptionHandler> exceptionHandlers = HashSetFactory.make(10);
public static ShrikeCFG make(IBytecodeMethod m) { public static ShrikeCFG make(IBytecodeMethod<IInstruction> m) {
return new ShrikeCFG(m); return new ShrikeCFG(m);
} }
private ShrikeCFG(IBytecodeMethod method) throws IllegalArgumentException { private ShrikeCFG(IBytecodeMethod<IInstruction> method) throws IllegalArgumentException {
super(method); super(method);
if (method == null) { if (method == null) {
throw new IllegalArgumentException("method cannot be null"); throw new IllegalArgumentException("method cannot be null");
@ -81,7 +81,7 @@ public class ShrikeCFG extends AbstractCFG<IInstruction, ShrikeCFG.BasicBlock> i
} }
@Override @Override
public IBytecodeMethod getMethod() { public IBytecodeMethod<IInstruction> getMethod() {
return method; return method;
} }

View File

@ -82,7 +82,7 @@ public class ControlDependenceGraph<T> extends AbstractNumberedGraph<T> {
for (Iterator<? extends T> ss = cfg.getSuccNodes(x); ss.hasNext();) { for (Iterator<? extends T> ss = cfg.getSuccNodes(x); ss.hasNext();) {
T s = ss.next(); T s = ss.next();
if (RDF.isDominatedBy(s, y)) { if (RDF.isDominatedBy(s, y)) {
labels.add(makeEdgeLabel(s)); labels.add(makeEdgeLabel(x, y, s));
} }
} }
} }
@ -92,7 +92,7 @@ public class ControlDependenceGraph<T> extends AbstractNumberedGraph<T> {
return controlDependence; return controlDependence;
} }
protected Object makeEdgeLabel(T s) { protected Object makeEdgeLabel(@SuppressWarnings("unused") T from, @SuppressWarnings("unused") T to, T s) {
return s; return s;
} }

View File

@ -13,7 +13,6 @@ package com.ibm.wala.classLoader;
import java.util.Collection; import java.util.Collection;
import com.ibm.wala.shrikeBT.ExceptionHandler; import com.ibm.wala.shrikeBT.ExceptionHandler;
import com.ibm.wala.shrikeBT.IInstruction;
import com.ibm.wala.shrikeBT.IndirectionData; import com.ibm.wala.shrikeBT.IndirectionData;
import com.ibm.wala.shrikeCT.InvalidClassFileException; import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.types.annotations.Annotation; import com.ibm.wala.types.annotations.Annotation;
@ -21,7 +20,7 @@ import com.ibm.wala.types.annotations.Annotation;
/** /**
* A method which originated in bytecode, decoded by Shrike * A method which originated in bytecode, decoded by Shrike
*/ */
public interface IBytecodeMethod extends IMethod { public interface IBytecodeMethod<I>extends IMethod {
/** /**
* @return the bytecode index corresponding to instruction i in the getInstructions() array * @return the bytecode index corresponding to instruction i in the getInstructions() array
@ -41,7 +40,7 @@ public interface IBytecodeMethod extends IMethod {
/** /**
* @return the Shrike instructions decoded from the bytecode * @return the Shrike instructions decoded from the bytecode
*/ */
IInstruction[] getInstructions() throws InvalidClassFileException; I[] getInstructions() throws InvalidClassFileException;
/**there /**there
* @return the call sites declared in the bytecode for this method * @return the call sites declared in the bytecode for this method

View File

@ -39,6 +39,7 @@ import com.ibm.wala.ipa.callgraph.propagation.cfa.ExceptionReturnValueKey;
import com.ibm.wala.ipa.cha.ClassHierarchy; import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory; import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.MethodReference; import com.ibm.wala.types.MethodReference;
import com.ibm.wala.util.CancelException; import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.collections.HashSetFactory; import com.ibm.wala.util.collections.HashSetFactory;
@ -58,12 +59,16 @@ public class JVMLDalvikComparisonTest extends DalvikCallGraphTestBase {
return Pair.make(CG, builder.getPointerAnalysis()); return Pair.make(CG, builder.getPointerAnalysis());
} }
private static Set<Pair<CGNode,CGNode>> edgeDiff(CallGraph from, CallGraph to) { private static Set<Pair<CGNode,CGNode>> edgeDiff(CallGraph from, CallGraph to, boolean userOnly) {
Set<Pair<CGNode,CGNode>> result = HashSetFactory.make(); Set<Pair<CGNode,CGNode>> result = HashSetFactory.make();
for(CGNode f : from) { for(CGNode f : from) {
if (! f.getMethod().isSynthetic()) { if (! f.getMethod().isSynthetic()) {
outer: for(CGNode t : from) { outer: for(CGNode t : from) {
if (!t.getMethod().isSynthetic() && from.hasEdge(f, t)) { if (!t.getMethod().isSynthetic() &&
from.hasEdge(f, t) &&
(!userOnly ||
!t.getMethod().getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Primordial)))
{
Set<CGNode> fts = to.getNodes(f.getMethod().getReference()); Set<CGNode> fts = to.getNodes(f.getMethod().getReference());
Set<CGNode> tts = to.getNodes(t.getMethod().getReference()); Set<CGNode> tts = to.getNodes(t.getMethod().getReference());
for(CGNode x : fts) { for(CGNode x : fts) {
@ -91,10 +96,18 @@ public class JVMLDalvikComparisonTest extends DalvikCallGraphTestBase {
Set<MethodReference> androidMethods = applicationMethods(android.fst); Set<MethodReference> androidMethods = applicationMethods(android.fst);
Set<MethodReference> javaMethods = applicationMethods(java.fst); Set<MethodReference> javaMethods = applicationMethods(java.fst);
Iterator<Pair<CGNode, CGNode>> javaExtraEdges = edgeDiff(java.fst, android.fst, false).iterator();
Assert.assertFalse(checkEdgeDiff(android, androidMethods, javaMethods, javaExtraEdges));
Iterator<Pair<CGNode, CGNode>> javaExtraEdges = edgeDiff(java.fst, android.fst).iterator(); Iterator<Pair<CGNode, CGNode>> androidExtraEdges = edgeDiff(android.fst, java.fst, true).iterator();
boolean fail = false; Assert.assertFalse(checkEdgeDiff(java, javaMethods, androidMethods, androidExtraEdges));
if (javaExtraEdges.hasNext()) { }
private static boolean checkEdgeDiff(Pair<CallGraph, PointerAnalysis<InstanceKey>> android, Set<MethodReference> androidMethods,
Set<MethodReference> javaMethods, Iterator<Pair<CGNode, CGNode>> javaExtraEdges) {
boolean fail = false;
if (javaExtraEdges.hasNext()) {
fail = true; fail = true;
Set<MethodReference> javaExtraNodes = HashSetFactory.make(javaMethods); Set<MethodReference> javaExtraNodes = HashSetFactory.make(javaMethods);
javaExtraNodes.removeAll(androidMethods); javaExtraNodes.removeAll(androidMethods);
@ -121,9 +134,8 @@ public class JVMLDalvikComparisonTest extends DalvikCallGraphTestBase {
} }
} }
} }
return fail;
Assert.assertTrue(!fail); }
}
@Test @Test
public void testJLex() throws ClassHierarchyException, IllegalArgumentException, IOException, CancelException { public void testJLex() throws ClassHierarchyException, IllegalArgumentException, IOException, CancelException {

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/dexlib-1.3.4.jar"/> <classpathentry exported="true" kind="lib" path="lib/dexlib2-2.2.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/guava-13.0.1.jar"/> <classpathentry exported="true" kind="lib" path="lib/util-2.2.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/guava-22.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-cli-1.2.jar"/> <classpathentry exported="true" kind="lib" path="lib/commons-cli-1.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-io-2.4.jar"/> <classpathentry exported="true" kind="lib" path="lib/commons-io-2.4.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>

View File

@ -13,14 +13,19 @@ Export-Package: com.google.common.annotations,
com.google.common.base.internal, com.google.common.base.internal,
com.google.common.cache, com.google.common.cache,
com.google.common.collect, com.google.common.collect,
com.google.common.escape,
com.google.common.eventbus, com.google.common.eventbus,
com.google.common.graph,
com.google.common.hash, com.google.common.hash,
com.google.common.html,
com.google.common.io, com.google.common.io,
com.google.common.math, com.google.common.math,
com.google.common.net, com.google.common.net,
com.google.common.primitives, com.google.common.primitives,
com.google.common.reflect, com.google.common.reflect,
com.google.common.util.concurrent, com.google.common.util.concurrent,
com.google.common.xml,
com.google.thirdparty.publicsuffix,
com.ibm.wala.dalvik.analysis.typeInference, com.ibm.wala.dalvik.analysis.typeInference,
com.ibm.wala.dalvik.classLoader, com.ibm.wala.dalvik.classLoader,
com.ibm.wala.dalvik.dex.instructions, com.ibm.wala.dalvik.dex.instructions,
@ -41,20 +46,53 @@ Export-Package: com.google.common.annotations,
org.apache.commons.io.input, org.apache.commons.io.input,
org.apache.commons.io.monitor, org.apache.commons.io.monitor,
org.apache.commons.io.output, org.apache.commons.io.output,
org.jf.dexlib, org.jf.dexlib2,
org.jf.dexlib.Code, org.jf.dexlib2.analysis,
org.jf.dexlib.Code.Analysis, org.jf.dexlib2.analysis.reflection,
org.jf.dexlib.Code.Format, org.jf.dexlib2.analysis.reflection.util,
org.jf.dexlib.Debug, org.jf.dexlib2.analysis.util,
org.jf.dexlib.EncodedValue, org.jf.dexlib2.base,
org.jf.dexlib.Util org.jf.dexlib2.base.reference,
org.jf.dexlib2.base.value,
org.jf.dexlib2.builder,
org.jf.dexlib2.builder.debug,
org.jf.dexlib2.builder.instruction,
org.jf.dexlib2.dexbacked,
org.jf.dexlib2.dexbacked.instruction,
org.jf.dexlib2.dexbacked.raw,
org.jf.dexlib2.dexbacked.raw.util,
org.jf.dexlib2.dexbacked.reference,
org.jf.dexlib2.dexbacked.util,
org.jf.dexlib2.dexbacked.value,
org.jf.dexlib2.iface,
org.jf.dexlib2.iface.debug,
org.jf.dexlib2.iface.instruction,
org.jf.dexlib2.iface.instruction.formats,
org.jf.dexlib2.iface.reference,
org.jf.dexlib2.iface.value,
org.jf.dexlib2.immutable,
org.jf.dexlib2.immutable.debug,
org.jf.dexlib2.immutable.instruction,
org.jf.dexlib2.immutable.reference,
org.jf.dexlib2.immutable.util,
org.jf.dexlib2.immutable.value,
org.jf.dexlib2.rewriter,
org.jf.dexlib2.util,
org.jf.dexlib2.writer,
org.jf.dexlib2.writer.builder,
org.jf.dexlib2.writer.io,
org.jf.dexlib2.writer.pool,
org.jf.dexlib2.writer.util,
org.jf.util,
org.jf.util.jcommander
Bundle-ClassPath: ., Bundle-ClassPath: .,
lib/commons-cli-1.2.jar, lib/commons-cli-1.2.jar,
lib/commons-io-2.4.jar, lib/commons-io-2.4.jar,
lib/dexlib-1.3.4.jar, lib/dexlib2-2.2.1.jar,
lib/guava-13.0.1.jar, lib/util-2.2.1.jar,
lib/logback-classic-1.0.9.jar, lib/logback-classic-1.0.9.jar,
lib/logback-core-1.0.9.jar, lib/logback-core-1.0.9.jar,
lib/slf4j-api-1.7.2.jar lib/slf4j-api-1.7.2.jar,
lib/guava-22.0.jar

View File

@ -2,14 +2,16 @@ bin.includes = META-INF/,\
.,\ .,\
lib/commons-cli-1.2.jar,\ lib/commons-cli-1.2.jar,\
lib/commons-io-2.4.jar,\ lib/commons-io-2.4.jar,\
lib/dexlib-1.3.4.jar,\ lib/dexlib2-2.2.1.jar,\
lib/guava-13.0.1.jar,\ lib/util-2.2.1.jar,\
lib/logback-classic-1.0.9.jar,\ lib/logback-classic-1.0.9.jar,\
lib/logback-core-1.0.9.jar,\ lib/logback-core-1.0.9.jar,\
lib/slf4j-api-1.7.2.jar,\ lib/slf4j-api-1.7.2.jar,\
OSGI-INF/l10n/bundle.properties,\ OSGI-INF/l10n/bundle.properties,\
OSGI-INF/ OSGI-INF/,\
lib/guava-22.0.jar
jars.compile.order = . jars.compile.order = .
output.. = bin/ output.. = bin/
source.. = src/ source.. = src/
javacProjectSettings = true

View File

@ -12,8 +12,38 @@
<packaging>eclipse-plugin</packaging> <packaging>eclipse-plugin</packaging>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.smali</groupId>
<artifactId>dexlib2</artifactId>
<version>2.2.1</version>
<type>jar</type>
<overWrite>false</overWrite>
</artifactItem>
<artifactItem>
<groupId>org.smali</groupId>
<artifactId>util</artifactId>
<version>2.2.1</version>
<type>jar</type>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${basedir}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId> <artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version> <version>1.7</version>
<executions> <executions>
@ -38,6 +68,7 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath> <systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.smali/dexlib2 -->
</dependencies> </dependencies>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -1,244 +0,0 @@
/*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html.
*
* This file is a derivative of code released under the terms listed below.
*
*/
/*
*
* Copyright (c) 2009-2012,
*
* Steve Suh <suhsteve@gmail.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The names of the contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
*/
package com.ibm.wala.dalvik.classLoader;
import static org.jf.dexlib.ItemType.TYPE_CLASS_DEF_ITEM;
import java.io.File;
import org.jf.dexlib.ClassDataItem.EncodedMethod;
import org.jf.dexlib.ClassDefItem;
import org.jf.dexlib.DexFile;
import org.jf.dexlib.Section;
import org.jf.dexlib.Code.Opcode;
import com.ibm.wala.dalvik.dex.instructions.Invoke;
import com.ibm.wala.util.io.FileProvider;
/**
* @deprecated building the Android-Livecycle is done in the class AndroidModel now
*/
@Deprecated
public class ActivityModelMethod extends DexIMethod {
private static EncodedMethod ActivityModelM;
public ActivityModelMethod(EncodedMethod encodedMethod, DexIClass klass) {
super(encodedMethod, klass);
}
public static void loadActivityModel() {
if (ActivityModelM == null) {
DexFile activityModelDF;
ClassDefItem activityModelCDI = null;
try {
FileProvider fp = new FileProvider();
File apkFile = fp.getFile("models/ActivityModel.apk", ActivityModelMethod.class.getClassLoader());
activityModelDF = new DexFile(apkFile);
/* new DexFile(new File(
ActivityModelMethod.class.getClassLoader()
.getResource("models/ActivityModel.apk")
.toURI())); */
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
Section<ClassDefItem> cldeff = activityModelDF.getSectionForType(TYPE_CLASS_DEF_ITEM);
for (ClassDefItem cdefitems : cldeff.getItems()) {
if (cdefitems.getClassType().getTypeDescriptor()
.equals("Lactivity/model/ActivityModelActivity;")) {
activityModelCDI = cdefitems;
}
}
assert (activityModelCDI != null);
// final EncodedMethod[] virtualMethods =
// ActivityModelCDI.getClassData().getVirtualMethods();
for (EncodedMethod virtualMethod : activityModelCDI.getClassData()
.getVirtualMethods()) {
if (virtualMethod.method.getMethodName().getStringValue()
.equals("ActivityModel"))
ActivityModelM = virtualMethod;
}
assert (ActivityModelM != null);
}
}
public static EncodedMethod getActivityModel() {
if (ActivityModelM == null) {
loadActivityModel();
}
return ActivityModelM;
}
// @Override
// public TypeReference[] getDeclaredExceptions() {
// return null;
// }
//
// @Override
// public MethodReference getReference() {
// if (methodReference == null) {
// // Set method name
// Atom name = Atom.findOrCreateUnicodeAtom("ActivityModel");
//
// // Set the descriptor
// ImmutableByteArray desc = ImmutableByteArray.make("()V");
// Descriptor D =
// Descriptor.findOrCreate(myClass.getClassLoader().getLanguage(), desc);
// methodReference = MethodReference.findOrCreate(myClass.getReference(),
// name, D);
// }
//
// return methodReference;
// }
//
// @Override
// public boolean hasExceptionHandler() {
// return false;
// }
//
// @Override
// public boolean isAbstract() {
// return false;
// }
//
// @Override
// public boolean isBridge() {
// return false;
// }
//
// @Override
// public boolean isClinit() {
// return false;
// }
//
// @Override
// public boolean isFinal() {
// return false;
// }
//
// @Override
// public boolean isInit() {
// return false;
// }
//
// @Override
// public boolean isNative() {
// return false;
// }
//
// @Override
// public boolean isPrivate() {
// return false;
// }
//
// @Override
// public boolean isProtected() {
// return false;
// }
//
// @Override
// public boolean isPublic() {
// return true;
// }
//
// @Override
// public boolean isSynchronized() {
// return false;
// }
//
// @Override
// public boolean isSynthetic() {
// return false;
// }
//
// @Override
// public boolean isStatic() {
// return false;
// }
//
// @Override
// public boolean isVolatile() {
// return false;
// }
//
// @Override
// public ExceptionHandler[][] getHandlers() throws
// InvalidClassFileException {
// this.handlers = new ExceptionHandler[instructions().size()][];
// return handlers;
// }
//
// @Override
// public int getMaxLocals() {
// return 12;
// }
//
// @Override
// public int getReturnReg() {
// return 10;
// }
//
// @Override
// public int getExceptionReg() {
// return 11;
// }
//
// @Override
// public int getNumberOfParameterRegisters() {
// return 1;
// }
@Override
protected void handleINVOKE_VIRTUAL(int instLoc, String cname,
String mname, String pname, int[] args, Opcode opcode) {
if (cname.equals("Lactivity/model/ActivityModelActivity")) {
cname = myClass.getName().toString();
}
instructions.add(new Invoke.InvokeVirtual(instLoc, cname, mname, pname,
args, opcode, this));
}
}

View File

@ -54,9 +54,10 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.jf.dexlib.ClassDefItem; import org.jf.dexlib2.DexFileFactory;
import org.jf.dexlib.DexFile; import org.jf.dexlib2.Opcodes;
import org.jf.dexlib.Section; import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib2.iface.DexFile;
import com.ibm.wala.classLoader.Module; import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.ModuleEntry; import com.ibm.wala.classLoader.ModuleEntry;
@ -103,7 +104,7 @@ public class DexFileModule implements Module {
*/ */
private DexFileModule(File f) throws IllegalArgumentException { private DexFileModule(File f) throws IllegalArgumentException {
try { try {
dexfile = new DexFile(f); dexfile = DexFileFactory.loadDexFile(f, Opcodes.forApi(25));
} catch (IOException e) { } catch (IOException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} }
@ -111,8 +112,7 @@ public class DexFileModule implements Module {
// create ModuleEntries from ClassDefItem // create ModuleEntries from ClassDefItem
entries = new HashSet<>(); entries = new HashSet<>();
Section<ClassDefItem> cldeff = dexfile.ClassDefsSection; for (ClassDef cdefitems : dexfile.getClasses()) {
for (ClassDefItem cdefitems : cldeff.getItems()) {
entries.add(new DexModuleEntry(cdefitems)); entries.add(new DexModuleEntry(cdefitems));
} }
} }

View File

@ -47,29 +47,20 @@
package com.ibm.wala.dalvik.classLoader; package com.ibm.wala.dalvik.classLoader;
import static org.jf.dexlib.Util.AccessFlags.ABSTRACT; import static org.jf.dexlib2.AccessFlags.*;
import static org.jf.dexlib.Util.AccessFlags.INTERFACE;
import static org.jf.dexlib.Util.AccessFlags.PRIVATE;
import static org.jf.dexlib.Util.AccessFlags.PUBLIC;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jf.dexlib.AnnotationDirectoryItem; import org.jf.dexlib2.AnnotationVisibility;
import org.jf.dexlib.AnnotationItem; import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib.AnnotationSetItem; import org.jf.dexlib2.iface.Field;
import org.jf.dexlib.AnnotationVisibility; import org.jf.dexlib2.iface.Method;
import org.jf.dexlib.ClassDataItem; import org.jf.dexlib2.iface.MethodParameter;
import org.jf.dexlib.ClassDataItem.EncodedField;
import org.jf.dexlib.ClassDataItem.EncodedMethod;
import org.jf.dexlib.ClassDefItem;
import org.jf.dexlib.FieldIdItem;
import org.jf.dexlib.MethodIdItem;
import org.jf.dexlib.TypeIdItem;
import org.jf.dexlib.TypeListItem;
import com.ibm.wala.classLoader.BytecodeClass; import com.ibm.wala.classLoader.BytecodeClass;
import com.ibm.wala.classLoader.IClassLoader; import com.ibm.wala.classLoader.IClassLoader;
@ -89,7 +80,7 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
* Item which contains the class definitions. * Item which contains the class definitions.
* (compute by DexFile, from the dexLib) * (compute by DexFile, from the dexLib)
*/ */
private final ClassDefItem classDef; private final ClassDef classDef;
/** /**
* Bitfields of these flags are used to indicate the accessibility and overall properties of classes and class members. * Bitfields of these flags are used to indicate the accessibility and overall properties of classes and class members.
@ -126,32 +117,28 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
//computeSuperName() //computeSuperName()
// Set Super Name; // Set Super Name;
String descriptor = classDef.getSuperclass() != null? classDef.getSuperclass().getTypeDescriptor(): null; String descriptor = classDef.getSuperclass() != null? classDef.getSuperclass(): null;
if (descriptor != null && descriptor.endsWith(";")) if (descriptor != null && descriptor.endsWith(";"))
descriptor = descriptor.substring(0,descriptor.length()-1); //remove last ';' descriptor = descriptor.substring(0,descriptor.length()-1); //remove last ';'
superName = descriptor != null? ImmutableByteArray.make(descriptor): null; superName = descriptor != null? ImmutableByteArray.make(descriptor): null;
//computeInterfaceNames() //computeInterfaceNames()
// Set interfaceNames // Set interfaceNames
final TypeListItem intfList = classDef.getInterfaces(); final List<String> intfList = classDef.getInterfaces();
int size = intfList == null ? 0 : intfList.getTypeCount(); int size = intfList == null ? 0 : intfList.size();
//if (size != 0) //if (size != 0)
// System.out.println(intfList.getTypes().get(0).getTypeDescriptor()); // System.out.println(intfList.getTypes().get(0).getTypeDescriptor());
interfaceNames = new ImmutableByteArray[size]; interfaceNames = new ImmutableByteArray[size];
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
TypeIdItem itf = intfList.getTypeIdItem(i); descriptor = intfList.get(i);
descriptor = itf.getTypeDescriptor();
if (descriptor.endsWith(";")) if (descriptor.endsWith(";"))
descriptor = descriptor.substring(0, descriptor.length()-1); descriptor = descriptor.substring(0, descriptor.length()-1);
interfaceNames[i] = ImmutableByteArray interfaceNames[i] = ImmutableByteArray
.make(descriptor); .make(descriptor);
} }
//Load class data
final ClassDataItem classData = classDef.getClassData();
// Set direct instance fields // Set direct instance fields
// if (classData == null) { // if (classData == null) {
// throw new RuntimeException("DexIClass::DexIClass(): classData is null"); // throw new RuntimeException("DexIClass::DexIClass(): classData is null");
@ -178,28 +165,29 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
// } // }
//computeFields() //computeFields()
if (classData != null) {
//final EncodedField[] encInstFields = classData.getInstanceFields(); //final EncodedField[] encInstFields = classData.getInstanceFields();
final List<EncodedField> encInstFields = classData.getInstanceFields(); final Iterable<? extends Field> encInstFields = classDef.getInstanceFields();
instanceFields = new IField[encInstFields.size()]; List<IField> ifs = new LinkedList<>();
for (int i = 0; i < encInstFields.size(); i++) { for (Field dexf : encInstFields) {
instanceFields[i] = new DexIField(encInstFields.get(i),this); ifs.add(new DexIField(dexf,this));
} }
instanceFields = ifs.toArray(new IField[ ifs.size() ]);
// Set direct static fields // Set direct static fields
final List<EncodedField> encStatFields = classData.getStaticFields(); final Iterable<? extends Field> encStatFields = classDef.getStaticFields();
staticFields = new IField[encStatFields.size()]; List<IField> sfs = new LinkedList<>();
for (int i = 0; i < encStatFields.size(); i++) { for (Field dexf : encStatFields) {
staticFields[i] = new DexIField(encStatFields.get(i),this); sfs.add(new DexIField(dexf,this));
} }
staticFields = sfs.toArray(new IField[ sfs.size() ]);
} }
}
/** /**
* @return The classDef Item associated with this class. * @return The classDef Item associated with this class.
*/ */
public ClassDefItem getClassDefItem(){ public ClassDef getClassDefItem(){
return classDef; return classDef;
} }
@ -269,14 +257,11 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
return hashCode; return hashCode;
} }
Collection<Annotation> getAnnotations(Set<AnnotationVisibility> types) { Collection<Annotation> getAnnotations(Set<String> types) {
Set<Annotation> result = HashSetFactory.make(); Set<Annotation> result = HashSetFactory.make();
AnnotationDirectoryItem d = dexModuleEntry.getClassDefItem().getAnnotations(); for(org.jf.dexlib2.iface.Annotation a : classDef.getAnnotations()) {
if (d.getClassAnnotations() != null) { if (types == null || types.contains(AnnotationVisibility.getVisibility(a.getVisibility()))) {
for(AnnotationItem a : d.getClassAnnotations().getAnnotations()) { result.add(DexUtil.getAnnotation(a, getClassLoader().getReference()));
if (types == null || types.contains(a.getVisibility())) {
result.add(DexUtil.getAnnotation(a, getClassLoader().getReference()));
}
} }
} }
return result; return result;
@ -284,7 +269,7 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
@Override @Override
public Collection<Annotation> getAnnotations() { public Collection<Annotation> getAnnotations() {
return getAnnotations((Set<AnnotationVisibility>)null); return getAnnotations((Set<String>)null);
} }
@Override @Override
@ -292,55 +277,46 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
return getAnnotations(getTypes(runtimeInvisible)); return getAnnotations(getTypes(runtimeInvisible));
} }
static Set<AnnotationVisibility> getTypes(boolean runtimeInvisible) { static Set<String> getTypes(boolean runtimeInvisible) {
Set<AnnotationVisibility> types = HashSetFactory.make(); Set<String> types = HashSetFactory.make();
types.add(AnnotationVisibility.SYSTEM); types.add(AnnotationVisibility.getVisibility(AnnotationVisibility.SYSTEM));
if (runtimeInvisible) { if (runtimeInvisible) {
types.add(AnnotationVisibility.BUILD); types.add(AnnotationVisibility.getVisibility(AnnotationVisibility.BUILD));
} else { } else {
types.add(AnnotationVisibility.RUNTIME); types.add(AnnotationVisibility.getVisibility(AnnotationVisibility.RUNTIME));
} }
return types; return types;
} }
List<AnnotationItem> getAnnotations(MethodIdItem m, Set<AnnotationVisibility> types) { List<Annotation> getAnnotations(Method m, Set<String> set) {
List<AnnotationItem> result = new ArrayList<>(); List<Annotation> result = new ArrayList<>();
AnnotationDirectoryItem d = dexModuleEntry.getClassDefItem().getAnnotations(); for(org.jf.dexlib2.iface.Annotation a : m.getAnnotations()) {
if (d != null && d.getMethodAnnotations(m) != null) { if (set == null || set.contains(AnnotationVisibility.getVisibility(a.getVisibility()))) {
for(AnnotationItem a : d.getMethodAnnotations(m).getAnnotations()) { result.add(DexUtil.getAnnotation(a, getClassLoader().getReference()));
if (types == null || types.contains(a.getVisibility())) {
result.add(a);
}
} }
} }
return result; return result;
} }
List<AnnotationItem> getAnnotations(FieldIdItem m) { Collection<Annotation> getAnnotations(Field m) {
List<AnnotationItem> result = new ArrayList<>(); List<Annotation> result = new ArrayList<>();
AnnotationDirectoryItem d = dexModuleEntry.getClassDefItem().getAnnotations(); for(org.jf.dexlib2.iface.Annotation a : m.getAnnotations()) {
if (d != null) { result.add(DexUtil.getAnnotation(a, getClassLoader().getReference()));
for(AnnotationItem a : d.getFieldAnnotations(m).getAnnotations()) {
result.add(a);
}
} }
return result; return result;
} }
Map<Integer,List<AnnotationItem>> getParameterAnnotations(MethodIdItem m) { Map<Integer,List<Annotation>> getParameterAnnotations(Method m) {
Map<Integer,List<AnnotationItem>> result = HashMapFactory.make(); Map<Integer,List<Annotation>> result = HashMapFactory.make();
AnnotationDirectoryItem d = dexModuleEntry.getClassDefItem().getAnnotations(); int i = 0;
if (d != null) { for(MethodParameter as : m.getParameters()) {
int i = 0; for(org.jf.dexlib2.iface.Annotation a : as.getAnnotations()) {
for(AnnotationSetItem as : d.getParameterAnnotations(m).getAnnotationSets()) { if (! result.containsKey(i)) {
for(AnnotationItem a : as.getAnnotations()) { result.put(i, new ArrayList<Annotation>());
if (! result.containsKey(i)) { }
result.put(i, new ArrayList<AnnotationItem>()); result.get(i).add(DexUtil.getAnnotation(a, getClassLoader().getReference()));
}
result.get(i).add(a);
}
i++;
} }
i++;
} }
return result; return result;
} }
@ -353,22 +329,20 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
protected IMethod[] computeDeclaredMethods() { protected IMethod[] computeDeclaredMethods() {
ArrayList<IMethod> methodsAL = new ArrayList<>(); ArrayList<IMethod> methodsAL = new ArrayList<>();
if (methods == null && classDef.getClassData() == null) if (methods == null){
methods = new IMethod[0];
if (methods == null && classDef.getClassData() != null){
// final EncodedMethod[] directMethods = classDef.getClassData().getDirectMethods(); // final EncodedMethod[] directMethods = classDef.getClassData().getDirectMethods();
// final EncodedMethod[] virtualMethods = classDef.getClassData().getVirtualMethods(); // final EncodedMethod[] virtualMethods = classDef.getClassData().getVirtualMethods();
final List<EncodedMethod> directMethods = classDef.getClassData().getDirectMethods(); final Iterable<? extends Method> directMethods = classDef.getDirectMethods();
final List<EncodedMethod> virtualMethods = classDef.getClassData().getVirtualMethods(); final Iterable<? extends Method> virtualMethods = classDef.getVirtualMethods();
//methods = new IMethod[dSize+vSize]; //methods = new IMethod[dSize+vSize];
// Create Direct methods (static, private, constructor) // Create Direct methods (static, private, constructor)
for (int i = 0; i < directMethods.size(); i++) { int i = 0;
EncodedMethod dMethod = directMethods.get(i); for (Method dMethod : directMethods) {
//methods[i] = new DexIMethod(dMethod,this); //methods[i] = new DexIMethod(dMethod,this);
methodsAL.add(new DexIMethod(dMethod,this)); DexIMethod method = new DexIMethod(dMethod,this);
methodsAL.add(method);
//Set construcorId //Set construcorId
//if ( (dMethod.accessFlags & CONSTRUCTOR.getValue()) != 0){ //if ( (dMethod.accessFlags & CONSTRUCTOR.getValue()) != 0){
@ -376,15 +350,16 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
//} //}
//Set clinitId //Set clinitId
//if (methods[i].isClinit()) //if (methods[i].isClinit())
if (methodsAL.get(i).isClinit()) { if (method.isClinit()) {
clinitId = i; clinitId = i;
} }
i++;
} }
// Create virtual methods (other methods) // Create virtual methods (other methods)
for (int i = 0; i < virtualMethods.size(); i++) { for (Method dexm : virtualMethods) {
//methods[dSize+i] = new DexIMethod(virtualMethods[i],this); //methods[dSize+i] = new DexIMethod(virtualMethods[i],this);
methodsAL.add(new DexIMethod(virtualMethods.get(i),this)); methodsAL.add(new DexIMethod(dexm,this));
//is this enough to determine if the class is an activity? //is this enough to determine if the class is an activity?
//maybe check superclass? -- but that may also not be enough //maybe check superclass? -- but that may also not be enough
//may need to keep checking superclass of superclass, etc. //may need to keep checking superclass of superclass, etc.

View File

@ -48,18 +48,11 @@
package com.ibm.wala.dalvik.classLoader; package com.ibm.wala.dalvik.classLoader;
import static org.jf.dexlib.Util.AccessFlags.FINAL; import static org.jf.dexlib2.AccessFlags.*;
import static org.jf.dexlib.Util.AccessFlags.PRIVATE;
import static org.jf.dexlib.Util.AccessFlags.PROTECTED;
import static org.jf.dexlib.Util.AccessFlags.PUBLIC;
import static org.jf.dexlib.Util.AccessFlags.STATIC;
import static org.jf.dexlib.Util.AccessFlags.VOLATILE;
import java.util.Collection; import java.util.Collection;
import org.jf.dexlib.ClassDataItem.EncodedField; import org.jf.dexlib2.iface.Field;
import org.jf.dexlib.StringIdItem;
import org.jf.dexlib.TypeIdItem;
import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IField; import com.ibm.wala.classLoader.IField;
@ -75,7 +68,7 @@ public class DexIField implements IField {
/* /*
* The EncodedFied object for which this DexIField is a wrapper * The EncodedFied object for which this DexIField is a wrapper
*/ */
private final EncodedField eField; private final Field eField;
/** /**
* The declaring class for this method. * The declaring class for this method.
@ -97,14 +90,14 @@ public class DexIField implements IField {
private Atom name; private Atom name;
public DexIField(EncodedField encodedField, DexIClass klass) { public DexIField(Field encodedField, DexIClass klass) {
//public DexIField(EncodedField encodedField) { //public DexIField(EncodedField encodedField) {
eField = encodedField; eField = encodedField;
myClass = klass; myClass = klass;
StringIdItem fieldName = eField.field.getFieldName(); String fieldName = eField.getName();
name = Atom.findOrCreateUnicodeAtom(fieldName.getStringValue()); name = Atom.findOrCreateUnicodeAtom(fieldName);
TypeIdItem fieldType = eField.field.getFieldType(); String fieldType = eField.getType();
TypeName T = DexUtil.getTypeName(fieldType); TypeName T = DexUtil.getTypeName(fieldType);
TypeReference type = TypeReference.findOrCreate(myClass.getClassLoader().getReference(), T); TypeReference type = TypeReference.findOrCreate(myClass.getClassLoader().getReference(), T);
myFieldRef = FieldReference.findOrCreate(myClass.getReference(), name, type); myFieldRef = FieldReference.findOrCreate(myClass.getReference(), name, type);
@ -144,27 +137,27 @@ public class DexIField implements IField {
@Override @Override
public boolean isFinal() { public boolean isFinal() {
return (eField.accessFlags & FINAL.getValue()) != 0; return (eField.getAccessFlags() & FINAL.getValue()) != 0;
} }
@Override @Override
public boolean isPrivate() { public boolean isPrivate() {
return (eField.accessFlags & PRIVATE.getValue()) != 0; return (eField.getAccessFlags() & PRIVATE.getValue()) != 0;
} }
@Override @Override
public boolean isProtected() { public boolean isProtected() {
return (eField.accessFlags & PROTECTED.getValue()) != 0; return (eField.getAccessFlags() & PROTECTED.getValue()) != 0;
} }
@Override @Override
public boolean isPublic() { public boolean isPublic() {
return (eField.accessFlags & PUBLIC.getValue()) != 0; return (eField.getAccessFlags() & PUBLIC.getValue()) != 0;
} }
@Override @Override
public boolean isStatic() { public boolean isStatic() {
return (eField.accessFlags & STATIC.getValue()) != 0; return (eField.getAccessFlags() & STATIC.getValue()) != 0;
} }
@Override @Override
@ -174,7 +167,7 @@ public class DexIField implements IField {
@Override @Override
public boolean isVolatile() { public boolean isVolatile() {
return (eField.accessFlags & VOLATILE.getValue()) != 0; return (eField.getAccessFlags() & VOLATILE.getValue()) != 0;
} }
@Override @Override
@ -184,7 +177,7 @@ public class DexIField implements IField {
@Override @Override
public Collection<Annotation> getAnnotations() { public Collection<Annotation> getAnnotations() {
return DexUtil.getAnnotations(myClass.getAnnotations(eField.field), myClass.getClassLoader().getReference()); return myClass.getAnnotations(eField);
} }
} }

View File

@ -50,19 +50,19 @@ package com.ibm.wala.dalvik.classLoader;
import java.io.InputStream; import java.io.InputStream;
import org.jf.dexlib.ClassDefItem; import org.jf.dexlib2.iface.ClassDef;
import com.ibm.wala.classLoader.Module; import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.ModuleEntry; import com.ibm.wala.classLoader.ModuleEntry;
public class DexModuleEntry implements ModuleEntry { public class DexModuleEntry implements ModuleEntry {
private final ClassDefItem classDefItem; private final ClassDef classDefItem;
private final String className; private final String className;
public DexModuleEntry(ClassDefItem cdefitems) { public DexModuleEntry(ClassDef cdefitems) {
classDefItem = cdefitems; classDefItem = cdefitems;
String temp =cdefitems.getClassType().getTypeDescriptor(); String temp =cdefitems.getType();
// className = temp; // className = temp;
if (temp.endsWith(";")) if (temp.endsWith(";"))
className = temp.substring(0,temp.length()-1); //remove last ';' className = temp.substring(0,temp.length()-1); //remove last ';'
@ -71,7 +71,7 @@ public class DexModuleEntry implements ModuleEntry {
// System.out.println(className); // System.out.println(className);
} }
public ClassDefItem getClassDefItem(){ public ClassDef getClassDefItem(){
return classDefItem; return classDefItem;
} }

View File

@ -1,29 +1,43 @@
package com.ibm.wala.dalvik.classLoader; package com.ibm.wala.dalvik.classLoader;
import static org.jf.dexlib2.ValueType.ANNOTATION;
import static org.jf.dexlib2.ValueType.ARRAY;
import static org.jf.dexlib2.ValueType.BOOLEAN;
import static org.jf.dexlib2.ValueType.BYTE;
import static org.jf.dexlib2.ValueType.CHAR;
import static org.jf.dexlib2.ValueType.DOUBLE;
import static org.jf.dexlib2.ValueType.ENUM;
import static org.jf.dexlib2.ValueType.FIELD;
import static org.jf.dexlib2.ValueType.FLOAT;
import static org.jf.dexlib2.ValueType.INT;
import static org.jf.dexlib2.ValueType.LONG;
import static org.jf.dexlib2.ValueType.METHOD;
import static org.jf.dexlib2.ValueType.NULL;
import static org.jf.dexlib2.ValueType.SHORT;
import static org.jf.dexlib2.ValueType.STRING;
import static org.jf.dexlib2.ValueType.TYPE;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.jf.dexlib.AnnotationItem; import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib.FieldIdItem; import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
import org.jf.dexlib.MethodIdItem; import org.jf.dexlib2.iface.value.ArrayEncodedValue;
import org.jf.dexlib.TypeIdItem; import org.jf.dexlib2.iface.value.BooleanEncodedValue;
import org.jf.dexlib.EncodedValue.AnnotationEncodedSubValue; import org.jf.dexlib2.iface.value.ByteEncodedValue;
import org.jf.dexlib.EncodedValue.ArrayEncodedValue; import org.jf.dexlib2.iface.value.CharEncodedValue;
import org.jf.dexlib.EncodedValue.BooleanEncodedValue; import org.jf.dexlib2.iface.value.DoubleEncodedValue;
import org.jf.dexlib.EncodedValue.ByteEncodedValue; import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib.EncodedValue.CharEncodedValue; import org.jf.dexlib2.iface.value.EnumEncodedValue;
import org.jf.dexlib.EncodedValue.DoubleEncodedValue; import org.jf.dexlib2.iface.value.FieldEncodedValue;
import org.jf.dexlib.EncodedValue.EncodedValue; import org.jf.dexlib2.iface.value.FloatEncodedValue;
import org.jf.dexlib.EncodedValue.EnumEncodedValue; import org.jf.dexlib2.iface.value.IntEncodedValue;
import org.jf.dexlib.EncodedValue.FieldEncodedValue; import org.jf.dexlib2.iface.value.LongEncodedValue;
import org.jf.dexlib.EncodedValue.FloatEncodedValue; import org.jf.dexlib2.iface.value.MethodEncodedValue;
import org.jf.dexlib.EncodedValue.IntEncodedValue; import org.jf.dexlib2.iface.value.ShortEncodedValue;
import org.jf.dexlib.EncodedValue.LongEncodedValue; import org.jf.dexlib2.iface.value.StringEncodedValue;
import org.jf.dexlib.EncodedValue.MethodEncodedValue; import org.jf.dexlib2.iface.value.TypeEncodedValue;
import org.jf.dexlib.EncodedValue.ShortEncodedValue;
import org.jf.dexlib.EncodedValue.StringEncodedValue;
import org.jf.dexlib.EncodedValue.TypeEncodedValue;
import org.jf.dexlib.EncodedValue.ValueType;
import com.ibm.wala.shrikeCT.AnnotationsReader.AnnotationAttribute; import com.ibm.wala.shrikeCT.AnnotationsReader.AnnotationAttribute;
import com.ibm.wala.shrikeCT.AnnotationsReader.ArrayElementValue; import com.ibm.wala.shrikeCT.AnnotationsReader.ArrayElementValue;
@ -44,25 +58,21 @@ import com.ibm.wala.util.strings.ImmutableByteArray;
public class DexUtil { public class DexUtil {
static Collection<Annotation> getAnnotations(Collection<AnnotationItem> as, ClassLoaderReference clr) { static Collection<Annotation> getAnnotations(Collection<org.jf.dexlib2.iface.Annotation> as, ClassLoaderReference clr) {
Collection<Annotation> result = HashSetFactory.make(); Collection<Annotation> result = HashSetFactory.make();
for(AnnotationItem a : as) { for(org.jf.dexlib2.iface.Annotation a : as) {
result.add(getAnnotation(a, clr)); result.add(getAnnotation(a, clr));
} }
return result; return result;
} }
static Annotation getAnnotation(AnnotationItem a, ClassLoaderReference clr) { static Annotation getAnnotation(org.jf.dexlib2.iface.Annotation ea, ClassLoaderReference clr) {
return getAnnotation(a.getEncodedAnnotation(), clr);
}
static Annotation getAnnotation(AnnotationEncodedSubValue ea, ClassLoaderReference clr) {
Map<String,ElementValue> values = HashMapFactory.make(); Map<String,ElementValue> values = HashMapFactory.make();
TypeReference at = getTypeRef(ea.annotationType, clr); TypeReference at = getTypeRef(ea.getType(), clr);
for(int i = 0; i < ea.names.length; i++) { for(AnnotationElement elt : ea.getElements()) {
String name = ea.names[i].getStringValue(); String name = elt.getName();
EncodedValue v = ea.values[i]; EncodedValue v = elt.getValue();
ElementValue value = getValue(clr, v); ElementValue value = getValue(clr, v);
values.put(name, value); values.put(name, value);
} }
@ -72,77 +82,89 @@ public class DexUtil {
static ElementValue getValue(ClassLoaderReference clr, EncodedValue v) { static ElementValue getValue(ClassLoaderReference clr, EncodedValue v) {
switch (v.getValueType()) { switch (v.getValueType()) {
case VALUE_ANNOTATION: case ANNOTATION: {
Annotation a = getAnnotation((AnnotationEncodedSubValue)v, clr); Map<String,ElementValue> values = HashMapFactory.make();
return new AnnotationAttribute(a.getType().getName().toString() +";", a.getNamedArguments()); String at = ((AnnotationEncodedValue)v).getType();
case VALUE_ARRAY: for(AnnotationElement elt : ((AnnotationEncodedValue)v).getElements()) {
EncodedValue[] vs = ((ArrayEncodedValue)v).values; String name = elt.getName();
ElementValue rs[] = new ElementValue[ vs.length ]; EncodedValue ev = elt.getValue();
for(int idx = 0; idx < vs.length; idx++) { ElementValue value = getValue(clr, ev);
rs[idx] = getValue(clr, vs[idx]); values.put(name, value);
}
return new AnnotationAttribute(at, values);
}
case ARRAY: {
List<? extends EncodedValue> vs = ((ArrayEncodedValue)v).getValue();
ElementValue[] rs = new ElementValue[ vs.size() ];
int idx = 0;
for(EncodedValue ev : vs) {
rs[idx++] = getValue(clr, ev);
} }
return new ArrayElementValue(rs); return new ArrayElementValue(rs);
}
case VALUE_BOOLEAN:
Boolean bl = ((BooleanEncodedValue)v).value; case BOOLEAN:
Boolean bl = ((BooleanEncodedValue)v).getValue();
return new ConstantElementValue(bl); return new ConstantElementValue(bl);
case VALUE_BYTE: case BYTE:
Byte bt = ((ByteEncodedValue)v).value; Byte bt = ((ByteEncodedValue)v).getValue();
return new ConstantElementValue(bt); return new ConstantElementValue(bt);
case VALUE_CHAR: case CHAR:
Character c = ((CharEncodedValue)v).value; Character c = ((CharEncodedValue)v).getValue();
return new ConstantElementValue(c); return new ConstantElementValue(c);
case VALUE_DOUBLE: case DOUBLE:
Double d = ((DoubleEncodedValue)v).value; Double d = ((DoubleEncodedValue)v).getValue();
return new ConstantElementValue(d); return new ConstantElementValue(d);
case VALUE_ENUM: case ENUM:
FieldIdItem o = ((EnumEncodedValue)v).value; org.jf.dexlib2.iface.reference.FieldReference o = ((EnumEncodedValue)v).getValue();
return new EnumElementValue(o.getFieldType().getTypeDescriptor(), o.getFieldName().getStringValue()); return new EnumElementValue(o.getType(), o.getName());
case VALUE_FIELD: case FIELD:
o = v.getValueType()==ValueType.VALUE_ENUM? ((EnumEncodedValue)v).value: ((FieldEncodedValue)v).value; o = v.getValueType()==ENUM? ((EnumEncodedValue)v).getValue(): ((FieldEncodedValue)v).getValue();
String fieldName = o.getFieldName().getStringValue(); String fieldName = o.getName();
TypeReference ft = getTypeRef(o.getFieldType(), clr); TypeReference ft = getTypeRef(o.getType(), clr);
TypeReference ct = getTypeRef(o.getContainingClass(), clr); TypeReference ct = getTypeRef(o.getDefiningClass(), clr);
return new ConstantElementValue(FieldReference.findOrCreate(ct, Atom.findOrCreateUnicodeAtom(fieldName), ft)); return new ConstantElementValue(FieldReference.findOrCreate(ct, Atom.findOrCreateUnicodeAtom(fieldName), ft));
case VALUE_FLOAT: case FLOAT:
Float f = ((FloatEncodedValue)v).value; Float f = ((FloatEncodedValue)v).getValue();
return new ConstantElementValue(f); return new ConstantElementValue(f);
case VALUE_INT: case INT:
Integer iv = ((IntEncodedValue)v).value; Integer iv = ((IntEncodedValue)v).getValue();
return new ConstantElementValue(iv); return new ConstantElementValue(iv);
case VALUE_LONG: case LONG:
Long l = ((LongEncodedValue)v).value; Long l = ((LongEncodedValue)v).getValue();
return new ConstantElementValue(l); return new ConstantElementValue(l);
case VALUE_METHOD: case METHOD:
MethodIdItem m = ((MethodEncodedValue)v).value; org.jf.dexlib2.iface.reference.MethodReference m = ((MethodEncodedValue)v).getValue();
ct = getTypeRef(m.getContainingClass(), clr); ct = getTypeRef(m.getDefiningClass(), clr);
String methodName = m.getMethodName().getStringValue(); String methodName = m.getName();
String methodSig = m.getPrototype().getPrototypeString(); String methodSig = getSignature(m);
return new ConstantElementValue(MethodReference.findOrCreate(ct, Atom.findOrCreateUnicodeAtom(methodName), Descriptor.findOrCreateUTF8(methodSig))); return new ConstantElementValue(MethodReference.findOrCreate(ct, Atom.findOrCreateUnicodeAtom(methodName), Descriptor.findOrCreateUTF8(methodSig)));
case VALUE_NULL: case NULL:
return new ConstantElementValue(null); return new ConstantElementValue(null);
case VALUE_SHORT: case SHORT:
Short s = ((ShortEncodedValue)v).value; Short s = ((ShortEncodedValue)v).getValue();
return new ConstantElementValue(s); return new ConstantElementValue(s);
case VALUE_STRING: case STRING:
String str = ((StringEncodedValue)v).value.getStringValue(); String str = ((StringEncodedValue)v).getValue();
return new ConstantElementValue(str); return new ConstantElementValue(str);
case VALUE_TYPE: case TYPE:
TypeIdItem t = ((TypeEncodedValue)v).value; String t = ((TypeEncodedValue)v).getValue();
return new ConstantElementValue(getTypeName(t) + ";"); return new ConstantElementValue(getTypeName(t) + ";");
default: default:
@ -151,12 +173,21 @@ public class DexUtil {
} }
} }
static TypeReference getTypeRef(TypeIdItem type, ClassLoaderReference clr) { static String getSignature(org.jf.dexlib2.iface.reference.MethodReference ref) {
StringBuilder sig = new StringBuilder("(");
for(CharSequence p : ref.getParameterTypes()) {
sig = sig.append(p);
}
sig.append(')').append(ref.getReturnType());
return sig.toString();
}
static TypeReference getTypeRef(String type, ClassLoaderReference clr) {
return TypeReference.findOrCreate(clr, getTypeName(type)); return TypeReference.findOrCreate(clr, getTypeName(type));
} }
static TypeName getTypeName(TypeIdItem fieldType) { static TypeName getTypeName(String fieldType) {
ImmutableByteArray fieldTypeArray = ImmutableByteArray.make(fieldType.getTypeDescriptor()); ImmutableByteArray fieldTypeArray = ImmutableByteArray.make(fieldType);
TypeName T = null; TypeName T = null;
if (fieldTypeArray.get(fieldTypeArray.length() - 1) == ';') { if (fieldTypeArray.get(fieldTypeArray.length() - 1) == ';') {
T = TypeName.findOrCreate(fieldTypeArray, 0, fieldTypeArray.length() - 1); T = TypeName.findOrCreate(fieldTypeArray, 0, fieldTypeArray.length() - 1);

View File

@ -51,8 +51,8 @@
*/ */
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import org.jf.dexlib.Code.Format.ArrayDataPseudoInstruction; import org.jf.dexlib2.iface.instruction.formats.ArrayPayload;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
import com.ibm.wala.types.TypeReference; import com.ibm.wala.types.TypeReference;
@ -63,7 +63,7 @@ public class ArrayFill extends Instruction {
public final int array; public final int array;
public final int tableAddressOffset; public final int tableAddressOffset;
public int registerIndex; public int registerIndex;
private ArrayDataPseudoInstruction table; private ArrayPayload table;
public final TypeReference type; public final TypeReference type;
@ -85,16 +85,16 @@ public class ArrayFill extends Instruction {
} }
public void setArrayDataTable(ArrayDataPseudoInstruction table) { public void setArrayDataTable(ArrayPayload inst) {
this.table = table; this.table = inst;
} }
public ArrayDataPseudoInstruction getTable() { public ArrayPayload getTable() {
return table; return table;
} }
public int getElementCount() { public int getElementCount() {
return table.getElementCount(); return table.getArrayElements().size();
} }
public TypeReference getType() { public TypeReference getType() {

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
import com.ibm.wala.types.TypeReference; import com.ibm.wala.types.TypeReference;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
import com.ibm.wala.dalvik.dex.instructions.ArrayGet.Type; import com.ibm.wala.dalvik.dex.instructions.ArrayGet.Type;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.cast.ir.ssa.CAstBinaryOp; import com.ibm.wala.cast.ir.ssa.CAstBinaryOp;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.cast.ir.ssa.CAstBinaryOp; import com.ibm.wala.cast.ir.ssa.CAstBinaryOp;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
@ -84,10 +84,8 @@ public class BinaryOperation extends Instruction {
visitor.visitBinaryOperation(this); visitor.visitBinaryOperation(this);
} }
public IBinaryOpInstruction.IOperator getOperator() public IBinaryOpInstruction.IOperator getOperator() {
{ switch(op) {
switch(op)
{
case CMPL_FLOAT: case CMPL_FLOAT:
return CAstBinaryOp.LT; return CAstBinaryOp.LT;
case CMPG_FLOAT: case CMPG_FLOAT:
@ -196,28 +194,20 @@ public class BinaryOperation extends Instruction {
} }
public boolean isUnsigned() { public boolean isUnsigned() {
switch(op) {
/** case AND_INT:
* At the moment, WALA asserts that false is returned here. Maybe WALA will support unsigned case OR_INT:
* arithmetic in its IR some time in the future - then the commented code will make sense. case XOR_INT:
*/ case SHL_INT:
return false; case USHR_INT:
// switch(op) case AND_LONG:
// { case OR_LONG:
// case AND_INT: case XOR_LONG:
// case OR_INT: case SHL_LONG:
// case XOR_INT: case USHR_LONG:
// case SHL_INT: return true;
// case USHR_INT: default:
// case AND_LONG: return false;
// case OR_LONG: }
// case XOR_LONG:
// case SHL_LONG:
// case USHR_LONG:
// return true;
// default:
// return false;
// }
} }
} }

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
import com.ibm.wala.shrikeBT.IConditionalBranchInstruction; import com.ibm.wala.shrikeBT.IConditionalBranchInstruction;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
import com.ibm.wala.types.TypeReference; import com.ibm.wala.types.TypeReference;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
import com.ibm.wala.types.TypeReference; import com.ibm.wala.types.TypeReference;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
import com.ibm.wala.types.TypeReference; import com.ibm.wala.types.TypeReference;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
@ -146,7 +146,7 @@ public abstract class Instruction {
* True if the instruction can continue. * True if the instruction can continue.
* @see com.ibm.wala.shrikeBT.IInstruction#isFallThrough() * @see com.ibm.wala.shrikeBT.IInstruction#isFallThrough()
*/ */
public boolean isFallThrough() { public boolean isFallThrough() {
return opcode.canContinue(); return opcode.canContinue();
} }
@ -154,7 +154,7 @@ public abstract class Instruction {
* True if the instruction can throw an exception * True if the instruction can throw an exception
* @see com.ibm.wala.shrikeBT.IInstruction#isPEI() * @see com.ibm.wala.shrikeBT.IInstruction#isPEI()
*/ */
public boolean isPEI() { public boolean isPEI() {
return opcode.canThrow(); return opcode.canThrow();
} }
@ -172,12 +172,10 @@ public abstract class Instruction {
return opcode; return opcode;
} }
public int[] getBranchTargets() { public int[] getBranchTargets() {
return noInstructions; return noInstructions;
} }
public abstract void visit(Visitor visitor); public abstract void visit(Visitor visitor);
} }

View File

@ -48,11 +48,12 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;
import com.ibm.wala.shrikeBT.IInvokeInstruction; import com.ibm.wala.shrikeBT.IInvokeInstruction;
import com.ibm.wala.shrikeBT.IInvokeInstruction.IDispatch; import com.ibm.wala.shrikeBT.IInvokeInstruction.IDispatch;
import com.ibm.wala.types.Descriptor;
public abstract class Invoke extends Instruction { public abstract class Invoke extends Instruction {
@ -68,6 +69,8 @@ public abstract class Invoke extends Instruction {
this.methodName = methodName; this.methodName = methodName;
this.descriptor = descriptor; this.descriptor = descriptor;
this.args = args; this.args = args;
assert Descriptor.findOrCreateUTF8(descriptor) != null;
} }
public static class InvokeVirtual extends Invoke public static class InvokeVirtual extends Invoke

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.classLoader.NewSiteReference; import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.classLoader.NewSiteReference; import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.classLoader.NewSiteReference; import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,19 +48,26 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Format.PackedSwitchDataPseudoInstruction; import org.jf.dexlib2.iface.instruction.SwitchElement;
import org.jf.dexlib2.iface.instruction.SwitchPayload;
public class PackedSwitchPad implements SwitchPad { public class PackedSwitchPad implements SwitchPad {
public final int firstValue; public int firstValue;
public final int[] offsets; public final int[] offsets;
public final int defaultOffset; public final int defaultOffset;
private int [] labelsAndOffsets; private int [] labelsAndOffsets;
private int[] values; private int[] values;
public PackedSwitchPad(PackedSwitchDataPseudoInstruction s, int defaultOffset) { public PackedSwitchPad(SwitchPayload inst, int defaultOffset) {
this.firstValue = s.getFirstKey(); int i = 0;
this.offsets = s.getTargets(); this.offsets = new int[inst.getSwitchElements().size()];
for(SwitchElement elt : inst.getSwitchElements()) {
if (i == 0) {
firstValue = elt.getKey();
}
offsets[i++] = elt.getOffset();
}
this.defaultOffset = defaultOffset; this.defaultOffset = defaultOffset;
} }

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,8 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Format.SparseSwitchDataPseudoInstruction; import org.jf.dexlib2.iface.instruction.SwitchElement;
import org.jf.dexlib2.iface.instruction.SwitchPayload;
public class SparseSwitchPad implements SwitchPad { public class SparseSwitchPad implements SwitchPad {
@ -57,10 +58,15 @@ public class SparseSwitchPad implements SwitchPad {
public final int defaultOffset; public final int defaultOffset;
private int [] labelsAndOffsets; private int [] labelsAndOffsets;
public SparseSwitchPad(SparseSwitchDataPseudoInstruction s, int defaultOffset) public SparseSwitchPad(SwitchPayload inst, int defaultOffset)
{ {
this.values = s.getKeys(); int i = 0;
this.offsets = s.getTargets(); this.values = new int[ inst.getSwitchElements().size() ];
this.offsets = new int[ inst.getSwitchElements().size() ];
for(SwitchElement elt : inst.getSwitchElements()) {
values[i] = elt.getKey();
offsets[i++] = elt.getOffset();
}
this.defaultOffset = defaultOffset; this.defaultOffset = defaultOffset;
} }

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
package com.ibm.wala.dalvik.dex.instructions; package com.ibm.wala.dalvik.dex.instructions;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib2.Opcode;
import com.ibm.wala.cast.ir.ssa.CAstUnaryOp; import com.ibm.wala.cast.ir.ssa.CAstUnaryOp;
import com.ibm.wala.dalvik.classLoader.DexIMethod; import com.ibm.wala.dalvik.classLoader.DexIMethod;

View File

@ -11,11 +11,8 @@
*******************************************************************************/ *******************************************************************************/
package com.ibm.wala.dalvik.ssa; package com.ibm.wala.dalvik.ssa;
import java.nio.ByteBuffer;
import java.util.Iterator; import java.util.Iterator;
import org.jf.dexlib.Code.Format.ArrayDataPseudoInstruction.ArrayElement;
import com.ibm.wala.cfg.IBasicBlock; import com.ibm.wala.cfg.IBasicBlock;
import com.ibm.wala.classLoader.CallSiteReference; import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.Language; import com.ibm.wala.classLoader.Language;
@ -480,46 +477,38 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
@Override @Override
public void visitArrayFill(ArrayFill instruction) { public void visitArrayFill(ArrayFill instruction) {
int ElementWidth = instruction.getTable().getElementWidth();
Iterator<ArrayElement> iae = instruction.getTable().getElements(); Iterator<Number> iae = instruction.getTable().getArrayElements().iterator();
int i = 0; int i = 0;
while (iae.hasNext()) while (iae.hasNext())
{ {
ArrayElement ae = iae.next(); Number ae = iae.next();
int ElementWidth = ae.elementWidth;
int index = symbolTable.getConstant(i); int index = symbolTable.getConstant(i);
int arrayRef = workingState.getLocal(instruction.array); int arrayRef = workingState.getLocal(instruction.array);
TypeReference t = instruction.getType(); TypeReference t = instruction.getType();
// System.out.println(t.getName().toString()); // System.out.println(t.getName().toString());
int value; int value;
//fetch the byte[] array for the element
byte[] temp_byte = new byte[ElementWidth];
for (int j = 0; j < ElementWidth; j++)
temp_byte[j] = ae.buffer[ae.bufferIndex+(ElementWidth-1)-j];
ByteBuffer byte_buffer = ByteBuffer.wrap(temp_byte);
// //
// System.out.println("Index: " + ae.bufferIndex + ", Width: " + ae.elementWidth + ", Value: " + byte_buffer.getSomethingDependingonType ); // System.out.println("Index: " + ae.bufferIndex + ", Width: " + ae.elementWidth + ", Value: " + byte_buffer.getSomethingDependingonType );
//okay to call the getConstant(String) for a char? //okay to call the getConstant(String) for a char?
if (t.equals(TypeReference.Char)) if (t.equals(TypeReference.Char))
value = symbolTable.getConstant(Character.toString(byte_buffer.getChar())); value = symbolTable.getConstant((char) ae.intValue());
else if (t.equals(TypeReference.Byte)) else if (t.equals(TypeReference.Byte))
value = symbolTable.getConstant(byte_buffer.get()); value = symbolTable.getConstant(ae.byteValue());
else if (t.equals(TypeReference.Short)) else if (t.equals(TypeReference.Short))
value = symbolTable.getConstant(byte_buffer.getShort()); value = symbolTable.getConstant(ae.shortValue());
else if (t.equals(TypeReference.Int)) else if (t.equals(TypeReference.Int))
value = symbolTable.getConstant(byte_buffer.getInt()); value = symbolTable.getConstant(ae.intValue());
else if (t.equals(TypeReference.Long)) else if (t.equals(TypeReference.Long))
value = symbolTable.getConstant(byte_buffer.getLong()); value = symbolTable.getConstant(ae.longValue());
else if (t.equals(TypeReference.Float)) else if (t.equals(TypeReference.Float))
value = symbolTable.getConstant(byte_buffer.getFloat()); value = symbolTable.getConstant(ae.floatValue());
else if (t.equals(TypeReference.Double)) else if (t.equals(TypeReference.Double))
value = symbolTable.getConstant(byte_buffer.getDouble()); value = symbolTable.getConstant(ae.doubleValue());
else if (t.equals(TypeReference.Boolean)) else if (t.equals(TypeReference.Boolean))
value = symbolTable.getConstant((byte_buffer.get() == 1)?true:false); value = symbolTable.getConstant(ae.intValue() != 0);
else else
{ {

View File

@ -37,13 +37,14 @@
*/ */
package com.ibm.wala.util.collections; package com.ibm.wala.util.collections;
import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
abstract class AbstractMultiMap<K, V> implements MultiMap<K, V> { abstract class AbstractMultiMap<K, V> implements Serializable, MultiMap<K, V> {
protected final Map<K, Set<V>> map = HashMapFactory.make(); protected final Map<K, Set<V>> map = HashMapFactory.make();

View File

@ -48,6 +48,7 @@
*/ */
package com.ibm.wala.util.graph.labeled; package com.ibm.wala.util.graph.labeled;
import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -64,7 +65,7 @@ import com.ibm.wala.util.intset.IntSet;
/** /**
*/ */
public class SparseNumberedLabeledEdgeManager<T, U> implements NumberedLabeledEdgeManager<T, U> { public class SparseNumberedLabeledEdgeManager<T, U> implements Serializable, NumberedLabeledEdgeManager<T, U> {
/** /**
* the label to be attached to an edge when no label is specified * the label to be attached to an edge when no label is specified

View File

@ -249,11 +249,11 @@
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<id>aggregate</id> <id>javadoc</id>
<goals> <goals>
<goal>aggregate</goal> <goal>javadoc</goal>
</goals> </goals>
<phase>generate-sources</phase> <phase>generate-resources</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>

View File

@ -12,6 +12,6 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<!-- module>e42</module --> <!-- module>e42</module -->
<module>e44</module> <module>e47</module>
</modules> </modules>
</project> </project>