Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:CROSSINGTUD/CryptoAnalysis into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
johspaeth committed May 14, 2019
2 parents a1b85ba + db393fd commit d9526d1
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import crypto.rules.CryptSLRule;
import soot.jimple.internal.JAssignStmt;

public abstract class AbstractError implements IError {
private final Statement errorLocation;
private final CryptSLRule rule;
public abstract class AbstractError implements IError{
private Statement errorLocation;
private CryptSLRule rule;
private final String outerMethod;
private final String invokeMethod;
private final String declaringClass;

public AbstractError(Statement errorLocation, CryptSLRule rule) {
this.errorLocation = errorLocation;
this.rule = rule;
Expand All @@ -21,7 +21,7 @@ public AbstractError(Statement errorLocation, CryptSLRule rule) {
this.invokeMethod = errorLocation.getUnit().get().getInvokeExpr().getMethod().toString();
}
else {
this.invokeMethod = ((JAssignStmt)errorLocation.getUnit().get()).getLeftOp().toString();
this.invokeMethod = ((JAssignStmt) errorLocation.getUnit().get()).getLeftOp().toString();
}
}

Expand All @@ -32,12 +32,12 @@ public Statement getErrorLocation() {
public CryptSLRule getRule() {
return rule;
}

public abstract String toErrorMarkerString();

public String toString() {
return toErrorMarkerString();
}


@Override
public int hashCode() {
Expand Down Expand Up @@ -81,9 +81,4 @@ public boolean equals(Object obj) {
return false;
return true;
}





}
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ private String evaluateValueConstraint(final CryptSLValueConstraint brokenConstr
public static String filterQuotes(final String dirty) {
return CharMatcher.anyOf("\"").removeFrom(dirty);
}

@Override
public int hashCode() {
final int paramIndex = callSiteWithParamIndex.getCallSite().getIndex();
final Value parameterValue = callSiteWithParamIndex.getVal().getValue();
final int prime = 31;
int result = super.hashCode();
result = prime * result + paramIndex;
result = prime * result + ((parameterValue == null) ? 0 : parameterValue.hashCode());
return result;
}

Expand All @@ -198,7 +200,11 @@ public boolean equals(Object obj) {
if (callSiteWithParamIndex.getCallSite().getIndex() != other.callSiteWithParamIndex.getCallSite().getIndex()) {
return false;
}
if (callSiteWithParamIndex.getVal().getValue() == null) {
if (other.callSiteWithParamIndex.getVal().getValue() != null)
return false;
} else if (!callSiteWithParamIndex.getVal().getValue().equals(other.callSiteWithParamIndex.getVal().getValue()))
return false;
return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
package crypto.analysis.errors;

import java.util.Collection;
import java.util.Set;

import com.google.common.base.Joiner;
import com.google.inject.internal.util.Sets;

import boomerang.jimple.Statement;
import crypto.rules.CryptSLRule;
import soot.SootMethod;

public class ForbiddenMethodError extends AbstractError{
public class ForbiddenMethodError extends AbstractError {

private Collection<SootMethod> alternatives;
private SootMethod calledMethod;
private Set<String> alternativesSet = Sets.newHashSet();

public ForbiddenMethodError(Statement errorLocation, CryptSLRule rule, SootMethod calledMethod, Collection<SootMethod> collection) {
public ForbiddenMethodError(Statement errorLocation, CryptSLRule rule, SootMethod calledMethod,
Collection<SootMethod> collection) {
super(errorLocation, rule);
this.calledMethod = calledMethod;
this.alternatives = collection;

for (SootMethod method : alternatives) {
this.alternativesSet.add(method.getSignature());
}
}

public Collection<SootMethod> getAlternatives() {
return alternatives;
}

public void accept(ErrorVisitor visitor){
public void accept(ErrorVisitor visitor) {
visitor.visit(this);
}

Expand All @@ -45,13 +53,13 @@ public String toErrorMarkerString() {
}
return msg.toString();
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((alternatives == null) ? 0 : alternatives.hashCode());
result = prime * result + ((calledMethod == null) ? 0 : calledMethod.hashCode());
result = prime * result + ((alternativesSet == null) ? 0 : alternativesSet.hashCode());
result = prime * result + ((calledMethod == null) ? 0 : calledMethod.getSignature().hashCode());
return result;
}

Expand All @@ -64,20 +72,20 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
ForbiddenMethodError other = (ForbiddenMethodError) obj;
if (alternatives == null) {
if (other.alternatives != null)
if (alternativesSet == null) {
if (other.alternativesSet != null)
return false;
} else if (!alternatives.equals(other.alternatives))
} else if (!alternativesSet.equals(other.alternativesSet))
return false;
if (calledMethod == null) {
if (other.calledMethod != null)
return false;
} else if (!calledMethod.equals(other.calledMethod))
} else if (!calledMethod.getSignature().equals(other.calledMethod.getSignature()))
return false;
return true;
}







}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String toErrorMarkerString() {
msg.append(" could not be evaluted due to insufficient information.");
return msg.toString();
}

@Override
public int hashCode() {
final int prime = 31;
Expand All @@ -54,6 +54,5 @@ public boolean equals(Object obj) {
return false;
return true;
}



}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package crypto.analysis.errors;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.inject.internal.util.Sets;

import boomerang.jimple.Statement;
import boomerang.jimple.Val;
Expand All @@ -19,12 +24,17 @@ public class IncompleteOperationError extends ErrorWithObjectAllocation{

private Val errorVariable;
private Collection<SootMethod> expectedMethodCalls;
private Set<String> expectedMethodCallsSet = Sets.newHashSet();

public IncompleteOperationError(Statement errorLocation,
Val errorVariable, CryptSLRule rule, IAnalysisSeed objectLocation, Collection<SootMethod> expectedMethodsToBeCalled) {
super(errorLocation, rule, objectLocation);
this.errorVariable = errorVariable;
this.expectedMethodCalls = expectedMethodsToBeCalled;
this.expectedMethodCalls = expectedMethodsToBeCalled;

for (SootMethod method : expectedMethodCalls) {
this.expectedMethodCallsSet.add(method.getSignature());
}
}

public Val getErrorVariable() {
Expand Down Expand Up @@ -79,12 +89,12 @@ private boolean stmtInvokesExpectedCallName(String expectedCallName){
}
return false;
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((expectedMethodCalls == null) ? 0 : expectedMethodCalls.hashCode());
result = prime * result + ((expectedMethodCallsSet == null) ? 0 : expectedMethodCallsSet.hashCode());
return result;
}

Expand All @@ -100,10 +110,19 @@ public boolean equals(Object obj) {
if (expectedMethodCalls == null) {
if (other.expectedMethodCalls != null)
return false;
} else if (!expectedMethodCalls.equals(other.expectedMethodCalls))
} else if (expectedMethodCallsSet != other.expectedMethodCallsSet)
return false;

return true;
}

private int expectedMethodCallsHashCode(Collection<SootMethod> expectedMethodCalls) {
Set<String> expectedMethodCallsSet = Sets.newHashSet();
for (SootMethod method : expectedMethodCalls) {
expectedMethodCallsSet.add(method.getSignature());
}
return expectedMethodCallsSet.hashCode();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,21 @@ public NeverTypeOfError(CallSiteWithExtractedValue cs, CryptSLRule rule, IAnalys
super(cs, rule, objectLocation, con);
}

@Override
public int hashCode() {
int result = super.hashCode();
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,23 @@ public String toErrorMarkerString() {
public Entry<CryptSLPredicate, CryptSLPredicate> getMismatchedPreds() {
return mismatchedPreds;
}

@Override
public int hashCode() {
int result = super.hashCode();
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;

return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String toErrorMarkerString() {
msg += " " + parts[i];
return msg;
}

@Override
public int hashCode() {
final int prime = 31;
Expand All @@ -65,6 +65,5 @@ public boolean equals(Object obj) {
return false;
return true;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.inject.internal.util.Sets;

import boomerang.jimple.Statement;
import crypto.analysis.IAnalysisSeed;
Expand All @@ -17,10 +18,15 @@
public class TypestateError extends ErrorWithObjectAllocation{

private Collection<SootMethod> expectedMethodCalls;
private Set<String> expectedMethodCallsSet = Sets.newHashSet();

public TypestateError(Statement stmt, CryptSLRule rule, IAnalysisSeed object, Collection<SootMethod> expectedMethodCalls) {
super(stmt, rule, object);
this.expectedMethodCalls = expectedMethodCalls;

for (SootMethod method : expectedMethodCalls) {
this.expectedMethodCallsSet.add(method.getSignature());
}
}

public Collection<SootMethod> getExpectedMethodCalls() {
Expand Down Expand Up @@ -93,12 +99,12 @@ private boolean useSignatures(){
}
return false;
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((expectedMethodCalls == null) ? 0 : expectedMethodCalls.hashCode());
result = prime * result + ((expectedMethodCallsSet == null) ? 0 : expectedMethodCallsSet.hashCode());
return result;
}

Expand All @@ -111,13 +117,11 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
TypestateError other = (TypestateError) obj;
if (expectedMethodCalls == null) {
if (other.expectedMethodCalls != null)
if (expectedMethodCallsSet == null) {
if (other.expectedMethodCallsSet != null)
return false;
} else if (!expectedMethodCalls.equals(other.expectedMethodCalls))
} else if (expectedMethodCallsSet != other.expectedMethodCallsSet)
return false;
return true;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private List<Entry<String, CallSiteWithExtractedValue>> getValFromVar(CryptSLObj

public abstract class EvaluableConstraint {

List<AbstractError> errors = Lists.newArrayList();
Set<AbstractError> errors = Sets.newHashSet();
ISLConstraint origin;

public abstract void evaluate();
Expand Down

0 comments on commit d9526d1

Please sign in to comment.