Revert "Fix 106 Eclipse warnings about unnecessary else clauses"

This reverts commit 04dafcf7f7.
This commit is contained in:
Ben Liblit 2017-03-25 16:29:26 -05:00
parent e04816ec7a
commit 83a9201613
44 changed files with 456 additions and 340 deletions

View File

@ -249,7 +249,8 @@ public class JDT2CAstUtils {
assert returnType.isTypeVariable() || returnType.isCapture();
if (returnType.getTypeBounds().length > 0)
return returnType.getTypeBounds()[0]; // TODO: why is there more than one bound?
return ast.resolveWellKnownType("java.lang.Object");
else
return ast.resolveWellKnownType("java.lang.Object");
}
public static InfixExpression.Operator mapAssignOperatorToInfixOperator(Assignment.Operator op) {

View File

@ -863,8 +863,9 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
public Iterator<CAstEntity> getScopedEntities(CAstNode construct) {
if (fEntities.containsKey(construct)) {
return (fEntities.get(construct)).iterator();
} else {
return EmptyIterator.instance();
}
return EmptyIterator.instance();
}
@Override
@ -1036,7 +1037,8 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
public Collection<CAstQualifier> getQualifiers() {
if (fDecl == null)
return JDT2CAstUtils.mapModifiersToQualifiers(Modifier.STATIC, false, false); // static init
return JDT2CAstUtils.mapModifiersToQualifiers(fModifiers, false, false);
else
return JDT2CAstUtils.mapModifiersToQualifiers(fModifiers, false, false);
}
@Override
@ -1052,7 +1054,8 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
Type type = fDecl == null ? null : (ast.apiLevel() == 2 ? fDecl.getReturnType() : fDecl.getReturnType2());
if (type == null)
return fTypeDict.getCAstTypeFor(ast.resolveWellKnownType("void"));
return fTypeDict.getCAstTypeFor(type.resolveBinding());
else
return fTypeDict.getCAstTypeFor(type.resolveBinding());
}
/**
@ -1481,12 +1484,13 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
target = visitNode(n.getExpression(), context);
if (target.getKind() == CAstNode.EMPTY || target.getKind() == CAstNode.THIS)
return createMethodInvocation(n, binding, makeNode(context, fFactory, null, CAstNode.VOID), n.arguments(), context);
return makeNode(context, fFactory, n, CAstNode.BLOCK_EXPR, target, createMethodInvocation(n, binding, makeNode(context,
fFactory, null, CAstNode.VOID), n.arguments(), context));
// target is evaluated but thrown away, and only result of method invocation is kept
else
return makeNode(context, fFactory, n, CAstNode.BLOCK_EXPR, target, createMethodInvocation(n, binding, makeNode(context,
fFactory, null, CAstNode.VOID), n.arguments(), context));
// target is evaluated but thrown away, and only result of method invocation is kept
}
CAstNode target;
} else {
CAstNode target;
if (n.getExpression() != null) {
target = visitNode(n.getExpression(), context);
} else {
@ -1521,6 +1525,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
return createCast(n, node, fromtype, realtype, context);
}
return node;
}
}
private CAstNode createMethodInvocation(ASTNode pos, IMethodBinding methodBinding, CAstNode target,
@ -1628,14 +1633,16 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
Expression retExpr = r.getExpression();
if (retExpr == null)
return makeNode(context, fFactory, r, CAstNode.RETURN);
return makeNode(context, fFactory, r, CAstNode.RETURN, visitNode(retExpr, context));
else
return makeNode(context, fFactory, r, CAstNode.RETURN, visitNode(retExpr, context));
}
private CAstNode visit(Assignment n, WalkContext context) {
if (n.getOperator() == Assignment.Operator.ASSIGN)
return makeNode(context, fFactory, n, CAstNode.ASSIGN, visitNode(n.getLeftHandSide(), new AssignmentContext(context)),
visitNode(n.getRightHandSide(), context));
CAstNode left = visitNode(n.getLeftHandSide(), context);
else {
CAstNode left = visitNode(n.getLeftHandSide(), context);
// GENERICs lvalue for pre op hack
if (left.getKind() == CAstNode.CAST) {
return doFunkyGenericAssignPreOpHack(n, context);
@ -1658,6 +1665,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
}
return result;
}
}
/**
@ -1809,10 +1817,11 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
}
return createFieldAccess(targetNode, n.getIdentifier(), binding, n, context);
}
// local
} else {
// local
CAstType t = fTypeDict.getCAstTypeFor(((IVariableBinding)n.resolveBinding()).getType());
return makeNode(context, fFactory, n, CAstNode.VAR, fFactory.makeConstant(n.getIdentifier()), fFactory.makeConstant(t));
}
}

View File

@ -27,8 +27,9 @@ public class ECJClassLoaderFactory extends ClassLoaderFactoryImpl {
ClassLoaderImpl cl = makeSourceLoader(classLoaderReference, cha, parent);
cl.init(scope.getModules(classLoaderReference));
return cl;
} else {
return super.makeNewClassLoader(classLoaderReference, cha, parent, scope);
}
return super.makeNewClassLoader(classLoaderReference, cha, parent, scope);
}
protected JavaSourceLoaderImpl makeSourceLoader(ClassLoaderReference classLoaderReference, IClassHierarchy cha, IClassLoader parent)

View File

@ -37,15 +37,16 @@ public class DalvikTypeInference extends TypeInference {
SymbolTable st = ir.getSymbolTable();
if (st.isIntegerConstant(valueNumber) && st.isZero(valueNumber)) {
return new DalvikTypeVariable(language.getPrimitive(language.getConstantType(Integer.valueOf(0))), true);
}
if (doPrimitives) {
if (st.isConstant(valueNumber)) {
if (st.isBooleanConstant(valueNumber)) {
return new DalvikTypeVariable(language.getPrimitive(language.getConstantType(Boolean.TRUE)));
} else {
if (doPrimitives) {
if (st.isConstant(valueNumber)) {
if (st.isBooleanConstant(valueNumber)) {
return new DalvikTypeVariable(language.getPrimitive(language.getConstantType(Boolean.TRUE)));
}
}
}
return new DalvikTypeVariable(TypeAbstraction.TOP);
}
return new DalvikTypeVariable(TypeAbstraction.TOP);
}
}
@ -87,9 +88,10 @@ public class DalvikTypeInference extends TypeInference {
}
if (lhsType.equals(meet)) {
return NOT_CHANGED;
} else {
lhs.setType(meet);
return CHANGED;
}
lhs.setType(meet);
return CHANGED;
}
private boolean containsNonPrimitiveAndZero(DalvikTypeVariable[] types) {

View File

@ -590,9 +590,10 @@ public class DexCFG extends AbstractCFG<Instruction, DexCFG.BasicBlock> implemen
if (getNumber() == (getMaxNumber() - 1)) {
// this is the last non-exit block
return getInstructions().length - 1;
} else {
BasicBlock next = getNode(getNumber() + 1);
return next.getFirstInstructionIndex() - 1;
}
BasicBlock next = getNode(getNumber() + 1);
return next.getFirstInstructionIndex() - 1;
}
public int getFirstInstructionIndex() {

View File

@ -76,8 +76,9 @@ public class DexFileModule implements Module {
try (final JarFile jar = new JarFile(f)) {
return new DexFileModule(jar);
}
} else {
return new DexFileModule(f);
}
return new DexFileModule(f);
}
private static File tf(JarFile f) {

View File

@ -255,8 +255,9 @@ public class DexIClass extends BytecodeClass<IClassLoader> {
// if (this.getClass().equals(obj.getClass())) {
if (obj instanceof DexIClass) {
return getReference().equals(((DexIClass) obj).getReference());
} else {
return false;
}
return false;
}
@Override

View File

@ -329,10 +329,12 @@ public class DexIMethod implements IBytecodeMethod {
if (!isStatic()) {
if (index == 0) {
return myClass.getReference();
} else {
return getReference().getParameterType(index - 1);
}
return getReference().getParameterType(index - 1);
} else {
return getReference().getParameterType(index);
}
return getReference().getParameterType(index);
}
/*
@ -557,8 +559,9 @@ public class DexIMethod implements IBytecodeMethod {
if (obj instanceof DexIMethod) {
DexIMethod that = (DexIMethod) obj;
return (getDeclaringClass().equals(that.getDeclaringClass()) && getReference().equals(that.getReference()));
} else {
return false;
}
return false;
}
/**

View File

@ -90,8 +90,9 @@ public class DexIRFactory extends DefaultIRFactory {
if (lineNumber == -1) {
return "";
} else {
return "(line " + lineNumber + ")";
}
return "(line " + lineNumber + ")";
} catch (InvalidClassFileException e) {
return "";
}

View File

@ -273,16 +273,18 @@ public class AndroidModel /* makes SummarizedMethod */
if (tRef.isClassType()) {
if (cha.lookupClass(tRef) != null) {
return tRef;
} else {
for (IClass c : cha) {
if (c.getName().toString().equals(tRef.getName().toString())) {
return c.getReference();
}
}
}
for (IClass c : cha) {
if (c.getName().toString().equals(tRef.getName().toString())) {
return c.getReference();
}
}
return tRef;
//throw new IllegalStateException("Error looking up " + tRef);
} else {
return tRef;
}
return tRef;
}
};

View File

@ -243,8 +243,9 @@ public final /* singleton */ class AndroidModelClass extends SyntheticClass {
public IField getField(Atom name) {
if (fields.containsKey(name)) {
return fields.get(name);
} else {
return null;
}
return null;
}
public void putField(Atom name, TypeReference type) {

View File

@ -189,26 +189,28 @@ public class AndroidModelParameterManager {
// param.setBy = setBy;
return;
} else {
continue;
}
continue;
}
throw new IllegalStateException("The parameter " + type.getName() + " has already been allocated!");
} else {
ManagedParameter param = new ManagedParameter();
param.status = ValueStatus.ALLOCATED;
param.type = type;
param.ssa = ssaValue;
if ((ssaValue + 1) > nextLocal) {
nextLocal = ssaValue + 1;
}
param.setInScope = currentScope;
List<ManagedParameter> aParam = new ArrayList<>();
aParam.add(param);
seenTypes.put(type, aParam);
return;
}
ManagedParameter param = new ManagedParameter();
param.status = ValueStatus.ALLOCATED;
param.type = type;
param.ssa = ssaValue;
if ((ssaValue + 1) > nextLocal) {
nextLocal = ssaValue + 1;
}
param.setInScope = currentScope;
List<ManagedParameter> aParam = new ArrayList<>();
aParam.add(param);
seenTypes.put(type, aParam);
return;
}
public void setAllocation(TypeReference type, int ssaValue) {
@ -283,22 +285,23 @@ public class AndroidModelParameterManager {
}
assert (didPhi);
return;
} else {
ManagedParameter param = new ManagedParameter();
param.status = ValueStatus.ALLOCATED;
param.type = type;
param.setInScope = currentScope;
param.ssa = ssaValue;
if ((ssaValue + 1) > nextLocal) {
nextLocal = ssaValue + 1;
}
List<ManagedParameter> aParam = new ArrayList<>();
aParam.add(param);
seenTypes.put(type, aParam);
return;
}
ManagedParameter param = new ManagedParameter();
param.status = ValueStatus.ALLOCATED;
param.type = type;
param.setInScope = currentScope;
param.ssa = ssaValue;
if ((ssaValue + 1) > nextLocal) {
nextLocal = ssaValue + 1;
}
List<ManagedParameter> aParam = new ArrayList<>();
aParam.add(param);
seenTypes.put(type, aParam);
return;
}
/**
@ -436,8 +439,9 @@ public class AndroidModelParameterManager {
if (candidateSSA < 0 ) {
return candidateSSA;
} else {
throw new IllegalStateException("No suitable candidate has been found for " + type.getName());
}
throw new IllegalStateException("No suitable candidate has been found for " + type.getName());
}
/**
@ -508,13 +512,15 @@ public class AndroidModelParameterManager {
if (withSuper) {
return seenTypes.containsKey(type);
} else {
if (seenTypes.containsKey(type)) {
if (seenTypes.get(type).get(0).type.equals(type)) {
return true;
}
}
return false;
}
if (seenTypes.containsKey(type)) {
if (seenTypes.get(type).get(0).type.equals(type)) {
return true;
}
}
return false;
}
public boolean isSeen(TypeReference type) {
@ -537,10 +543,12 @@ public class AndroidModelParameterManager {
if (seenTypes.containsKey(type)) {
if (seenTypes.get(type).size() > 1) { // TODO INCORRECT may all be UNALLOCATED
return false;
} else {
return (seenTypes.get(type).get(0).status == ValueStatus.UNALLOCATED);
}
return (seenTypes.get(type).get(0).status == ValueStatus.UNALLOCATED);
} else {
return true;
}
return true;
}
/**
@ -568,8 +576,9 @@ public class AndroidModelParameterManager {
if (param.status == ValueStatus.ALLOCATED) {
if (seenLive) {
return true;
} else {
seenLive = true;
}
seenLive = true;
}
}
} else {

View File

@ -105,8 +105,9 @@ public class DefaultInstantiationBehavior extends IInstantiationBehavior impleme
if (o instanceof BehaviorKey) {
BehaviorKey<?> other = (BehaviorKey<?>) o;
return base.equals(other.base);
} else {
return false;
}
return false;
}
@Override

View File

@ -121,8 +121,9 @@ public class FlatInstantiator implements IInstantiator {
if (this.analysisScope.getExclusions() != null && this.analysisScope.getExclusions().contains(cls.getName().toString())) { // XXX FUUUUU
logger.info("Hit exclusions with {}", cls);
return true;
} else {
return false;
}
return false;
}
/**
@ -472,32 +473,34 @@ public class FlatInstantiator implements IInstantiator {
logger.debug("The interface {} has no known implementors - skipping over it", T);
}
return ret; // XXX: This is a bad idea?
} else {
// ADD all
for (IClass impl: impls) {
if (impl.isAbstract()) {
ret.addAll(getTypes(impl.getReference(), ret)); // impl added through recursion
} else {
ret.add(impl.getReference());
}
}
}
// ADD all
for (IClass impl: impls) {
if (impl.isAbstract()) {
ret.addAll(getTypes(impl.getReference(), ret)); // impl added through recursion
} else {
ret.add(impl.getReference());
}
}
} else if (cls.isAbstract()) {
final Collection<IClass> subs = cha.computeSubClasses(T);
if (subs.isEmpty()) {
throw new IllegalStateException("The class " + T + " is abstract but has no subclasses known to the ClassHierarchy");
} else {
for (final IClass sub: subs) {
if (seen.contains(sub.getReference())) {
logger.debug("Seen: {}", sub);
continue;
}
if (sub.isAbstract()) {
// Recurse on abstract classes
ret.addAll(getTypes(sub.getReference(), ret)); // sub added through recursion
} else {
ret.add(sub.getReference());
}
}
}
for (final IClass sub: subs) {
if (seen.contains(sub.getReference())) {
logger.debug("Seen: {}", sub);
continue;
}
if (sub.isAbstract()) {
// Recurse on abstract classes
ret.addAll(getTypes(sub.getReference(), ret)); // sub added through recursion
} else {
ret.add(sub.getReference());
}
}
} else if (cls.isArrayClass()) {
final ArrayClass aCls = (ArrayClass) cls;
final int dim = aCls.getDimensionality();
@ -651,8 +654,9 @@ public class FlatInstantiator implements IInstantiator {
if (ctor == null) {
logger.warn("Still found no CTor for {}", T);
return cha.resolveMethod(klass, MethodReference.initSelector);
} else {
return ctor;
}
return ctor;
}
/**

View File

@ -110,8 +110,9 @@ public class Instantiator implements IInstantiator {
if (this.analysisScope.getExclusions() != null && this.analysisScope.getExclusions().contains(cls.getName().toString())) { // XXX FUUUUU
logger.info("Hit exclusions with {}", cls);
return true;
} else {
return false;
}
return false;
}
/**
@ -178,8 +179,9 @@ public class Instantiator implements IInstantiator {
this.body.addStatement(getInst);
pm.setAllocation(instance, getInst);
return instance;
} else {
logger.info("NEW Component {} \n\tbreadCrumb: {}", instance, pm.breadCrumb);
}
logger.info("NEW Component {} \n\tbreadCrumb: {}", instance, pm.breadCrumb);
} else {
logger.info("NEW Component {} \n\tbreadCrumb: {}", instance, pm.breadCrumb);
}
@ -472,32 +474,34 @@ public class Instantiator implements IInstantiator {
logger.debug("The interface {} has no known implementors - skipping over it", T);
}
return ret; // XXX: This is a bad idea?
} else {
// ADD all
for (IClass impl: impls) {
if (impl.isAbstract()) {
ret.addAll(getTypes(impl.getReference(), ret)); // impl added through recursion
} else {
ret.add(impl.getReference());
}
}
}
// ADD all
for (IClass impl: impls) {
if (impl.isAbstract()) {
ret.addAll(getTypes(impl.getReference(), ret)); // impl added through recursion
} else {
ret.add(impl.getReference());
}
}
} else if (cls.isAbstract()) {
final Collection<IClass> subs = cha.computeSubClasses(T);
if (subs.isEmpty()) {
throw new IllegalStateException("The class " + T + " is abstract but has no subclasses known to the ClassHierarchy");
} else {
for (final IClass sub: subs) {
if (seen.contains(sub.getReference())) {
logger.debug("Seen: {}", sub);
continue;
}
if (sub.isAbstract()) {
// Recurse on abstract classes
ret.addAll(getTypes(sub.getReference(), ret)); // sub added through recursion
} else {
ret.add(sub.getReference());
}
}
}
for (final IClass sub: subs) {
if (seen.contains(sub.getReference())) {
logger.debug("Seen: {}", sub);
continue;
}
if (sub.isAbstract()) {
// Recurse on abstract classes
ret.addAll(getTypes(sub.getReference(), ret)); // sub added through recursion
} else {
ret.add(sub.getReference());
}
}
} else if (cls.isArrayClass()) {
final ArrayClass aCls = (ArrayClass) cls;
final int dim = aCls.getDimensionality();
@ -631,8 +635,9 @@ public class Instantiator implements IInstantiator {
if (ctor == null) {
logger.warn("Still found no CTor for {}", T);
return cha.resolveMethod(klass, MethodReference.initSelector);
} else {
return ctor;
}
return ctor;
}
/**

View File

@ -107,8 +107,9 @@ public class LoadedInstantiationBehavior extends IInstantiationBehavior implemen
if (o instanceof BehaviorKey) {
BehaviorKey<?> other = (BehaviorKey<?>) o;
return base.equals(other.base);
} else {
return false;
}
return false;
}
@Override
@ -252,8 +253,9 @@ public class LoadedInstantiationBehavior extends IInstantiationBehavior implemen
public InstanceBehavior getDafultBehavior() {
if (this.defaultBehavior == null) {
return InstanceBehavior.REUSE;
} else {
return this.defaultBehavior;
}
return this.defaultBehavior;
}
public void setBehavior(final TypeName type, final TypeName asParameterTo, final MethodReference inCall,

View File

@ -153,8 +153,9 @@ public class ReuseParameters {
if (inCallTo.isStatic()) {
return paramNo + 1;
} else {
return paramNo + 1; // TODO 2 or 1?
}
return paramNo + 1; // TODO 2 or 1?
}
/**

View File

@ -524,11 +524,12 @@ public class AndroidStartComponentTool {
public SSAValue addPhi(List<? extends SSAValue> from) {
if (from.size() == 1) {
return from.get(0);
} else {
final SSAValue retVal = this.pm.getUnmanaged(from.get(0).getType(), "forPhi");
final int phiPC = redirect.getNextProgramCounter();
final SSAInstruction phi = instructionFactory.PhiInstruction(phiPC, retVal, from);
this.redirect.addStatement(phi);
return retVal;
}
final SSAValue retVal = this.pm.getUnmanaged(from.get(0).getType(), "forPhi");
final int phiPC = redirect.getNextProgramCounter();
final SSAInstruction phi = instructionFactory.PhiInstruction(phiPC, retVal, from);
this.redirect.addStatement(phi);
return retVal;
}
}

View File

@ -164,16 +164,18 @@ public class ExternalModel extends AndroidModel {
if (tRef.isClassType()) {
if (cha.lookupClass(tRef) != null) {
return tRef;
} else {
for (IClass c : cha) {
if (c.getName().toString().equals(tRef.getName().toString())) {
return c.getReference();
}
}
}
for (IClass c : cha) {
if (c.getName().toString().equals(tRef.getName().toString())) {
return c.getReference();
}
}
throw new IllegalStateException("Error looking up " + tRef);
} else {
return tRef;
}
return tRef;
}
};

View File

@ -162,16 +162,18 @@ public class SystemServiceModel extends AndroidModel {
if (tRef.isClassType()) {
if (cha.lookupClass(tRef) != null) {
return tRef;
} else {
for (IClass c : cha) {
if (c.getName().toString().equals(tRef.getName().toString())) {
return c.getReference();
}
}
}
for (IClass c : cha) {
if (c.getName().toString().equals(tRef.getName().toString())) {
return c.getReference();
}
}
throw new IllegalStateException("Error looking up " + tRef);
} else {
return tRef;
}
return tRef;
}
};

View File

@ -214,16 +214,18 @@ public class UnknownTargetModel extends AndroidModel {
if (tRef.isClassType()) {
if (cha.lookupClass(tRef) != null) {
return tRef;
} else {
for (IClass c : cha) {
if (c.getName().toString().equals(tRef.getName().toString())) {
return c.getReference();
}
}
}
for (IClass c : cha) {
if (c.getName().toString().equals(tRef.getName().toString())) {
return c.getReference();
}
}
throw new IllegalStateException("Error looking up " + tRef);
} else {
return tRef;
}
return tRef;
}
}; // of this.model
}

View File

@ -442,8 +442,9 @@ public class AndroidEntryPoint extends DexEntryPoint {
if (o instanceof AndroidEntryPoint) {
AndroidEntryPoint other = (AndroidEntryPoint) o;
return this.getMethod().equals(other.getMethod());
} else {
return false;
}
return false;
}
@Override

View File

@ -101,16 +101,20 @@ public class AndroidContext implements Context {
if (this.aCtxT.equals(other.aCtxT)) {
if (this.parent != null) {
return this.parent.equals(other.parent);
} else {
return other.parent == null;
}
return other.parent == null;
} else {
return false;
}
} else {
if (this.parent != null) {
// TODO: do we really want this?
return this.parent.equals(obj);
} else {
return false;
}
return false;
}
if (this.parent != null) {
// TODO: do we really want this?
return this.parent.equals(obj);
}
return false;
}
@Override
@ -123,7 +127,8 @@ public class AndroidContext implements Context {
public String toString() {
if (this.parent == null) {
return "AndroidContext: " + this.aCtxT;
} else {
return "AndroidContext: " + this.aCtxT + ", parent: " + this.parent;
}
return "AndroidContext: " + this.aCtxT + ", parent: " + this.parent;
}
}

View File

@ -227,18 +227,19 @@ public class Intent implements ContextItem, Comparable<Intent> {
public IntentType getType() {
if (this.type != null) {
return this.type;
} else {
if (isSystemService(this)) {
this.type = IntentType.SYSTEM_SERVICE;
} else if (isStandardAction(this)) {
this.type = IntentType.STANDARD_ACTION;
} else if (isInternal(this)) {
this.type = IntentType.INTERNAL_TARGET;
} else if (isExternal(this)) {
this.type = IntentType.EXTERNAL_TARGET;
} else {
this.type = IntentType.UNKNOWN_TARGET;
}
}
if (isSystemService(this)) {
this.type = IntentType.SYSTEM_SERVICE;
} else if (isStandardAction(this)) {
this.type = IntentType.STANDARD_ACTION;
} else if (isInternal(this)) {
this.type = IntentType.INTERNAL_TARGET;
} else if (isExternal(this)) {
this.type = IntentType.EXTERNAL_TARGET;
} else {
this.type = IntentType.UNKNOWN_TARGET;
}
return this.type;
}
@ -406,8 +407,9 @@ public class Intent implements ContextItem, Comparable<Intent> {
// DO NOT USE TYPE!
if (this.uri != null) {
return getAction().hashCode() * this.uri.hashCode();
} else {
return getAction().hashCode();
}
return getAction().hashCode();
}
/**
@ -432,11 +434,13 @@ public class Intent implements ContextItem, Comparable<Intent> {
// DO NOT USE TYPE!
if (this.uri != null) {
return ( (this.uri.equals(other.uri)) && equalAction(other) ); // && (this.explicit == other.explicit));
} else {
return ( (other.uri == null) && equalAction(other) ); // && (this.explicit == other.explicit)) ;
}
return ( (other.uri == null) && equalAction(other) ); // && (this.explicit == other.explicit)) ;
} else {
System.err.println("WARNING: Can't compare Intent to " + o.getClass());
return false;
}
System.err.println("WARNING: Can't compare Intent to " + o.getClass());
return false;
}
public Intent resolve() {

View File

@ -102,16 +102,20 @@ public class IntentContext implements Context {
if (this.intent.equals(other.intent)) {
if (this.parent != null) {
return this.parent.equals(other.parent);
} else {
return other.parent == null;
}
return other.parent == null;
} else {
return false;
}
} else {
if (this.parent != null) {
// TODO: do we really want this?
return this.parent.equals(obj);
} else {
return false;
}
return false;
}
if (this.parent != null) {
// TODO: do we really want this?
return this.parent.equals(obj);
}
return false;
}
@Override
@ -124,8 +128,9 @@ public class IntentContext implements Context {
public String toString() {
if (this.parent == null) {
return "Intent: " + this.intent;
} else {
return "Intent: " + this.intent + ", parent: " + this.parent;
}
return "Intent: " + this.intent + ", parent: " + this.parent;
}
public Intent getIntent() {

View File

@ -123,11 +123,12 @@ public class IntentContextInterpreter implements SSAContextInterpreter {
if (possibleTargets.size() == 1) {
final Iterator<AndroidComponent> it = possibleTargets.iterator();
return it.next();
} else {
// TODO: Go interactive and ask user?
final Iterator<AndroidComponent> it = possibleTargets.iterator();
final AndroidComponent targetComponent = it.next();
return targetComponent;
}
// TODO: Go interactive and ask user?
final Iterator<AndroidComponent> it = possibleTargets.iterator();
final AndroidComponent targetComponent = it.next();
return targetComponent;
}
}
@ -225,22 +226,23 @@ public class IntentContextInterpreter implements SSAContextInterpreter {
} catch (CancelException e) {
throw new IllegalStateException("The operation was canceled.", e);
}
}
// This should _not_ happen: IntentContextSelector should always create an IntentContext.
//
final IMethod method = node.getMethod();
final IntentStarters.StartInfo info = intentStarters.getInfo(method.getReference());
assert (info != null) : "IntentInfo is null! Every Starter should have an StartInfo... - Method " + method.getReference();
final Intent intent = new Intent(Intent.UNBOUND);
final AndroidComponent targetComponent = fetchTargetComponent(intent, method);
} else {
// This should _not_ happen: IntentContextSelector should always create an IntentContext.
//
final IMethod method = node.getMethod();
final IntentStarters.StartInfo info = intentStarters.getInfo(method.getReference());
assert (info != null) : "IntentInfo is null! Every Starter should have an StartInfo... - Method " + method.getReference();
final Intent intent = new Intent(Intent.UNBOUND);
final AndroidComponent targetComponent = fetchTargetComponent(intent, method);
try {
final UnknownTargetModel model = new UnknownTargetModel(this.cha, this.options, this.cache, targetComponent);
final SummarizedMethod override = model.getMethodAs(method.getReference(), callingClass, intentStarters.getInfo(method.getReference()), node);
return override.makeIR(ctx, this.options.getSSAOptions());
} catch (CancelException e) {
throw new IllegalStateException("The operation was canceled.", e);
}
try {
final UnknownTargetModel model = new UnknownTargetModel(this.cha, this.options, this.cache, targetComponent);
final SummarizedMethod override = model.getMethodAs(method.getReference(), callingClass, intentStarters.getInfo(method.getReference()), node);
return override.makeIR(ctx, this.options.getSSAOptions());
} catch (CancelException e) {
throw new IllegalStateException("The operation was canceled.", e);
}
}
}
}

View File

@ -135,9 +135,10 @@ public class IntentContextSelector implements ContextSelector {
logger.error("Unable to resolve Intent called from {}", caller.getMethod());
logger.error("Search Key: {} hash: {}", param, param.hashCode());
break;
} else {
intent = intents.find(param);
break;
}
intent = intents.find(param);
break;
}
}
}
@ -148,13 +149,14 @@ public class IntentContextSelector implements ContextSelector {
final Intent iintent = intents.findOrCreateImmutable(intent);
return new IntentContext(ctx, iintent);
//return new IntentContext(iintent);
} else {
logger.warn("Encountered unresolvable Intent");
intent = new Intent("Unresolvable");
intent.setImmutable();
AndroidEntryPointManager.MANAGER.addCallSeen(site, intent);
return new IntentContext(ctx, intent);
//return new IntentContext(intent);
}
logger.warn("Encountered unresolvable Intent");
intent = new Intent("Unresolvable");
intent.setImmutable();
AndroidEntryPointManager.MANAGER.addCallSeen(site, intent);
return new IntentContext(ctx, intent);
//return new IntentContext(intent);
} else if (callee.getReference().toString().contains("getSystemService")) {
assert(actualParameters.length == 2) : "PARAMS LENGTH IS" + actualParameters.length;
final InstanceKey param = actualParameters[1];
@ -419,10 +421,11 @@ public class IntentContextSelector implements ContextSelector {
if (target.getNumberOfParameters() == 0) {
// public IntentSender()
return IntSetUtil.make(new int[] { 0 });
} else {
// public IntentSender(IIntentSender target)
// public IntentSender(IBinder target)
return IntSetUtil.make(new int[] { 0, 1 });
}
// public IntentSender(IIntentSender target)
// public IntentSender(IBinder target)
return IntSetUtil.make(new int[] { 0, 1 });
} /*else if (site.isSpecial() && target.getDeclaringClass().getName().equals(
AndroidTypes.ContextWrapperName)) {
logger.debug("Fetched ContextWrapper ctor");

View File

@ -64,13 +64,14 @@ import com.ibm.wala.util.strings.StringStuff;
if (immutables.containsKey(intent)) {
final Intent immutable = immutables.get(intent);
assert (immutable.getAction().equals(intent.getAction()));
return immutable;
} else {
final Intent immutable = intent.clone();
immutable.setImmutable();
immutables.put(intent, immutable);
return immutable;
}
final Intent immutable = intent.clone();
immutable.setImmutable();
immutables.put(intent, immutable);
return immutable;
}
public Intent find(final InstanceKey key) throws IndexOutOfBoundsException {
@ -122,8 +123,9 @@ import com.ibm.wala.util.strings.StringStuff;
public Intent findOrCreate(final InstanceKey key) {
if (seen.containsKey(key)) {
return find(key);
} else {
return create(key);
}
return create(key);
}
public void put(final InstanceKey key, final Intent intent) {
@ -159,11 +161,12 @@ import com.ibm.wala.util.strings.StringStuff;
final Intent intent = find(key);
intent.setExplicit();
return intent;
} else {
throw new IllegalArgumentException("setAction: No Intent found for key " + key);
//final Intent intent = create(key);
//intent.setExplicit();
//return intent;
}
throw new IllegalArgumentException("setAction: No Intent found for key " + key);
//final Intent intent = create(key);
//intent.setExplicit();
//return intent;
}
public Intent setAction(final InstanceKey key, final Atom action, boolean isExplicit) {
@ -175,9 +178,11 @@ import com.ibm.wala.util.strings.StringStuff;
intent.setAction(action);
}
return intent;
} else {
final Intent intent = create(key, action);
return intent;
}
final Intent intent = create(key, action);
return intent;
}
public Intent setAction(final Intent intent, final String action, boolean isExplicit) {

View File

@ -137,9 +137,10 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
MachineState newExit = flow.flow(entry, node);
if (newExit.stateEquals(exit)) {
return NOT_CHANGED;
} else {
exit.copyState(newExit);
return CHANGED;
}
exit.copyState(newExit);
return CHANGED;
}
@Override
@ -170,9 +171,10 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
MachineState newExit = flow.flow(entry, from, to);
if (newExit.stateEquals(exit)) {
return NOT_CHANGED;
} else {
exit.copyState(newExit);
return CHANGED;
}
exit.copyState(newExit);
return CHANGED;
}
@Override
@ -294,8 +296,9 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
if (!bb.isCatchBlock()) {
return meet(lhs, rhs, bb, meeter) ? CHANGED : NOT_CHANGED;
} else {
return meetForCatchBlock(lhs, rhs, bb, meeter) ? CHANGED : NOT_CHANGED;
}
return meetForCatchBlock(lhs, rhs, bb, meeter) ? CHANGED : NOT_CHANGED;
}
@Override
@ -308,8 +311,9 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
if (o instanceof MeetOperator) {
MeetOperator other = (MeetOperator) o;
return meeter.equals(other.meeter);
} else {
return false;
}
return false;
}
@Override
@ -621,8 +625,9 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
if (locals == null) {
if (OPTIMISTIC && (j == TOP)) {
return;
} else {
allocateLocals();
}
allocateLocals();
}
locals[i] = j;
}
@ -635,10 +640,12 @@ public abstract class AbstractIntRegisterMachine implements FixedPointConstants
if (locals == null) {
if (OPTIMISTIC) {
return TOP;
} else {
return BOTTOM;
}
return BOTTOM;
} else {
return locals[i];
}
return locals[i];
}
public void replaceValue(int from, int to) {

View File

@ -206,28 +206,29 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
}
// didn't find anything but TOP
return TOP;
} else {
SSACFG.BasicBlock newBB = cfg.getNode(dexCFG.getNumber(bb));
if (bb.isExitBlock()) {
// no phis in exit block please
return TOP;
}
// if we already have a phi for this local
SSAPhiInstruction phi = newBB.getPhiForLocal(n);
int result;
if (phi == null) {
// no phi already exists. create one.
result = symbolTable.newPhi(rhs);
PhiValue v = symbolTable.getPhiValue(result);
phi = v.getPhiInstruction();
newBB.addPhiForLocal(n, phi);
} else {
// already created a phi. update it to account for the
// new merge.
result = phi.getDef();
phi.setValues(rhs.clone());
}
return result;
}
SSACFG.BasicBlock newBB = cfg.getNode(dexCFG.getNumber(bb));
if (bb.isExitBlock()) {
// no phis in exit block please
return TOP;
}
// if we already have a phi for this local
SSAPhiInstruction phi = newBB.getPhiForLocal(n);
int result;
if (phi == null) {
// no phi already exists. create one.
result = symbolTable.newPhi(rhs);
PhiValue v = symbolTable.getPhiValue(result);
phi = v.getPhiInstruction();
newBB.addPhiForLocal(n, phi);
} else {
// already created a phi. update it to account for the
// new merge.
result = phi.getDef();
phi.setValues(rhs.clone());
}
return result;
}
/**
@ -391,8 +392,9 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
private int reuseOrCreateDef() {
if (getCurrentInstruction() == null || !getCurrentInstruction().hasDef()) {
return symbolTable.newSymbol();
} else {
return getCurrentInstruction().getDef();
}
return getCurrentInstruction().getDef();
}
/**
@ -406,9 +408,10 @@ public class DexSSABuilder extends AbstractIntRegisterMachine {
}
if (getCurrentInstruction() == null) {
return symbolTable.newSymbol();
} else {
SSAInvokeInstruction s = (SSAInvokeInstruction) getCurrentInstruction();
return s.getException();
}
SSAInvokeInstruction s = (SSAInvokeInstruction) getCurrentInstruction();
return s.getException();
}

View File

@ -415,17 +415,19 @@ nextMethod:
return true;
}
return false;
} else {
return true;
}
return true;
}
private boolean isExcluded(final IClass cls) {
final SetOfClasses set = cls.getClassHierarchy().getScope().getExclusions();
if (set == null) {
return false; // exclusions null ==> no exclusions ==> no class is excluded
} else {
final String clsName = cls.getReference().getName().toString().substring(1);
return set.contains(clsName);
}
final String clsName = cls.getReference().getName().toString().substring(1);
return set.contains(clsName);
}
/**

View File

@ -204,8 +204,9 @@ public final /* singleton */ class AndroidEntryPointManager implements Serializa
public IProgressMonitor getProgressMonitor() {
if (this.progressMonitor == null) {
return new NullProgressMonitor();
} else {
return this.progressMonitor;
}
return this.progressMonitor;
}
/**
@ -268,24 +269,25 @@ public final /* singleton */ class AndroidEntryPointManager implements Serializa
SSAValueManager paramManager, Iterable<? extends Entrypoint> entryPoints) {
if (abstractAndroidModel == null) {
return new LoopAndroidModel(body, insts, paramManager, entryPoints);
} else {
try {
final Constructor<? extends AbstractAndroidModel> ctor = this.abstractAndroidModel.getDeclaredConstructor(
VolatileMethodSummary.class, TypeSafeInstructionFactory.class, SSAValueManager.class,
Iterable.class);
if (ctor == null) {
throw new IllegalStateException("Canot find the constructor of " + this.abstractAndroidModel);
}
return ctor.newInstance(body, insts, paramManager, entryPoints);
} catch (java.lang.InstantiationException e) {
throw new IllegalStateException(e);
} catch (java.lang.IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (java.lang.reflect.InvocationTargetException e) {
throw new IllegalStateException(e);
} catch (java.lang.NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
try {
final Constructor<? extends AbstractAndroidModel> ctor = this.abstractAndroidModel.getDeclaredConstructor(
VolatileMethodSummary.class, TypeSafeInstructionFactory.class, SSAValueManager.class,
Iterable.class);
if (ctor == null) {
throw new IllegalStateException("Canot find the constructor of " + this.abstractAndroidModel);
}
return ctor.newInstance(body, insts, paramManager, entryPoints);
} catch (java.lang.InstantiationException e) {
throw new IllegalStateException(e);
} catch (java.lang.IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (java.lang.reflect.InvocationTargetException e) {
throw new IllegalStateException(e);
} catch (java.lang.NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
/**
@ -366,8 +368,9 @@ public final /* singleton */ class AndroidEntryPointManager implements Serializa
if (this.pack == null) {
logger.warn("Returning null as package");
return null;
} else {
return this.pack;
}
return this.pack;
}
/**
@ -382,14 +385,15 @@ public final /* singleton */ class AndroidEntryPointManager implements Serializa
public String guessPackage() {
if (this.pack != null) {
return this.pack;
} else {
if (ENTRIES.isEmpty()) {
logger.error("guessPackage() called when no entrypoints had been set");
return null;
}
final String first = ENTRIES.get(0).getMethod().getReference().getDeclaringClass().getName().getPackage().toString();
// TODO: Iterate all?
return first;
}
if (ENTRIES.isEmpty()) {
logger.error("guessPackage() called when no entrypoints had been set");
return null;
}
final String first = ENTRIES.get(0).getMethod().getReference().getDeclaringClass().getName().getPackage().toString();
// TODO: Iterate all?
return first;
}
//
@ -589,26 +593,28 @@ public final /* singleton */ class AndroidEntryPointManager implements Serializa
if (!overrideIntents.containsKey(intent)) {
logger.info("Resolved {} to {}", intent, ret);
return ret;
}
logger.debug("Resolving {} hop over {}", intent, ret);
final Intent old = ret;
ret = overrideIntents.get(ret);
} else {
logger.debug("Resolving {} hop over {}", intent, ret);
final Intent old = ret;
ret = overrideIntents.get(ret);
if (ret == old) { // Yes, ==
// This is an evil hack(tm). I should fix the Intent-Table!
logger.warn("Malformend Intent-Table, staying with " + ret + " for " + intent);
return ret;
}
if (ret == old) { // Yes, ==
// This is an evil hack(tm). I should fix the Intent-Table!
logger.warn("Malformend Intent-Table, staying with " + ret + " for " + intent);
return ret;
}
}
}
ret = overrideIntents.get(ret); // Once again to get Info set in register
logger.info("Resolved {} to {}", intent, ret);
return ret;
} else {
logger.info("No information on {} hash: {}", intent, intent.hashCode());
for (Intent known : overrideIntents.keySet()) {
logger.debug("Known Intents: {} hash: {}", known, known.hashCode());
}
return intent;
}
logger.info("No information on {} hash: {}", intent, intent.hashCode());
for (Intent known : overrideIntents.keySet()) {
logger.debug("Known Intents: {} hash: {}", known, known.hashCode());
}
return intent;
}
/**

View File

@ -293,8 +293,9 @@ public class AndroidManifestXMLReader {
if (reverseMap.containsKey(tag)) {
return reverseMap.get(tag);
} else {
return Tag.UNIMPORTANT;
}
return Tag.UNIMPORTANT;
}
}

View File

@ -204,11 +204,13 @@ public class AndroidSettingFactory {
String pack = AndroidEntryPointManager.MANAGER.getPackage();
if (pack != null) {
return intent(pack, fullyQualifiedAction, uri);
}
throw new IllegalArgumentException("The action " + fullyQualifiedAction + " is not fully qualified and the application package is unknown! Use " +
} else {
throw new IllegalArgumentException("The action " + fullyQualifiedAction + " is not fully qualified and the application package is unknown! Use " +
" intent(String pack, String name, String uri) to build the intent!");
}
} else {
return intent(null, fullyQualifiedAction, uri);
}
return intent(null, fullyQualifiedAction, uri);
}
public static Intent intent(String fullyQualifiedAction) {

View File

@ -87,7 +87,8 @@ public class GlobalIdentityFunction <E extends ISSABasicBlock>
// if the query domain element is a local, then it is /not/ passed through.
return TaintTransferFunctions.EMPTY_SET;
} else {
return SparseIntSet.singleton(d1);
}
return SparseIntSet.singleton(d1);
}
}

View File

@ -194,8 +194,9 @@ public class TaintTransferFunctions<E extends ISSABasicBlock> implements
// new CallFlowFunction<E>(domain, actualParams)));
return union(globalId,
new CallFlowFunction<>(domain, actualParams));
} else {
throw new RuntimeException("src block not an invoke instruction");
}
throw new RuntimeException("src block not an invoke instruction");
}
@Override

View File

@ -81,7 +81,10 @@ public abstract class FlowType<E extends ISSABasicBlock> {
}
public String descString() {
return source ? "I" : "O";
if(source)
return "I";
else
return "O";
}
@Override

View File

@ -74,8 +74,9 @@ public class ReturnFlow <E extends ISSABasicBlock> extends FlowType<E> {
if(isSource()) {
SSAInvokeInstruction inv = (SSAInvokeInstruction)getBlock().getLastInstruction();
return "ret:" + inv.getDeclaredTarget().getSignature();
} else {
return "ret";
}
return "ret";
}
@Override

View File

@ -311,8 +311,10 @@ public class AppModelMethod {
private int makeArgument(TypeReference tr) {
if (tr.isPrimitiveType())
return addLocal();
SSANewInstruction n = processAllocation(tr, nextLocal++, false);
return (n == null) ? -1 : n.getDef();
else {
SSANewInstruction n = processAllocation(tr, nextLocal++, false);
return (n == null) ? -1 : n.getDef();
}
}
private int addLocal() {

View File

@ -95,11 +95,14 @@ public class BlockSearch {
}
continue;
}
Iterator<ISSABasicBlock> predNodes = cfg.getPredNodes(current);
while(predNodes.hasNext())
{
blockQueue.add(predNodes.next());
}
else
{
Iterator<ISSABasicBlock> predNodes = cfg.getPredNodes(current);
while(predNodes.hasNext())
{
blockQueue.add(predNodes.next());
}
}
}
return candidate;
}

View File

@ -117,11 +117,14 @@ public class PrefixVariable extends AbstractVariable<PrefixVariable>{
knownPrefixes.put(instance, prefix);
return true;
}
String newPrefix = intersect(prevPrefix,prefix);
if(newPrefix.equals(prevPrefix))
return false;
knownPrefixes.put(instance, newPrefix);
return true;
else
{
String newPrefix = intersect(prevPrefix,prefix);
if(newPrefix.equals(prevPrefix))
return false;
knownPrefixes.put(instance, newPrefix);
return true;
}
}
public String toString() {

View File

@ -178,8 +178,9 @@ public class CGAnalysisContext<E extends ISSABasicBlock> {
graphBuilt = false;
if (!options.testCGBuilder()) {
throw new RuntimeException(e);
} else {
e.printStackTrace();
}
e.printStackTrace();
}
if (options.testCGBuilder()) {
@ -221,22 +222,23 @@ public class CGAnalysisContext<E extends ISSABasicBlock> {
// Node in APK
if (LoaderUtils.fromLoader(node, ClassLoaderReference.Application)) {
return true;
} else {
Iterator<CGNode> n = cg.getPredNodes(node);
while (n.hasNext()) {
// Primordial node has a successor in APK
if (LoaderUtils.fromLoader(n.next(), ClassLoaderReference.Application))
return true;
}
n = cg.getSuccNodes(node);
while (n.hasNext()) {
// Primordial node has a predecessor in APK
if (LoaderUtils.fromLoader(n.next(), ClassLoaderReference.Application))
return true;
}
// Primordial node with no direct successors or predecessors
// to APK code
return false;
}
Iterator<CGNode> n = cg.getPredNodes(node);
while (n.hasNext()) {
// Primordial node has a successor in APK
if (LoaderUtils.fromLoader(n.next(), ClassLoaderReference.Application))
return true;
}
n = cg.getSuccNodes(node);
while (n.hasNext()) {
// Primordial node has a predecessor in APK
if (LoaderUtils.fromLoader(n.next(), ClassLoaderReference.Application))
return true;
}
// Primordial node with no direct successors or predecessors
// to APK code
return false;
}
});

View File

@ -179,8 +179,9 @@ public class CLISCanDroidOptions implements ISCanDroidOptions {
private URI processURIArg(String arg) {
if (arg == null) {
return null;
} else {
return new File(arg).toURI();
}
return new File(arg).toURI();
}
private URI processClasspath(boolean reqArgs) {
@ -204,8 +205,9 @@ public class CLISCanDroidOptions implements ISCanDroidOptions {
final String reflection = getOption(REFLECTION);
if (reflection == null) {
return ReflectionOptions.NONE;
} else {
return ReflectionOptions.valueOf(reflection);
}
return ReflectionOptions.valueOf(reflection);
}
private boolean hasOption(String s) {

View File

@ -366,13 +366,13 @@ public class EntryPoints {
intent.contentEquals("android.media.action.VIDEO_CAMERA"))
return "onCreate(Landroid/os/Bundle;)V";
// if (intent.contentEquals("android.intent.action.BOOT_COMPLETED") ||
// else if (intent.contentEquals("android.intent.action.BOOT_COMPLETED") ||
// intent.contentEquals("android.appwidget.action.APPWIDGET_UPDATE") ||
// intent.contentEquals("android.provider.Telephony.SECRET_CODE") )
// return "onReceive(Landroid/content/Context;Landroid/content/Intent;)V";
return null;
else return null;
}
private ArrayList<String[]> chooseIntentList(String name) {