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

Fix soot errors #20

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected void setupSoot(String targetTestClassName) {

Options.v().set_no_bodies_for_excluded(true);
Options.v().set_allow_phantom_refs(true);
Options.v().setPhaseOption("jb.sils", "enabled:false");
Options.v().setPhaseOption("jb", "use-original-names:true");
Options.v().set_prepend_classpath(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package boomerang.scene.jimple;

import com.google.common.collect.Sets;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -55,13 +57,13 @@
public class BoomerangPretransformer extends BodyTransformer {

public static boolean TRANSFORM_CONSTANTS = true;
public static String UNITIALIZED_FIELD_TAG_NAME = "UnitializedField";
public static String UNINITIALIZED_FIELD_TAG_NAME = "UninitializedField";
public static Tag UNITIALIZED_FIELD_TAG =
new Tag() {

@Override
public String getName() {
return UNITIALIZED_FIELD_TAG_NAME;
return UNINITIALIZED_FIELD_TAG_NAME;
}

@Override
Expand All @@ -87,7 +89,7 @@ private void transformConstantAtFieldWrites(Body body) {
if (isFieldRef(assignStmt.getLeftOp())
&& assignStmt.getRightOp() instanceof Constant
&& !(assignStmt.getRightOp() instanceof ClassConstant)) {
String label = "varReplacer" + new Integer(replaceCounter++).toString();
String label = "varReplacer" + replaceCounter++;
Local paramVal = new JimpleLocal(label, assignStmt.getRightOp().getType());
AssignStmt newUnit = new JAssignStmt(paramVal, assignStmt.getRightOp());
body.getLocals().add(paramVal);
Expand All @@ -103,33 +105,41 @@ private void transformConstantAtFieldWrites(Body body) {
&& !u.toString().contains("test.assertions.Assertions:")
&& !u.toString().contains("intQueryFor")) {
Stmt stmt = (Stmt) u;
if (stmt.getInvokeExpr()
.getMethod()
.getSignature()
.equals("<java.math.BigInteger: java.math.BigInteger valueOf(long)>")) {
continue;
}

List<ValueBox> useBoxes = stmt.getInvokeExpr().getUseBoxes();
for (Value v : stmt.getInvokeExpr().getArgs()) {
List<Map.Entry<Integer, Value>> newArgs = new ArrayList<>();

for (int i = 0; i < stmt.getInvokeExpr().getArgs().size(); i++) {
Value v = stmt.getInvokeExpr().getArg(i);

if (v instanceof Constant && !(v instanceof ClassConstant)) {
String label = "varReplacer" + new Integer(replaceCounter++).toString();
String label = "varReplacer" + replaceCounter++;
Local paramVal = new JimpleLocal(label, v.getType());
AssignStmt newUnit = new JAssignStmt(paramVal, v);
newUnit.addAllTagsOf(u);
body.getLocals().add(paramVal);
body.getUnits().insertBefore(newUnit, u);

for (ValueBox b : useBoxes) {
backPropagateSourceLineTags(b, newUnit);
if (b.getValue().equals(v)) {
b.setValue(paramVal);
}
}

Map.Entry<Integer, Value> entry = new AbstractMap.SimpleEntry<>(i, paramVal);
newArgs.add(entry);
}
}

// Update the parameters
for (Map.Entry<Integer, Value> entry : newArgs) {
int position = entry.getKey();
Value newArg = entry.getValue();

stmt.getInvokeExpr().setArg(position, newArg);
}
}
if (u instanceof ReturnStmt) {
ReturnStmt returnStmt = (ReturnStmt) u;
String label = "varReplacer" + new Integer(replaceCounter++).toString();
String label = "varReplacer" + replaceCounter++;
Local paramVal = new JimpleLocal(label, returnStmt.getOp().getType());
AssignStmt newUnit = new JAssignStmt(paramVal, returnStmt.getOp());
newUnit.addAllTagsOf(u);
Expand All @@ -147,23 +157,23 @@ private void transformConstantAtFieldWrites(Body body) {
* AssignStmt, to revert the forward propagation done in {@link
* soot.jimple.toolkits.scalar.CopyPropagator}
*
* @param valueBox
* @param assignStmt
* @param valueBox the constant value box
* @param assignStmt the newly create AssignStmt
*/
private void backPropagateSourceLineTags(ValueBox valueBox, AssignStmt assignStmt) {
Tag tag = valueBox.getTag(SourceLnPosTag.IDENTIFIER);
Tag tag = valueBox.getTag(SourceLnPosTag.NAME);
if (tag != null) {
// in case that we copied a line number tag from the original statement, we want to remove
// that now since the valueBox contains the correct lin number tag for the assign statement as
// it was before copy propagation
assignStmt.removeTag(SourceLnPosTag.IDENTIFIER);
assignStmt.removeTag(SourceLnPosTag.NAME);
assignStmt.addTag(tag);
}

tag = valueBox.getTag(LineNumberTag.IDENTIFIER);
tag = valueBox.getTag(LineNumberTag.NAME);
if (tag != null) {
// same as for the above case
assignStmt.removeTag(LineNumberTag.IDENTIFIER);
assignStmt.removeTag(LineNumberTag.NAME);
assignStmt.addTag(tag);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,6 @@ public boolean isCatchStmt() {
}

public boolean isUnitializedFieldStatement() {
return delegate.hasTag(BoomerangPretransformer.UNITIALIZED_FIELD_TAG_NAME);
return delegate.hasTag(BoomerangPretransformer.UNINITIALIZED_FIELD_TAG_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private void initializeSootWithEntryPoint() {

Options.v().set_include(getIncludeList());

Options.v().setPhaseOption("jb.sils", "enabled:false");
Options.v().setPhaseOption("jb", "use-original-names:true");

Options.v().set_exclude(excludedPackages());
Expand Down
Loading