Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated PredicateHandler to handle OR-ed predicates #265

Merged
merged 9 commits into from
Nov 24, 2023
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package crypto.analysis.errors;

import java.util.List;
import java.util.stream.Collectors;

import boomerang.jimple.Statement;
import crypto.extractparameter.CallSiteWithExtractedValue;
import crypto.rules.CrySLPredicate;
import crypto.rules.CrySLRule;

public class RequiredPredicateError extends AbstractError{

private CrySLPredicate contradictedPredicate;
private List<CrySLPredicate> contradictedPredicate;
private CallSiteWithExtractedValue extractedValues;

public RequiredPredicateError(CrySLPredicate contradictedPredicate, Statement location, CrySLRule rule, CallSiteWithExtractedValue multimap) {
public RequiredPredicateError(List<CrySLPredicate> contradictedPredicates, Statement location, CrySLRule rule, CallSiteWithExtractedValue multimap) {
super(location, rule);
this.contradictedPredicate = contradictedPredicate;
this.contradictedPredicate = contradictedPredicates;
this.extractedValues = multimap;
}

public CrySLPredicate getContradictedPredicate() {
public List<CrySLPredicate> getContradictedPredicate() {
rakshitkr marked this conversation as resolved.
Show resolved Hide resolved
return contradictedPredicate;
}

Expand All @@ -33,7 +36,7 @@ public void accept(ErrorVisitor visitor){
public String toErrorMarkerString() {
String msg = extractedValues.toString();
msg += " was not properly generated as ";
String predicateName = getContradictedPredicate().getPredName();
String predicateName = getContradictedPredicate().stream().map(e -> e.toString()).collect(Collectors.joining(" OR "));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do getPredName and toString yield the same result? Because i wonder why you changed the method call

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is that " OR " comming from ? Also please use a constant for such important strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a unit test for this issue already? If not, please create one.

Please find the updated tests here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is that " OR " comming from ? Also please use a constant for such important strings.

It is used to generate error statements like below
Second parameter was not properly generated as generated E C Public Key Parameters(params) O R generated R S A Private Crt Key Parameters(params) O R generated R S A Key Parameters(params)

Copy link
Contributor Author

@rakshitkr rakshitkr Jun 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do getPredName and toString yield the same result? Because i wonder why you changed the method call

No, they don't. getPredName only returns the predicate name. Whereas toString returns predicate name with respective parameter, like in above comment.

Have changed it to getPredName in commit 6f00e0c

String[] parts = predicateName.split("(?=[A-Z])");
msg += parts[0];
for(int i=1; i<parts.length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,15 @@ public ConstraintSolver(AnalysisSeedWithSpecification object, Collection<Stateme
private ISLConstraint collectAlternativePredicates(CrySLConstraint cons, AlternativeReqPredicate alt) {
CrySLPredicate right = (CrySLPredicate) cons.getRight();
if (alt == null) {
alt = new AlternativeReqPredicate(right, right.getLocation());
for (CallSiteWithParamIndex cwpi : this.parameterAnalysisQuerySites) {
for (ICrySLPredicateParameter p : right.getParameters()) {
if (p.getName().equals("transformation"))
continue;
if (cwpi.getVarName().equals(p.getName())) {
alt = new AlternativeReqPredicate(right, cwpi.stmt());
}
}
}
} else {
alt.addAlternative(right);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package crypto.predicates;

import java.util.AbstractMap.SimpleEntry;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import com.google.common.collect.Table.Cell;

import boomerang.jimple.Statement;
import boomerang.jimple.Val;
import boomerang.results.ForwardBoomerangResults;
Expand All @@ -25,7 +28,6 @@
import crypto.extractparameter.CallSiteWithExtractedValue;
import crypto.extractparameter.CallSiteWithParamIndex;
import crypto.interfaces.ISLConstraint;
import crypto.rules.CrySLConstraint;
import crypto.rules.CrySLPredicate;
import crypto.rules.CrySLRule;
import soot.SootMethod;
Expand Down Expand Up @@ -219,10 +221,8 @@ private void checkMissingRequiredPredicates() {
for (ISLConstraint pred : missingPredicates) {
if (pred instanceof RequiredCrySLPredicate) {
reportMissingPred(seed, (RequiredCrySLPredicate) pred);
} else if (pred instanceof CrySLConstraint) {
for (CrySLPredicate altPred : ((AlternativeReqPredicate) pred).getAlternatives()) {
reportMissingPred(seed, new RequiredCrySLPredicate(altPred, altPred.getLocation()));
}
} else if (pred instanceof AlternativeReqPredicate) {
reportMissingPred(seed, (AlternativeReqPredicate) pred);
}
}
}
Expand All @@ -234,7 +234,19 @@ private void reportMissingPred(AnalysisSeedWithSpecification seed, RequiredCrySL
for (CallSiteWithParamIndex v : seed.getParameterAnalysis().getAllQuerySites()) {
if (missingPred.getPred().getInvolvedVarNames().contains(v.getVarName()) && v.stmt().equals(missingPred.getLocation())) {
cryptoScanner.getAnalysisListener().reportError(seed,
new RequiredPredicateError(missingPred.getPred(), missingPred.getLocation(), seed.getSpec().getRule(), new CallSiteWithExtractedValue(v, null)));
new RequiredPredicateError(Arrays.asList(missingPred.getPred()), missingPred.getLocation(), seed.getSpec().getRule(), new CallSiteWithExtractedValue(v, null)));
}
}
}
}

private void reportMissingPred(AnalysisSeedWithSpecification seed, AlternativeReqPredicate missingPred) {
CrySLRule rule = seed.getSpec().getRule();
if (!rule.getPredicates().parallelStream().anyMatch(e -> missingPred.getAlternatives().stream().anyMatch(e1 -> e1.getPredName().equals(e.getPredName())) && missingPred.getAlternatives().stream().anyMatch(e2 -> e2.getParameters().get(0).equals(e.getParameters().get(0))))) {
for (CallSiteWithParamIndex v : seed.getParameterAnalysis().getAllQuerySites()) {
if (missingPred.getAlternatives().parallelStream().anyMatch(e4 -> e4.getInvolvedVarNames().contains(v.getVarName())) && v.stmt().equals(missingPred.getLocation())) {
cryptoScanner.getAnalysisListener().reportError(seed,
new RequiredPredicateError(missingPred.getAlternatives(), missingPred.getLocation(), seed.getSpec().getRule(), new CallSiteWithExtractedValue(v, null)));
}
}
}
Expand Down