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:
packages:
- realpath
- xvfb
before_install:
- git clone --depth=1 https://github.com/secure-software-engineering/DroidBench.git
/tmp/DroidBench
- git clone --depth=1 https://github.com/secure-software-engineering/DroidBench.git /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:
- mvn clean verify -DskipTests=true -B -q
script:
- xvfb-run mvn clean verify -B -q
- xvfb-run mvn clean install -B -q
- bash ./dependent-projects-trigger.sh $AUTH_TOKEN
- mvn javadoc:aggregate -B -q
- bash ./upload-javascript.sh $GH_TOKEN
- jdk_switcher use oraclejdk7
- ./build-maven-jars.py "install -Dgpg.skip"
sudo: false
cache:
directories:
- "$HOME/.m2"
- "$HOME/apache-maven-3.5.0"
- "$TRAVIS_BUILD_DIR/com.ibm.wala.core.testdata/ocaml/ocamljava-2.0-alpha1/lib"
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.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.shrikeBT.IInstruction;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.FieldReference;
@ -96,9 +97,9 @@ public class AnnotationTest extends WalaTestCase {
BytecodeClass<?> bcClassUnderTest = (BytecodeClass<?>) classUnderTest;
Collection<Annotation> runtimeInvisibleAnnotations = bcClassUnderTest.getAnnotations(true);
harness.assertEqualCollections(expectedRuntimeInvisibleAnnotations, runtimeInvisibleAnnotations);
Collection<Annotation> runtimeVisibleAnnotations = bcClassUnderTest.getAnnotations(false);
harness.assertEqualCollections(expectedRuntimeInvisibleAnnotations, runtimeInvisibleAnnotations);
harness.assertEqualCollections(expectedRuntimeVisibleAnnotations, runtimeVisibleAnnotations);
}
@ -120,7 +121,7 @@ public class AnnotationTest extends WalaTestCase {
IMethod methodUnderTest = cha.resolveMethod(methodRefUnderTest);
harness.assertNotNull(methodRefUnderTest.toString() + " not found", methodUnderTest);
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);
harness.assertEquals(1, runtimeInvisibleAnnotations.size());
@ -182,7 +183,7 @@ public class AnnotationTest extends WalaTestCase {
IMethod methodUnderTest = cha.resolveMethod(methodRefUnderTest);
harness.assertTrue(methodRefUnderTest.toString() + " not found", methodUnderTest != null);
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();
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 final IBytecodeMethod method;
private final IBytecodeMethod<IInstruction> method;
/**
* 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);
public static ShrikeCFG make(IBytecodeMethod m) {
public static ShrikeCFG make(IBytecodeMethod<IInstruction> m) {
return new ShrikeCFG(m);
}
private ShrikeCFG(IBytecodeMethod method) throws IllegalArgumentException {
private ShrikeCFG(IBytecodeMethod<IInstruction> method) throws IllegalArgumentException {
super(method);
if (method == null) {
throw new IllegalArgumentException("method cannot be null");
@ -81,7 +81,7 @@ public class ShrikeCFG extends AbstractCFG<IInstruction, ShrikeCFG.BasicBlock> i
}
@Override
public IBytecodeMethod getMethod() {
public IBytecodeMethod<IInstruction> getMethod() {
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();) {
T s = ss.next();
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;
}
protected Object makeEdgeLabel(T s) {
protected Object makeEdgeLabel(@SuppressWarnings("unused") T from, @SuppressWarnings("unused") T to, T s) {
return s;
}

View File

@ -13,7 +13,6 @@ package com.ibm.wala.classLoader;
import java.util.Collection;
import com.ibm.wala.shrikeBT.ExceptionHandler;
import com.ibm.wala.shrikeBT.IInstruction;
import com.ibm.wala.shrikeBT.IndirectionData;
import com.ibm.wala.shrikeCT.InvalidClassFileException;
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
*/
public interface IBytecodeMethod extends IMethod {
public interface IBytecodeMethod<I>extends IMethod {
/**
* @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
*/
IInstruction[] getInstructions() throws InvalidClassFileException;
I[] getInstructions() throws InvalidClassFileException;
/**there
* @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.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.collections.HashSetFactory;
@ -58,12 +59,16 @@ public class JVMLDalvikComparisonTest extends DalvikCallGraphTestBase {
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();
for(CGNode f : from) {
if (! f.getMethod().isSynthetic()) {
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> tts = to.getNodes(t.getMethod().getReference());
for(CGNode x : fts) {
@ -91,10 +96,18 @@ public class JVMLDalvikComparisonTest extends DalvikCallGraphTestBase {
Set<MethodReference> androidMethods = applicationMethods(android.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();
boolean fail = false;
if (javaExtraEdges.hasNext()) {
Iterator<Pair<CGNode, CGNode>> androidExtraEdges = edgeDiff(android.fst, java.fst, true).iterator();
Assert.assertFalse(checkEdgeDiff(java, javaMethods, androidMethods, androidExtraEdges));
}
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;
Set<MethodReference> javaExtraNodes = HashSetFactory.make(javaMethods);
javaExtraNodes.removeAll(androidMethods);
@ -121,9 +134,8 @@ public class JVMLDalvikComparisonTest extends DalvikCallGraphTestBase {
}
}
}
Assert.assertTrue(!fail);
}
return fail;
}
@Test
public void testJLex() throws ClassHierarchyException, IllegalArgumentException, IOException, CancelException {

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/dexlib-1.3.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/guava-13.0.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/dexlib2-2.2.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-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"/>

View File

@ -13,14 +13,19 @@ Export-Package: com.google.common.annotations,
com.google.common.base.internal,
com.google.common.cache,
com.google.common.collect,
com.google.common.escape,
com.google.common.eventbus,
com.google.common.graph,
com.google.common.hash,
com.google.common.html,
com.google.common.io,
com.google.common.math,
com.google.common.net,
com.google.common.primitives,
com.google.common.reflect,
com.google.common.util.concurrent,
com.google.common.xml,
com.google.thirdparty.publicsuffix,
com.ibm.wala.dalvik.analysis.typeInference,
com.ibm.wala.dalvik.classLoader,
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.monitor,
org.apache.commons.io.output,
org.jf.dexlib,
org.jf.dexlib.Code,
org.jf.dexlib.Code.Analysis,
org.jf.dexlib.Code.Format,
org.jf.dexlib.Debug,
org.jf.dexlib.EncodedValue,
org.jf.dexlib.Util
org.jf.dexlib2,
org.jf.dexlib2.analysis,
org.jf.dexlib2.analysis.reflection,
org.jf.dexlib2.analysis.reflection.util,
org.jf.dexlib2.analysis.util,
org.jf.dexlib2.base,
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: .,
lib/commons-cli-1.2.jar,
lib/commons-io-2.4.jar,
lib/dexlib-1.3.4.jar,
lib/guava-13.0.1.jar,
lib/dexlib2-2.2.1.jar,
lib/util-2.2.1.jar,
lib/logback-classic-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-io-2.4.jar,\
lib/dexlib-1.3.4.jar,\
lib/guava-13.0.1.jar,\
lib/dexlib2-2.2.1.jar,\
lib/util-2.2.1.jar,\
lib/logback-classic-1.0.9.jar,\
lib/logback-core-1.0.9.jar,\
lib/slf4j-api-1.7.2.jar,\
OSGI-INF/l10n/bundle.properties,\
OSGI-INF/
OSGI-INF/,\
lib/guava-22.0.jar
jars.compile.order = .
output.. = bin/
source.. = src/
javacProjectSettings = true

View File

@ -12,8 +12,38 @@
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
<plugins>
<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>
<version>1.7</version>
<executions>
@ -38,6 +68,7 @@
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/org.smali/dexlib2 -->
</dependencies>
</plugin>
</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.jar.JarFile;
import org.jf.dexlib.ClassDefItem;
import org.jf.dexlib.DexFile;
import org.jf.dexlib.Section;
import org.jf.dexlib2.DexFileFactory;
import org.jf.dexlib2.Opcodes;
import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib2.iface.DexFile;
import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.ModuleEntry;
@ -103,7 +104,7 @@ public class DexFileModule implements Module {
*/
private DexFileModule(File f) throws IllegalArgumentException {
try {
dexfile = new DexFile(f);
dexfile = DexFileFactory.loadDexFile(f, Opcodes.forApi(25));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
@ -111,8 +112,7 @@ public class DexFileModule implements Module {
// create ModuleEntries from ClassDefItem
entries = new HashSet<>();
Section<ClassDefItem> cldeff = dexfile.ClassDefsSection;
for (ClassDefItem cdefitems : cldeff.getItems()) {
for (ClassDef cdefitems : dexfile.getClasses()) {
entries.add(new DexModuleEntry(cdefitems));
}
}

View File

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

View File

@ -48,18 +48,11 @@
package com.ibm.wala.dalvik.classLoader;
import static org.jf.dexlib.Util.AccessFlags.FINAL;
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 static org.jf.dexlib2.AccessFlags.*;
import java.util.Collection;
import org.jf.dexlib.ClassDataItem.EncodedField;
import org.jf.dexlib.StringIdItem;
import org.jf.dexlib.TypeIdItem;
import org.jf.dexlib2.iface.Field;
import com.ibm.wala.classLoader.IClass;
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
*/
private final EncodedField eField;
private final Field eField;
/**
* The declaring class for this method.
@ -97,14 +90,14 @@ public class DexIField implements IField {
private Atom name;
public DexIField(EncodedField encodedField, DexIClass klass) {
public DexIField(Field encodedField, DexIClass klass) {
//public DexIField(EncodedField encodedField) {
eField = encodedField;
myClass = klass;
StringIdItem fieldName = eField.field.getFieldName();
name = Atom.findOrCreateUnicodeAtom(fieldName.getStringValue());
String fieldName = eField.getName();
name = Atom.findOrCreateUnicodeAtom(fieldName);
TypeIdItem fieldType = eField.field.getFieldType();
String fieldType = eField.getType();
TypeName T = DexUtil.getTypeName(fieldType);
TypeReference type = TypeReference.findOrCreate(myClass.getClassLoader().getReference(), T);
myFieldRef = FieldReference.findOrCreate(myClass.getReference(), name, type);
@ -144,27 +137,27 @@ public class DexIField implements IField {
@Override
public boolean isFinal() {
return (eField.accessFlags & FINAL.getValue()) != 0;
return (eField.getAccessFlags() & FINAL.getValue()) != 0;
}
@Override
public boolean isPrivate() {
return (eField.accessFlags & PRIVATE.getValue()) != 0;
return (eField.getAccessFlags() & PRIVATE.getValue()) != 0;
}
@Override
public boolean isProtected() {
return (eField.accessFlags & PROTECTED.getValue()) != 0;
return (eField.getAccessFlags() & PROTECTED.getValue()) != 0;
}
@Override
public boolean isPublic() {
return (eField.accessFlags & PUBLIC.getValue()) != 0;
return (eField.getAccessFlags() & PUBLIC.getValue()) != 0;
}
@Override
public boolean isStatic() {
return (eField.accessFlags & STATIC.getValue()) != 0;
return (eField.getAccessFlags() & STATIC.getValue()) != 0;
}
@Override
@ -174,7 +167,7 @@ public class DexIField implements IField {
@Override
public boolean isVolatile() {
return (eField.accessFlags & VOLATILE.getValue()) != 0;
return (eField.getAccessFlags() & VOLATILE.getValue()) != 0;
}
@Override
@ -184,7 +177,7 @@ public class DexIField implements IField {
@Override
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 org.jf.dexlib.ClassDefItem;
import org.jf.dexlib2.iface.ClassDef;
import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.ModuleEntry;
public class DexModuleEntry implements ModuleEntry {
private final ClassDefItem classDefItem;
private final ClassDef classDefItem;
private final String className;
public DexModuleEntry(ClassDefItem cdefitems) {
public DexModuleEntry(ClassDef cdefitems) {
classDefItem = cdefitems;
String temp =cdefitems.getClassType().getTypeDescriptor();
String temp =cdefitems.getType();
// className = temp;
if (temp.endsWith(";"))
className = temp.substring(0,temp.length()-1); //remove last ';'
@ -71,7 +71,7 @@ public class DexModuleEntry implements ModuleEntry {
// System.out.println(className);
}
public ClassDefItem getClassDefItem(){
public ClassDef getClassDefItem(){
return classDefItem;
}

View File

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

View File

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

View File

@ -48,7 +48,7 @@
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.types.TypeReference;

View File

@ -48,7 +48,7 @@
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;

View File

@ -48,7 +48,7 @@
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.dex.instructions.ArrayGet.Type;

View File

@ -48,7 +48,7 @@
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.dalvik.classLoader.DexIMethod;

View File

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

View File

@ -48,7 +48,7 @@
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.types.TypeReference;

View File

@ -48,7 +48,7 @@
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.types.TypeReference;

View File

@ -48,7 +48,7 @@
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;

View File

@ -48,7 +48,7 @@
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;

View File

@ -48,7 +48,7 @@
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.types.TypeReference;

View File

@ -48,7 +48,7 @@
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;
@ -146,7 +146,7 @@ public abstract class Instruction {
* True if the instruction can continue.
* @see com.ibm.wala.shrikeBT.IInstruction#isFallThrough()
*/
public boolean isFallThrough() {
public boolean isFallThrough() {
return opcode.canContinue();
}
@ -154,7 +154,7 @@ public abstract class Instruction {
* True if the instruction can throw an exception
* @see com.ibm.wala.shrikeBT.IInstruction#isPEI()
*/
public boolean isPEI() {
public boolean isPEI() {
return opcode.canThrow();
}
@ -172,12 +172,10 @@ public abstract class Instruction {
return opcode;
}
public int[] getBranchTargets() {
public int[] getBranchTargets() {
return noInstructions;
}
public abstract void visit(Visitor visitor);
}

View File

@ -48,11 +48,12 @@
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.shrikeBT.IInvokeInstruction;
import com.ibm.wala.shrikeBT.IInvokeInstruction.IDispatch;
import com.ibm.wala.types.Descriptor;
public abstract class Invoke extends Instruction {
@ -68,6 +69,8 @@ public abstract class Invoke extends Instruction {
this.methodName = methodName;
this.descriptor = descriptor;
this.args = args;
assert Descriptor.findOrCreateUTF8(descriptor) != null;
}
public static class InvokeVirtual extends Invoke

View File

@ -48,7 +48,7 @@
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;

View File

@ -48,7 +48,7 @@
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.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
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.dalvik.classLoader.DexIMethod;

View File

@ -48,7 +48,7 @@
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.dalvik.classLoader.DexIMethod;

View File

@ -48,19 +48,26 @@
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 final int firstValue;
public int firstValue;
public final int[] offsets;
public final int defaultOffset;
private int [] labelsAndOffsets;
private int[] values;
public PackedSwitchPad(PackedSwitchDataPseudoInstruction s, int defaultOffset) {
this.firstValue = s.getFirstKey();
this.offsets = s.getTargets();
public PackedSwitchPad(SwitchPayload inst, int defaultOffset) {
int i = 0;
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;
}

View File

@ -48,7 +48,7 @@
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;

View File

@ -48,7 +48,7 @@
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;

View File

@ -48,7 +48,8 @@
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 {
@ -57,10 +58,15 @@ public class SparseSwitchPad implements SwitchPad {
public final int defaultOffset;
private int [] labelsAndOffsets;
public SparseSwitchPad(SparseSwitchDataPseudoInstruction s, int defaultOffset)
public SparseSwitchPad(SwitchPayload inst, int defaultOffset)
{
this.values = s.getKeys();
this.offsets = s.getTargets();
int i = 0;
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;
}

View File

@ -48,7 +48,7 @@
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;

View File

@ -48,7 +48,7 @@
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;

View File

@ -48,7 +48,7 @@
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.dalvik.classLoader.DexIMethod;

View File

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

View File

@ -37,13 +37,14 @@
*/
package com.ibm.wala.util.collections;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
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();

View File

@ -48,6 +48,7 @@
*/
package com.ibm.wala.util.graph.labeled;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
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

View File

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

View File

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