crypto.extractparameter.transformation.StringTransformation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of CryptoAnalysis Show documentation
Show all versions of CryptoAnalysis Show documentation
CogniCrypt_SAST: CrySL-to-Static Analysis Compiler
The newest version!
package crypto.extractparameter.transformation;
import boomerang.scene.AllocVal;
import boomerang.scene.InvokeExpr;
import boomerang.scene.Statement;
import boomerang.scene.Val;
import crypto.extractparameter.ExtractParameterDefinition;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;
public class StringTransformation extends Transformation {
private final Collection baseStringSignatures =
Arrays.asList(
"",
"",
"",
"",
"",
"",
"");
private final Collection paramStringSignatures =
Arrays.asList("");
private static final String REPLACE_CHAR_SEQUENCE_CHAR_SEQUENCE =
"";
public StringTransformation(ExtractParameterDefinition definition) {
super(definition);
}
@Override
public Optional evaluateExpression(Statement statement) {
if (!statement.containsInvokeExpr() || !statement.isAssign()) {
return Optional.empty();
}
InvokeExpr invokeExpr = statement.getInvokeExpr();
String signature = invokeExpr.getMethod().getSignature();
if (baseStringSignatures.contains(signature)) {
Val base = invokeExpr.getBase();
return evaluateVal(statement, base);
}
if (paramStringSignatures.contains(signature)) {
Val param = invokeExpr.getArg(0);
return evaluateVal(statement, param);
}
if (signature.equals(REPLACE_CHAR_SEQUENCE_CHAR_SEQUENCE)) {
return evaluateReplaceCharSequenceCharSequence(statement, invokeExpr);
}
return Optional.empty();
}
private Optional evaluateVal(Statement statement, Val val) {
Optional baseStringOpt = extractStringFromVal(statement, val);
if (baseStringOpt.isEmpty()) {
return Optional.empty();
}
String baseString = baseStringOpt.get();
AllocVal allocVal = createTransformedAllocVal(baseString, statement);
return Optional.of(allocVal);
}
private Optional evaluateReplaceCharSequenceCharSequence(
Statement statement, InvokeExpr invokeExpr) {
Val base = invokeExpr.getBase();
Val arg1 = invokeExpr.getArg(0);
Val arg2 = invokeExpr.getArg(1);
Optional baseStringOpt = extractStringFromVal(statement, base);
Optional arg1StringOpt = extractStringFromVal(statement, arg1);
Optional arg2StringOpt = extractStringFromVal(statement, arg2);
if (baseStringOpt.isEmpty() || arg1StringOpt.isEmpty() || arg2StringOpt.isEmpty()) {
return Optional.empty();
}
String baseString = baseStringOpt.get();
String arg1String = arg1StringOpt.get();
String arg2String = arg2StringOpt.get();
String result = baseString.replace(arg1String, arg2String);
AllocVal allocVal = createTransformedAllocVal(result, statement);
return Optional.of(allocVal);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy