-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
664 additions
and
451 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
CryptoAnalysis/src/main/java/crypto/extractparameter/ExtendedBoomerangOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package crypto.extractparameter; | ||
|
||
import boomerang.DefaultBoomerangOptions; | ||
import boomerang.scene.AllocVal; | ||
import boomerang.scene.Method; | ||
import boomerang.scene.Statement; | ||
import boomerang.scene.Type; | ||
import boomerang.scene.Val; | ||
import boomerang.scene.sparse.SparseCFGCache; | ||
import crypto.extractparameter.transformation.OperatorTransformation; | ||
import crypto.extractparameter.transformation.Transformation; | ||
import java.util.Optional; | ||
|
||
public class ExtendedBoomerangOptions extends DefaultBoomerangOptions { | ||
|
||
private final int timeout; | ||
private final SparseCFGCache.SparsificationStrategy strategy; | ||
|
||
public ExtendedBoomerangOptions(int timeout, SparseCFGCache.SparsificationStrategy strategy) { | ||
this.timeout = timeout; | ||
this.strategy = strategy; | ||
} | ||
|
||
@Override | ||
public Optional<AllocVal> getAllocationVal(Method m, Statement stmt, Val fact) { | ||
if (!stmt.isAssign()) { | ||
return Optional.empty(); | ||
} | ||
|
||
Val leftOp = stmt.getLeftOp(); | ||
Val rightOp = stmt.getRightOp(); | ||
|
||
if (!leftOp.equals(fact)) { | ||
return Optional.empty(); | ||
} | ||
|
||
if (stmt.containsInvokeExpr()) { | ||
/* If we have an invoke expression, we check if it corresponds to an | ||
* implemented transformation | ||
*/ | ||
if (Transformation.isTransformationExpression(stmt)) { | ||
AllocVal allocVal = new AllocVal(leftOp, stmt, rightOp); | ||
|
||
return Optional.of(allocVal); | ||
} | ||
} else { | ||
if (OperatorTransformation.isOperatorTransformation(rightOp)) { | ||
AllocVal allocVal = new AllocVal(leftOp, stmt, rightOp); | ||
|
||
return Optional.of(allocVal); | ||
} | ||
|
||
/* Extract cast value from cast expressions, e.g. | ||
* int i = (int) 65000 -> AllocVal: 65000 | ||
*/ | ||
if (rightOp.isCast()) { | ||
Val castOp = rightOp.getCastOp(); | ||
|
||
if (isAllocationVal(castOp)) { | ||
return Optional.of(new AllocVal(leftOp, stmt, castOp)); | ||
} | ||
} | ||
|
||
/* Strings are initialized in two steps, where we need the second one: | ||
* r0 = new java.lang.String; | ||
* r0 = "value"; | ||
*/ | ||
if (rightOp.isNewExpr()) { | ||
Type type = rightOp.getNewExprType(); | ||
|
||
if (type.toString().equals("java.lang.String")) { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
// Basic values: constants, array allocations and null | ||
if (isAllocationVal(rightOp)) { | ||
return Optional.of(new AllocVal(leftOp, stmt, rightOp)); | ||
} | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public boolean isAllocationVal(Val val) { | ||
// Constants: var = <constant> | ||
if (val.isConstant()) { | ||
return true; | ||
} | ||
|
||
// null: var = null | ||
if (val.isNull()) { | ||
return true; | ||
} | ||
|
||
// arrays: var = new arr[..] | ||
if (val.isArrayAllocationVal()) { | ||
return true; | ||
} | ||
|
||
return val.isNewExpr(); | ||
} | ||
|
||
@Override | ||
public int analysisTimeoutMS() { | ||
return timeout; | ||
} | ||
|
||
@Override | ||
public boolean trackStaticFieldAtEntryPointToClinit() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public SparseCFGCache.SparsificationStrategy getSparsificationStrategy() { | ||
return strategy; | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterDefinition.java
This file was deleted.
Oops, something went wrong.
140 changes: 0 additions & 140 deletions
140
CryptoAnalysis/src/main/java/crypto/extractparameter/ExtractParameterOptions.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.