repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
|---|---|---|---|---|---|---|
soot
|
soot-master/src/main/java/soot/jbco/bafTransformations/WrapSwitchesInTrys.java
|
package soot.jbco.bafTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.Iterator;
import java.util.Map;
import soot.Body;
import soot.BodyTransformer;
import soot.PatchingChain;
import soot.Trap;
import soot.Unit;
import soot.baf.Baf;
import soot.baf.TableSwitchInst;
import soot.baf.ThrowInst;
import soot.jbco.IJbcoTransform;
import soot.jbco.util.BodyBuilder;
import soot.jbco.util.Rand;
import soot.jbco.util.ThrowSet;
import soot.util.Chain;
/**
* @author Michael Batchelder
*
* Created on 24-May-2006
*/
public class WrapSwitchesInTrys extends BodyTransformer implements IJbcoTransform {
int totaltraps = 0;
public static String dependancies[] = new String[] { "bb.jbco_ptss", "bb.jbco_ful", "bb.lp" };
public String[] getDependencies() {
return dependancies;
}
public static String name = "bb.jbco_ptss";
public String getName() {
return name;
}
public void outputSummary() {
out.println("Switches wrapped in Tries: " + totaltraps);
}
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
int weight = soot.jbco.Main.getWeight(phaseName, b.getMethod().getSignature());
if (weight == 0) {
return;
}
int i = 0;
Unit handler = null;
Chain<Trap> traps = b.getTraps();
PatchingChain<Unit> units = b.getUnits();
Iterator<Unit> it = units.snapshotIterator();
while (it.hasNext()) {
Unit u = (Unit) it.next();
if (u instanceof TableSwitchInst) {
TableSwitchInst twi = (TableSwitchInst) u;
if (!BodyBuilder.isExceptionCaughtAt(units, twi, traps.iterator()) && Rand.getInt(10) <= weight) {
if (handler == null) {
Iterator<Unit> uit = units.snapshotIterator();
while (uit.hasNext()) {
Unit uthrow = (Unit) uit.next();
if (uthrow instanceof ThrowInst && !BodyBuilder.isExceptionCaughtAt(units, uthrow, traps.iterator())) {
handler = uthrow;
break;
}
}
if (handler == null) {
handler = Baf.v().newThrowInst();
units.add(handler);
}
}
int size = 4;
Unit succ = (Unit) units.getSuccOf(twi);
while (!BodyBuilder.isExceptionCaughtAt(units, succ, traps.iterator()) && size-- > 0) {
Object o = units.getSuccOf(succ);
if (o != null) {
succ = (Unit) o;
} else {
break;
}
}
traps.add(Baf.v().newTrap(ThrowSet.getRandomThrowable(), twi, succ, handler));
i++;
}
}
}
totaltraps += i;
if (i > 0 && debug) {
StackTypeHeightCalculator.calculateStackHeights(b);
}
}
}
| 3,559
| 27.943089
| 117
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/bafTransformations/package-info.java
|
@Deprecated
package soot.jbco.bafTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2018 Raja Vallée-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
| 868
| 33.76
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/AddSwitches.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import soot.Body;
import soot.BodyTransformer;
import soot.BooleanType;
import soot.IntType;
import soot.Local;
import soot.PatchingChain;
import soot.PrimType;
import soot.RefType;
import soot.SootField;
import soot.SootMethod;
import soot.Trap;
import soot.Unit;
import soot.Value;
import soot.jbco.IJbcoTransform;
import soot.jbco.util.Rand;
import soot.jimple.IdentityStmt;
import soot.jimple.IfStmt;
import soot.jimple.IntConstant;
import soot.jimple.Jimple;
import soot.toolkits.graph.BriefUnitGraph;
/**
* @author Michael Batchelder
*
* Created on 10-Jul-2006
*/
public class AddSwitches extends BodyTransformer implements IJbcoTransform {
int switchesadded = 0;
public void outputSummary() {
out.println("Switches added: " + switchesadded);
}
public static String dependancies[] = new String[] { "wjtp.jbco_fr", "jtp.jbco_adss", "bb.jbco_ful" };
public String[] getDependencies() {
return dependancies;
}
public static String name = "jtp.jbco_adss";
public String getName() {
return name;
}
public boolean checkTraps(Unit u, Body b) {
Iterator<Trap> it = b.getTraps().iterator();
while (it.hasNext()) {
Trap t = it.next();
if (t.getBeginUnit() == u || t.getEndUnit() == u || t.getHandlerUnit() == u) {
return true;
}
}
return false;
}
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
if (b.getMethod().getSignature().indexOf("<clinit>") >= 0) {
return;
}
int weight = soot.jbco.Main.getWeight(phaseName, b.getMethod().getSignature());
if (weight == 0) {
return;
}
New2InitFlowAnalysis fa = new New2InitFlowAnalysis(new BriefUnitGraph(b));
Vector<Unit> zeroheight = new Vector<Unit>();
PatchingChain<Unit> units = b.getUnits();
Unit first = null;
for (Unit unit : units) {
if (unit instanceof IdentityStmt) {
continue;
}
first = unit;
break;
}
Iterator<Unit> it = units.snapshotIterator();
while (it.hasNext()) {
Unit unit = (Unit) it.next();
if (unit instanceof IdentityStmt || checkTraps(unit, b)) {
continue;
}
// very conservative estimate about where new-<init> ranges are
if (fa.getFlowAfter(unit).isEmpty() && fa.getFlowBefore(unit).isEmpty()) {
zeroheight.add(unit);
}
}
if (zeroheight.size() < 3) {
return;
}
int idx = 0;
Unit u = null;
for (int i = 0; i < zeroheight.size(); i++) {
idx = Rand.getInt(zeroheight.size() - 1) + 1;
u = (Unit) zeroheight.get(idx);
if (u.fallsThrough()) {
break;
}
u = null;
}
// couldn't find a unit that fell through
if (u == null || Rand.getInt(10) > weight) {
return;
}
zeroheight.remove(idx);
while (zeroheight.size() > (weight > 3 ? weight : 3)) {
zeroheight.remove(Rand.getInt(zeroheight.size()));
}
Collection<Local> locals = b.getLocals();
List<Unit> targs = new ArrayList<Unit>();
targs.addAll(zeroheight);
SootField ops[] = FieldRenamer.v().getRandomOpaques();
Local b1 = Jimple.v().newLocal("addswitchesbool1", BooleanType.v());
locals.add(b1);
Local b2 = Jimple.v().newLocal("addswitchesbool2", BooleanType.v());
locals.add(b2);
if (ops[0].getType() instanceof PrimType) {
units.insertBefore(Jimple.v().newAssignStmt(b1, Jimple.v().newStaticFieldRef(ops[0].makeRef())), u);
} else {
RefType rt = (RefType) ops[0].getType();
SootMethod m = rt.getSootClass().getMethodByName("booleanValue");
Local B = Jimple.v().newLocal("addswitchesBOOL1", rt);
locals.add(B);
units.insertBefore(Jimple.v().newAssignStmt(B, Jimple.v().newStaticFieldRef(ops[0].makeRef())), u);
units.insertBefore(
Jimple.v().newAssignStmt(b1, Jimple.v().newVirtualInvokeExpr(B, m.makeRef(), Collections.<Value>emptyList())), u);
}
if (ops[1].getType() instanceof PrimType) {
units.insertBefore(Jimple.v().newAssignStmt(b2, Jimple.v().newStaticFieldRef(ops[1].makeRef())), u);
} else {
RefType rt = (RefType) ops[1].getType();
SootMethod m = rt.getSootClass().getMethodByName("booleanValue");
Local B = Jimple.v().newLocal("addswitchesBOOL2", rt);
locals.add(B);
units.insertBefore(Jimple.v().newAssignStmt(B, Jimple.v().newStaticFieldRef(ops[1].makeRef())), u);
units.insertBefore(
Jimple.v().newAssignStmt(b2, Jimple.v().newVirtualInvokeExpr(B, m.makeRef(), Collections.<Value>emptyList())), u);
}
IfStmt ifstmt = Jimple.v().newIfStmt(Jimple.v().newNeExpr(b1, b2), u);
units.insertBefore(ifstmt, u);
Local l = Jimple.v().newLocal("addswitchlocal", IntType.v());
locals.add(l);
units.insertBeforeNoRedirect(Jimple.v().newAssignStmt(l, IntConstant.v(0)), first);
units.insertAfter(Jimple.v().newTableSwitchStmt(l, 1, zeroheight.size(), targs, u), ifstmt);
switchesadded += zeroheight.size() + 1;
Iterator<Unit> tit = targs.iterator();
while (tit.hasNext()) {
Unit nxt = (Unit) tit.next();
if (Rand.getInt(5) < 4) {
units.insertBefore(Jimple.v().newAssignStmt(l, Jimple.v().newAddExpr(l, IntConstant.v(Rand.getInt(3) + 1))), nxt);
}
}
ifstmt.setTarget(u);
}
}
| 6,362
| 29.88835
| 124
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/ArithmeticTransformer.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import soot.Body;
import soot.BodyTransformer;
import soot.DoubleType;
import soot.IntType;
import soot.Local;
import soot.LongType;
import soot.PatchingChain;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.jbco.IJbcoTransform;
import soot.jbco.util.Rand;
import soot.jimple.AssignStmt;
import soot.jimple.DivExpr;
import soot.jimple.DoubleConstant;
import soot.jimple.Expr;
import soot.jimple.FloatConstant;
import soot.jimple.IntConstant;
import soot.jimple.Jimple;
import soot.jimple.LongConstant;
import soot.jimple.MulExpr;
import soot.jimple.NumericConstant;
import soot.util.Chain;
/**
* @author Michael Batchelder
* <p>
* Created on 6-Mar-2006
*/
// when shifting, add multiple of 32 or 64 to the shift value, since it will
// have no effect
// shift negatively to confuse things further?
// look into calculating operational cost and limiting to those transforms that
// will
// not hurt the speed of the program. Empirically: 4 adds/shifts == 1 mult?
public class ArithmeticTransformer extends BodyTransformer implements IJbcoTransform {
private static int mulPerformed = 0;
private static int divPerformed = 0;
private static int total = 0;
public static String dependancies[] = new String[] { "jtp.jbco_cae2bo" };
public static String name = "jtp.jbco_cae2bo";
public String[] getDependencies() {
return dependancies;
}
public String getName() {
return name;
}
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
int weight = soot.jbco.Main.getWeight(phaseName, b.getMethod().getSignature());
if (weight == 0) {
return;
}
PatchingChain<Unit> units = b.getUnits();
int localCount = 0;
Chain<Local> locals = b.getLocals();
if (output) {
out.println("*** Performing Arithmetic Transformation on " + b.getMethod().getSignature());
}
Iterator<Unit> it = units.snapshotIterator();
while (it.hasNext()) {
Unit u = it.next();
if (u instanceof AssignStmt) {
AssignStmt as = (AssignStmt) u;
Value v = as.getRightOp();
if (v instanceof MulExpr) {
total++;
MulExpr me = (MulExpr) v;
Value op1 = me.getOp1();
Value op = null, op2 = me.getOp2();
NumericConstant nc = null;
if (op1 instanceof NumericConstant) {
nc = (NumericConstant) op1;
op = op2;
} else if (op2 instanceof NumericConstant) {
nc = (NumericConstant) op2;
op = op1;
}
if (nc != null) {
if (output) {
out.println("Considering: " + as + "\r");
}
Type opType = op.getType();
int max = opType instanceof IntType ? 32 : opType instanceof LongType ? 64 : 0;
if (max != 0) {
Object shft_rem[] = checkNumericValue(nc);
if (shft_rem[0] != null && (Integer) shft_rem[0] < max && Rand.getInt(10) <= weight) {
List<Unit> unitsBuilt = new ArrayList<>();
int rand = Rand.getInt(16);
int shift = (Integer) shft_rem[0];
boolean neg = (Boolean) shft_rem[2];
if (rand % 2 == 0) {
shift += rand * max;
} else {
shift -= rand * max;
}
Expr e;
if (shft_rem[1] != null) { // if there is an additive floating component
Local tmp2 = null, tmp1 = Jimple.v().newLocal("__tmp_shft_lcl" + localCount++, opType);
locals.add(tmp1);
// shift the integral portion
Unit newU = Jimple.v().newAssignStmt(tmp1, Jimple.v().newShlExpr(op, IntConstant.v(shift)));
unitsBuilt.add(newU);
units.insertBefore(newU, u);
// grab remainder (that not part of the 2^x)
double rem = (Double) shft_rem[1];
if (rem != 1) {
if (rem == ((int) rem) && opType instanceof IntType) {
nc = IntConstant.v((int) rem);
} else if (rem == ((long) rem) && opType instanceof LongType) {
nc = LongConstant.v((long) rem);
} else {
nc = DoubleConstant.v(rem);
}
if (nc instanceof DoubleConstant) {
tmp2 = Jimple.v().newLocal("__tmp_shft_lcl" + localCount++, DoubleType.v());
locals.add(tmp2);
newU = Jimple.v().newAssignStmt(tmp2, Jimple.v().newCastExpr(op, DoubleType.v()));
unitsBuilt.add(newU);
units.insertBefore(newU, u);
newU = Jimple.v().newAssignStmt(tmp2, Jimple.v().newMulExpr(tmp2, nc));
} else {
tmp2 = Jimple.v().newLocal("__tmp_shft_lcl" + localCount++, nc.getType());
locals.add(tmp2);
newU = Jimple.v().newAssignStmt(tmp2, Jimple.v().newMulExpr(op, nc));
}
unitsBuilt.add(newU);
units.insertBefore(newU, u);
}
if (tmp2 == null) {
e = Jimple.v().newAddExpr(tmp1, op);
} else if (tmp2.getType().getClass() != tmp1.getType().getClass()) {
Local tmp3 = Jimple.v().newLocal("__tmp_shft_lcl" + localCount++, tmp2.getType());
locals.add(tmp3);
newU = Jimple.v().newAssignStmt(tmp3, Jimple.v().newCastExpr(tmp1, tmp2.getType()));
unitsBuilt.add(newU);
units.insertBefore(newU, u);
e = Jimple.v().newAddExpr(tmp3, tmp2);
} else {
e = Jimple.v().newAddExpr(tmp1, tmp2);
}
} else {
e = Jimple.v().newShlExpr(op, IntConstant.v(shift));
}
if (e.getType().getClass() != as.getLeftOp().getType().getClass()) {
Local tmp = Jimple.v().newLocal("__tmp_shft_lcl" + localCount++, e.getType());
locals.add(tmp);
Unit newU = Jimple.v().newAssignStmt(tmp, e);
unitsBuilt.add(newU);
units.insertAfter(newU, u);
e = Jimple.v().newCastExpr(tmp, as.getLeftOp().getType());
}
as.setRightOp(e);
unitsBuilt.add(as);
if (neg) {
Unit newU = Jimple.v().newAssignStmt(as.getLeftOp(), Jimple.v().newNegExpr(as.getLeftOp()));
unitsBuilt.add(newU);
units.insertAfter(newU, u);
}
mulPerformed++;
printOutput(unitsBuilt);
}
}
}
} else if (v instanceof DivExpr) {
total++;
DivExpr de = (DivExpr) v;
Value op2 = de.getOp2();
NumericConstant nc;
if (op2 instanceof NumericConstant) {
nc = (NumericConstant) op2;
Type opType = de.getOp1().getType();
int max = opType instanceof IntType ? 32 : opType instanceof LongType ? 64 : 0;
if (max != 0) {
Object shft_rem[] = checkNumericValue(nc);
if (shft_rem[0] != null && (shft_rem[1] == null || (Double) shft_rem[1] == 0) && (Integer) shft_rem[0] < max
&& Rand.getInt(10) <= weight) {
List<Unit> unitsBuilt = new ArrayList<>();
int rand = Rand.getInt(16);
int shift = (Integer) shft_rem[0];
boolean neg = (Boolean) shft_rem[2];
if (Rand.getInt() % 2 == 0) {
shift += rand * max;
} else {
shift -= rand * max;
}
Expr e = Jimple.v().newShrExpr(de.getOp1(), IntConstant.v(shift));
if (e.getType().getClass() != as.getLeftOp().getType().getClass()) {
Local tmp = Jimple.v().newLocal("__tmp_shft_lcl" + localCount++, e.getType());
locals.add(tmp);
Unit newU = Jimple.v().newAssignStmt(tmp, e);
unitsBuilt.add(newU);
units.insertAfter(newU, u);
e = Jimple.v().newCastExpr(tmp, as.getLeftOp().getType());
}
as.setRightOp(e);
unitsBuilt.add(as);
if (neg) {
Unit newU = Jimple.v().newAssignStmt(as.getLeftOp(), Jimple.v().newNegExpr(as.getLeftOp()));
unitsBuilt.add(newU);
units.insertAfter(newU, u);
}
divPerformed++;
printOutput(unitsBuilt);
}
}
}
}
}
}
}
private void printOutput(List<Unit> unitsBuilt) {
if (!output) {
return;
}
out.println(" after as: ");
for (Unit uu : unitsBuilt) {
out.println(
"\t" + uu + "\ttype : " + (uu instanceof AssignStmt ? ((AssignStmt) uu).getLeftOp().getType().toString() : ""));
}
}
public void outputSummary() {
if (!output) {
return;
}
out.println("Replaced mul/div expressions: " + (divPerformed + mulPerformed));
out.println("Total mul/div expressions: " + total);
}
private Object[] checkNumericValue(NumericConstant nc) {
Double dnc = null;
if (nc instanceof IntConstant) {
dnc = (double) ((IntConstant) nc).value;
} else if (nc instanceof DoubleConstant) {
dnc = ((DoubleConstant) nc).value;
} else if (nc instanceof FloatConstant) {
dnc = (double) ((FloatConstant) nc).value;
} else if (nc instanceof LongConstant) {
dnc = (double) ((LongConstant) nc).value;
}
Object shift[] = new Object[3];
if (dnc != null) {
shift[2] = dnc < 0;
double tmp[] = checkShiftValue(dnc);
if (tmp[0] != 0) {
shift[0] = (int) tmp[0];
if (tmp[1] != 0) {
shift[1] = tmp[1];
} else {
shift[1] = null;
}
} else {
dnc = null;
}
}
if (dnc == null) {
shift[0] = null;
shift[1] = null;
}
return shift;
}
private double[] checkShiftValue(double val) {
double shift[] = new double[2];
if (val == 0 || val == 1 || val == -1) {
shift[0] = 0;
shift[1] = 0;
} else {
double shift_dbl = Math.log(val) / Math.log(2);
double shift_int = Math.rint(shift_dbl);
if (shift_dbl == shift_int) {
shift[1] = 0;
} else {
if (Math.pow(2, shift_int) > val) {
shift_int--;
}
shift[1] = val - Math.pow(2, shift_int);
}
shift[0] = shift_int;
}
return shift;
}
}
| 11,927
| 32.694915
| 122
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/BuildIntermediateAppClasses.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import static soot.SootMethod.constructorName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import soot.Body;
import soot.FastHierarchy;
import soot.Hierarchy;
import soot.Local;
import soot.Modifier;
import soot.PatchingChain;
import soot.PrimType;
import soot.Scene;
import soot.SceneTransformer;
import soot.SootClass;
import soot.SootMethod;
import soot.SootMethodRef;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
import soot.VoidType;
import soot.jbco.IJbcoTransform;
import soot.jbco.Main;
import soot.jbco.util.BodyBuilder;
import soot.jimple.IntConstant;
import soot.jimple.Jimple;
import soot.jimple.JimpleBody;
import soot.jimple.NullConstant;
import soot.jimple.SpecialInvokeExpr;
import soot.jimple.ThisRef;
import soot.util.Chain;
/**
* @author Michael Batchelder
* <p>
* Created on 1-Feb-2006
* <p>
* This class builds buffer classes between Application classes and their corresponding library superclasses. This
* allows for the hiding of all library method overrides to be hidden in a different class, thereby cloaking somewhat
* the mechanisms.
*/
public class BuildIntermediateAppClasses extends SceneTransformer implements IJbcoTransform {
private static int newclasses = 0;
private static int newmethods = 0;
public void outputSummary() {
out.println("New buffer classes created: " + newclasses);
out.println("New buffer class methods created: " + newmethods);
}
public static String dependancies[] = new String[] { "wjtp.jbco_bapibm" };
public String[] getDependencies() {
return dependancies;
}
public static String name = "wjtp.jbco_bapibm";
public String getName() {
return name;
}
protected void internalTransform(String phaseName, Map<String, String> options) {
if (output) {
out.println("Building Intermediate Classes...");
}
BodyBuilder.retrieveAllBodies();
// iterate through application classes, build intermediate classes
Iterator<SootClass> it = Scene.v().getApplicationClasses().snapshotIterator();
while (it.hasNext()) {
List<SootMethod> initMethodsToRewrite = new ArrayList<>();
Map<String, SootMethod> methodsToAdd = new HashMap<>();
SootClass sc = it.next();
SootClass originalSuperclass = sc.getSuperclass();
if (output) {
out.println("Processing " + sc.getName() + " with super " + originalSuperclass.getName());
}
Iterator<SootMethod> methodIterator = sc.methodIterator();
while (methodIterator.hasNext()) {
SootMethod method = methodIterator.next();
if (!method.isConcrete()) {
continue;
}
try {
method.getActiveBody();
} catch (Exception e) {
if (method.retrieveActiveBody() == null) {
throw new RuntimeException(method.getSignature() + " has no body. This was not expected dude.");
}
}
String subSig = method.getSubSignature();
if (subSig.equals("void main(java.lang.String[])") && method.isPublic() && method.isStatic()) {
continue; // skip the main method - it needs to be named 'main'
} else if (subSig.indexOf("init>(") > 0) {
if (subSig.startsWith("void <init>(")) {
initMethodsToRewrite.add(method);
}
continue; // skip constructors, just add for rewriting at the end
} else {
Scene.v().releaseActiveHierarchy();
findAccessibleInSuperClassesBySubSig(sc, subSig).ifPresent(m -> methodsToAdd.put(subSig, m));
}
}
if (methodsToAdd.size() > 0) {
final String fullName = ClassRenamer.v().getOrAddNewName(ClassRenamer.getPackageName(sc.getName()), null);
if (output) {
out.println("\tBuilding " + fullName);
}
// make non-final soot class
SootClass mediatingClass = new SootClass(fullName, sc.getModifiers() & (~Modifier.FINAL));
Main.IntermediateAppClasses.add(mediatingClass);
mediatingClass.setSuperclass(originalSuperclass);
Scene.v().addClass(mediatingClass);
mediatingClass.setApplicationClass();
mediatingClass.setInScene(true);
ThisRef thisRef = new ThisRef(mediatingClass.getType());
for (String subSig : methodsToAdd.keySet()) {
SootMethod originalSuperclassMethod = methodsToAdd.get(subSig);
List<Type> paramTypes = originalSuperclassMethod.getParameterTypes();
Type returnType = originalSuperclassMethod.getReturnType();
List<SootClass> exceptions = originalSuperclassMethod.getExceptions();
int modifiers = originalSuperclassMethod.getModifiers() & ~Modifier.ABSTRACT & ~Modifier.NATIVE;
SootMethod newMethod;
{ // build new junk method to call original method
String newMethodName = MethodRenamer.v().getNewName();
newMethod = Scene.v().makeSootMethod(newMethodName, paramTypes, returnType, modifiers, exceptions);
mediatingClass.addMethod(newMethod);
Body body = Jimple.v().newBody(newMethod);
newMethod.setActiveBody(body);
Chain<Local> locals = body.getLocals();
PatchingChain<Unit> units = body.getUnits();
BodyBuilder.buildThisLocal(units, thisRef, locals);
BodyBuilder.buildParameterLocals(units, locals, paramTypes);
if (returnType instanceof VoidType) {
units.add(Jimple.v().newReturnVoidStmt());
} else if (returnType instanceof PrimType) {
units.add(Jimple.v().newReturnStmt(IntConstant.v(0)));
} else {
units.add(Jimple.v().newReturnStmt(NullConstant.v()));
}
newmethods++;
} // end build new junk method to call original method
{ // build copy of old method
newMethod = Scene.v().makeSootMethod(originalSuperclassMethod.getName(), paramTypes, returnType, modifiers,
exceptions);
mediatingClass.addMethod(newMethod);
Body body = Jimple.v().newBody(newMethod);
newMethod.setActiveBody(body);
Chain<Local> locals = body.getLocals();
PatchingChain<Unit> units = body.getUnits();
Local ths = BodyBuilder.buildThisLocal(units, thisRef, locals);
List<Local> args = BodyBuilder.buildParameterLocals(units, locals, paramTypes);
SootMethodRef superclassMethodRef = originalSuperclassMethod.makeRef();
if (returnType instanceof VoidType) {
units.add(Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(ths, superclassMethodRef, args)));
units.add(Jimple.v().newReturnVoidStmt());
} else {
Local loc = Jimple.v().newLocal("retValue", returnType);
body.getLocals().add(loc);
units.add(Jimple.v().newAssignStmt(loc, Jimple.v().newSpecialInvokeExpr(ths, superclassMethodRef, args)));
units.add(Jimple.v().newReturnStmt(loc));
}
newmethods++;
} // end build copy of old method
}
sc.setSuperclass(mediatingClass);
// rewrite class init methods to call the proper superclass inits
int i = initMethodsToRewrite.size();
while (i-- > 0) {
SootMethod im = initMethodsToRewrite.remove(i);
Body b = im.getActiveBody();
Local thisLocal = b.getThisLocal();
Iterator<Unit> uIt = b.getUnits().snapshotIterator();
while (uIt.hasNext()) {
for (ValueBox valueBox : uIt.next().getUseBoxes()) {
Value v = valueBox.getValue();
if (v instanceof SpecialInvokeExpr) {
SpecialInvokeExpr sie = (SpecialInvokeExpr) v;
SootMethodRef smr = sie.getMethodRef();
if (sie.getBase().equivTo(thisLocal) && smr.declaringClass().getName().equals(originalSuperclass.getName())
&& smr.getSubSignature().getString().startsWith("void " + constructorName)) {
SootMethod newSuperInit;
if (!mediatingClass.declaresMethod(constructorName, smr.parameterTypes())) {
List<Type> paramTypes = smr.parameterTypes();
newSuperInit = Scene.v().makeSootMethod(constructorName, paramTypes, smr.returnType());
mediatingClass.addMethod(newSuperInit);
JimpleBody body = Jimple.v().newBody(newSuperInit);
newSuperInit.setActiveBody(body);
PatchingChain<Unit> initUnits = body.getUnits();
Collection<Local> locals = body.getLocals();
Local ths = BodyBuilder.buildThisLocal(initUnits, thisRef, locals);
List<Local> args = BodyBuilder.buildParameterLocals(initUnits, locals, paramTypes);
initUnits.add(Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(ths, smr, args)));
initUnits.add(Jimple.v().newReturnVoidStmt());
} else {
newSuperInit = mediatingClass.getMethod(constructorName, smr.parameterTypes());
}
sie.setMethodRef(newSuperInit.makeRef());
}
}
}
}
} // end of rewrite class init methods to call the proper superclass inits
}
}
newclasses = Main.IntermediateAppClasses.size();
Scene.v().releaseActiveHierarchy();
Scene.v().getActiveHierarchy();
Scene.v().setFastHierarchy(new FastHierarchy());
}
private Optional<SootMethod> findAccessibleInSuperClassesBySubSig(SootClass base, String subSig) {
Hierarchy hierarchy = Scene.v().getActiveHierarchy();
for (SootClass superClass : hierarchy.getSuperclassesOfIncluding(base.getSuperclass())) {
if (superClass.isLibraryClass() && superClass.declaresMethod(subSig)) {
SootMethod method = superClass.getMethod(subSig);
if (hierarchy.isVisible(base, method)) {
return Optional.of(method);
}
}
}
return Optional.empty();
}
}
| 11,196
| 38.287719
| 125
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/ClassRenamer.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiPredicate;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.ArrayType;
import soot.Body;
import soot.FastHierarchy;
import soot.G;
import soot.RefType;
import soot.Scene;
import soot.SceneTransformer;
import soot.Singletons;
import soot.SootClass;
import soot.SootMethod;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
import soot.jbco.IJbcoTransform;
import soot.jbco.name.JunkNameGenerator;
import soot.jbco.name.NameGenerator;
import soot.jbco.util.BodyBuilder;
import soot.jimple.CastExpr;
import soot.jimple.ClassConstant;
import soot.jimple.Expr;
import soot.jimple.InstanceOfExpr;
import soot.jimple.Ref;
import soot.tagkit.SourceFileTag;
/**
* {@link SceneTransformer} that renames class names as well as packages.
*
* @author Michael Batchelder, Pavel Nesterovich
* @since 26-Jan-2006
*/
public class ClassRenamer extends SceneTransformer implements IJbcoTransform {
private static final Logger logger = LoggerFactory.getLogger(ClassRenamer.class);
private boolean removePackages = false;
private boolean renamePackages = false;
public static final String name = "wjtp.jbco_cr";
private final Map<String, String> oldToNewPackageNames = new HashMap<>();
private final Map<String, String> oldToNewClassNames = new HashMap<>();
private final Map<String, SootClass> newNameToClass = new HashMap<>();
private final Object classNamesMapLock = new Object();
private final Object packageNamesMapLock = new Object();
private final NameGenerator nameGenerator;
/**
* Singleton constructor.
*
* @param global
* the singletons container. Must not be {@code null}
* @throws NullPointerException
* when {@code global} argument is {@code null}
*/
public ClassRenamer(Singletons.Global global) {
if (global == null) {
throw new NullPointerException("Cannot instantiate ClassRenamer with null Singletons.Global");
}
this.nameGenerator = new JunkNameGenerator();
}
/**
* Singleton getter.
*
* @return returns instance of {@link ClassRenamer}
*/
public static ClassRenamer v() {
return G.v().soot_jbco_jimpleTransformations_ClassRenamer();
}
@Override
public String getName() {
return name;
}
@Override
public String[] getDependencies() {
return new String[] { ClassRenamer.name };
}
@Override
public void outputSummary() {
final StringBuilder stringBuilder = new StringBuilder("ClassName mapping:").append(System.lineSeparator());
oldToNewClassNames.forEach(
(oldName, newName) -> stringBuilder.append(oldName).append(" -> ").append(newName).append(System.lineSeparator()));
logger.info(stringBuilder.toString());
}
/**
* Checks if transformer must remove package from fully qualified class name.
*
* @return {@code true} if {@link ClassRenamer} removes packages from fully qualified class name; {@code false} otherwise
*/
public boolean isRemovePackages() {
return removePackages;
}
/**
* Sets flag indicating that transformer must remove package from fully qualified class name.
*
* @param removePackages
* the flag value
*/
public void setRemovePackages(boolean removePackages) {
this.removePackages = removePackages;
}
/**
* Checks if transformer must rename package in fully qualified class name.
*
* @return {@code true} if {@link ClassRenamer} renames packages in fully qualified class name; {@code false} otherwise
*/
public boolean isRenamePackages() {
return renamePackages;
}
/**
* Sets flag indicating that transformer must rename package in fully qualified class name.
*
* @param renamePackages
* the flag value
*/
public void setRenamePackages(boolean renamePackages) {
this.renamePackages = renamePackages;
}
/**
* Adds mapping for class name.
*
* @param classNameSource
* the class name to rename
* @param classNameTarget
* the new class name
*/
public void addClassNameMapping(String classNameSource, String classNameTarget) {
synchronized (classNamesMapLock) {
if (!oldToNewClassNames.containsKey(classNameSource) && !oldToNewClassNames.containsValue(classNameTarget)
&& !BodyBuilder.nameList.contains(classNameTarget)) {
oldToNewClassNames.put(classNameSource, classNameTarget);
BodyBuilder.nameList.add(classNameTarget);
return;
}
}
throw new IllegalStateException("Cannot generate unique name: too long for JVM.");
}
/**
* Gets mapping by predicate.
*
* @param predicate
* the predicate to decide if mapping should be filtered. Can be {@code null}
*/
public Map<String, String> getClassNameMapping(BiPredicate<String, String> predicate) {
if (predicate == null) {
return new HashMap<>(oldToNewClassNames);
}
return oldToNewClassNames.entrySet().stream().filter(entry -> predicate.test(entry.getKey(), entry.getValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
@Override
protected void internalTransform(String phaseName, Map<String, String> options) {
if (isVerbose()) {
logger.info("Transforming Class Names...");
}
BodyBuilder.retrieveAllBodies();
BodyBuilder.retrieveAllNames();
final SootClass mainClass = getMainClassSafely();
for (SootClass applicationClass : Scene.v().getApplicationClasses()) {
final String fullyQualifiedName = applicationClass.getName();
if (applicationClass.equals(mainClass) || oldToNewClassNames.containsValue(fullyQualifiedName)
|| soot.jbco.Main.getWeight(phaseName, fullyQualifiedName) == 0) {
continue;
}
String newClassName = getOrAddNewName(getPackageName(fullyQualifiedName), getClassName(fullyQualifiedName));
applicationClass.setName(newClassName);
RefType crt = RefType.v(newClassName);
crt.setSootClass(applicationClass);
applicationClass.setRefType(crt);
applicationClass.setResolvingLevel(SootClass.BODIES);
// will this fix dangling classes?
// Scene.v().addRefType(applicationClass.getType());
// set source name
SourceFileTag sourceFileTag = (SourceFileTag) applicationClass.getTag(SourceFileTag.NAME);
if (sourceFileTag == null) {
logger.info("Adding SourceFileTag for class {}", fullyQualifiedName);
sourceFileTag = new SourceFileTag();
applicationClass.addTag(sourceFileTag);
}
sourceFileTag.setSourceFile(newClassName);
newNameToClass.put(newClassName, applicationClass);
if (isVerbose()) {
logger.info("Renaming {} to {}", fullyQualifiedName, newClassName);
}
}
Scene.v().releaseActiveHierarchy();
Scene.v().setFastHierarchy(new FastHierarchy());
if (isVerbose()) {
logger.info("Updating bytecode class references");
}
for (SootClass sootClass : Scene.v().getApplicationClasses()) {
for (SootMethod sootMethod : sootClass.getMethods()) {
if (!sootMethod.isConcrete()) {
continue;
}
if (isVerbose()) {
logger.info(sootMethod.getSignature());
}
Body aBody;
try {
aBody = sootMethod.getActiveBody();
} catch (Exception e) {
continue;
}
for (Unit u : aBody.getUnits()) {
for (ValueBox vb : u.getUseAndDefBoxes()) {
Value v = vb.getValue();
if (v instanceof ClassConstant) {
ClassConstant constant = (ClassConstant) v;
RefType type = (RefType) constant.toSootType();
RefType updatedType = type.getSootClass().getType();
vb.setValue(ClassConstant.fromType(updatedType));
} else if (v instanceof Expr) {
if (v instanceof CastExpr) {
CastExpr castExpr = (CastExpr) v;
updateType(castExpr.getCastType());
} else if (v instanceof InstanceOfExpr) {
InstanceOfExpr instanceOfExpr = (InstanceOfExpr) v;
updateType(instanceOfExpr.getCheckType());
}
} else if (v instanceof Ref) {
updateType(v.getType());
}
}
}
}
}
Scene.v().releaseActiveHierarchy();
Scene.v().setFastHierarchy(new FastHierarchy());
}
private void updateType(Type type) {
if (type instanceof RefType) {
RefType rt = (RefType) type;
if (!rt.getSootClass().isLibraryClass() && oldToNewClassNames.containsKey(rt.getClassName())) {
rt.setSootClass(newNameToClass.get(oldToNewClassNames.get(rt.getClassName())));
rt.setClassName(oldToNewClassNames.get(rt.getClassName()));
}
} else if (type instanceof ArrayType) {
ArrayType at = (ArrayType) type;
if (at.baseType instanceof RefType) {
RefType rt = (RefType) at.baseType;
if (!rt.getSootClass().isLibraryClass() && oldToNewClassNames.containsKey(rt.getClassName())) {
rt.setSootClass(newNameToClass.get(oldToNewClassNames.get(rt.getClassName())));
}
}
}
}
/**
* Generates new <strong>unique</strong> name that have not existed before and mapping for it or gets already generated
* name if one was generated before.
*
* @param packageName
* the package where class is located. Can be {@code null}
* @param className
* the class name (without package) to create mapping for. Can be {@code null}
* @return the new <strong>unique</strong> name
*/
public String getOrAddNewName(final String packageName, final String className) {
int size = 5;
int tries = 0;
String newFqn = "";
// if className == null we must generate new name
// so check for already existing mapping is not applicable
if (className != null) {
newFqn = removePackages ? className : packageName == null ? className : packageName + '.' + className;
if (oldToNewClassNames.containsKey(newFqn)) {
return oldToNewClassNames.get(newFqn);
}
}
synchronized (classNamesMapLock) {
// check one more time when oldToNewClassNames is locked
if (oldToNewClassNames.containsKey(newFqn)) {
return oldToNewClassNames.get(newFqn);
}
while (newFqn.length() < NameGenerator.NAME_MAX_LENGTH) {
final String name = nameGenerator.generateName(size);
newFqn = name; // when removePackages is true
if (!removePackages) {
final String newPackage = renamePackages ? getOrAddNewPackageName(packageName) : packageName;
newFqn = newPackage == null ? name : newPackage + '.' + name;
}
final String oldFqn;
if (className == null) {
// there were no old name, so create dumb mapping: newFqn -> newFqn
oldFqn = newFqn;
} else {
oldFqn = (packageName == null ? "" : packageName + '.') + className;
}
if (!oldToNewClassNames.containsKey(oldFqn) && !oldToNewClassNames.containsValue(newFqn)
&& !BodyBuilder.nameList.contains(newFqn)) {
addClassNameMapping(oldFqn, newFqn);
return newFqn;
}
if (tries++ > size) {
size++;
tries = 0;
}
}
}
throw new IllegalStateException("Cannot generate unique package name part: too long for JVM.");
}
/**
* Extracts package name from class name.
*
* @param fullyQualifiedClassName
* the fully qualified class name. Can be {@code null}
* @return package name or {@code null} when class name is {@code null}, no '.' in the name, or package name is '.'
*/
public static String getPackageName(String fullyQualifiedClassName) {
if (fullyQualifiedClassName == null || fullyQualifiedClassName.isEmpty()) {
return null;
}
int idx = fullyQualifiedClassName.lastIndexOf('.');
return idx >= 1 ? fullyQualifiedClassName.substring(0, idx) : null;
}
/**
* Extracts class name from fully qualified name.
*
* @param fullyQualifiedClassName
* the fully qualified class name. Can be {@code null}
* @return class name or {@code null} when class name is {@code null}, no '.' in the name
*/
public static String getClassName(String fullyQualifiedClassName) {
if (fullyQualifiedClassName == null || fullyQualifiedClassName.isEmpty()) {
return null;
}
int idx = fullyQualifiedClassName.lastIndexOf('.');
if (idx < 0) {
return fullyQualifiedClassName;
}
return idx < fullyQualifiedClassName.length() - 1 ? fullyQualifiedClassName.substring(idx + 1) : null;
}
private static SootClass getMainClassSafely() {
if (Scene.v().hasMainClass()) {
return Scene.v().getMainClass();
} else {
return null;
}
}
private String getOrAddNewPackageName(String packageName) {
if (packageName == null || packageName.isEmpty()) {
return getNewPackageNamePart("");
}
final String[] packageNameParts = packageName.split("\\.");
final StringBuilder newPackageName = new StringBuilder((int) (5 * (packageNameParts.length + 1) * 1.5));
for (int i = 0; i < packageNameParts.length; i++) {
newPackageName.append(getNewPackageNamePart(packageNameParts[i]));
if (i < packageNameParts.length - 1) {
newPackageName.append('.');
}
}
return newPackageName.toString();
}
private String getNewPackageNamePart(String oldPackageNamePart) {
if (oldPackageNamePart != null && oldToNewPackageNames.containsKey(oldPackageNamePart)) {
return oldToNewPackageNames.get(oldPackageNamePart);
}
int size = 5;
int tries = 0;
String newPackageNamePart = "";
while (newPackageNamePart.length() < NameGenerator.NAME_MAX_LENGTH) {
synchronized (packageNamesMapLock) {
if (oldToNewPackageNames.containsValue(newPackageNamePart)) {
return oldToNewPackageNames.get(newPackageNamePart);
}
newPackageNamePart = nameGenerator.generateName(size);
if (!oldToNewPackageNames.containsValue(newPackageNamePart)) {
final String key = oldPackageNamePart == null ? newPackageNamePart : oldPackageNamePart;
oldToNewPackageNames.put(key, newPackageNamePart);
return newPackageNamePart;
}
}
if (tries++ > size) {
size++;
tries = 0;
}
}
throw new IllegalStateException("Cannot generate unique package name part: too long for JVM.");
}
}
| 15,573
| 31.244306
| 123
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/CollectConstants.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import static java.util.Collections.emptyList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.Body;
import soot.Hierarchy;
import soot.Modifier;
import soot.NullType;
import soot.PatchingChain;
import soot.RefType;
import soot.Scene;
import soot.SceneTransformer;
import soot.SootClass;
import soot.SootField;
import soot.SootMethod;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
import soot.VoidType;
import soot.jbco.IJbcoTransform;
import soot.jbco.util.BodyBuilder;
import soot.jbco.util.Rand;
import soot.jimple.ClassConstant;
import soot.jimple.Constant;
import soot.jimple.DoubleConstant;
import soot.jimple.FloatConstant;
import soot.jimple.IntConstant;
import soot.jimple.Jimple;
import soot.jimple.LongConstant;
import soot.jimple.NullConstant;
import soot.jimple.StringConstant;
import soot.util.Chain;
/**
* @author Michael Batchelder
* @since 31-May-2006
*/
public class CollectConstants extends SceneTransformer implements IJbcoTransform {
private static final Logger logger = LoggerFactory.getLogger(FieldRenamer.class);
public static final String name = "wjtp.jbco_cc";
private final Map<Type, List<Constant>> typeToConstants = new HashMap<>();
public static HashMap<Constant, SootField> constantsToFields = new HashMap<>();
private int constants = 0;
private int updatedConstants = 0;
@Override
public String getName() {
return name;
}
@Override
public String[] getDependencies() {
return new String[] { name };
}
@Override
public void outputSummary() {
logger.info("Found {} constants, updated {} ones", constants, updatedConstants);
}
@Override
protected void internalTransform(String phaseName, Map<String, String> options) {
if (isVerbose()) {
logger.info("Collecting Constant Data");
}
BodyBuilder.retrieveAllNames();
final Chain<SootClass> applicationClasses = Scene.v().getApplicationClasses();
for (SootClass applicationClass : applicationClasses) {
for (SootMethod method : applicationClass.getMethods()) {
if (!method.hasActiveBody() || method.getName().contains(SootMethod.staticInitializerName)) {
continue;
}
for (ValueBox useBox : method.getActiveBody().getUseBoxes()) {
final Value value = useBox.getValue();
if (value instanceof Constant) {
final Constant constant = (Constant) value;
Type type = constant.getType();
List<Constant> constants = typeToConstants.computeIfAbsent(type, t -> new ArrayList<>());
if (!constants.contains(constant)) {
this.constants++;
constants.add(constant);
}
}
}
}
}
int count = 0;
String name = "newConstantJbcoName";
SootClass[] classes = applicationClasses.toArray(new SootClass[applicationClasses.size()]);
for (Type type : typeToConstants.keySet()) {
if (type instanceof NullType) {
continue; // type = RefType.v("java.lang.Object");
}
for (Constant constant : typeToConstants.get(type)) {
name += "_";
SootClass randomClass;
do {
randomClass = classes[Rand.getInt(classes.length)];
} while (!isSuitableClassToAddFieldConstant(randomClass, constant));
final SootField newField
= Scene.v().makeSootField(FieldRenamer.v().getOrAddNewName(name), type, Modifier.STATIC ^ Modifier.PUBLIC);
randomClass.addField(newField);
constantsToFields.put(constant, newField);
addInitializingValue(randomClass, newField, constant);
count++;
}
}
updatedConstants += count;
}
private boolean isSuitableClassToAddFieldConstant(SootClass sc, Constant constant) {
if (sc.isInterface()) {
return false;
}
if (constant instanceof ClassConstant) {
ClassConstant classConstant = (ClassConstant) constant;
RefType type = (RefType) classConstant.toSootType();
SootClass classFromConstant = type.getSootClass();
Hierarchy hierarchy = Scene.v().getActiveHierarchy();
return hierarchy.isVisible(sc, classFromConstant);
}
return true;
}
private void addInitializingValue(SootClass sc, SootField f, Constant constant) {
if (constant instanceof NullConstant) {
return;
} else if (constant instanceof IntConstant) {
if (((IntConstant) constant).value == 0) {
return;
}
} else if (constant instanceof LongConstant) {
if (((LongConstant) constant).value == 0) {
return;
}
} else if (constant instanceof StringConstant) {
if (((StringConstant) constant).value == null) {
return;
}
} else if (constant instanceof DoubleConstant) {
if (((DoubleConstant) constant).value == 0) {
return;
}
} else if (constant instanceof FloatConstant) {
if (((FloatConstant) constant).value == 0) {
return;
}
}
Body b;
boolean newInit = false;
if (!sc.declaresMethodByName(SootMethod.staticInitializerName)) {
SootMethod m = Scene.v().makeSootMethod(SootMethod.staticInitializerName, emptyList(), VoidType.v(), Modifier.STATIC);
sc.addMethod(m);
b = Jimple.v().newBody(m);
m.setActiveBody(b);
newInit = true;
} else {
SootMethod m = sc.getMethodByName(SootMethod.staticInitializerName);
if (!m.hasActiveBody()) {
b = Jimple.v().newBody(m);
m.setActiveBody(b);
newInit = true;
} else {
b = m.getActiveBody();
}
}
PatchingChain<Unit> units = b.getUnits();
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(f.makeRef()), constant));
if (newInit) {
units.addLast(Jimple.v().newReturnVoidStmt());
}
}
}
| 6,779
| 29.958904
| 124
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/CollectJimpleLocals.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.ArrayList;
import java.util.Map;
import soot.Body;
import soot.BodyTransformer;
import soot.Local;
import soot.jbco.IJbcoTransform;
/**
* @author Michael Batchelder
*
* Created on 7-Feb-2006
*/
public class CollectJimpleLocals extends BodyTransformer implements IJbcoTransform {
public void outputSummary() {
}
public static String dependancies[] = new String[] { "jtp.jbco_jl" };
public String[] getDependencies() {
return dependancies;
}
public static String name = "jtp.jbco_jl";
public String getName() {
return name;
}
protected void internalTransform(Body body, String phaseName, Map<String, String> options) {
soot.jbco.Main.methods2JLocals.put(body.getMethod(), new ArrayList<Local>(body.getLocals()));
}
}
| 1,633
| 27.172414
| 97
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/FieldRenamer.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.Body;
import soot.BooleanType;
import soot.G;
import soot.IntegerType;
import soot.Local;
import soot.Modifier;
import soot.PatchingChain;
import soot.RefType;
import soot.Scene;
import soot.SceneTransformer;
import soot.Singletons;
import soot.SootClass;
import soot.SootField;
import soot.SootFieldRef;
import soot.SootMethod;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
import soot.VoidType;
import soot.jbco.IJbcoTransform;
import soot.jbco.name.JunkNameGenerator;
import soot.jbco.name.NameGenerator;
import soot.jbco.util.BodyBuilder;
import soot.jbco.util.Rand;
import soot.jimple.FieldRef;
import soot.jimple.IntConstant;
import soot.jimple.Jimple;
import soot.tagkit.SignatureTag;
/**
* @author Michael Batchelder, Pavel Nesterovich
* @since 26-Jan-2006
*/
public class FieldRenamer extends SceneTransformer implements IJbcoTransform {
private static final Logger logger = LoggerFactory.getLogger(FieldRenamer.class);
public static final String name = "wjtp.jbco_fr";
private static final String BOOLEAN_CLASS_NAME = Boolean.class.getName();
private static final SootField[] EMPTY_ARRAY = new SootField[0];
private final NameGenerator nameGenerator;
private final Map<String, String> oldToNewFieldNames = new HashMap<>();
private final Map<SootClass, SootField> opaquePredicate1ByClass = new HashMap<>();
private final Map<SootClass, SootField> opaquePredicate2ByClass = new HashMap<>();
private SootField[][] opaquePairs = null;
private final Set<String> skipFields = new HashSet<>();
public static int handedOutPairs[] = null;
public static int handedOutRunPairs[] = null;
private boolean renameFields = false;
private final Object fieldNamesLock = new Object();
/**
* Singleton constructor.
*
* @param global
* the singletons container. Must not be {@code null}
* @throws NullPointerException
* when {@code global} argument is {@code null}
*/
public FieldRenamer(Singletons.Global global) {
if (global == null) {
throw new NullPointerException("Cannot instantiate FieldRenamer with null Singletons.Global");
}
this.nameGenerator = new JunkNameGenerator();
}
/**
* Singleton getter.
*
* @return returns instance of {@link FieldRenamer}
*/
public static FieldRenamer v() {
return G.v().soot_jbco_jimpleTransformations_FieldRenamer();
}
@Override
public String getName() {
return name;
}
@Override
public String[] getDependencies() {
return new String[] { name };
}
@Override
public void outputSummary() {
logger.info("Processed field mapping:");
oldToNewFieldNames.forEach((oldName, newName) -> logger.info("{} -> {}", oldName, newName));
}
public boolean isRenameFields() {
return renameFields;
}
public void setRenameFields(boolean renameFields) {
this.renameFields = renameFields;
}
public void setSkipFields(Collection<String> fields) {
if (!skipFields.isEmpty()) {
skipFields.clear();
}
if (fields != null && !fields.isEmpty()) {
skipFields.addAll(fields);
}
}
public Set<String> getSkipFields() {
return skipFields;
}
@Override
protected void internalTransform(String phaseName, Map<String, String> options) {
if (isVerbose()) {
logger.info(renameFields ? "Transforming Field Names and Adding Opaque Predicates..." : "Adding Opaques...");
}
final RefType booleanWrapperRefType = Scene.v().getRefType(BOOLEAN_CLASS_NAME);
BodyBuilder.retrieveAllBodies();
BodyBuilder.retrieveAllNames();
for (SootClass applicationClass : Scene.v().getApplicationClasses()) {
String className = applicationClass.getName();
if (className.contains(".")) {
className = className.substring(className.lastIndexOf(".") + 1);
}
oldToNewFieldNames.put(className, className);
if (renameFields) {
if (isVerbose()) {
logger.info("Class [{}]", applicationClass.getName());
}
// rename all the fields in the class
for (SootField field : applicationClass.getFields()) {
if (soot.jbco.Main.getWeight(phaseName, field.getSignature()) > 0) {
renameField(applicationClass, field);
field.removeTag(SignatureTag.NAME);
}
}
}
// skip interfaces - they can only hold final fields
if (applicationClass.isInterface()) {
continue;
}
// add one opaque predicate for true and one for false to each class
String opaquePredicate = getOrAddNewName(null);
Type type = Rand.getInt() % 2 == 0 ? BooleanType.v() : booleanWrapperRefType;
SootField opaquePredicateField = Scene.v().makeSootField(opaquePredicate, type, Modifier.PUBLIC | Modifier.STATIC);
renameField(applicationClass, opaquePredicateField);
opaquePredicate1ByClass.put(applicationClass, opaquePredicateField);
applicationClass.addField(opaquePredicateField);
setBooleanTo(applicationClass, opaquePredicateField, true);
opaquePredicate = getOrAddNewName(null);
type = type == BooleanType.v() ? booleanWrapperRefType : BooleanType.v();
opaquePredicateField = Scene.v().makeSootField(opaquePredicate, type, Modifier.PUBLIC | Modifier.STATIC);
renameField(applicationClass, opaquePredicateField);
opaquePredicate2ByClass.put(applicationClass, opaquePredicateField);
applicationClass.addField(opaquePredicateField);
if (type == booleanWrapperRefType) {
setBooleanTo(applicationClass, opaquePredicateField, false);
}
}
buildOpaquePairings();
if (!renameFields) {
return;
}
if (isVerbose()) {
logger.info("Updating field references in bytecode");
}
for (SootClass applicationClass : Scene.v().getApplicationClasses()) {
for (SootMethod method : applicationClass.getMethods()) {
if (!method.isConcrete()) {
continue;
}
if (!method.hasActiveBody()) {
method.retrieveActiveBody();
}
for (Unit unit : method.getActiveBody().getUnits()) {
for (ValueBox box : unit.getUseAndDefBoxes()) {
final Value value = box.getValue();
if (value instanceof FieldRef) {
final FieldRef fieldRef = (FieldRef) value;
SootFieldRef sootFieldRef = fieldRef.getFieldRef();
if (sootFieldRef.declaringClass().isLibraryClass()) {
continue;
}
final String oldName = sootFieldRef.name();
final String fullyQualifiedName = sootFieldRef.declaringClass().getName() + '.' + oldName;
if (skipFields.contains(fullyQualifiedName)) {
continue;
}
String newName = oldToNewFieldNames.get(oldName);
if (!oldToNewFieldNames.containsKey(oldName)) {
// We ran into already renamed field.
// To update related references proceed with oldName
newName = oldName;
} else if (newName == null) {
throw new IllegalStateException("Found incorrect field mapping [" + fullyQualifiedName + "] -> [null].");
} else if (newName.equals(oldName)) {
logger.warn("The new name of the field \"{}\" is equal to the old one. Check if it is a mistake.",
fullyQualifiedName);
}
sootFieldRef = Scene.v().makeFieldRef(sootFieldRef.declaringClass(), newName, sootFieldRef.type(),
sootFieldRef.isStatic());
fieldRef.setFieldRef(sootFieldRef);
try {
sootFieldRef.resolve();
} catch (Exception exception) {
logger.error("Cannot rename field \"" + oldName + "\" to \"" + newName + "\" due to error.", exception);
logger.info("Fields of {}: {}", sootFieldRef.declaringClass().getName(),
sootFieldRef.declaringClass().getFields());
throw new RuntimeException(exception);
}
}
}
}
}
}
}
protected void setBooleanTo(SootClass sootClass, SootField field, boolean value) {
if (!value && field.getType() instanceof IntegerType && Rand.getInt() % 2 > 0) {
return;
}
final RefType booleanWrapperRefType = Scene.v().getRefType(BOOLEAN_CLASS_NAME);
final boolean addStaticInitializer = !sootClass.declaresMethodByName(SootMethod.staticInitializerName);
final Body body;
if (addStaticInitializer) {
final SootMethod staticInitializerMethod = Scene.v().makeSootMethod(SootMethod.staticInitializerName,
Collections.emptyList(), VoidType.v(), Modifier.STATIC);
sootClass.addMethod(staticInitializerMethod);
body = Jimple.v().newBody(staticInitializerMethod);
staticInitializerMethod.setActiveBody(body);
} else {
body = sootClass.getMethodByName(SootMethod.staticInitializerName).getActiveBody();
}
final PatchingChain<Unit> units = body.getUnits();
if (field.getType() instanceof IntegerType) {
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(field.makeRef()), IntConstant.v(value ? 1 : 0)));
} else {
Local bool = Jimple.v().newLocal("boolLcl", booleanWrapperRefType);
body.getLocals().add(bool);
final SootMethod booleanWrapperConstructor = booleanWrapperRefType.getSootClass().getMethod("void <init>(boolean)");
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(field.makeRef()), bool));
units.addFirst(Jimple.v().newInvokeStmt(
Jimple.v().newSpecialInvokeExpr(bool, booleanWrapperConstructor.makeRef(), IntConstant.v(value ? 1 : 0))));
units.addFirst(Jimple.v().newAssignStmt(bool, Jimple.v().newNewExpr(booleanWrapperRefType)));
}
if (addStaticInitializer) {
units.addLast(Jimple.v().newReturnVoidStmt());
}
}
protected void renameField(SootClass sootClass, SootField field) {
final String fullyQualifiedName = sootClass.getName() + "." + field.getName();
final String newName = getOrAddNewName(field.getName());
if (isVerbose()) {
logger.info("Changing {} to {}", fullyQualifiedName, newName);
}
field.setName(newName);
}
/**
* Generates new <strong>unique</strong> name that have not existed before and mapping for it, or gets new name if one was
* already generated.
*
* @param originalName
* the original field name. If {@code null} then will be the same as generated one
* @return the new <strong>unique</strong> name
*/
public String getOrAddNewName(final String originalName) {
int size = 5;
int tries = 0;
String newName = "";
if (originalName != null) {
newName = originalName;
if (oldToNewFieldNames.containsKey(newName)) {
return oldToNewFieldNames.get(originalName);
}
}
synchronized (fieldNamesLock) {
// check one more time when oldToNewFieldNames is locked
if (oldToNewFieldNames.containsKey(newName)) {
return oldToNewFieldNames.get(newName);
}
while (newName.length() < NameGenerator.NAME_MAX_LENGTH) {
newName = nameGenerator.generateName(size);
final String key = originalName == null ? newName : originalName;
if (!oldToNewFieldNames.containsKey(key) && !oldToNewFieldNames.containsValue(newName)
&& !BodyBuilder.nameList.contains(newName)) {
oldToNewFieldNames.put(key, newName);
BodyBuilder.nameList.add(newName);
return newName;
}
if (tries++ > size) {
size++;
tries = 0;
}
}
}
throw new IllegalStateException("Cannot generate unique package name part: too long for JVM.");
}
public SootField[] getRandomOpaques() {
if (handedOutPairs == null) {
handedOutPairs = new int[opaquePairs.length];
}
int lowValue = 99999;
List<Integer> available = new ArrayList<>();
for (int element : handedOutPairs) {
if (lowValue > element) {
lowValue = element;
}
}
for (int i = 0; i < handedOutPairs.length; i++) {
if (handedOutPairs[i] == lowValue) {
available.add(i);
}
}
int index = available.get(Rand.getInt(available.size()));
handedOutPairs[index]++;
return opaquePairs[index];
}
public int getRandomOpaquesForRunnable() {
if (handedOutRunPairs == null) {
handedOutRunPairs = new int[opaquePairs.length];
}
int lowValue = 99999;
List<Integer> available = new ArrayList<>();
for (int element : handedOutRunPairs) {
if (lowValue > element) {
lowValue = element;
}
}
if (lowValue > 2) {
return -1;
}
for (int i = 0; i < handedOutRunPairs.length; i++) {
if (handedOutRunPairs[i] == lowValue) {
available.add(i);
}
}
return available.get(Rand.getInt(available.size()));
}
public static void updateOpaqueRunnableCount(int i) {
handedOutRunPairs[i]++;
}
private void buildOpaquePairings() {
final SootField[] fields1 = opaquePredicate1ByClass.values().toArray(EMPTY_ARRAY);
final SootField[] fields2 = opaquePredicate2ByClass.values().toArray(EMPTY_ARRAY);
int length = fields1.length;
for (int i = 0; i < fields1.length * 2 && fields1.length > 1; i++) {
swap(fields1);
swap(fields2);
}
opaquePairs = new SootField[length][2];
for (int i = 0; i < length; i++) {
opaquePairs[i] = new SootField[] { fields1[i], fields2[i] };
}
}
/**
* Swaps random elements.
*/
private static <T> void swap(T[] x) {
final int a = Rand.getInt(x.length);
int b = Rand.getInt(x.length);
while (a == b) {
b = Rand.getInt(x.length);
}
T t = x[a];
x[a] = x[b];
x[b] = t;
}
}
| 15,079
| 31.222222
| 124
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/GotoInstrumenter.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.Body;
import soot.BodyTransformer;
import soot.Local;
import soot.PatchingChain;
import soot.RefType;
import soot.Scene;
import soot.SootMethod;
import soot.Trap;
import soot.Unit;
import soot.UnitBox;
import soot.jbco.IJbcoTransform;
import soot.jbco.util.Rand;
import soot.jimple.GotoStmt;
import soot.jimple.IdentityStmt;
import soot.jimple.Jimple;
import soot.jimple.Stmt;
import soot.util.Chain;
/**
* Changes the sequence of statements in which they appear in methods, preserving the sequence they are executed using
* {@code goto} commands and {@code labels}. Also if possible adds {@code try-catch} block in random position.
*
* @author Michael Batchelder
* @since 15-Feb-2006
*/
public class GotoInstrumenter extends BodyTransformer implements IJbcoTransform {
private static final Logger logger = LoggerFactory.getLogger(GotoInstrumenter.class);
public static final String name = "jtp.jbco_gia";
public static final String dependencies[] = new String[] { GotoInstrumenter.name };
private int trapsAdded = 0;
private int gotosInstrumented = 0;
private static final UnitBox[] EMPTY_UNIT_BOX_ARRAY = new UnitBox[0];
private static final int MAX_TRIES_TO_GET_REORDER_COUNT = 10;
@Override
public String getName() {
return name;
}
@Override
public String[] getDependencies() {
return Arrays.copyOf(dependencies, dependencies.length);
}
@Override
public void outputSummary() {
logger.info("Instrumented {} GOTOs, added {} traps.", gotosInstrumented, trapsAdded);
}
@Override
protected void internalTransform(Body body, String phaseName, Map<String, String> options) {
if (SootMethod.constructorName.equals(body.getMethod().getName())
|| SootMethod.staticInitializerName.equals(body.getMethod().getName())) {
if (isVerbose()) {
logger.info("Skipping {} method GOTO instrumentation as it is constructor/initializer.",
body.getMethod().getSignature());
}
return;
}
if (soot.jbco.Main.getWeight(phaseName, body.getMethod().getSignature()) == 0) {
return;
}
final PatchingChain<Unit> units = body.getUnits();
int precedingFirstNotIdentityIndex = 0;
Unit precedingFirstNotIdentity = null;
for (Unit unit : units) {
if (unit instanceof IdentityStmt) {
precedingFirstNotIdentity = unit;
precedingFirstNotIdentityIndex++;
continue;
}
break;
}
final int unitsLeft = units.size() - precedingFirstNotIdentityIndex;
if (unitsLeft < 8) {
if (isVerbose()) {
logger.info("Skipping {} method GOTO instrumentation as it is too small.", body.getMethod().getSignature());
}
return;
}
int tries = 0;
int unitsQuantityToReorder = 0;
while (tries < MAX_TRIES_TO_GET_REORDER_COUNT) {
// value must be in (0; unitsLeft - 1]
// - greater than 0 to avoid modifying the precedingFirstNotIdentity
// - less than unitsLeft - 1 to avoid getting out of bounds
unitsQuantityToReorder = Rand.getInt(unitsLeft - 2) + 1;
tries++;
final Unit selectedUnit = Iterables.get(units, precedingFirstNotIdentityIndex + unitsQuantityToReorder);
if (isExceptionCaught(selectedUnit, units, body.getTraps())) {
continue;
}
break;
}
// if 10 tries, we give up
if (tries >= MAX_TRIES_TO_GET_REORDER_COUNT) {
return;
}
if (isVerbose()) {
logger.info("Adding GOTOs to \"{}\".", body.getMethod().getName());
}
final Unit first = precedingFirstNotIdentity == null ? units.getFirst() : precedingFirstNotIdentity;
final Unit firstReorderingUnit = units.getSuccOf(first);
// move random-size chunk at beginning to end
Unit reorderingUnit = firstReorderingUnit;
for (int reorder = 0; reorder < unitsQuantityToReorder; reorder++) {
// create separate array to avoid coming modifications
final UnitBox pointingToReorderingUnit[] = reorderingUnit.getBoxesPointingToThis().toArray(EMPTY_UNIT_BOX_ARRAY);
for (UnitBox element : pointingToReorderingUnit) {
reorderingUnit.removeBoxPointingToThis(element);
}
// unit box targets stay with a unit even if the unit is removed.
final Unit nextReorderingUnit = units.getSuccOf(reorderingUnit);
units.remove(reorderingUnit);
units.add(reorderingUnit);
for (UnitBox element : pointingToReorderingUnit) {
reorderingUnit.addBoxPointingToThis(element);
}
reorderingUnit = nextReorderingUnit;
}
// add goto as FIRST unit to point to new chunk location
final Unit firstReorderingNotGotoStmt
= first instanceof GotoStmt ? ((GotoStmt) first).getTargetBox().getUnit() : firstReorderingUnit;
final GotoStmt gotoFirstReorderingNotGotoStmt = Jimple.v().newGotoStmt(firstReorderingNotGotoStmt);
units.insertBeforeNoRedirect(gotoFirstReorderingNotGotoStmt, reorderingUnit);
// add goto as LAST unit to point to new position of second chunk
if (units.getLast().fallsThrough()) {
final Stmt gotoStmt = (reorderingUnit instanceof GotoStmt)
? Jimple.v().newGotoStmt(((GotoStmt) reorderingUnit).getTargetBox().getUnit())
: Jimple.v().newGotoStmt(reorderingUnit);
units.add(gotoStmt);
}
gotosInstrumented++;
Unit secondReorderedUnit = units.getSuccOf(firstReorderingNotGotoStmt);
if (secondReorderedUnit == null
|| (secondReorderedUnit.equals(units.getLast()) && secondReorderedUnit instanceof IdentityStmt)) {
if (firstReorderingNotGotoStmt instanceof IdentityStmt) {
if (isVerbose()) {
logger.info("Skipping adding try-catch block at \"{}\".", body.getMethod().getSignature());
}
return;
}
secondReorderedUnit = firstReorderingNotGotoStmt;
}
final RefType throwable = Scene.v().getRefType("java.lang.Throwable");
final Local caughtExceptionLocal = Jimple.v().newLocal("jbco_gi_caughtExceptionLocal", throwable);
body.getLocals().add(caughtExceptionLocal);
final Unit caughtExceptionHandler = Jimple.v().newIdentityStmt(caughtExceptionLocal, Jimple.v().newCaughtExceptionRef());
units.add(caughtExceptionHandler);
units.add(Jimple.v().newThrowStmt(caughtExceptionLocal));
final Iterator<Unit> reorderedUnitsIterator
= units.iterator(secondReorderedUnit, units.getPredOf(caughtExceptionHandler));
Unit trapEndUnit = reorderedUnitsIterator.next();
while (trapEndUnit instanceof IdentityStmt && reorderedUnitsIterator.hasNext()) {
trapEndUnit = reorderedUnitsIterator.next();
}
trapEndUnit = units.getSuccOf(trapEndUnit);
body.getTraps().add(Jimple.v().newTrap(throwable.getSootClass(), units.getPredOf(firstReorderingNotGotoStmt),
trapEndUnit, caughtExceptionHandler));
trapsAdded++;
}
private static boolean isExceptionCaught(Unit unit, Chain<Unit> units, Chain<Trap> traps) {
for (Trap trap : traps) {
final Unit end = trap.getEndUnit();
if (end.equals(unit)) {
return true;
}
final Iterator<Unit> unitsInTryIterator = units.iterator(trap.getBeginUnit(), units.getPredOf(end));
if (Iterators.contains(unitsInTryIterator, unit)) {
return true;
}
}
return false;
}
}
| 8,380
| 32.931174
| 125
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/LibraryMethodWrappersBuilder.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.Body;
import soot.BooleanType;
import soot.ByteType;
import soot.CharType;
import soot.DoubleType;
import soot.FastHierarchy;
import soot.FloatType;
import soot.IntType;
import soot.Local;
import soot.LongType;
import soot.Modifier;
import soot.PatchingChain;
import soot.Scene;
import soot.SceneTransformer;
import soot.SootClass;
import soot.SootMethod;
import soot.SootMethodRef;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
import soot.VoidType;
import soot.jbco.IJbcoTransform;
import soot.jbco.util.BodyBuilder;
import soot.jbco.util.Rand;
import soot.jimple.DoubleConstant;
import soot.jimple.FloatConstant;
import soot.jimple.IdentityStmt;
import soot.jimple.InstanceInvokeExpr;
import soot.jimple.IntConstant;
import soot.jimple.InterfaceInvokeExpr;
import soot.jimple.InvokeExpr;
import soot.jimple.Jimple;
import soot.jimple.JimpleBody;
import soot.jimple.LongConstant;
import soot.jimple.NullConstant;
import soot.jimple.SpecialInvokeExpr;
import soot.jimple.StaticInvokeExpr;
import soot.jimple.VirtualInvokeExpr;
import soot.util.Chain;
/**
* Creates methods that "wraps" library method calls.
*
* @author Michael Batchelder
* <p>
* Created on 7-Feb-2006
*/
public class LibraryMethodWrappersBuilder extends SceneTransformer implements IJbcoTransform {
private static final Logger logger = LoggerFactory.getLogger(LibraryMethodWrappersBuilder.class);
public static final String name = "wjtp.jbco_blbc";
public static final String dependencies[] = new String[] { "wjtp.jbco_blbc" };
private static final Map<SootClass, Map<SootMethod, SootMethodRef>> libClassesToMethods = new HashMap<>();
public static List<SootMethod> builtByMe = new ArrayList<>();
private int newmethods = 0;
private int methodcalls = 0;
@Override
public String[] getDependencies() {
return Arrays.copyOf(dependencies, dependencies.length);
}
@Override
public String getName() {
return name;
}
@Override
public void outputSummary() {
logger.info("Created {} new methods. Replaced {} method calls.", newmethods, methodcalls);
}
protected void internalTransform(String phaseName, Map<String, String> options) {
if (isVerbose()) {
logger.info("Building Library Wrapper Methods...");
}
BodyBuilder.retrieveAllBodies();
// iterate through application classes to find library calls
final Iterator<SootClass> applicationClassesIterator = Scene.v().getApplicationClasses().snapshotIterator();
while (applicationClassesIterator.hasNext()) {
final SootClass applicationClass = applicationClassesIterator.next();
if (isVerbose()) {
logger.info("\tProcessing class {}", applicationClass.getName());
}
// create local copy to prevent java.util.ConcurrentModificationException
final List<SootMethod> methods = new ArrayList<>(applicationClass.getMethods());
for (SootMethod method : methods) {
if (!method.isConcrete() || builtByMe.contains(method)) {
continue;
}
final Body body = getBodySafely(method);
if (body == null) {
continue;
}
int localName = 0;
final Unit first = getFirstNotIdentityStmt(body);
final Iterator<Unit> unitIterator = body.getUnits().snapshotIterator();
while (unitIterator.hasNext()) {
final Unit unit = unitIterator.next();
for (ValueBox valueBox : unit.getUseBoxes()) {
final Value value = valueBox.getValue();
// skip calls to 'super' as they cannot be called from static method and/or on object from the
// outside (this is prohibited on language level as that would violate encapsulation)
if (!(value instanceof InvokeExpr) || value instanceof SpecialInvokeExpr) {
continue;
}
final InvokeExpr invokeExpr = (InvokeExpr) value;
final SootMethod invokedMethod = getMethodSafely(invokeExpr);
if (invokedMethod == null) {
continue;
}
SootMethodRef invokedMethodRef = getNewMethodRef(invokedMethod);
if (invokedMethodRef == null) {
invokedMethodRef = buildNewMethod(applicationClass, invokedMethod, invokeExpr);
setNewMethodRef(invokedMethod, invokedMethodRef);
newmethods++;
}
if (isVerbose()) {
logger.info("\t\t\tChanging {} to {}\tUnit: ", invokedMethod.getSignature(), invokedMethodRef.getSignature(),
unit);
}
List<Value> args = invokeExpr.getArgs();
List<Type> parameterTypes = invokedMethodRef.parameterTypes();
int argsCount = args.size();
int paramCount = parameterTypes.size();
if (invokeExpr instanceof InstanceInvokeExpr || invokeExpr instanceof StaticInvokeExpr) {
if (invokeExpr instanceof InstanceInvokeExpr) {
argsCount++;
args.add(((InstanceInvokeExpr) invokeExpr).getBase());
}
while (argsCount < paramCount) {
Type pType = parameterTypes.get(argsCount);
Local newLocal = Jimple.v().newLocal("newLocal" + localName++, pType);
body.getLocals().add(newLocal);
body.getUnits().insertBeforeNoRedirect(Jimple.v().newAssignStmt(newLocal, getConstantType(pType)), first);
args.add(newLocal);
argsCount++;
}
valueBox.setValue(Jimple.v().newStaticInvokeExpr(invokedMethodRef, args));
}
methodcalls++;
}
}
}
}
Scene.v().releaseActiveHierarchy();
Scene.v().setFastHierarchy(new FastHierarchy());
}
private SootMethodRef getNewMethodRef(SootMethod method) {
Map<SootMethod, SootMethodRef> methods
= libClassesToMethods.computeIfAbsent(method.getDeclaringClass(), key -> new HashMap<>());
return methods.get(method);
}
private void setNewMethodRef(SootMethod sm, SootMethodRef smr) {
Map<SootMethod, SootMethodRef> methods
= libClassesToMethods.computeIfAbsent(sm.getDeclaringClass(), key -> new HashMap<>());
methods.put(sm, smr);
}
private SootMethodRef buildNewMethod(SootClass fromC, SootMethod sm, InvokeExpr origIE) {
final List<SootClass> availableClasses = getVisibleApplicationClasses(sm);
final int classCount = availableClasses.size();
if (classCount == 0) {
throw new RuntimeException("There appears to be no public non-interface Application classes!");
}
SootClass randomClass;
String methodNewName;
do {
int index = Rand.getInt(classCount);
if ((randomClass = availableClasses.get(index)) == fromC && classCount > 1) {
index = Rand.getInt(classCount);
randomClass = availableClasses.get(index);
}
final List<SootMethod> methods = randomClass.getMethods();
index = Rand.getInt(methods.size());
final SootMethod randMethod = methods.get(index);
methodNewName = randMethod.getName();
} while (methodNewName.equals(SootMethod.constructorName) || methodNewName.equals(SootMethod.staticInitializerName));
final List<Type> smParamTypes = new ArrayList<>(sm.getParameterTypes());
if (!sm.isStatic()) {
smParamTypes.add(sm.getDeclaringClass().getType());
}
// add random class params until we don't match any other method
int extraParams = 0;
if (randomClass.declaresMethod(methodNewName, smParamTypes)) {
int rtmp = Rand.getInt(classCount + 7);
if (rtmp >= classCount) {
rtmp -= classCount;
smParamTypes.add(getPrimType(rtmp));
} else {
smParamTypes.add(availableClasses.get(rtmp).getType());
}
extraParams++;
}
final int mods = ((((sm.getModifiers() | Modifier.STATIC | Modifier.PUBLIC) & (Modifier.ABSTRACT ^ 0xFFFF))
& (Modifier.NATIVE ^ 0xFFFF)) & (Modifier.SYNCHRONIZED ^ 0xFFFF));
SootMethod newMethod = Scene.v().makeSootMethod(methodNewName, smParamTypes, sm.getReturnType(), mods);
randomClass.addMethod(newMethod);
JimpleBody body = Jimple.v().newBody(newMethod);
newMethod.setActiveBody(body);
Chain<Local> locals = body.getLocals();
PatchingChain<Unit> units = body.getUnits();
List<Local> args = BodyBuilder.buildParameterLocals(units, locals, smParamTypes);
while (extraParams-- > 0) {
args.remove(args.size() - 1);
}
InvokeExpr ie = null;
if (sm.isStatic()) {
ie = Jimple.v().newStaticInvokeExpr(sm.makeRef(), args);
} else {
Local libObj = args.remove(args.size() - 1);
if (origIE instanceof InterfaceInvokeExpr) {
ie = Jimple.v().newInterfaceInvokeExpr(libObj, sm.makeRef(), args);
} else if (origIE instanceof VirtualInvokeExpr) {
ie = Jimple.v().newVirtualInvokeExpr(libObj, sm.makeRef(), args);
}
}
if (sm.getReturnType() instanceof VoidType) {
units.add(Jimple.v().newInvokeStmt(ie));
units.add(Jimple.v().newReturnVoidStmt());
} else {
Local assign = Jimple.v().newLocal("returnValue", sm.getReturnType());
locals.add(assign);
units.add(Jimple.v().newAssignStmt(assign, ie));
units.add(Jimple.v().newReturnStmt(assign));
}
if (isVerbose()) {
logger.info("{} was replaced by {} which calls {}", sm.getName(), newMethod.getName(), ie);
}
if (units.size() < 2) {
logger.warn("THERE AREN'T MANY UNITS IN THIS METHOD {}", units);
}
builtByMe.add(newMethod);
return newMethod.makeRef();
}
private static Type getPrimType(int idx) {
switch (idx) {
case 0:
return IntType.v();
case 1:
return CharType.v();
case 2:
return ByteType.v();
case 3:
return LongType.v();
case 4:
return BooleanType.v();
case 5:
return DoubleType.v();
case 6:
return FloatType.v();
default:
return IntType.v();
}
}
private static Value getConstantType(Type t) {
if (t instanceof BooleanType) {
return IntConstant.v(Rand.getInt(1));
}
if (t instanceof IntType) {
return IntConstant.v(Rand.getInt());
}
if (t instanceof CharType) {
return Jimple.v().newCastExpr(IntConstant.v(Rand.getInt()), CharType.v());
}
if (t instanceof ByteType) {
return Jimple.v().newCastExpr(IntConstant.v(Rand.getInt()), ByteType.v());
}
if (t instanceof LongType) {
return LongConstant.v(Rand.getLong());
}
if (t instanceof FloatType) {
return FloatConstant.v(Rand.getFloat());
}
if (t instanceof DoubleType) {
return DoubleConstant.v(Rand.getDouble());
}
return Jimple.v().newCastExpr(NullConstant.v(), t);
}
private static Body getBodySafely(SootMethod method) {
try {
return method.getActiveBody();
} catch (Exception exception) {
logger.warn("Getting Body from SootMethod {} caused exception that was suppressed.", exception);
return method.retrieveActiveBody();
}
}
private static Unit getFirstNotIdentityStmt(Body body) {
final Iterator<Unit> unitIterator = body.getUnits().snapshotIterator();
while (unitIterator.hasNext()) {
final Unit unit = unitIterator.next();
if (unit instanceof IdentityStmt) {
continue;
}
return unit;
}
logger.debug("There are no non-identity units in the method body.");
return null;
}
private static SootMethod getMethodSafely(InvokeExpr invokeExpr) {
try {
final SootMethod invokedMethod = invokeExpr.getMethod();
if (invokedMethod == null) {
return null;
}
if (SootMethod.constructorName.equals(invokedMethod.getName())
|| SootMethod.staticInitializerName.equals(invokedMethod.getName())) {
logger.debug("Skipping wrapping method {} as it is constructor/initializer.", invokedMethod);
return null;
}
final SootClass invokedMethodClass = invokedMethod.getDeclaringClass();
if (!invokedMethodClass.isLibraryClass()) {
logger.debug("Skipping wrapping method {} as it is not library one.", invokedMethod);
return null;
}
if (invokeExpr.getMethodRef().declaringClass().isInterface() && !invokedMethodClass.isInterface()) {
logger.debug(
"Skipping wrapping method {} as original code suppose to execute it on interface {}"
+ " but resolved code trying to execute it on class {}",
invokedMethod, invokeExpr.getMethodRef().declaringClass(), invokedMethodClass);
return null;
}
return invokedMethod;
} catch (RuntimeException exception) {
logger.debug("Cannot resolve method of InvokeExpr: " + invokeExpr.toString(), exception);
return null;
}
}
private static List<SootClass> getVisibleApplicationClasses(SootMethod visibleBy) {
final List<SootClass> result = new ArrayList<>();
final Iterator<SootClass> applicationClassesIterator = Scene.v().getApplicationClasses().snapshotIterator();
while (applicationClassesIterator.hasNext()) {
final SootClass applicationClass = applicationClassesIterator.next();
if (applicationClass.isConcrete() && !applicationClass.isInterface() && applicationClass.isPublic()
&& Scene.v().getActiveHierarchy().isVisible(applicationClass, visibleBy)) {
result.add(applicationClass);
}
}
return result;
}
}
| 14,647
| 33.224299
| 123
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/MethodRenamer.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.ArrayType;
import soot.Body;
import soot.FastHierarchy;
import soot.G;
import soot.RefType;
import soot.Scene;
import soot.SceneTransformer;
import soot.Singletons;
import soot.SootClass;
import soot.SootField;
import soot.SootMethod;
import soot.SootMethodRef;
import soot.Type;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
import soot.VoidType;
import soot.jbco.IJbcoTransform;
import soot.jbco.name.JunkNameGenerator;
import soot.jbco.name.NameGenerator;
import soot.jbco.util.BodyBuilder;
import soot.jbco.util.HierarchyUtils;
import soot.jbco.util.Rand;
import soot.jimple.InvokeExpr;
/**
* Creates new method names using names of fields or generates randomly. New names are <strong>unique</strong> through the
* whole application.
* <p>
* Some methods cannot be renamed:
* <ul>
* <li>{@code main} methods</li>
* <li>constructors</li>
* <li>static initializers</li>
* </ul>
* (these methods are filtered by names)
* <ul>
* <li>ones that override/implement library methods</li>
* </ul>
* <p>
* To find methods from last group the next approach is used. All superclasses and interfaces that processing class extends /
* implements are collected. The children of that items are taken and united together along with processing class. The same
* action is performed for every item of the obtained result until the full "tree" is not created. Then from this tree, the
* classes that do not have methods with <similar>similar</similar> to searching signature, are removed. The left items that
* have {@link SootClass#isLibraryClass()} {@code true} are searching ones.
* <p>
* This complex approach is used to detect <i>indirect</i> inheritance. Consider next example:
*
* <pre>
* ,--------.
* |A |
* |--------|
* |--------|
* |method()|
* `--------'
* / \
* / \
* ,-----------------------------. ,--------. ,--------. ,--------------------------------.
* |D | |B | |E | | Note: E is a library interface |
* |-----------------------------| |--------| |--------| `--------------------------------'
* |-----------------------------| |--------| |--------|
* |method() | |method()| |method()|
* |method(java.lang.String, int)| `--------' `--------'
* `-----------------------------' \ /
* ,------------------------.
* |C |
* |------------------------|
* |------------------------|
* |method() |
* |method(java.lang.String)|
* |method(long, int) |
* `------------------------'
* </pre>
*
* Thus when {@code D#method()} is processed, it must not be renamed as there is class {@code C} that implements library one
* ({@code E#method()}).
* <p>
* After applying this transformer the next result is expected:
* <ul>
* <li>{@code #method()} is not renamed in any application classes as it overrides one from library</li>
* <li>{@code #method(java.lang.String)}, {@code #method(long, int)} and {@code #method(java.lang.String, int)} are renamed
* and have the <strong>same</strong> name. Such renaming behaviour allows having <i>renaming map</i> for every class with
* old method name as a key and new method name as a value</li>
* </ul>
*
* @author Michael Batchelder, Pavel Nesterovich
* @since 24-Jan-2006
*/
public class MethodRenamer extends SceneTransformer implements IJbcoTransform {
private static final Logger logger = LoggerFactory.getLogger(MethodRenamer.class);
public static final String name = "wjtp.jbco_mr";
private static final String MAIN_METHOD_SUB_SIGNATURE
= SootMethod.getSubSignature("main", singletonList(ArrayType.v(RefType.v("java.lang.String"), 1)), VoidType.v());
private static final Function<SootClass, Map<String, String>> RENAMING_MAP_CREATOR = key -> new HashMap<>();
private final Map<SootClass, Map<String, String>> classToRenamingMap = new HashMap<>();
private final NameGenerator nameGenerator;
/**
* Singleton constructor.
*
* @param global
* the singletons container. Must not be {@code null}
* @throws NullPointerException
* when {@code global} argument is {@code null}
*/
public MethodRenamer(Singletons.Global global) {
if (global == null) {
throw new NullPointerException("Cannot instantiate MethodRenamer with null Singletons.Global");
}
nameGenerator = new JunkNameGenerator();
}
/**
* Singleton getter.
*
* @return returns instance of {@link MethodRenamer}
*/
public static MethodRenamer v() {
return G.v().soot_jbco_jimpleTransformations_MethodRenamer();
}
@Override
public String getName() {
return name;
}
@Override
public String[] getDependencies() {
return new String[] { name };
}
@Override
public void outputSummary() {
final Integer newNames = classToRenamingMap.values().stream().map(Map::values).flatMap(Collection::stream)
.collect(collectingAndThen(toSet(), Set::size));
logger.info("{} methods were renamed.", newNames);
}
/**
* Gets renaming map for specific class.
*
* @param className
* the name of class to get renaming map for
* @return the map where the key is old method name, the value - new method name. Never {@code null}
*/
public Map<String, String> getRenamingMap(String className) {
return classToRenamingMap.entrySet().stream().filter(entry -> entry.getKey().getName().equals(className))
.flatMap(entry -> entry.getValue().entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
@Override
protected void internalTransform(String phaseName, Map<String, String> options) {
if (isVerbose()) {
logger.info("Transforming method names...");
}
BodyBuilder.retrieveAllBodies();
BodyBuilder.retrieveAllNames();
Scene.v().releaseActiveHierarchy();
// iterate through application classes and create new junk names
// but DO NOT RENAME METHODS YET as it might break searching of declaring classes
for (SootClass applicationClass : Scene.v().getApplicationClasses()) {
final List<String> fieldNames = applicationClass.getFields().stream().map(SootField::getName)
.collect(collectingAndThen(toList(), Collections::unmodifiableList));
final List<String> leftFieldNames = new ArrayList<>(fieldNames);
// create local copy to avoid ConcurrentModificationException -- methods are being updated
final List<SootMethod> methods = new ArrayList<>(applicationClass.getMethods());
for (SootMethod method : methods) {
if (!isRenamingAllowed(method)) {
continue;
}
final Set<SootClass> declaringClasses = getDeclaringClasses(applicationClass, method);
if (declaringClasses.isEmpty()) {
throw new IllegalStateException("Cannot find classes that declare " + method.getSignature() + ".");
}
final Optional<SootClass> libraryClass = declaringClasses.stream().filter(SootClass::isLibraryClass).findAny();
if (libraryClass.isPresent()) {
if (isVerbose()) {
logger.info("Skipping renaming {} method as it overrides library one from {}.", method.getSignature(),
libraryClass.get().getName());
}
continue;
}
// we unite declaringClasses with parents of application class (excluding library ones)
// to be sure that every class in this hierarchy has the only new name
// for all methods (in this hierarchy) with the same old name and different parameters
final Set<SootClass> union = uniteWithApplicationParents(applicationClass, declaringClasses);
String newName = getNewName(union, method.getName());
if (newName == null) {
if (leftFieldNames.isEmpty()) {
newName = getNewName();
} else {
final int randomIndex = Rand.getInt(leftFieldNames.size());
final String randomFieldName = leftFieldNames.remove(randomIndex);
// check both value and existing methods, if class already contains method and field with
// same name then we likely will fall in trouble when renaming this method before previous
if (isNotUnique(randomFieldName) || fieldNames.contains(randomFieldName)) {
newName = getNewName();
} else {
newName = randomFieldName;
}
}
}
// It is important to share renaming between different class trees as they might be intersecting.
// For example, pretend we have class tree (A,B) with renaming ["aa"=>"bb", "cc"=>"dd"].
// When we receive tree (B,C) with method "aa" and realize that (B,C) ∩ (A,B),
// we not just skip generating new name but share mapping ["aa"=>"bb"] of tree (A,B)
// with tree (B,C). As a result we will have (B,C) with mapping ["aa"=>"bb"].
// We share this to handle case when the methods are renamed and it is impossible to get
// this indirect connection between classes (with A and C in example above), we will still be able
// to rename methods (and their calls) correctly
for (SootClass declaringClass : union) {
classToRenamingMap.computeIfAbsent(declaringClass, RENAMING_MAP_CREATOR).put(method.getName(), newName);
}
}
}
// rename methods AFTER creating mapping
for (SootClass applicationClass : Scene.v().getApplicationClasses()) {
final List<SootMethod> methods = new ArrayList<>(applicationClass.getMethods());
for (SootMethod method : methods) {
final String newName = getNewName(Collections.singleton(applicationClass), method.getName());
if (newName != null) {
if (isVerbose()) {
logger.info("Method \"{}\" is being renamed to \"{}\".", method.getSignature(), newName);
}
method.setName(newName);
}
}
}
// iterate through application classes, update references of renamed methods
for (SootClass applicationClass : Scene.v().getApplicationClasses()) {
final List<SootMethod> methods = new ArrayList<>(applicationClass.getMethods());
for (SootMethod method : methods) {
if (!method.isConcrete() || method.getDeclaringClass().isLibraryClass()) {
continue;
}
final Body body = getActiveBodySafely(method);
if (body == null) {
continue;
}
for (Unit unit : body.getUnits()) {
for (ValueBox valueBox : unit.getUseBoxes()) {
Value v = valueBox.getValue();
if (!(v instanceof InvokeExpr)) {
continue;
}
final InvokeExpr invokeExpr = (InvokeExpr) v;
final SootMethodRef methodRef = invokeExpr.getMethodRef();
final Set<SootClass> parents = getParents(methodRef.getDeclaringClass());
// 1. we check if method overrides one from library directly
// Note: we cannot use getDeclaringClasses(applicationClass, method) as method can be renamed
final Optional<SootClass> declaringLibraryClass = findDeclaringLibraryClass(parents, methodRef);
if (declaringLibraryClass.isPresent()) {
if (isVerbose()) {
logger.info("Skipping replacing method call \"{}\" in \"{}\" as it is overrides one " + " from library {}.",
methodRef.getSignature(), method.getSignature(), declaringLibraryClass.get().getName());
}
continue;
}
final String newName = getNewName(parents, methodRef.getName());
// 2. we indirectly check that method is not overrides one from library indirectly:
// we will get new name only if no one from class tree do not overrides library method
if (newName == null) {
continue;
}
final SootMethodRef newMethodRef = Scene.v().makeMethodRef(methodRef.getDeclaringClass(), newName,
methodRef.getParameterTypes(), methodRef.getReturnType(), methodRef.isStatic());
invokeExpr.setMethodRef(newMethodRef);
if (isVerbose()) {
logger.info("Method call \"{}\" is being replaced with \"{}\" in {}.", methodRef.getSignature(),
newMethodRef.getSignature(), method.getSignature());
}
}
}
}
}
Scene.v().releaseActiveHierarchy();
Scene.v().setFastHierarchy(new FastHierarchy());
if (isVerbose()) {
logger.info("Transforming method names is completed.");
}
}
/**
* Creates new <strong>unique</strong> method name.
*
* @return newly generated junk name that DOES NOT exist yet
*/
public String getNewName() {
int size = 5;
int tries = 0;
String newName = nameGenerator.generateName(size);
while (isNotUnique(newName) || BodyBuilder.nameList.contains(newName)) {
if (tries++ > size) {
size++;
tries = 0;
}
newName = nameGenerator.generateName(size);
}
BodyBuilder.nameList.add(newName);
return newName;
}
private boolean isRenamingAllowed(SootMethod method) {
if (soot.jbco.Main.getWeight(MethodRenamer.name, method.getSignature()) == 0) {
return false;
}
final String subSignature = method.getSubSignature();
if (MAIN_METHOD_SUB_SIGNATURE.equals(subSignature) && method.isPublic() && method.isStatic()) {
if (isVerbose()) {
logger.info("Skipping renaming \"{}\" method as it is main one.", subSignature);
}
return false; // skip the main method
}
if (method.getName().equals(SootMethod.constructorName) || method.getName().equals(SootMethod.staticInitializerName)) {
if (isVerbose()) {
logger.info("Skipping renaming \"{}\" method as it is constructor or static initializer.", subSignature);
}
return false; // skip constructors/initializers
}
return true;
}
private boolean isNotUnique(String methodName) {
return classToRenamingMap.values().stream().map(Map::values).flatMap(Collection::stream).anyMatch(methodName::equals);
}
private Set<SootClass> uniteWithApplicationParents(SootClass applicationClass, Collection<SootClass> classes) {
final Set<SootClass> parents = getApplicationParents(applicationClass);
final Set<SootClass> result = new HashSet<>(parents.size() + classes.size());
result.addAll(parents);
result.addAll(classes);
return result;
}
private Optional<SootClass> findDeclaringLibraryClass(Collection<SootClass> classes, SootMethodRef methodRef) {
return classes.stream().filter(SootClass::isLibraryClass)
.filter(sootClass -> isDeclared(sootClass, methodRef.getName(), methodRef.getParameterTypes())).findAny();
}
private Set<SootClass> getDeclaringClasses(SootClass applicationClass, SootMethod method) {
return getTree(applicationClass).stream()
.filter(sootClass -> isDeclared(sootClass, method.getName(), method.getParameterTypes())).collect(toSet());
}
private Set<SootClass> getTree(SootClass applicationClass) {
final Set<SootClass> children = getChildrenOfIncluding(getParentsOfIncluding(applicationClass));
int count = 0;
do {
count = children.size();
children.addAll(getChildrenOfIncluding(getParentsOfIncluding(children)));
} while (count < children.size());
return children;
}
private Set<SootClass> getParents(SootClass applicationClass) {
final Set<SootClass> parents = new HashSet<>(getParentsOfIncluding(applicationClass));
int count = 0;
do {
count = parents.size();
parents.addAll(getParentsOfIncluding(parents));
} while (count < parents.size());
return parents;
}
private Set<SootClass> getApplicationParents(SootClass applicationClass) {
return getParents(applicationClass).stream().filter(parent -> !parent.isLibraryClass()).collect(toSet());
}
private List<SootClass> getParentsOfIncluding(SootClass applicationClass) {
// result contains of interfaces that implements passed applicationClass
final List<SootClass> result = HierarchyUtils.getAllInterfacesOf(applicationClass);
// add implementing interfaces
result.addAll(applicationClass.getInterfaces());
// add extending class if any
if (!applicationClass.isInterface() && applicationClass.hasSuperclass()) {
result.add(applicationClass.getSuperclass());
}
// and superclasses (superinterfaces) of passed applicationClass
result.addAll(
applicationClass.isInterface() ? Scene.v().getActiveHierarchy().getSuperinterfacesOfIncluding(applicationClass)
: Scene.v().getActiveHierarchy().getSuperclassesOfIncluding(applicationClass));
return result;
}
private Set<SootClass> getChildrenOfIncluding(Collection<SootClass> classes) {
return Stream
.concat(classes.stream().filter(c -> !c.getName().equals("java.lang.Object"))
.map(c -> c.isInterface() ? Scene.v().getActiveHierarchy().getImplementersOf(c)
: Scene.v().getActiveHierarchy().getSubclassesOf(c))
.flatMap(Collection::stream), classes.stream())
.collect(toSet());
}
private Set<SootClass> getParentsOfIncluding(Collection<SootClass> classes) {
final Set<SootClass> parents = new HashSet<>(classes);
for (SootClass clazz : classes) {
// add implementing interfaces
parents.addAll(clazz.getInterfaces());
// add extending class if any
if (!clazz.isInterface() && clazz.hasSuperclass()) {
parents.add(clazz.getSuperclass());
}
// and superclasses (superinterfaces) of passed applicationClass
parents.addAll(clazz.isInterface() ? Scene.v().getActiveHierarchy().getSuperinterfacesOfIncluding(clazz)
: Scene.v().getActiveHierarchy().getSuperclassesOfIncluding(clazz));
}
return parents;
}
private String getNewName(Collection<SootClass> classes, String name) {
final Set<String> names = classToRenamingMap.entrySet().stream().filter(entry -> classes.contains(entry.getKey()))
.map(Map.Entry::getValue).map(Map::entrySet).flatMap(Collection::stream).filter(entry -> entry.getKey().equals(name))
.map(Map.Entry::getValue).collect(toSet());
if (names.size() > 1) {
logger.warn("Found {} names for method \"{}\": {}.", names.size(), name, String.join(", ", names));
}
return names.isEmpty() ? null : names.iterator().next();
}
/**
* Checks that method is declared in class. We assume that method is declared in class if class contains method with the
* same name and the same number of arguments. The exact types are not compared.
*
* @param sootClass
* the class to search in
* @param methodName
* the searching method name
* @param parameterTypes
* the searching method parameters
* @return {@code true} if passed class contains similar method; {@code false} otherwise
*/
private boolean isDeclared(SootClass sootClass, String methodName, List<Type> parameterTypes) {
for (SootMethod declared : sootClass.getMethods()) {
if (declared.getName().equals(methodName) && declared.getParameterCount() == parameterTypes.size()) {
return true;
}
}
return false;
}
private static Body getActiveBodySafely(SootMethod method) {
try {
return method.getActiveBody();
} catch (Exception exception) {
logger.warn("Getting Body from SootMethod {} caused exception that was suppressed.", exception);
}
return null;
}
}
| 21,679
| 37.992806
| 125
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/New2InitFlowAnalysis.java
|
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Local;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
import soot.jimple.DefinitionStmt;
import soot.jimple.NewExpr;
import soot.toolkits.graph.DirectedGraph;
import soot.toolkits.scalar.ArraySparseSet;
import soot.toolkits.scalar.BackwardFlowAnalysis;
import soot.toolkits.scalar.FlowSet;
/**
* @author Michael Batchelder
*
* Created on 10-Jul-2006
*/
public class New2InitFlowAnalysis extends BackwardFlowAnalysis<Unit, FlowSet> {
FlowSet emptySet = new ArraySparseSet();
public New2InitFlowAnalysis(DirectedGraph<Unit> graph) {
super(graph);
doAnalysis();
}
@Override
protected void flowThrough(FlowSet in, Unit d, FlowSet out) {
in.copy(out);
if (d instanceof DefinitionStmt) {
DefinitionStmt ds = (DefinitionStmt) d;
if (ds.getRightOp() instanceof NewExpr) {
Value v = ds.getLeftOp();
if (v instanceof Local && in.contains(v)) {
out.remove(v);
}
}
} else {
for (ValueBox useBox : d.getUseBoxes()) {
Value v = useBox.getValue();
if (v instanceof Local) {
out.add(v);
}
}
}
/*
* else if (d instanceof InvokeStmt) { InvokeExpr ie = ((InvokeStmt)d).getInvokeExpr(); if (ie instanceof
* SpecialInvokeExpr) { Value v = ((SpecialInvokeExpr)ie).getBase(); if (v instanceof Local && !inf.contains(v))
* outf.add(v); } }
*/
}
@Override
protected FlowSet newInitialFlow() {
return emptySet.clone();
}
@Override
protected FlowSet entryInitialFlow() {
return emptySet.clone();
}
@Override
protected void merge(FlowSet in1, FlowSet in2, FlowSet out) {
in1.union(in2, out);
}
@Override
protected void copy(FlowSet source, FlowSet dest) {
source.copy(dest);
}
}
| 2,644
| 25.989796
| 116
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/jimpleTransformations/package-info.java
|
@Deprecated
package soot.jbco.jimpleTransformations;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2018 Raja Vallée-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
| 871
| 33.88
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/name/AbstractNameGenerator.java
|
package soot.jbco.name;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2018 Raja Vallée-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.jbco.util.Rand;
/**
* Abstract class that implements {@link NameGenerator#generateName(int)}.
*
* @author p.nesterovich
* @since 21.03.18
*/
public abstract class AbstractNameGenerator implements NameGenerator {
@Override
public String generateName(final int size) {
if (size > NAME_MAX_LENGTH) {
throw new IllegalArgumentException("Cannot generate junk name: too long for JVM.");
}
final char[][] chars = getChars();
final int index = Rand.getInt(chars.length);
final int length = chars[index].length;
char newName[] = new char[size];
do {
newName[0] = chars[index][Rand.getInt(length)];
} while (!Character.isJavaIdentifierStart(newName[0]));
// generate random string
for (int i = 1; i < newName.length; i++) {
int rand = Rand.getInt(length);
newName[i] = chars[index][rand];
}
return String.valueOf(newName);
}
protected abstract char[][] getChars();
}
| 1,805
| 28.129032
| 89
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/name/HorrorNameGenerator.java
|
package soot.jbco.name;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2018 Raja Vallée-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
/**
* Implementation that generates names consisting of hard recognizable symbols.
*
* @author p.nesterovich
* @since 21.03.18
*/
public class HorrorNameGenerator extends AbstractNameGenerator implements NameGenerator {
private static final char stringChars[][] = { { 'S', '5', '$' }, // latin s, five, dollar sign
{ 'l', '1', 'I', 'Ι' }, // l, one, I, greek iota
{ '0', 'O', 'О', 'Ο', 'Օ' }, // zero, english O, russian O, greek omicron, armenian Օ
{ 'o', 'о', 'ο' }, // english o, russian o and greek omicron
{ 'T', 'Т', 'Τ' }, // english T, russian T, greek tau
{ 'H', 'Н', 'Η' }, // english, russian, greek
{ 'E', 'Е', 'Ε' }, // english, russian, greek
{ 'P', 'Р', 'Ρ' }, // english, russian, greek
{ 'B', 'В', 'Β' }, // english, russian, greek
{ '_' } };
@Override
protected char[][] getChars() {
return stringChars;
}
}
| 1,743
| 33.88
| 96
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/name/JunkNameGenerator.java
|
package soot.jbco.name;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2018 Raja Vallée-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
/**
* Implementation that generates names consisting of hard recognizable symbols.
*
* @author p.nesterovich
* @since 21.03.18
*/
public class JunkNameGenerator extends AbstractNameGenerator implements NameGenerator {
private static final char stringChars[][] = { { 'S', '5', '$' }, { 'l', '1', 'I' }, { '_' } };
@Override
protected char[][] getChars() {
return stringChars;
}
}
| 1,242
| 29.317073
| 96
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/name/NameGenerator.java
|
package soot.jbco.name;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2018 Raja Vallée-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
/**
* Generates names that are compatible with Java identifiers.
*
* @author p.nesterovich
* @since 21.03.18
*/
public interface NameGenerator {
/**
* According to JVM specification, the name is limited to 65535 characters by the 16-bit unsigned length item of the
* CONSTANT_Utf8_info structure. As the limit is on the number of bytes and UTF-8 encodes some characters using two or
* three bytes, we assume that in worst case number or characters is 65535 / 3
*/
int NAME_MAX_LENGTH = 65_535 / 3;
/**
* Generates random name of required length that can be used as Java identifier.
*
* @param size
* the expected size
* @return the name of expected length
* @throws IllegalArgumentException
* when passed size is more than {@link NameGenerator#NAME_MAX_LENGTH}
*/
String generateName(int size);
}
| 1,711
| 31.923077
| 120
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/util/BodyBuilder.java
|
package soot.jbco.util;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import soot.Local;
import soot.PatchingChain;
import soot.RefType;
import soot.SootClass;
import soot.SootField;
import soot.SootMethod;
import soot.Trap;
import soot.Type;
import soot.Unit;
import soot.baf.IfCmpEqInst;
import soot.baf.IfCmpGeInst;
import soot.baf.IfCmpGtInst;
import soot.baf.IfCmpLeInst;
import soot.baf.IfCmpLtInst;
import soot.baf.IfCmpNeInst;
import soot.baf.IfEqInst;
import soot.baf.IfGeInst;
import soot.baf.IfGtInst;
import soot.baf.IfLeInst;
import soot.baf.IfLtInst;
import soot.baf.IfNeInst;
import soot.baf.IfNonNullInst;
import soot.baf.IfNullInst;
import soot.jimple.Jimple;
import soot.jimple.ThisRef;
import soot.util.Chain;
/**
* @author Michael Batchelder
*
* Created on 7-Feb-2006
*/
public class BodyBuilder {
public static boolean bodiesHaveBeenBuilt = false;
public static boolean namesHaveBeenRetrieved = false;
public static List<String> nameList = new ArrayList<String>();
public static void retrieveAllBodies() {
if (bodiesHaveBeenBuilt) {
return;
}
// iterate through application classes, rename fields with junk
for (SootClass c : soot.Scene.v().getApplicationClasses()) {
for (SootMethod m : c.getMethods()) {
if (!m.isConcrete()) {
continue;
}
if (!m.hasActiveBody()) {
m.retrieveActiveBody();
}
}
}
bodiesHaveBeenBuilt = true;
}
public static void retrieveAllNames() {
if (namesHaveBeenRetrieved) {
return;
}
// iterate through application classes, rename fields with junk
for (SootClass c : soot.Scene.v().getApplicationClasses()) {
nameList.add(c.getName());
for (SootMethod m : c.getMethods()) {
nameList.add(m.getName());
}
for (SootField m : c.getFields()) {
nameList.add(m.getName());
}
}
namesHaveBeenRetrieved = true;
}
public static Local buildThisLocal(PatchingChain<Unit> units, ThisRef tr, Collection<Local> locals) {
Local ths = Jimple.v().newLocal("ths", tr.getType());
locals.add(ths);
units.add(Jimple.v().newIdentityStmt(ths, Jimple.v().newThisRef((RefType) tr.getType())));
return ths;
}
public static List<Local> buildParameterLocals(PatchingChain<Unit> units, Collection<Local> locals,
List<Type> paramTypes) {
List<Local> args = new ArrayList<Local>();
for (int k = 0; k < paramTypes.size(); k++) {
Type type = paramTypes.get(k);
Local loc = Jimple.v().newLocal("l" + k, type);
locals.add(loc);
units.add(Jimple.v().newIdentityStmt(loc, Jimple.v().newParameterRef(type, k)));
args.add(loc);
}
return args;
}
public static void updateTraps(Unit oldu, Unit newu, Chain<Trap> traps) {
int size = traps.size();
if (size == 0) {
return;
}
Trap t = traps.getFirst();
do {
if (t.getBeginUnit() == oldu) {
t.setBeginUnit(newu);
}
if (t.getEndUnit() == oldu) {
t.setEndUnit(newu);
}
if (t.getHandlerUnit() == oldu) {
t.setHandlerUnit(newu);
}
} while ((--size > 0) && (t = traps.getSuccOf(t)) != null);
}
public static boolean isExceptionCaughtAt(Chain<Unit> units, Unit u, Iterator<Trap> trapsIt) {
while (trapsIt.hasNext()) {
Trap t = trapsIt.next();
Iterator<Unit> it = units.iterator(t.getBeginUnit(), units.getPredOf(t.getEndUnit()));
while (it.hasNext()) {
if (u.equals(it.next())) {
return true;
}
}
}
return false;
}
public static int getIntegerNine() {
int r1 = Rand.getInt(8388606) * 256;
int r2 = Rand.getInt(28) * 9;
if (r2 > 126) {
r2 += 4;
}
return r1 + r2;
}
public static boolean isBafIf(Unit u) {
if (u instanceof IfCmpEqInst || u instanceof IfCmpGeInst || u instanceof IfCmpGtInst || u instanceof IfCmpLeInst
|| u instanceof IfCmpLtInst || u instanceof IfCmpNeInst || u instanceof IfEqInst || u instanceof IfGeInst
|| u instanceof IfGtInst || u instanceof IfLeInst || u instanceof IfLtInst || u instanceof IfNeInst
|| u instanceof IfNonNullInst || u instanceof IfNullInst) {
return true;
}
return false;
}
}
| 5,160
| 26.306878
| 116
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/util/Debugger.java
|
package soot.jbco.util;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import soot.Body;
import soot.PatchingChain;
import soot.Trap;
import soot.Unit;
import soot.baf.JSRInst;
import soot.baf.TableSwitchInst;
import soot.baf.TargetArgInst;
public class Debugger {
public static void printBaf(Body b) {
System.out.println(b.getMethod().getName() + "\n");
int i = 0;
Map<Unit, Integer> index = new HashMap<Unit, Integer>();
Iterator<Unit> it = b.getUnits().iterator();
while (it.hasNext()) {
index.put(it.next(), new Integer(i++));
}
it = b.getUnits().iterator();
while (it.hasNext()) {
Object o = it.next();
System.out.println(index.get(o).toString() + " " + o + " "
+ (o instanceof TargetArgInst ? index.get(((TargetArgInst) o).getTarget()).toString() : ""));
}
System.out.println("\n");
}
public static void printUnits(Body b, String msg) {
int i = 0;
Map<Unit, Integer> numbers = new HashMap<Unit, Integer>();
PatchingChain<Unit> u = b.getUnits();
Iterator<Unit> it = u.snapshotIterator();
while (it.hasNext()) {
numbers.put(it.next(), new Integer(i++));
}
int jsr = 0;
System.out.println("\r\r" + b.getMethod().getName() + " " + msg);
Iterator<Unit> udit = u.snapshotIterator();
while (udit.hasNext()) {
Unit unit = (Unit) udit.next();
Integer numb = numbers.get(unit);
if (numb.intValue() == 149) {
System.out.println("hi");
}
if (unit instanceof TargetArgInst) {
if (unit instanceof JSRInst) {
jsr++;
}
TargetArgInst ti = (TargetArgInst) unit;
if (ti.getTarget() == null) {
System.out.println(unit + " null null null null null null null null null");
continue;
}
System.out.println(numbers.get(unit).toString() + " " + unit + " #" + numbers.get(ti.getTarget()).toString());
continue;
} else if (unit instanceof TableSwitchInst) {
TableSwitchInst tswi = (TableSwitchInst) unit;
System.out.println(numbers.get(unit).toString() + " SWITCH:");
System.out.println("\tdefault: " + tswi.getDefaultTarget() + " " + numbers.get(tswi.getDefaultTarget()).toString());
int index = 0;
for (int x = tswi.getLowIndex(); x <= tswi.getHighIndex(); x++) {
System.out
.println("\t " + x + ": " + tswi.getTarget(index) + " " + numbers.get(tswi.getTarget(index++)).toString());
}
continue;
}
System.out.println(numb.toString() + " " + unit);
}
Iterator<Trap> tit = b.getTraps().iterator();
while (tit.hasNext()) {
Trap t = tit.next();
System.out.println(numbers.get(t.getBeginUnit()) + " " + t.getBeginUnit() + " to " + numbers.get(t.getEndUnit()) + " "
+ t.getEndUnit() + " at " + numbers.get(t.getHandlerUnit()) + " " + t.getHandlerUnit());
}
if (jsr > 0) {
System.out.println("\r\tJSR Instructions: " + jsr);
}
}
public static void printUnits(PatchingChain<Unit> u, String msg) {
int i = 0;
HashMap<Unit, Integer> numbers = new HashMap<Unit, Integer>();
Iterator<Unit> it = u.snapshotIterator();
while (it.hasNext()) {
numbers.put(it.next(), new Integer(i++));
}
System.out.println("\r\r*********** " + msg);
Iterator<Unit> udit = u.snapshotIterator();
while (udit.hasNext()) {
Unit unit = (Unit) udit.next();
Integer numb = numbers.get(unit);
if (numb.intValue() == 149) {
System.out.println("hi");
}
if (unit instanceof TargetArgInst) {
TargetArgInst ti = (TargetArgInst) unit;
if (ti.getTarget() == null) {
System.out.println(unit + " null null null null null null null null null");
continue;
}
System.out.println(numbers.get(unit).toString() + " " + unit + " #" + numbers.get(ti.getTarget()).toString());
continue;
} else if (unit instanceof TableSwitchInst) {
TableSwitchInst tswi = (TableSwitchInst) unit;
System.out.println(numbers.get(unit).toString() + " SWITCH:");
System.out.println("\tdefault: " + tswi.getDefaultTarget() + " " + numbers.get(tswi.getDefaultTarget()).toString());
int index = 0;
for (int x = tswi.getLowIndex(); x <= tswi.getHighIndex(); x++) {
System.out
.println("\t " + x + ": " + tswi.getTarget(index) + " " + numbers.get(tswi.getTarget(index++)).toString());
}
continue;
}
System.out.println(numb.toString() + " " + unit);
}
}
}
| 5,447
| 34.376623
| 125
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/util/HierarchyUtils.java
|
package soot.jbco.util;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2018 Raja Vallée-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import static java.util.stream.Collectors.toList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import soot.Hierarchy;
import soot.Scene;
import soot.SootClass;
/**
* Utility class for convenient hierarchy checks.
*
* @since 07.02.18
*/
public final class HierarchyUtils {
private HierarchyUtils() {
throw new IllegalAccessError();
}
/**
* Get whole tree of interfaces on {@code Scene} for class/interface.
*
* @param sc
* class or interface to get all its interfaces
* @return all interfaces on {@code Scene} for class or interface
*/
public static List<SootClass> getAllInterfacesOf(SootClass sc) {
Hierarchy hierarchy = Scene.v().getActiveHierarchy();
Stream<SootClass> superClassInterfaces = sc.isInterface() ? Stream.empty()
: hierarchy.getSuperclassesOf(sc).stream().map(HierarchyUtils::getAllInterfacesOf).flatMap(Collection::stream);
Stream<SootClass> directInterfaces = Stream.concat(sc.getInterfaces().stream(),
sc.getInterfaces().stream().map(HierarchyUtils::getAllInterfacesOf).flatMap(Collection::stream));
return Stream.concat(superClassInterfaces, directInterfaces).collect(toList());
}
}
| 2,068
| 31.84127
| 119
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/util/Rand.java
|
package soot.jbco.util;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
/**
* @author Michael Batchelder
*
* Created on 17-Feb-2006
*/
public class Rand {
private static final java.util.Random r = new java.util.Random(1);// System.currentTimeMillis());
public static int getInt(int n) {
return r.nextInt(n);
}
public static int getInt() {
return r.nextInt();
}
public static float getFloat() {
return r.nextFloat();
}
public static long getLong() {
return r.nextLong();
}
public static double getDouble() {
return r.nextDouble();
}
}
| 1,355
| 24.111111
| 99
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/util/SimpleExceptionalGraph.java
|
package soot.jbco.util;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import soot.Body;
import soot.Trap;
import soot.Unit;
import soot.toolkits.graph.TrapUnitGraph;
/**
* @author Michael Batchelder
*
* Created on 15-Jun-2006
*/
public class SimpleExceptionalGraph extends TrapUnitGraph {
/**
* @param body
*/
public SimpleExceptionalGraph(Body body) {
super(body);
int size = unitChain.size();
unitToSuccs = new HashMap<Unit, List<Unit>>(size * 2 + 1, 0.7f);
unitToPreds = new HashMap<Unit, List<Unit>>(size * 2 + 1, 0.7f);
buildUnexceptionalEdges(unitToSuccs, unitToPreds);
buildSimpleExceptionalEdges(unitToSuccs, unitToPreds);
buildHeadsAndTails();
}
protected void buildSimpleExceptionalEdges(Map<Unit, List<Unit>> unitToSuccs, Map<Unit, List<Unit>> unitToPreds) {
for (Trap trap : body.getTraps()) {
Unit handler = trap.getHandlerUnit();
for (Unit pred : unitToPreds.get(trap.getBeginUnit())) {
addEdge(unitToSuccs, unitToPreds, pred, handler);
}
}
}
}
| 1,888
| 28.515625
| 116
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/util/StringTrie.java
|
package soot.jbco.util;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
/**
* @author Michael Batchelder
*
* Created on 30-Mar-2006
*/
public class StringTrie {
private char[] startChars = new char[0];
private StringTrie[] tries = new StringTrie[0];
public StringTrie() {
super();
}
public void add(char[] chars, int index) {
if (chars.length == index) {
return;
}
if (startChars.length == 0) {
startChars = new char[1];
startChars[0] = chars[0];
tries = new StringTrie[1];
tries[0].add(chars, index++);
} else {
int i = findStart(chars[index], 0, startChars.length - 1);
if (i >= 0) {
tries[i].add(chars, index++);
} else {
i = addChar(chars[index]);
tries[i].add(chars, index++);
}
}
}
private int addChar(char c) {
int oldLength = startChars.length;
int i = findSpot(c, 0, oldLength - 1);
char tmp[] = startChars.clone();
StringTrie t[] = tries.clone();
startChars = new char[oldLength + 1];
tries = new StringTrie[oldLength + 1];
if (i > 0) {
System.arraycopy(tmp, 0, startChars, 0, i);
System.arraycopy(t, 0, tries, 0, i);
}
if (i < oldLength) {
System.arraycopy(tmp, i, startChars, i + 1, oldLength - i);
System.arraycopy(t, i, tries, i + 1, oldLength - i);
}
startChars[i] = c;
tries[i] = new StringTrie();
return i;
}
private int findSpot(char c, int first, int last) {
int diff = last - first;
if (diff == 1) {
return c < startChars[first] ? first : c < startChars[last] ? last : last + 1;
}
diff /= 2;
if (startChars[first + diff] < c) {
return findSpot(c, first + diff, last);
} else {
return findSpot(c, first, last - diff);
}
}
public boolean contains(char[] chars, int index) {
if (chars.length == index) {
return true;
} else if (startChars.length == 0) {
return false;
}
int i = findStart(chars[index], 0, startChars.length - 1);
if (i >= 0) {
return tries[i].contains(chars, index++);
}
return false;
}
private int findStart(char c, int first, int last) {
int diff = last - first;
if (diff <= 1) {
return c == startChars[first] ? first : c == startChars[last] ? last : -1;
}
diff /= 2;
if (startChars[first + diff] <= c) {
return findStart(c, first + diff, last);
} else {
return findStart(c, first, last - diff);
}
}
}
| 3,270
| 24.755906
| 84
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/util/ThrowSet.java
|
package soot.jbco.util;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Scene;
import soot.SootClass;
/**
* @author Michael Batchelder
*
* Created on 20-Jun-2006
*/
public class ThrowSet {
private static SootClass throwable[] = null;
public static SootClass getRandomThrowable() {
if (throwable == null) {
initThrowables();
}
return throwable[Rand.getInt(throwable.length)];
}
private static void initThrowables() {
Scene sc = Scene.v();
throwable = new SootClass[10];
throwable[0] = sc.getRefType("java.lang.RuntimeException").getSootClass();
throwable[1] = sc.getRefType("java.lang.ArithmeticException").getSootClass();
throwable[2] = sc.getRefType("java.lang.ArrayStoreException").getSootClass();
throwable[3] = sc.getRefType("java.lang.ClassCastException").getSootClass();
throwable[4] = sc.getRefType("java.lang.IllegalMonitorStateException").getSootClass();
throwable[5] = sc.getRefType("java.lang.IndexOutOfBoundsException").getSootClass();
throwable[6] = sc.getRefType("java.lang.ArrayIndexOutOfBoundsException").getSootClass();
throwable[7] = sc.getRefType("java.lang.NegativeArraySizeException").getSootClass();
throwable[8] = sc.getRefType("java.lang.NullPointerException").getSootClass();
throwable[9] = sc.getRefType("java.lang.Throwable").getSootClass();
}
}
| 2,140
| 34.098361
| 92
|
java
|
soot
|
soot-master/src/main/java/soot/jbco/util/package-info.java
|
@Deprecated
package soot.jbco.util;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2018 Raja Vallée-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
| 854
| 33.2
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AbstractConstantSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public abstract class AbstractConstantSwitch<T> implements ConstantSwitch {
T result;
@Override
public void caseDoubleConstant(DoubleConstant v) {
defaultCase(v);
}
@Override
public void caseFloatConstant(FloatConstant v) {
defaultCase(v);
}
@Override
public void caseIntConstant(IntConstant v) {
defaultCase(v);
}
@Override
public void caseLongConstant(LongConstant v) {
defaultCase(v);
}
@Override
public void caseNullConstant(NullConstant v) {
defaultCase(v);
}
@Override
public void caseStringConstant(StringConstant v) {
defaultCase(v);
}
@Override
public void caseClassConstant(ClassConstant v) {
defaultCase(v);
}
@Override
public void caseMethodHandle(MethodHandle v) {
defaultCase(v);
}
@Override
public void caseMethodType(MethodType v) {
defaultCase(v);
}
@Override
public void defaultCase(Object v) {
}
public void setResult(T result) {
this.result = result;
}
public T getResult() {
return result;
}
}
| 1,871
| 20.767442
| 75
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AbstractExprSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public abstract class AbstractExprSwitch<T> implements ExprSwitch {
T result;
@Override
public void caseAddExpr(AddExpr v) {
defaultCase(v);
}
@Override
public void caseAndExpr(AndExpr v) {
defaultCase(v);
}
@Override
public void caseCmpExpr(CmpExpr v) {
defaultCase(v);
}
@Override
public void caseCmpgExpr(CmpgExpr v) {
defaultCase(v);
}
@Override
public void caseCmplExpr(CmplExpr v) {
defaultCase(v);
}
@Override
public void caseDivExpr(DivExpr v) {
defaultCase(v);
}
@Override
public void caseEqExpr(EqExpr v) {
defaultCase(v);
}
@Override
public void caseNeExpr(NeExpr v) {
defaultCase(v);
}
@Override
public void caseGeExpr(GeExpr v) {
defaultCase(v);
}
@Override
public void caseGtExpr(GtExpr v) {
defaultCase(v);
}
@Override
public void caseLeExpr(LeExpr v) {
defaultCase(v);
}
@Override
public void caseLtExpr(LtExpr v) {
defaultCase(v);
}
@Override
public void caseMulExpr(MulExpr v) {
defaultCase(v);
}
@Override
public void caseOrExpr(OrExpr v) {
defaultCase(v);
}
@Override
public void caseRemExpr(RemExpr v) {
defaultCase(v);
}
@Override
public void caseShlExpr(ShlExpr v) {
defaultCase(v);
}
@Override
public void caseShrExpr(ShrExpr v) {
defaultCase(v);
}
@Override
public void caseUshrExpr(UshrExpr v) {
defaultCase(v);
}
@Override
public void caseSubExpr(SubExpr v) {
defaultCase(v);
}
@Override
public void caseXorExpr(XorExpr v) {
defaultCase(v);
}
@Override
public void caseInterfaceInvokeExpr(InterfaceInvokeExpr v) {
defaultCase(v);
}
@Override
public void caseSpecialInvokeExpr(SpecialInvokeExpr v) {
defaultCase(v);
}
@Override
public void caseStaticInvokeExpr(StaticInvokeExpr v) {
defaultCase(v);
}
@Override
public void caseVirtualInvokeExpr(VirtualInvokeExpr v) {
defaultCase(v);
}
@Override
public void caseDynamicInvokeExpr(DynamicInvokeExpr v) {
defaultCase(v);
}
@Override
public void caseCastExpr(CastExpr v) {
defaultCase(v);
}
@Override
public void caseInstanceOfExpr(InstanceOfExpr v) {
defaultCase(v);
}
@Override
public void caseNewArrayExpr(NewArrayExpr v) {
defaultCase(v);
}
@Override
public void caseNewMultiArrayExpr(NewMultiArrayExpr v) {
defaultCase(v);
}
@Override
public void caseNewExpr(NewExpr v) {
defaultCase(v);
}
@Override
public void caseLengthExpr(LengthExpr v) {
defaultCase(v);
}
@Override
public void caseNegExpr(NegExpr v) {
defaultCase(v);
}
@Override
public void defaultCase(Object obj) {
}
public void setResult(T result) {
this.result = result;
}
public T getResult() {
return result;
}
}
| 3,663
| 17.228856
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AbstractImmediateSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Local;
public abstract class AbstractImmediateSwitch<T> extends AbstractConstantSwitch<T> implements ImmediateSwitch {
@Override
public void caseLocal(Local v) {
defaultCase(v);
}
}
| 1,034
| 30.363636
| 111
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AbstractJimpleValueSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Local;
public abstract class AbstractJimpleValueSwitch<T> extends AbstractExprSwitch<T> implements JimpleValueSwitch {
@Override
public void caseLocal(Local v) {
defaultCase(v);
}
@Override
public void caseDoubleConstant(DoubleConstant v) {
defaultCase(v);
}
@Override
public void caseFloatConstant(FloatConstant v) {
defaultCase(v);
}
@Override
public void caseIntConstant(IntConstant v) {
defaultCase(v);
}
@Override
public void caseLongConstant(LongConstant v) {
defaultCase(v);
}
@Override
public void caseNullConstant(NullConstant v) {
defaultCase(v);
}
@Override
public void caseStringConstant(StringConstant v) {
defaultCase(v);
}
@Override
public void caseClassConstant(ClassConstant v) {
defaultCase(v);
}
@Override
public void caseMethodHandle(MethodHandle v) {
defaultCase(v);
}
@Override
public void caseMethodType(MethodType v) {
defaultCase(v);
}
@Override
public void caseArrayRef(ArrayRef v) {
defaultCase(v);
}
@Override
public void caseStaticFieldRef(StaticFieldRef v) {
defaultCase(v);
}
@Override
public void caseInstanceFieldRef(InstanceFieldRef v) {
defaultCase(v);
}
@Override
public void caseParameterRef(ParameterRef v) {
defaultCase(v);
}
@Override
public void caseCaughtExceptionRef(CaughtExceptionRef v) {
defaultCase(v);
}
@Override
public void caseThisRef(ThisRef v) {
defaultCase(v);
}
}
| 2,337
| 20.449541
| 111
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AbstractRefSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public abstract class AbstractRefSwitch<T> implements RefSwitch {
T result;
@Override
public void caseArrayRef(ArrayRef v) {
defaultCase(v);
}
@Override
public void caseStaticFieldRef(StaticFieldRef v) {
defaultCase(v);
}
@Override
public void caseInstanceFieldRef(InstanceFieldRef v) {
defaultCase(v);
}
@Override
public void caseParameterRef(ParameterRef v) {
defaultCase(v);
}
@Override
public void caseCaughtExceptionRef(CaughtExceptionRef v) {
defaultCase(v);
}
@Override
public void caseThisRef(ThisRef v) {
defaultCase(v);
}
@Override
public void defaultCase(Object obj) {
}
public void setResult(T result) {
this.result = result;
}
public T getResult() {
return result;
}
}
| 1,605
| 21.619718
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AbstractStmtSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public abstract class AbstractStmtSwitch<T> implements StmtSwitch {
T result;
@Override
public void caseBreakpointStmt(BreakpointStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseInvokeStmt(InvokeStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseAssignStmt(AssignStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseIdentityStmt(IdentityStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseEnterMonitorStmt(EnterMonitorStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseExitMonitorStmt(ExitMonitorStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseGotoStmt(GotoStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseIfStmt(IfStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseLookupSwitchStmt(LookupSwitchStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseNopStmt(NopStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseRetStmt(RetStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseReturnStmt(ReturnStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseTableSwitchStmt(TableSwitchStmt stmt) {
defaultCase(stmt);
}
@Override
public void caseThrowStmt(ThrowStmt stmt) {
defaultCase(stmt);
}
@Override
public void defaultCase(Object obj) {
}
public void setResult(T result) {
this.result = result;
}
public T getResult() {
return result;
}
}
| 2,443
| 20.068966
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AddExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface AddExpr extends BinopExpr {
}
| 876
| 31.481481
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AndExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface AndExpr extends BinopExpr {
}
| 876
| 31.481481
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AnyNewExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 2004 Ondrej Lhotak
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
/**
* Any expression that allocates objects.
*
* @author Ondrej Lhotak
*/
public interface AnyNewExpr extends Expr {
}
| 945
| 27.666667
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ArithmeticConstant.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
@SuppressWarnings("serial")
public abstract class ArithmeticConstant extends NumericConstant {
// PTC 1999/06/28
public abstract ArithmeticConstant and(ArithmeticConstant c);
public abstract ArithmeticConstant or(ArithmeticConstant c);
public abstract ArithmeticConstant xor(ArithmeticConstant c);
public abstract ArithmeticConstant shiftLeft(ArithmeticConstant c);
public abstract ArithmeticConstant shiftRight(ArithmeticConstant c);
public abstract ArithmeticConstant unsignedShiftRight(ArithmeticConstant c);
}
| 1,363
| 32.268293
| 78
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ArrayRef.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Local;
import soot.Type;
import soot.Value;
import soot.ValueBox;
import soot.util.Switch;
public interface ArrayRef extends ConcreteRef {
public Value getBase();
public void setBase(Local base);
public ValueBox getBaseBox();
public Value getIndex();
public void setIndex(Value index);
public ValueBox getIndexBox();
public Type getType();
public void apply(Switch sw);
}
| 1,237
| 24.791667
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/AssignStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
public interface AssignStmt extends DefinitionStmt {
public void setLeftOp(Value variable);
public void setRightOp(Value rvalue);
}
| 986
| 29.84375
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/BinopExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
import soot.ValueBox;
public interface BinopExpr extends Expr {
public Value getOp1();
public Value getOp2();
public ValueBox getOp1Box();
public ValueBox getOp2Box();
public void setOp1(Value op1);
public void setOp2(Value op2);
public String getSymbol();
public String toString();
}
| 1,157
| 24.733333
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/BreakpointStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface BreakpointStmt extends Stmt {
}
| 878
| 31.555556
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/CastExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Type;
import soot.Value;
import soot.ValueBox;
import soot.util.Switch;
public interface CastExpr extends Expr {
public Value getOp();
public void setOp(Value op);
public ValueBox getOpBox();
public Type getCastType();
public void setCastType(Type castType);
public Type getType();
public void apply(Switch sw);
}
| 1,176
| 25.155556
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/CaughtExceptionRef.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Type;
import soot.util.Switch;
public interface CaughtExceptionRef extends IdentityRef {
public Type getType();
public void apply(Switch sw);
}
| 991
| 29.060606
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ClassConstant.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 2005 - Jennifer Lhotak
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.ArrayType;
import soot.BooleanType;
import soot.ByteType;
import soot.CharType;
import soot.DoubleType;
import soot.FloatType;
import soot.IntType;
import soot.LongType;
import soot.PrimType;
import soot.RefType;
import soot.ShortType;
import soot.Type;
import soot.util.StringTools;
import soot.util.Switch;
public class ClassConstant extends Constant {
public final String value;
private ClassConstant(String s) {
this.value = s;
}
public static ClassConstant v(String value) {
if (value.indexOf('.') > -1) {
throw new RuntimeException("ClassConstants must use class names separated by '/', not '.'!");
}
return new ClassConstant(value);
}
public static ClassConstant fromType(Type tp) {
return v(sootTypeToString(tp));
}
private static String sootTypeToString(Type tp) {
if (tp instanceof RefType) {
return "L" + ((RefType) tp).getClassName().replace('.', '/') + ";";
} else if (tp instanceof ArrayType) {
return "[" + sootTypeToString(((ArrayType) tp).getElementType());
} else if (tp instanceof PrimType) {
if (tp instanceof IntType) {
return "I";
} else if (tp instanceof ByteType) {
return "B";
} else if (tp instanceof CharType) {
return "C";
} else if (tp instanceof DoubleType) {
return "D";
} else if (tp instanceof FloatType) {
return "F";
} else if (tp instanceof LongType) {
return "J";
} else if (tp instanceof ShortType) {
return "S";
} else if (tp instanceof BooleanType) {
return "Z";
} else {
throw new RuntimeException("Unsupported primitive type");
}
} else {
throw new RuntimeException("Unsupported type" + tp);
}
}
/**
* Gets whether this class constant denotes a reference type. This does not check for arrays.
*
* @return True if this class constant denotes a reference type, otherwise false
*/
public boolean isRefType() {
String tmp = this.value;
return !tmp.isEmpty() && tmp.charAt(0) == 'L' && tmp.charAt(tmp.length() - 1) == ';';
}
public Type toSootType() {
int numDimensions = 0;
String tmp = this.value;
while (!tmp.isEmpty() && tmp.charAt(0) == '[') {
numDimensions++;
tmp = tmp.substring(1);
}
Type baseType = null;
if (!tmp.isEmpty() && tmp.charAt(0) == 'L') {
tmp = tmp.substring(1);
int lastIdx = tmp.length() - 1;
if (!tmp.isEmpty() && tmp.charAt(lastIdx) == ';') {
tmp = tmp.substring(0, lastIdx);
}
tmp = tmp.replace('/', '.');
baseType = RefType.v(tmp);
} else {
switch (tmp) {
case "I":
baseType = IntType.v();
break;
case "B":
baseType = ByteType.v();
break;
case "C":
baseType = CharType.v();
break;
case "D":
baseType = DoubleType.v();
break;
case "F":
baseType = FloatType.v();
break;
case "J":
baseType = LongType.v();
break;
case "S":
baseType = ShortType.v();
break;
case "Z":
baseType = BooleanType.v();
break;
default:
throw new RuntimeException("Unsupported class constant: " + value);
}
}
return numDimensions > 0 ? ArrayType.v(baseType, numDimensions) : baseType;
}
/**
* Gets an internal representation of the class used in Java bytecode. The returned string is similar to the fully
* qualified name but with '/' instead of '.'. Example: "java/lang/Object". See
* https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.2.1
*/
public String toInternalString() {
String internal = this.value;
while (!internal.isEmpty() && internal.charAt(0) == '[') {
internal = internal.substring(1);
}
int lastIdx = internal.length() - 1;
if (!internal.isEmpty() && internal.charAt(lastIdx) == ';') {
internal = internal.substring(0, lastIdx);
if (!internal.isEmpty() && internal.charAt(0) == 'L') {
internal = internal.substring(1);
}
}
return internal;
}
// In this case, equals should be structural equality.
@Override
public boolean equals(Object c) {
return (c instanceof ClassConstant && ((ClassConstant) c).value.equals(this.value));
}
/** Returns a hash code for this ClassConstant object. */
@Override
public int hashCode() {
return value.hashCode();
}
@Override
public String toString() {
return "class " + StringTools.getQuotedStringOf(value);
}
public String getValue() {
return value;
}
@Override
public Type getType() {
return RefType.v("java.lang.Class");
}
@Override
public void apply(Switch sw) {
((ConstantSwitch) sw).caseClassConstant(this);
}
}
| 5,703
| 27.378109
| 116
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/CmpExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface CmpExpr extends BinopExpr {
}
| 876
| 31.481481
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/CmpgExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface CmpgExpr extends BinopExpr {
}
| 877
| 31.518519
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/CmplExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface CmplExpr extends BinopExpr {
}
| 877
| 31.518519
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ConcreteRef.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface ConcreteRef extends Ref {
}
| 874
| 31.407407
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ConditionExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface ConditionExpr extends BinopExpr {
}
| 882
| 31.703704
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/Constant.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.Collections;
import java.util.List;
import soot.Immediate;
import soot.Unit;
import soot.UnitPrinter;
import soot.Value;
import soot.ValueBox;
import soot.baf.Baf;
@SuppressWarnings("serial")
public abstract class Constant implements Value, ConvertToBaf, Immediate {
@Override
public final List<ValueBox> getUseBoxes() {
return Collections.emptyList();
}
/** Adds a Baf instruction pushing this constant to the stack onto <code>out</code>. */
@Override
public void convertToBaf(JimpleToBafContext context, List<Unit> out) {
Unit u = Baf.v().newPushInst(this);
u.addAllTagsOf(context.getCurrentUnit());
out.add(u);
}
/** Clones the current constant. Not implemented here. */
@Override
public Object clone() {
throw new RuntimeException();
}
/**
* Returns true if this object is structurally equivalent to c. For Constants, equality is structural equality, so we just
* call equals().
*/
@Override
public boolean equivTo(Object c) {
return equals(c);
}
/**
* Returns a hash code consistent with structural equality for this object. For Constants, equality is structural equality;
* we hope that each subclass defines hashCode() correctly.
*/
@Override
public int equivHashCode() {
return hashCode();
}
@Override
public void toString(UnitPrinter up) {
up.constant(this);
}
}
| 2,220
| 26.7625
| 125
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ConstantSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface ConstantSwitch extends soot.util.Switch {
public abstract void caseDoubleConstant(DoubleConstant v);
public abstract void caseFloatConstant(FloatConstant v);
public abstract void caseIntConstant(IntConstant v);
public abstract void caseLongConstant(LongConstant v);
public abstract void caseNullConstant(NullConstant v);
public abstract void caseStringConstant(StringConstant v);
public abstract void caseClassConstant(ClassConstant v);
public abstract void caseMethodHandle(MethodHandle handle);
public abstract void caseMethodType(MethodType type);
public abstract void defaultCase(Object object);
}
| 1,479
| 31.173913
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ConvertToBaf.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.List;
import soot.Unit;
public interface ConvertToBaf {
public void convertToBaf(JimpleToBafContext context, List<Unit> out);
}
| 978
| 29.59375
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/DefinitionStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
import soot.ValueBox;
public interface DefinitionStmt extends Stmt {
public Value getLeftOp();
public Value getRightOp();
public ValueBox getLeftOpBox();
public ValueBox getRightOpBox();
}
| 1,049
| 27.378378
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/DivExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface DivExpr extends BinopExpr {
}
| 876
| 31.481481
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/DoubleConstant.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.DoubleType;
import soot.Type;
import soot.util.Switch;
/**
* Floating point constant with double precision.
*/
public class DoubleConstant extends RealConstant {
private static final long serialVersionUID = -6890604195758898783L;
public final double value;
public static final DoubleConstant ZERO = new DoubleConstant(0);
public static final DoubleConstant ONE = new DoubleConstant(1);
private DoubleConstant(double value) {
this.value = value;
}
public static DoubleConstant v(double value) {
if (Double.compare(value, 0D) == 0) {
return ZERO;
}
if (Double.compare(value, 1D) == 0) {
return ONE;
}
return new DoubleConstant(value);
}
@Override
public boolean equals(Object c) {
return (c instanceof DoubleConstant && Double.compare(((DoubleConstant) c).value, this.value) == 0);
}
/**
* Returns a hash code for this DoubleConstant object.
*/
@Override
public int hashCode() {
long v = Double.doubleToLongBits(value);
return (int) (v ^ (v >>> 32));
}
// PTC 1999/06/28
@Override
public NumericConstant add(NumericConstant c) {
assertInstanceOf(c);
return DoubleConstant.v(this.value + ((DoubleConstant) c).value);
}
@Override
public NumericConstant subtract(NumericConstant c) {
assertInstanceOf(c);
return DoubleConstant.v(this.value - ((DoubleConstant) c).value);
}
@Override
public NumericConstant multiply(NumericConstant c) {
assertInstanceOf(c);
return DoubleConstant.v(this.value * ((DoubleConstant) c).value);
}
@Override
public NumericConstant divide(NumericConstant c) {
assertInstanceOf(c);
return DoubleConstant.v(this.value / ((DoubleConstant) c).value);
}
@Override
public NumericConstant remainder(NumericConstant c) {
assertInstanceOf(c);
return DoubleConstant.v(this.value % ((DoubleConstant) c).value);
}
@Override
public NumericConstant equalEqual(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Double.compare(this.value, ((DoubleConstant) c).value) == 0 ? 1 : 0);
}
@Override
public NumericConstant notEqual(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Double.compare(this.value, ((DoubleConstant) c).value) != 0 ? 1 : 0);
}
@Override
public boolean isLessThan(NumericConstant c) {
assertInstanceOf(c);
return Double.compare(this.value, ((DoubleConstant) c).value) < 0;
}
@Override
public NumericConstant lessThan(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Double.compare(this.value, ((DoubleConstant) c).value) < 0 ? 1 : 0);
}
@Override
public NumericConstant lessThanOrEqual(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Double.compare(this.value, ((DoubleConstant) c).value) <= 0 ? 1 : 0);
}
@Override
public NumericConstant greaterThan(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Double.compare(this.value, ((DoubleConstant) c).value) > 0 ? 1 : 0);
}
@Override
public NumericConstant greaterThanOrEqual(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Double.compare(this.value, ((DoubleConstant) c).value) >= 0 ? 1 : 0);
}
@Override
public IntConstant cmpg(RealConstant constant) {
assertInstanceOf(constant);
final double cValue = ((DoubleConstant) constant).value;
if (this.value < cValue) {
return IntConstant.v(-1);
} else if (this.value == cValue) {
return IntConstant.v(0);
} else {
return IntConstant.v(1);
}
}
@Override
public IntConstant cmpl(RealConstant constant) {
assertInstanceOf(constant);
final double cValue = ((DoubleConstant) constant).value;
if (this.value > cValue) {
return IntConstant.v(1);
} else if (this.value == cValue) {
return IntConstant.v(0);
} else {
return IntConstant.v(-1);
}
}
@Override
public NumericConstant negate() {
return DoubleConstant.v(-(this.value));
}
@Override
public String toString() {
String doubleString = Double.toString(value);
switch (doubleString) {
case "NaN":
case "Infinity":
case "-Infinity":
return "#" + doubleString;
default:
return doubleString;
}
}
@Override
public Type getType() {
return DoubleType.v();
}
@Override
public void apply(Switch sw) {
((ConstantSwitch) sw).caseDoubleConstant(this);
}
/**
* Checks if passed argument is instance of expected class.
*
* @param constant
* the instance to check
* @throws IllegalArgumentException
* when check fails
*/
private void assertInstanceOf(NumericConstant constant) {
if (!(constant instanceof DoubleConstant)) {
throw new IllegalArgumentException("DoubleConstant expected");
}
}
}
| 5,697
| 26.133333
| 104
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/DynamicInvokeExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.List;
import soot.SootMethodRef;
import soot.Value;
public interface DynamicInvokeExpr extends InvokeExpr {
public SootMethodRef getBootstrapMethodRef();
public List<Value> getBootstrapArgs();
public Value getBootstrapArg(int index);
public int getBootstrapArgCount();
/*
* Tag of the method handle, see JVM-spec. 5.4.3.5.
*/
public int getHandleTag();
}
| 1,225
| 26.863636
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/EnterMonitorStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
import soot.ValueBox;
public interface EnterMonitorStmt extends MonitorStmt {
public Value getOp();
public void setOp(Value op);
public ValueBox getOpBox();
}
| 1,016
| 28.057143
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/EqExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface EqExpr extends ConditionExpr {
}
| 879
| 31.592593
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/EqualLocals.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.List;
import soot.Local;
public interface EqualLocals {
public boolean isLocalEqualToAt(Local l1, Local l2, Stmt s);
public List getCopiesAt(Stmt s);
}
| 1,006
| 27.771429
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ExitMonitorStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
import soot.ValueBox;
public interface ExitMonitorStmt extends MonitorStmt {
public Value getOp();
public void setOp(Value op);
public ValueBox getOpBox();
}
| 1,015
| 28.028571
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/Expr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
public interface Expr extends Value {
}
| 889
| 29.689655
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ExprSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface ExprSwitch extends soot.util.Switch {
public abstract void caseAddExpr(AddExpr v);
public abstract void caseAndExpr(AndExpr v);
public abstract void caseCmpExpr(CmpExpr v);
public abstract void caseCmpgExpr(CmpgExpr v);
public abstract void caseCmplExpr(CmplExpr v);
public abstract void caseDivExpr(DivExpr v);
public abstract void caseEqExpr(EqExpr v);
public abstract void caseNeExpr(NeExpr v);
public abstract void caseGeExpr(GeExpr v);
public abstract void caseGtExpr(GtExpr v);
public abstract void caseLeExpr(LeExpr v);
public abstract void caseLtExpr(LtExpr v);
public abstract void caseMulExpr(MulExpr v);
public abstract void caseOrExpr(OrExpr v);
public abstract void caseRemExpr(RemExpr v);
public abstract void caseShlExpr(ShlExpr v);
public abstract void caseShrExpr(ShrExpr v);
public abstract void caseUshrExpr(UshrExpr v);
public abstract void caseSubExpr(SubExpr v);
public abstract void caseXorExpr(XorExpr v);
public abstract void caseInterfaceInvokeExpr(InterfaceInvokeExpr v);
public abstract void caseSpecialInvokeExpr(SpecialInvokeExpr v);
public abstract void caseStaticInvokeExpr(StaticInvokeExpr v);
public abstract void caseVirtualInvokeExpr(VirtualInvokeExpr v);
public abstract void caseDynamicInvokeExpr(DynamicInvokeExpr v);
public abstract void caseCastExpr(CastExpr v);
public abstract void caseInstanceOfExpr(InstanceOfExpr v);
public abstract void caseNewArrayExpr(NewArrayExpr v);
public abstract void caseNewMultiArrayExpr(NewMultiArrayExpr v);
public abstract void caseNewExpr(NewExpr v);
public abstract void caseLengthExpr(LengthExpr v);
public abstract void caseNegExpr(NegExpr v);
public abstract void defaultCase(Object obj);
}
| 2,616
| 27.445652
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/FieldRef.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* Copyright (C) 2004 Ondrej Lhotak
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.SootField;
import soot.SootFieldRef;
public interface FieldRef extends ConcreteRef {
public SootFieldRef getFieldRef();
public void setFieldRef(SootFieldRef sfr);
public SootField getField();
}
| 1,080
| 29.027778
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/FloatConstant.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.FloatType;
import soot.Type;
import soot.util.Switch;
/**
* Floating point constant with single precision.
*/
public class FloatConstant extends RealConstant {
private static final long serialVersionUID = 8670501761494749605L;
public static final FloatConstant ZERO = new FloatConstant(0);
public static final FloatConstant ONE = new FloatConstant(1);
public final float value;
private FloatConstant(float value) {
this.value = value;
}
public static FloatConstant v(float value) {
if (Float.compare(value, 0F) == 0) {
return ZERO;
}
if (Float.compare(value, 1F) == 0) {
return ONE;
}
return new FloatConstant(value);
}
@Override
public boolean equals(Object c) {
return c instanceof FloatConstant && Float.compare(((FloatConstant) c).value, value) == 0;
}
/**
* Returns a hash code for this FloatConstant object.
*/
@Override
public int hashCode() {
return Float.floatToIntBits(value);
}
// PTC 1999/06/28
@Override
public NumericConstant add(NumericConstant c) {
assertInstanceOf(c);
return FloatConstant.v(this.value + ((FloatConstant) c).value);
}
@Override
public NumericConstant subtract(NumericConstant c) {
assertInstanceOf(c);
return FloatConstant.v(this.value - ((FloatConstant) c).value);
}
@Override
public NumericConstant multiply(NumericConstant c) {
assertInstanceOf(c);
return FloatConstant.v(this.value * ((FloatConstant) c).value);
}
@Override
public NumericConstant divide(NumericConstant c) {
assertInstanceOf(c);
return FloatConstant.v(this.value / ((FloatConstant) c).value);
}
@Override
public NumericConstant remainder(NumericConstant c) {
assertInstanceOf(c);
return FloatConstant.v(this.value % ((FloatConstant) c).value);
}
@Override
public NumericConstant equalEqual(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Float.compare(this.value, ((FloatConstant) c).value) == 0 ? 1 : 0);
}
@Override
public NumericConstant notEqual(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Float.compare(this.value, ((FloatConstant) c).value) != 0 ? 1 : 0);
}
@Override
public boolean isLessThan(NumericConstant c) {
assertInstanceOf(c);
return Float.compare(this.value, ((FloatConstant) c).value) < 0;
}
@Override
public NumericConstant lessThan(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Float.compare(this.value, ((FloatConstant) c).value) < 0 ? 1 : 0);
}
@Override
public NumericConstant lessThanOrEqual(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Float.compare(this.value, ((FloatConstant) c).value) <= 0 ? 1 : 0);
}
@Override
public NumericConstant greaterThan(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Float.compare(this.value, ((FloatConstant) c).value) > 0 ? 1 : 0);
}
@Override
public NumericConstant greaterThanOrEqual(NumericConstant c) {
assertInstanceOf(c);
return IntConstant.v(Float.compare(this.value, ((FloatConstant) c).value) >= 0 ? 1 : 0);
}
@Override
public IntConstant cmpg(RealConstant constant) {
assertInstanceOf(constant);
final float cValue = ((FloatConstant) constant).value;
if (this.value < cValue) {
return IntConstant.v(-1);
} else if (this.value == cValue) {
return IntConstant.v(0);
} else {
return IntConstant.v(1);
}
}
@Override
public IntConstant cmpl(RealConstant constant) {
assertInstanceOf(constant);
final float cValue = ((FloatConstant) constant).value;
if (this.value > cValue) {
return IntConstant.v(1);
} else if (this.value == cValue) {
return IntConstant.v(0);
} else {
return IntConstant.v(-1);
}
}
@Override
public NumericConstant negate() {
return FloatConstant.v(-(this.value));
}
@Override
public String toString() {
String floatString = Float.toString(value);
switch (floatString) {
case "NaN":
case "Infinity":
case "-Infinity":
return "#" + floatString + "F";
default:
return floatString + "F";
}
}
@Override
public Type getType() {
return FloatType.v();
}
@Override
public void apply(Switch sw) {
((ConstantSwitch) sw).caseFloatConstant(this);
}
/**
* Checks if passed argument is instance of expected class.
*
* @param constant
* the instance to check
* @throws IllegalArgumentException
* when check fails
*/
private void assertInstanceOf(NumericConstant constant) {
if (!(constant instanceof FloatConstant)) {
throw new IllegalArgumentException("FloatConstant expected");
}
}
}
| 5,605
| 25.822967
| 94
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/GeExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface GeExpr extends ConditionExpr {
}
| 879
| 31.592593
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/GotoStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Unit;
import soot.UnitBox;
public interface GotoStmt extends Stmt {
public Unit getTarget();
public void setTarget(Unit target);
public UnitBox getTargetBox();
}
| 1,012
| 27.942857
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/GroupIntPair.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public class GroupIntPair {
public final Object group;
public final int x;
public GroupIntPair(Object group, int x) {
this.group = group;
this.x = x;
}
@Override
public boolean equals(Object other) {
if (other instanceof GroupIntPair) {
GroupIntPair cast = (GroupIntPair) other;
return cast.group.equals(this.group) && cast.x == this.x;
} else {
return false;
}
}
@Override
public int hashCode() {
return group.hashCode() + 1013 * x;
}
@Override
public String toString() {
return this.group + ": " + this.x;
}
}
| 1,417
| 25.259259
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/GtExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface GtExpr extends ConditionExpr {
}
| 879
| 31.592593
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/IdentityRef.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface IdentityRef extends Ref {
}
| 874
| 31.407407
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/IdentityStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.IdentityUnit;
import soot.Value;
public interface IdentityStmt extends DefinitionStmt, IdentityUnit {
public void setLeftOp(Value local);
public void setRightOp(Value identityRef);
}
| 1,030
| 30.242424
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/IfStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Unit;
import soot.UnitBox;
import soot.Value;
import soot.ValueBox;
public interface IfStmt extends Stmt {
public Value getCondition();
/**
* condition must be soot.jimple.ConditionExpr
*/
public void setCondition(Value condition);
public ValueBox getConditionBox();
public Stmt getTarget();
public void setTarget(Unit target);
public UnitBox getTargetBox();
}
| 1,228
| 25.717391
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/ImmediateSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Local;
public interface ImmediateSwitch extends ConstantSwitch {
public abstract void caseLocal(Local l);
}
| 952
| 30.766667
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/InstanceFieldRef.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
import soot.ValueBox;
public interface InstanceFieldRef extends FieldRef {
public Value getBase();
public ValueBox getBaseBox();
public void setBase(Value base);
}
| 1,021
| 28.2
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/InstanceInvokeExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
import soot.ValueBox;
public interface InstanceInvokeExpr extends InvokeExpr {
/**
* @return the target (qualifier) of this method invocation expression.
*/
public Value getBase();
public ValueBox getBaseBox();
public void setBase(Value base);
}
| 1,111
| 28.263158
| 73
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/InstanceOfExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Type;
import soot.Value;
import soot.ValueBox;
public interface InstanceOfExpr extends Expr {
public Value getOp();
public void setOp(Value op);
public ValueBox getOpBox();
public Type getCheckType();
public void setCheckType(Type checkType);
}
| 1,101
| 26.55
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/IntConstant.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.IntType;
import soot.Type;
import soot.util.Switch;
public class IntConstant extends ArithmeticConstant {
private static final long serialVersionUID = 8622167089453261784L;
public final int value;
private static final int MAX_CACHE = 128;
private static final int MIN_CACHE = -127;
private static final int ABS_MIN_CACHE = Math.abs(MIN_CACHE);
private static final IntConstant[] CACHED = new IntConstant[MAX_CACHE + ABS_MIN_CACHE];
protected IntConstant(int value) {
this.value = value;
}
public static IntConstant v(int value) {
if (value > MIN_CACHE && value < MAX_CACHE) {
int idx = value + ABS_MIN_CACHE;
IntConstant c = CACHED[idx];
if (c != null) {
return c;
}
c = new IntConstant(value);
CACHED[idx] = c;
return c;
}
return new IntConstant(value);
}
@Override
public boolean equals(Object c) {
return c instanceof IntConstant && ((IntConstant) c).value == value;
}
@Override
public int hashCode() {
return value;
}
// PTC 1999/06/28
@Override
public NumericConstant add(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value + ((IntConstant) c).value);
}
@Override
public NumericConstant subtract(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value - ((IntConstant) c).value);
}
@Override
public NumericConstant multiply(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value * ((IntConstant) c).value);
}
@Override
public NumericConstant divide(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value / ((IntConstant) c).value);
}
@Override
public NumericConstant remainder(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value % ((IntConstant) c).value);
}
@Override
public NumericConstant equalEqual(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v((this.value == ((IntConstant) c).value) ? 1 : 0);
}
@Override
public NumericConstant notEqual(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v((this.value != ((IntConstant) c).value) ? 1 : 0);
}
@Override
public boolean isLessThan(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return this.value < ((IntConstant) c).value;
}
@Override
public NumericConstant lessThan(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v((this.value < ((IntConstant) c).value) ? 1 : 0);
}
@Override
public NumericConstant lessThanOrEqual(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v((this.value <= ((IntConstant) c).value) ? 1 : 0);
}
@Override
public NumericConstant greaterThan(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v((this.value > ((IntConstant) c).value) ? 1 : 0);
}
@Override
public NumericConstant greaterThanOrEqual(NumericConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v((this.value >= ((IntConstant) c).value) ? 1 : 0);
}
@Override
public NumericConstant negate() {
return IntConstant.v(-(this.value));
}
@Override
public ArithmeticConstant and(ArithmeticConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value & ((IntConstant) c).value);
}
@Override
public ArithmeticConstant or(ArithmeticConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value | ((IntConstant) c).value);
}
@Override
public ArithmeticConstant xor(ArithmeticConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value ^ ((IntConstant) c).value);
}
@Override
public ArithmeticConstant shiftLeft(ArithmeticConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value << ((IntConstant) c).value);
}
@Override
public ArithmeticConstant shiftRight(ArithmeticConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value >> ((IntConstant) c).value);
}
@Override
public ArithmeticConstant unsignedShiftRight(ArithmeticConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return IntConstant.v(this.value >>> ((IntConstant) c).value);
}
@Override
public String toString() {
return Integer.toString(value);
}
@Override
public Type getType() {
return IntType.v();
}
@Override
public void apply(Switch sw) {
((ConstantSwitch) sw).caseIntConstant(this);
}
}
| 6,783
| 28.11588
| 89
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/InterfaceInvokeExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface InterfaceInvokeExpr extends InstanceInvokeExpr {
}
| 897
| 32.259259
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/InvokeExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* Copyright (C) 2004 Ondrej Lhotak
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.List;
import soot.SootMethod;
import soot.SootMethodRef;
import soot.Value;
import soot.ValueBox;
/**
* Represents method invocation expression.
*
* @see VirtualInvokeExpr invokevirtual
* @see InterfaceInvokeExpr invokeinterface
* @see SpecialInvokeExpr invokespecial
* @see StaticInvokeExpr invokestatic
* @see DynamicInvokeExpr invokedynamic
*/
public interface InvokeExpr extends Expr {
void setMethodRef(SootMethodRef smr);
SootMethodRef getMethodRef();
/**
* Resolves {@link SootMethodRef} to {@link SootMethod}.
*
* @return {@link SootMethod} instance, or {@code null} when reference cannot be resolved and
* {@link soot.options.Options#ignore_resolution_errors} is {@code true}
* @throws soot.SootMethodRefImpl.ClassResolutionFailedException
* when reference cannot be resolved and {@link soot.options.Options#ignore_resolution_errors} is {@code false}
*/
SootMethod getMethod();
List<Value> getArgs();
Value getArg(int index);
int getArgCount();
void setArg(int index, Value arg);
ValueBox getArgBox(int index);
}
| 1,980
| 27.710145
| 123
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/InvokeStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
import soot.ValueBox;
public interface InvokeStmt extends Stmt {
public void setInvokeExpr(Value invokeExpr);
public InvokeExpr getInvokeExpr();
public ValueBox getInvokeExprBox();
}
| 1,040
| 28.742857
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/JasminClass.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.AbstractJasminClass;
import soot.ArrayType;
import soot.Body;
import soot.BooleanType;
import soot.ByteType;
import soot.CharType;
import soot.DoubleType;
import soot.FloatType;
import soot.G;
import soot.IntType;
import soot.IntegerType;
import soot.Local;
import soot.LongType;
import soot.Modifier;
import soot.NullType;
import soot.RefType;
import soot.ShortType;
import soot.SootClass;
import soot.SootFieldRef;
import soot.SootMethod;
import soot.SootMethodRef;
import soot.StmtAddressType;
import soot.Timers;
import soot.Trap;
import soot.Type;
import soot.TypeSwitch;
import soot.Unit;
import soot.UnitBox;
import soot.Value;
import soot.ValueBox;
import soot.VoidType;
import soot.grimp.AbstractGrimpValueSwitch;
import soot.grimp.NewInvokeExpr;
import soot.jimple.internal.StmtBox;
import soot.options.Options;
import soot.tagkit.LineNumberTag;
import soot.toolkits.graph.ExceptionalUnitGraph;
import soot.toolkits.graph.ExceptionalUnitGraphFactory;
import soot.toolkits.scalar.FastColorer;
import soot.toolkits.scalar.LocalDefs;
import soot.toolkits.scalar.LocalUses;
import soot.util.Chain;
/*
* TODO This is the right JasminClass
*/
/** Methods for producing Jasmin code from Jimple. */
public class JasminClass extends AbstractJasminClass {
private static final Logger logger = LoggerFactory.getLogger(JasminClass.class);
void emit(String s, int stackChange) {
modifyStackHeight(stackChange);
okayEmit(s);
}
void modifyStackHeight(int stackChange) {
if (currentStackHeight > maxStackHeight) {
maxStackHeight = currentStackHeight;
}
currentStackHeight += stackChange;
if (currentStackHeight < 0) {
throw new RuntimeException("Stack height is negative!");
}
if (currentStackHeight > maxStackHeight) {
maxStackHeight = currentStackHeight;
}
}
public JasminClass(SootClass sootClass) {
super(sootClass);
}
@Override
protected void assignColorsToLocals(Body body) {
super.assignColorsToLocals(body);
// Call the graph colorer.
FastColorer.assignColorsToLocals(body, localToGroup, localToColor, groupToColorCount);
if (Options.v().time()) {
Timers.v().packTimer.end();
}
}
@Override
protected void emitMethodBody(SootMethod method) {
if (Options.v().time()) {
Timers.v().buildJasminTimer.end();
}
Body activeBody = method.getActiveBody();
if (!(activeBody instanceof StmtBody)) {
throw new RuntimeException("method: " + method.getName() + " has an invalid active body!");
}
StmtBody body = (StmtBody) activeBody;
body.validate();
// if(body == null)
if (Options.v().time()) {
Timers.v().buildJasminTimer.start();
}
if (Options.v().verbose()) {
logger.debug("[" + body.getMethod().getName() + "] Performing peephole optimizations...");
}
subroutineToReturnAddressSlot = new HashMap<Unit, Integer>(10, 0.7f);
Chain<Unit> units = body.getUnits();
// Determine the unitToLabel map
{
unitToLabel = new HashMap<Unit, String>(units.size() * 2 + 1, 0.7f);
labelCount = 0;
for (UnitBox ubox : body.getUnitBoxes(true)) {
// Assign a label for each statement reference
StmtBox box = (StmtBox) ubox;
if (!unitToLabel.containsKey(box.getUnit())) {
unitToLabel.put(box.getUnit(), "label" + labelCount++);
}
}
}
// Emit the exceptions
for (Trap trap : body.getTraps()) {
if (trap.getBeginUnit() != trap.getEndUnit()) {
emit(".catch " + slashify(trap.getException().getName()) + " from " + unitToLabel.get(trap.getBeginUnit()) + " to "
+ unitToLabel.get(trap.getEndUnit()) + " using " + unitToLabel.get(trap.getHandlerUnit()));
}
}
int stackLimitIndex = -1;
// Determine where the locals go
{
int localCount = 0;
int[] paramSlots = new int[method.getParameterCount()];
int thisSlot = 0;
Set<Local> assignedLocals = new HashSet<Local>();
Map<GroupIntPair, Integer> groupColorPairToSlot =
new HashMap<GroupIntPair, Integer>(body.getLocalCount() * 2 + 1, 0.7f);
localToSlot = new HashMap<Local, Integer>(body.getLocalCount() * 2 + 1, 0.7f);
assignColorsToLocals(body);
// Determine slots for 'this' and parameters
{
if (!method.isStatic()) {
thisSlot = 0;
localCount++;
}
List<Type> paramTypes = method.getParameterTypes();
for (int i = 0; i < paramTypes.size(); i++) {
paramSlots[i] = localCount;
localCount += sizeOfType((Type) paramTypes.get(i));
}
}
// Handle identity statements
for (Unit u : units) {
if (u instanceof IdentityStmt) {
IdentityStmt is = (IdentityStmt) u;
Value leftOp = is.getLeftOp();
if (leftOp instanceof Local) {
int slot = 0;
IdentityRef identity = (IdentityRef) is.getRightOp();
if (identity instanceof ThisRef) {
if (method.isStatic()) {
throw new RuntimeException("Attempting to use 'this' in static method");
}
slot = thisSlot;
} else if (identity instanceof ParameterRef) {
slot = paramSlots[((ParameterRef) identity).getIndex()];
} else {
// Exception ref. Skip over this
continue;
}
Local l = (Local) leftOp;
// Make this (group, color) point to the given slot,
// so that all locals of the same color can be pointed here too
groupColorPairToSlot.put(new GroupIntPair(localToGroup.get(l), localToColor.get(l)), slot);
localToSlot.put(l, slot);
assignedLocals.add(l);
}
}
}
// Assign the rest of the locals
{
for (Local local : body.getLocals()) {
if (!assignedLocals.contains(local)) {
int slot;
GroupIntPair pair = new GroupIntPair(localToGroup.get(local), localToColor.get(local));
if (groupColorPairToSlot.containsKey(pair)) {
// This local should share the same slot as the previous local with
// the same (group, color);
slot = groupColorPairToSlot.get(pair);
} else {
slot = localCount;
localCount += sizeOfType(local.getType());
groupColorPairToSlot.put(pair, slot);
}
localToSlot.put(local, slot);
assignedLocals.add(local);
}
}
int modifiers = method.getModifiers();
if (!Modifier.isNative(modifiers) && !Modifier.isAbstract(modifiers)) {
emit(" .limit stack ?");
stackLimitIndex = code.size() - 1;
emit(" .limit locals " + localCount);
}
}
}
// let's create a u-d web for the ++ peephole optimization.
ExceptionalUnitGraph stmtGraph = null;
LocalDefs ld = null;
LocalUses lu = null;
// final boolean enablePeephole = !PhaseOptions.getBoolean(options, "no-peephole");
final boolean enablePeephole = false;
if (enablePeephole) {
stmtGraph = ExceptionalUnitGraphFactory.createExceptionalUnitGraph(body);
ld = G.v().soot_toolkits_scalar_LocalDefsFactory().newLocalDefs(stmtGraph);
lu = LocalUses.Factory.newLocalUses(body, ld);
}
// Emit code in one pass
{
isEmittingMethodCode = true;
maxStackHeight = 0;
isNextGotoAJsr = false;
LOOP: for (Iterator<Unit> codeIt = units.iterator(); codeIt.hasNext();) {
Stmt s = (Stmt) codeIt.next();
if (unitToLabel.containsKey(s)) {
emit(unitToLabel.get(s) + ":");
}
if (subroutineToReturnAddressSlot.containsKey(s)) {
AssignStmt assignStmt = (AssignStmt) s;
modifyStackHeight(1); // simulate the pushing of address onto the stack by the jsr
int slot = localToSlot.get(assignStmt.getLeftOp());
if (slot >= 0 && slot <= 3) {
emit("astore_" + slot, -1);
} else {
emit("astore " + slot, -1);
}
// emit("astore " + ( ( Integer ) subroutineToReturnAddressSlot.get( s ) ).intValue() );
}
PEEP: if (enablePeephole) {
// Test for postincrement operators ++ and --
// We can optimize them further.
if (!(s instanceof AssignStmt)) {
break PEEP;
}
// sanityCheck: see that we have another statement after s.
if (!codeIt.hasNext()) {
break PEEP;
}
AssignStmt nextStmt;
Stmt nextNextStmt;
{
Stmt ns = (Stmt) stmtGraph.getSuccsOf(s).get(0);
if (!(ns instanceof AssignStmt)) {
break PEEP;
}
List<Unit> l = stmtGraph.getSuccsOf(ns);
if (l.size() != 1) {
break PEEP;
}
nextStmt = (AssignStmt) ns;
nextNextStmt = (Stmt) l.get(0);
}
AssignStmt stmt = (AssignStmt) s;
final Value lvalue = stmt.getLeftOp();
final Value rvalue = stmt.getRightOp();
// we're looking for this pattern:
// a: <lvalue> = <rvalue>; <rvalue> = <rvalue> +/- 1; use(<lvalue>);
// b: <lvalue> = <rvalue>; <rvalue> = <lvalue> +/- 1; use(<lvalue>);
// case a is emitted when rvalue is a local;
// case b when rvalue is, eg. a field ref.
//
// we use structural equality
// for rvalue & nextStmt.getLeftOp().
if (!(lvalue instanceof Local) || !nextStmt.getLeftOp().equivTo(rvalue)
|| !(nextStmt.getRightOp() instanceof AddExpr)) {
break PEEP;
}
// make sure that nextNextStmt uses the local exactly once
{
boolean foundExactlyOnce = false;
for (ValueBox box : nextNextStmt.getUseBoxes()) {
if (box.getValue() == lvalue) {
if (!foundExactlyOnce) {
foundExactlyOnce = true;
} else {
foundExactlyOnce = false;
break;
}
}
}
if (!foundExactlyOnce) {
break PEEP;
}
}
// Specifically exclude the case where rvalue is on the lhs
// of nextNextStmt (what a mess!)
// this takes care of the extremely pathological case where
// the thing being incremented is also on the lhs of nns (!)
for (ValueBox box : nextNextStmt.getDefBoxes()) {
if (box.getValue().equivTo(rvalue)) {
break PEEP;
}
}
AddExpr addexp = (AddExpr) nextStmt.getRightOp();
{
Value op1 = addexp.getOp1();
if (!op1.equivTo(lvalue) && !op1.equivTo(rvalue)) {
break PEEP;
}
Value op2 = addexp.getOp2();
if (!(op2 instanceof IntConstant) || ((IntConstant) (op2)).value != 1) {
break PEEP;
}
}
/* check that we have two uses and that these */
/* uses live precisely in nextStmt and nextNextStmt */
/* LocalDefs tells us this: if there was no use, */
/* there would be no corresponding def. */
if (addexp.getOp1().equivTo(lvalue)) {
if (lu.getUsesOf(s).size() != 2 || ld.getDefsOfAt((Local) lvalue, nextStmt).size() != 1
|| ld.getDefsOfAt((Local) lvalue, nextNextStmt).size() != 1) {
break PEEP;
}
plusPlusState = 0;
} else {
if (lu.getUsesOf(s).size() != 1 || ld.getDefsOfAt((Local) lvalue, nextNextStmt).size() != 1) {
break PEEP;
}
plusPlusState = 10;
}
/* emit dup slot */
// logger.debug("found ++ instance:");
// logger.debug(""+s); logger.debug(""+nextStmt);
// logger.debug(""+nextNextStmt);
/* this should be redundant, but we do it */
/* just in case. */
if (!IntType.v().equals(lvalue.getType())) {
break PEEP;
}
/* our strategy is as follows: eat the */
/* two incrementing statements, push the lvalue to */
/* be incremented & its holding local on a */
/* plusPlusStack and deal with it in */
/* emitLocal. */
currentStackHeight = 0;
/* emit statements as before */
plusPlusValue = rvalue;
plusPlusHolder = (Local) lvalue;
plusPlusIncrementer = nextStmt;
/* emit new statement with quickness */
emitStmt(nextNextStmt);
/* hm. we didn't use local. emit incrementage */
if (plusPlusHolder != null) {
emitStmt(s);
emitStmt(nextStmt);
}
if (currentStackHeight != 0) {
throw new RuntimeException("Stack has height " + currentStackHeight + " after execution of stmt: " + s);
}
codeIt.next();
codeIt.next();
continue LOOP;
} // end of peephole opts.
// emit this statement
{
currentStackHeight = 0;
emitStmt(s);
if (currentStackHeight != 0) {
throw new RuntimeException("Stack has height " + currentStackHeight + " after execution of stmt: " + s);
}
}
}
isEmittingMethodCode = false;
int modifiers = method.getModifiers();
if (!Modifier.isNative(modifiers) && !Modifier.isAbstract(modifiers)) {
code.set(stackLimitIndex, " .limit stack " + maxStackHeight);
}
}
}
void emitAssignStmt(AssignStmt stmt) {
final Value lvalue = stmt.getLeftOp();
final Value rvalue = stmt.getRightOp();
// Handle simple subcase where you can use the efficient iinc bytecode
if (lvalue instanceof Local && (rvalue instanceof AddExpr || rvalue instanceof SubExpr)) {
Local l = (Local) lvalue;
BinopExpr expr = (BinopExpr) rvalue;
Value op1 = expr.getOp1();
Value op2 = expr.getOp2();
// more peephole stuff.
if (lvalue == plusPlusHolder) {
emitValue(lvalue);
plusPlusHolder = null;
plusPlusState = 0;
}
// end of peephole
if (IntType.v().equals(l.getType())) {
boolean isValidCase = false;
int x = 0;
if (op1 == l && op2 instanceof IntConstant) {
x = ((IntConstant) op2).value;
isValidCase = true;
} else if (expr instanceof AddExpr && op2 == l && op1 instanceof IntConstant) {
// Note expr can't be a SubExpr because that would be x = 3 - x
x = ((IntConstant) op1).value;
isValidCase = true;
}
if (isValidCase && x >= Short.MIN_VALUE && x <= Short.MAX_VALUE) {
emit("iinc " + localToSlot.get(l) + " " + ((expr instanceof AddExpr) ? x : -x), 0);
return;
}
}
}
lvalue.apply(new AbstractJimpleValueSwitch<Object>() {
@Override
public void caseArrayRef(ArrayRef v) {
emitValue(v.getBase());
emitValue(v.getIndex());
emitValue(rvalue);
v.getType().apply(new TypeSwitch<Object>() {
@Override
public void caseArrayType(ArrayType t) {
emit("aastore", -3);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dastore", -4);
}
@Override
public void caseFloatType(FloatType t) {
emit("fastore", -3);
}
@Override
public void caseIntType(IntType t) {
emit("iastore", -3);
}
@Override
public void caseLongType(LongType t) {
emit("lastore", -4);
}
@Override
public void caseRefType(RefType t) {
emit("aastore", -3);
}
@Override
public void caseByteType(ByteType t) {
emit("bastore", -3);
}
@Override
public void caseBooleanType(BooleanType t) {
emit("bastore", -3);
}
@Override
public void caseCharType(CharType t) {
emit("castore", -3);
}
@Override
public void caseShortType(ShortType t) {
emit("sastore", -3);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid type: " + t);
}
});
}
@Override
public void caseInstanceFieldRef(InstanceFieldRef v) {
emitValue(v.getBase());
emitValue(rvalue);
emit("putfield " + slashify(v.getFieldRef().declaringClass().getName()) + '/' + v.getFieldRef().name() + ' '
+ jasminDescriptorOf(v.getFieldRef().type()), -1 + -sizeOfType(v.getFieldRef().type()));
}
@Override
public void caseLocal(final Local v) {
final int slot = localToSlot.get(v);
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntegerType(IntegerType t) {
emitValue(rvalue);
if (slot >= 0 && slot <= 3) {
emit("istore_" + slot, -1);
} else {
emit("istore " + slot, -1);
}
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntegerType(t);
}
@Override
public void caseByteType(ByteType t) {
handleIntegerType(t);
}
@Override
public void caseShortType(ShortType t) {
handleIntegerType(t);
}
@Override
public void caseCharType(CharType t) {
handleIntegerType(t);
}
@Override
public void caseIntType(IntType t) {
handleIntegerType(t);
}
@Override
public void caseArrayType(ArrayType t) {
emitValue(rvalue);
if (slot >= 0 && slot <= 3) {
emit("astore_" + slot, -1);
} else {
emit("astore " + slot, -1);
}
}
@Override
public void caseDoubleType(DoubleType t) {
emitValue(rvalue);
if (slot >= 0 && slot <= 3) {
emit("dstore_" + slot, -2);
} else {
emit("dstore " + slot, -2);
}
}
@Override
public void caseFloatType(FloatType t) {
emitValue(rvalue);
if (slot >= 0 && slot <= 3) {
emit("fstore_" + slot, -1);
} else {
emit("fstore " + slot, -1);
}
}
@Override
public void caseLongType(LongType t) {
emitValue(rvalue);
if (slot >= 0 && slot <= 3) {
emit("lstore_" + slot, -2);
} else {
emit("lstore " + slot, -2);
}
}
@Override
public void caseRefType(RefType t) {
emitValue(rvalue);
if (slot >= 0 && slot <= 3) {
emit("astore_" + slot, -1);
} else {
emit("astore " + slot, -1);
}
}
@Override
public void caseStmtAddressType(StmtAddressType t) {
isNextGotoAJsr = true;
returnAddressSlot = slot;
/*
* if ( slot >= 0 && slot <= 3) emit("astore_" + slot, ); else emit("astore " + slot, );
*/
}
@Override
public void caseNullType(NullType t) {
emitValue(rvalue);
if (slot >= 0 && slot <= 3) {
emit("astore_" + slot, -1);
} else {
emit("astore " + slot, -1);
}
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid local type: " + t);
}
});
}
@Override
public void caseStaticFieldRef(StaticFieldRef v) {
SootFieldRef field = v.getFieldRef();
emitValue(rvalue);
emit("putstatic " + slashify(field.declaringClass().getName()) + '/' + field.name() + ' '
+ jasminDescriptorOf(field.type()), -sizeOfType(v.getFieldRef().type()));
}
});
}
void emitIfStmt(IfStmt stmt) {
Value cond = stmt.getCondition();
final Value op1 = ((BinopExpr) cond).getOp1();
final Value op2 = ((BinopExpr) cond).getOp2();
final String label = unitToLabel.get(stmt.getTarget());
// Handle simple subcase where op1 is null
if (op2 instanceof NullConstant || op1 instanceof NullConstant) {
if (op2 instanceof NullConstant) {
emitValue(op1);
} else {
emitValue(op2);
}
if (cond instanceof EqExpr) {
emit("ifnull " + label, -1);
} else if (cond instanceof NeExpr) {
emit("ifnonnull " + label, -1);
} else {
throw new RuntimeException("invalid condition");
}
return;
}
// Handle simple subcase where op2 is 0
if (op2 instanceof IntConstant && ((IntConstant) op2).value == 0) {
emitValue(op1);
cond.apply(new AbstractJimpleValueSwitch<Object>() {
@Override
public void caseEqExpr(EqExpr expr) {
emit("ifeq " + label, -1);
}
@Override
public void caseNeExpr(NeExpr expr) {
emit("ifne " + label, -1);
}
@Override
public void caseLtExpr(LtExpr expr) {
emit("iflt " + label, -1);
}
@Override
public void caseLeExpr(LeExpr expr) {
emit("ifle " + label, -1);
}
@Override
public void caseGtExpr(GtExpr expr) {
emit("ifgt " + label, -1);
}
@Override
public void caseGeExpr(GeExpr expr) {
emit("ifge " + label, -1);
}
});
return;
}
// Handle simple subcase where op1 is 0 (flip directions)
if (op1 instanceof IntConstant && ((IntConstant) op1).value == 0) {
emitValue(op2);
cond.apply(new AbstractJimpleValueSwitch<Object>() {
@Override
public void caseEqExpr(EqExpr expr) {
emit("ifeq " + label, -1);
}
@Override
public void caseNeExpr(NeExpr expr) {
emit("ifne " + label, -1);
}
@Override
public void caseLtExpr(LtExpr expr) {
emit("ifgt " + label, -1);
}
@Override
public void caseLeExpr(LeExpr expr) {
emit("ifge " + label, -1);
}
@Override
public void caseGtExpr(GtExpr expr) {
emit("iflt " + label, -1);
}
@Override
public void caseGeExpr(GeExpr expr) {
emit("ifle " + label, -1);
}
});
return;
}
emitValue(op1);
emitValue(op2);
cond.apply(new AbstractJimpleValueSwitch<Object>() {
@Override
public void caseEqExpr(EqExpr expr) {
op1.getType().apply(new TypeSwitch<Object>() {
@Override
public void caseIntType(IntType t) {
emit("if_icmpeq " + label, -2);
}
@Override
public void caseBooleanType(BooleanType t) {
emit("if_icmpeq " + label, -2);
}
@Override
public void caseShortType(ShortType t) {
emit("if_icmpeq " + label, -2);
}
@Override
public void caseCharType(CharType t) {
emit("if_icmpeq " + label, -2);
}
@Override
public void caseByteType(ByteType t) {
emit("if_icmpeq " + label, -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emit("ifeq " + label, -1);
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emit("ifeq " + label, -1);
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emit("ifeq " + label, -1);
}
@Override
public void caseArrayType(ArrayType t) {
emit("if_acmpeq " + label, -2);
}
@Override
public void caseRefType(RefType t) {
emit("if_acmpeq " + label, -2);
}
@Override
public void caseNullType(NullType t) {
emit("if_acmpeq " + label, -2);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseNeExpr(NeExpr expr) {
op1.getType().apply(new TypeSwitch<Object>() {
@Override
public void caseIntType(IntType t) {
emit("if_icmpne " + label, -2);
}
@Override
public void caseBooleanType(BooleanType t) {
emit("if_icmpne " + label, -2);
}
@Override
public void caseShortType(ShortType t) {
emit("if_icmpne " + label, -2);
}
@Override
public void caseCharType(CharType t) {
emit("if_icmpne " + label, -2);
}
@Override
public void caseByteType(ByteType t) {
emit("if_icmpne " + label, -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emit("ifne " + label, -1);
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emit("ifne " + label, -1);
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emit("ifne " + label, -1);
}
@Override
public void caseArrayType(ArrayType t) {
emit("if_acmpne " + label, -2);
}
@Override
public void caseRefType(RefType t) {
emit("if_acmpne " + label, -2);
}
@Override
public void caseNullType(NullType t) {
emit("if_acmpne " + label, -2);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type for NeExpr: " + t);
}
});
}
@Override
public void caseLtExpr(LtExpr expr) {
op1.getType().apply(new TypeSwitch<Object>() {
@Override
public void caseIntType(IntType t) {
emit("if_icmplt " + label, -2);
}
@Override
public void caseBooleanType(BooleanType t) {
emit("if_icmplt " + label, -2);
}
@Override
public void caseShortType(ShortType t) {
emit("if_icmplt " + label, -2);
}
@Override
public void caseCharType(CharType t) {
emit("if_icmplt " + label, -2);
}
@Override
public void caseByteType(ByteType t) {
emit("if_icmplt " + label, -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emit("iflt " + label, -1);
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emit("iflt " + label, -1);
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emit("iflt " + label, -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseLeExpr(LeExpr expr) {
op1.getType().apply(new TypeSwitch<Object>() {
@Override
public void caseIntType(IntType t) {
emit("if_icmple " + label, -2);
}
@Override
public void caseBooleanType(BooleanType t) {
emit("if_icmple " + label, -2);
}
@Override
public void caseShortType(ShortType t) {
emit("if_icmple " + label, -2);
}
@Override
public void caseCharType(CharType t) {
emit("if_icmple " + label, -2);
}
@Override
public void caseByteType(ByteType t) {
emit("if_icmple " + label, -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emit("ifle " + label, -1);
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emit("ifle " + label, -1);
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emit("ifle " + label, -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseGtExpr(GtExpr expr) {
op1.getType().apply(new TypeSwitch<Object>() {
@Override
public void caseIntType(IntType t) {
emit("if_icmpgt " + label, -2);
}
@Override
public void caseBooleanType(BooleanType t) {
emit("if_icmpgt " + label, -2);
}
@Override
public void caseShortType(ShortType t) {
emit("if_icmpgt " + label, -2);
}
@Override
public void caseCharType(CharType t) {
emit("if_icmpgt " + label, -2);
}
@Override
public void caseByteType(ByteType t) {
emit("if_icmpgt " + label, -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emit("ifgt " + label, -1);
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emit("ifgt " + label, -1);
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emit("ifgt " + label, -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseGeExpr(GeExpr expr) {
op1.getType().apply(new TypeSwitch<Object>() {
@Override
public void caseIntType(IntType t) {
emit("if_icmpge " + label, -2);
}
@Override
public void caseBooleanType(BooleanType t) {
emit("if_icmpge " + label, -2);
}
@Override
public void caseShortType(ShortType t) {
emit("if_icmpge " + label, -2);
}
@Override
public void caseCharType(CharType t) {
emit("if_icmpge " + label, -2);
}
@Override
public void caseByteType(ByteType t) {
emit("if_icmpge " + label, -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emit("ifge " + label, -1);
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emit("ifge " + label, -1);
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emit("ifge " + label, -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
});
}
void emitStmt(Stmt stmt) {
LineNumberTag lnTag = (LineNumberTag) stmt.getTag(LineNumberTag.NAME);
if (lnTag != null) {
emit(".line " + lnTag.getLineNumber());
}
stmt.apply(new AbstractStmtSwitch<Object>() {
@Override
public void caseAssignStmt(AssignStmt s) {
emitAssignStmt(s);
}
@Override
public void caseIdentityStmt(IdentityStmt s) {
if (s.getRightOp() instanceof CaughtExceptionRef) {
Value leftOp = s.getLeftOp();
if (leftOp instanceof Local) {
// simulate the pushing of the exception onto the stack by the jvm
modifyStackHeight(1);
int slot = localToSlot.get((Local) leftOp);
if (slot >= 0 && slot <= 3) {
emit("astore_" + slot, -1);
} else {
emit("astore " + slot, -1);
}
}
}
}
@Override
public void caseBreakpointStmt(BreakpointStmt s) {
emit("breakpoint", 0);
}
@Override
public void caseInvokeStmt(InvokeStmt s) {
emitValue(s.getInvokeExpr());
Type returnType = ((InvokeExpr) s.getInvokeExpr()).getMethodRef().returnType();
if (!VoidType.v().equals(returnType)) {
// Need to do some cleanup because this value is not used.
if (sizeOfType(returnType) == 1) {
emit("pop", -1);
} else {
emit("pop2", -2);
}
}
}
@Override
public void caseEnterMonitorStmt(EnterMonitorStmt s) {
emitValue(s.getOp());
emit("monitorenter", -1);
}
@Override
public void caseExitMonitorStmt(ExitMonitorStmt s) {
emitValue(s.getOp());
emit("monitorexit", -1);
}
@Override
public void caseGotoStmt(GotoStmt s) {
if (isNextGotoAJsr) {
emit("jsr " + unitToLabel.get(s.getTarget()));
isNextGotoAJsr = false;
subroutineToReturnAddressSlot.put(s.getTarget(), returnAddressSlot);
} else {
emit("goto " + unitToLabel.get(s.getTarget()));
}
}
@Override
public void caseIfStmt(IfStmt s) {
emitIfStmt(s);
}
@Override
public void caseLookupSwitchStmt(LookupSwitchStmt s) {
emitValue(s.getKey());
emit("lookupswitch", -1);
List<Unit> targets = s.getTargets();
List<IntConstant> lookupValues = s.getLookupValues();
for (int i = 0; i < lookupValues.size(); i++) {
emit(" " + lookupValues.get(i) + " : " + unitToLabel.get(targets.get(i)));
}
emit(" default : " + unitToLabel.get(s.getDefaultTarget()));
}
@Override
public void caseNopStmt(NopStmt s) {
emit("nop", 0);
}
@Override
public void caseRetStmt(RetStmt s) {
emit("ret " + localToSlot.get(s.getStmtAddress()), 0);
}
@Override
public void caseReturnStmt(ReturnStmt s) {
Value returnValue = s.getOp();
emitValue(returnValue);
returnValue.getType().apply(new TypeSwitch<Object>() {
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid return type " + t.toString());
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dreturn", -2);
}
@Override
public void caseFloatType(FloatType t) {
emit("freturn", -1);
}
@Override
public void caseIntType(IntType t) {
emit("ireturn", -1);
}
@Override
public void caseByteType(ByteType t) {
emit("ireturn", -1);
}
@Override
public void caseShortType(ShortType t) {
emit("ireturn", -1);
}
@Override
public void caseCharType(CharType t) {
emit("ireturn", -1);
}
@Override
public void caseBooleanType(BooleanType t) {
emit("ireturn", -1);
}
@Override
public void caseLongType(LongType t) {
emit("lreturn", -2);
}
@Override
public void caseArrayType(ArrayType t) {
emit("areturn", -1);
}
@Override
public void caseRefType(RefType t) {
emit("areturn", -1);
}
@Override
public void caseNullType(NullType t) {
emit("areturn", -1);
}
});
}
@Override
public void caseReturnVoidStmt(ReturnVoidStmt s) {
emit("return", 0);
}
@Override
public void caseTableSwitchStmt(TableSwitchStmt s) {
emitValue(s.getKey());
emit("tableswitch " + s.getLowIndex() + " ; high = " + s.getHighIndex(), -1);
for (Unit t : s.getTargets()) {
emit(" " + unitToLabel.get(t));
}
emit("default : " + unitToLabel.get(s.getDefaultTarget()));
}
@Override
public void caseThrowStmt(ThrowStmt s) {
emitValue(s.getOp());
emit("athrow", -1);
}
});
}
/* try to pre-duplicate a local and fix-up its dup_xn parameter. */
/* if we find that we're unable to proceed, we swap the dup_xn */
/* for a store pl, load pl combination */
Value plusPlusValue;
Local plusPlusHolder;
int plusPlusState;
int plusPlusPlace;
int plusPlusHeight;
Stmt plusPlusIncrementer;
/* end of plusplus stuff. */
void emitLocal(final Local v) {
final int slot = localToSlot.get(v);
v.getType().apply(new TypeSwitch<Object>() {
@Override
public void caseArrayType(ArrayType t) {
if (slot >= 0 && slot <= 3) {
emit("aload_" + slot, 1);
} else {
emit("aload " + slot, 1);
}
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid local type to load" + t);
}
@Override
public void caseDoubleType(DoubleType t) {
if (slot >= 0 && slot <= 3) {
emit("dload_" + slot, 2);
} else {
emit("dload " + slot, 2);
}
}
@Override
public void caseFloatType(FloatType t) {
if (slot >= 0 && slot <= 3) {
emit("fload_" + slot, 1);
} else {
emit("fload " + slot, 1);
}
}
// add boolean, byte, short, and char type
@Override
public void caseBooleanType(BooleanType t) {
handleIntegerType(t);
}
@Override
public void caseByteType(ByteType t) {
handleIntegerType(t);
}
@Override
public void caseShortType(ShortType t) {
handleIntegerType(t);
}
@Override
public void caseCharType(CharType t) {
handleIntegerType(t);
}
@Override
public void caseIntType(IntType t) {
handleIntegerType(t);
}
// peephole stuff appears here.
public void handleIntegerType(IntegerType t) {
if (v.equals(plusPlusHolder)) {
switch (plusPlusState) {
case 0: {
// ok, we're called upon to emit the
// ++ target, whatever it was.
// now we need to emit a statement incrementing
// the correct value.
// actually, just remember the local to be incremented.
// here ppi is of the form ppv = pph + 1
plusPlusState = 1;
emitStmt(plusPlusIncrementer);
int diff = plusPlusHeight - currentStackHeight + 1;
if (diff > 0) {
code.set(plusPlusPlace, " dup_x" + diff);
}
plusPlusHolder = null;
// afterwards we have the value on the stack.
return;
}
case 1:
plusPlusHeight = currentStackHeight;
plusPlusHolder = null;
emitValue(plusPlusValue);
plusPlusPlace = code.size();
emit("dup", 1);
return;
case 10: {
// this time we have ppi of the form ppv = ppv + 1
plusPlusState = 11;
// logger.debug("ppV "+plusPlusValue);
// logger.debug("ppH "+plusPlusHolder);
// logger.debug("ppI "+plusPlusIncrementer);
plusPlusHolder = (Local) plusPlusValue;
emitStmt(plusPlusIncrementer);
int diff = plusPlusHeight - currentStackHeight + 1;
if (diff > 0 && plusPlusState == 11) {
code.set(plusPlusPlace, " dup_x" + diff);
}
plusPlusHolder = null;
// afterwards we have the value on the stack.
return;
}
case 11:
plusPlusHeight = currentStackHeight;
plusPlusHolder = null;
emitValue(plusPlusValue);
if (plusPlusState != 11) {
emit("dup", 1);
}
plusPlusPlace = code.size();
return;
}
}
if (slot >= 0 && slot <= 3) {
emit("iload_" + slot, 1);
} else {
emit("iload " + slot, 1);
}
}
// end of peephole stuff.
@Override
public void caseLongType(LongType t) {
if (slot >= 0 && slot <= 3) {
emit("lload_" + slot, 2);
} else {
emit("lload " + slot, 2);
}
}
@Override
public void caseRefType(RefType t) {
if (slot >= 0 && slot <= 3) {
emit("aload_" + slot, 1);
} else {
emit("aload " + slot, 1);
}
}
@Override
public void caseNullType(NullType t) {
if (slot >= 0 && slot <= 3) {
emit("aload_" + slot, 1);
} else {
emit("aload " + slot, 1);
}
}
});
}
void emitValue(Value value) {
value.apply(new AbstractGrimpValueSwitch<Object>() {
@Override
public void caseAddExpr(AddExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("iadd", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("ladd", -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dadd", -2);
}
@Override
public void caseFloatType(FloatType t) {
emit("fadd", -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for add");
}
});
}
@Override
public void caseAndExpr(AndExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("iand", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("land", -2);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for and");
}
});
}
@Override
public void caseArrayRef(ArrayRef v) {
emitValue(v.getBase());
emitValue(v.getIndex());
v.getType().apply(new TypeSwitch<Object>() {
@Override
public void caseArrayType(ArrayType ty) {
emit("aaload", -1);
}
@Override
public void caseBooleanType(BooleanType ty) {
emit("baload", -1);
}
@Override
public void caseByteType(ByteType ty) {
emit("baload", -1);
}
@Override
public void caseCharType(CharType ty) {
emit("caload", -1);
}
@Override
public void defaultCase(Type ty) {
throw new RuntimeException("invalid base type");
}
@Override
public void caseDoubleType(DoubleType ty) {
emit("daload", 0);
}
@Override
public void caseFloatType(FloatType ty) {
emit("faload", -1);
}
@Override
public void caseIntType(IntType ty) {
emit("iaload", -1);
}
@Override
public void caseLongType(LongType ty) {
emit("laload", 0);
}
@Override
public void caseNullType(NullType ty) {
emit("aaload", -1);
}
@Override
public void caseRefType(RefType ty) {
emit("aaload", -1);
}
@Override
public void caseShortType(ShortType ty) {
emit("saload", -1);
}
});
}
@Override
public void caseCastExpr(final CastExpr v) {
final Value op = v.getOp();
emitValue(op);
final Type toType = v.getCastType();
if (toType instanceof RefType) {
emit("checkcast " + slashify(toType.toString()), 0);
} else if (toType instanceof ArrayType) {
emit("checkcast " + jasminDescriptorOf(toType), 0);
} else {
op.getType().apply(new TypeSwitch<Object>() {
@Override
public void defaultCase(Type ty) {
throw new RuntimeException("invalid fromType " + op.getType());
}
@Override
public void caseDoubleType(DoubleType ty) {
if (IntType.v().equals(toType)) {
emit("d2i", -1);
} else if (LongType.v().equals(toType)) {
emit("d2l", 0);
} else if (FloatType.v().equals(toType)) {
emit("d2f", -1);
} else {
throw new RuntimeException("invalid toType from double: " + toType);
}
}
@Override
public void caseFloatType(FloatType ty) {
if (IntType.v().equals(toType)) {
emit("f2i", 0);
} else if (LongType.v().equals(toType)) {
emit("f2l", 1);
} else if (DoubleType.v().equals(toType)) {
emit("f2d", 1);
} else {
throw new RuntimeException("invalid toType from float: " + toType);
}
}
@Override
public void caseIntType(IntType ty) {
emitIntToTypeCast();
}
@Override
public void caseBooleanType(BooleanType ty) {
emitIntToTypeCast();
}
@Override
public void caseByteType(ByteType ty) {
emitIntToTypeCast();
}
@Override
public void caseCharType(CharType ty) {
emitIntToTypeCast();
}
@Override
public void caseShortType(ShortType ty) {
emitIntToTypeCast();
}
private void emitIntToTypeCast() {
if (ByteType.v().equals(toType)) {
emit("i2b", 0);
} else if (CharType.v().equals(toType)) {
emit("i2c", 0);
} else if (ShortType.v().equals(toType)) {
emit("i2s", 0);
} else if (FloatType.v().equals(toType)) {
emit("i2f", 0);
} else if (LongType.v().equals(toType)) {
emit("i2l", 1);
} else if (DoubleType.v().equals(toType)) {
emit("i2d", 1);
} else if (IntType.v().equals(toType)) {
// this shouldn't happen?
} else if (BooleanType.v().equals(toType)) {
// intentionally empty
} else {
throw new RuntimeException("invalid toType from int: " + toType + " " + v.toString());
}
}
@Override
public void caseLongType(LongType ty) {
if (IntType.v().equals(toType)) {
emit("l2i", -1);
} else if (FloatType.v().equals(toType)) {
emit("l2f", -1);
} else if (DoubleType.v().equals(toType)) {
emit("l2d", 0);
} else if (ByteType.v().equals(toType)) {
emit("l2i", -1);
emitIntToTypeCast();
} else if (ShortType.v().equals(toType)) {
emit("l2i", -1);
emitIntToTypeCast();
} else if (CharType.v().equals(toType)) {
emit("l2i", -1);
emitIntToTypeCast();
} else if (BooleanType.v().equals(toType)) {
emit("l2i", -1);
emitIntToTypeCast();
} else {
throw new RuntimeException("invalid toType from long: " + toType);
}
}
});
}
}
@Override
public void caseCmpExpr(CmpExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
emit("lcmp", -3);
}
@Override
public void caseCmpgExpr(CmpgExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
if (FloatType.v().equals(v.getOp1().getType())) {
emit("fcmpg", -1);
} else {
emit("dcmpg", -3);
}
}
@Override
public void caseCmplExpr(CmplExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
if (FloatType.v().equals(v.getOp1().getType())) {
emit("fcmpl", -1);
} else {
emit("dcmpl", -3);
}
}
@Override
public void caseDivExpr(DivExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("idiv", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("ldiv", -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("ddiv", -2);
}
@Override
public void caseFloatType(FloatType t) {
emit("fdiv", -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for div");
}
});
}
@Override
public void caseDoubleConstant(DoubleConstant v) {
double val = v.value;
if ((val == 0) && ((1.0 / val) > 0.0)) {
emit("dconst_0", 2);
} else if (val == 1) {
emit("dconst_1", 2);
} else {
emit("ldc2_w " + doubleToString(v), 2);
}
}
@Override
public void caseFloatConstant(FloatConstant v) {
float val = v.value;
if ((val == 0) && ((1.0f / val) > 0.0f)) {
emit("fconst_0", 1);
} else if (val == 1) {
emit("fconst_1", 1);
} else if (val == 2) {
emit("fconst_2", 1);
} else {
emit("ldc " + floatToString(v), 1);
}
}
@Override
public void caseInstanceFieldRef(InstanceFieldRef v) {
emitValue(v.getBase());
SootFieldRef field = v.getFieldRef();
emit("getfield " + slashify(field.declaringClass().getName()) + '/' + field.name() + ' '
+ jasminDescriptorOf(field.type()), -1 + sizeOfType(field.type()));
}
@Override
public void caseInstanceOfExpr(InstanceOfExpr v) {
emitValue(v.getOp());
Type checkType = v.getCheckType();
if (checkType instanceof RefType) {
emit("instanceof " + slashify(checkType.toString()), 0);
} else if (checkType instanceof ArrayType) {
emit("instanceof " + jasminDescriptorOf(checkType), 0);
}
}
@Override
public void caseIntConstant(IntConstant v) {
int val = v.value;
if (val == -1) {
emit("iconst_m1", 1);
} else if (val >= 0 && val <= 5) {
emit("iconst_" + val, 1);
} else if (val >= Byte.MIN_VALUE && val <= Byte.MAX_VALUE) {
emit("bipush " + val, 1);
} else if (val >= Short.MIN_VALUE && val <= Short.MAX_VALUE) {
emit("sipush " + val, 1);
} else {
emit("ldc " + v.toString(), 1);
}
}
@Override
public void caseInterfaceInvokeExpr(InterfaceInvokeExpr v) {
emitValue(v.getBase());
SootMethodRef m = v.getMethodRef();
for (int i = 0; i < m.parameterTypes().size(); i++) {
emitValue(v.getArg(i));
}
emit("invokeinterface " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m) + " "
+ (argCountOf(m) + 1), -(argCountOf(m) + 1) + sizeOfType(m.returnType()));
}
@Override
public void caseLengthExpr(LengthExpr v) {
emitValue(v.getOp());
emit("arraylength", 0);
}
@Override
public void caseLocal(Local v) {
emitLocal(v);
}
@Override
public void caseLongConstant(LongConstant v) {
long val = v.value;
if (val == 0) {
emit("lconst_0", 2);
} else if (val == 1) {
emit("lconst_1", 2);
} else {
emit("ldc2_w " + v.toString(), 2);
}
}
@Override
public void caseMulExpr(MulExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("imul", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lmul", -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dmul", -2);
}
@Override
public void caseFloatType(FloatType t) {
emit("fmul", -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for mul");
}
});
}
@Override
public void caseLtExpr(LtExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getOp1().getType().apply(new TypeSwitch<Object>() {
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emitBooleanBranch("iflt");
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emitBooleanBranch("iflt");
}
private void handleIntCase() {
emit("if_icmplt", -2);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emitBooleanBranch("iflt");
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseLeExpr(LeExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getOp1().getType().apply(new TypeSwitch<Object>() {
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emitBooleanBranch("ifle");
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emitBooleanBranch("ifle");
}
private void handleIntCase() {
emit("if_icmple", -2);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emitBooleanBranch("ifle");
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseGtExpr(GtExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getOp1().getType().apply(new TypeSwitch<Object>() {
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emitBooleanBranch("ifgt");
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emitBooleanBranch("ifgt");
}
private void handleIntCase() {
emit("if_icmpgt", -2);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emitBooleanBranch("ifgt");
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseGeExpr(GeExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getOp1().getType().apply(new TypeSwitch<Object>() {
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emitBooleanBranch("ifge");
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emitBooleanBranch("ifge");
}
private void handleIntCase() {
emit("if_icmpge", -2);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emitBooleanBranch("ifge");
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseNeExpr(NeExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getOp1().getType().apply(new TypeSwitch<Object>() {
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emit("iconst_0", 1);
emitBooleanBranch("if_icmpne");
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -1);
emit("iconst_0", 1);
emitBooleanBranch("if_icmpne");
}
private void handleIntCase() {
emit("if_icmpne", -2);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emit("iconst_0", 1);
emitBooleanBranch("if_icmpne");
}
@Override
public void caseArrayType(ArrayType t) {
emitBooleanBranch("if_acmpne");
}
@Override
public void caseRefType(RefType t) {
emitBooleanBranch("if_acmpne");
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseEqExpr(EqExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getOp1().getType().apply(new TypeSwitch<Object>() {
@Override
public void caseDoubleType(DoubleType t) {
emit("dcmpg", -3);
emit("iconst_0", 1);
emitBooleanBranch("if_icmpeq");
}
@Override
public void caseFloatType(FloatType t) {
emit("fcmpg", -3);
emit("iconst_0", 1);
emitBooleanBranch("if_icmpeq");
}
private void handleIntCase() {
emit("if_icmpeq", -2);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lcmp", -3);
emit("iconst_0", 1);
emitBooleanBranch("if_icmpeq");
}
@Override
public void caseArrayType(ArrayType t) {
emitBooleanBranch("if_acmpeq");
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("invalid type");
}
});
}
@Override
public void caseNegExpr(final NegExpr v) {
emitValue(v.getOp());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("ineg", 0);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lneg", 0);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dneg", 0);
}
@Override
public void caseFloatType(FloatType t) {
emit("fneg", 0);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for neg: " + t + ": " + v);
}
});
}
@Override
public void caseNewArrayExpr(NewArrayExpr v) {
emitValue(v.getSize());
Type baseType = v.getBaseType();
if (baseType instanceof RefType) {
emit("anewarray " + slashify(baseType.toString()), 0);
} else if (baseType instanceof ArrayType) {
emit("anewarray " + jasminDescriptorOf(baseType), 0);
} else {
emit("newarray " + baseType.toString(), 0);
}
}
@Override
public void caseNewMultiArrayExpr(NewMultiArrayExpr v) {
for (Value val : v.getSizes()) {
emitValue(val);
}
int size = v.getSizeCount();
emit("multianewarray " + jasminDescriptorOf(v.getBaseType()) + " " + size, -size + 1);
}
@Override
public void caseNewExpr(NewExpr v) {
emit("new " + slashify(v.getBaseType().toString()), 1);
}
@Override
public void caseNewInvokeExpr(NewInvokeExpr v) {
emit("new " + slashify(v.getBaseType().toString()), 1);
emit("dup", 1);
// emitValue(v.getBase());
// already on the stack
SootMethodRef m = v.getMethodRef();
for (int i = 0; i < m.parameterTypes().size(); i++) {
emitValue(v.getArg(i));
}
emit("invokespecial " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m),
-(argCountOf(m) + 1) + sizeOfType(m.returnType()));
}
@Override
public void caseNullConstant(NullConstant v) {
emit("aconst_null", 1);
}
@Override
public void caseOrExpr(OrExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("ior", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lor", -2);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for or");
}
});
}
@Override
public void caseRemExpr(RemExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("irem", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lrem", -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("drem", -2);
}
@Override
public void caseFloatType(FloatType t) {
emit("frem", -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for rem");
}
});
}
@Override
public void caseShlExpr(ShlExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("ishl", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lshl", -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for shl");
}
});
}
@Override
public void caseShrExpr(ShrExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("ishr", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lshr", -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for shr");
}
});
}
@Override
public void caseSpecialInvokeExpr(SpecialInvokeExpr v) {
emitValue(v.getBase());
SootMethodRef m = v.getMethodRef();
for (int i = 0; i < m.parameterTypes().size(); i++) {
emitValue(v.getArg(i));
}
emit("invokespecial " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m),
-(argCountOf(m) + 1) + sizeOfType(m.returnType()));
}
@Override
public void caseStaticInvokeExpr(StaticInvokeExpr v) {
SootMethodRef m = v.getMethodRef();
for (int i = 0; i < m.parameterTypes().size(); i++) {
emitValue(v.getArg(i));
}
emit("invokestatic " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m),
-(argCountOf(m)) + sizeOfType(m.returnType()));
}
@Override
public void caseStaticFieldRef(StaticFieldRef v) {
SootFieldRef field = v.getFieldRef();
emit("getstatic " + slashify(field.declaringClass().getName()) + "/" + field.name() + " "
+ jasminDescriptorOf(field.type()), sizeOfType(field.type()));
}
@Override
public void caseStringConstant(StringConstant v) {
emit("ldc " + v.toString(), 1);
}
@Override
public void caseClassConstant(ClassConstant v) {
emit("ldc " + v.toInternalString(), 1);
}
@Override
public void caseSubExpr(SubExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("isub", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lsub", -2);
}
@Override
public void caseDoubleType(DoubleType t) {
emit("dsub", -2);
}
@Override
public void caseFloatType(FloatType t) {
emit("fsub", -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for sub");
}
});
}
@Override
public void caseUshrExpr(UshrExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("iushr", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lushr", -1);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for ushr");
}
});
}
@Override
public void caseVirtualInvokeExpr(VirtualInvokeExpr v) {
emitValue(v.getBase());
SootMethodRef m = v.getMethodRef();
for (int i = 0; i < m.parameterTypes().size(); i++) {
emitValue(v.getArg(i));
}
emit("invokevirtual " + slashify(m.declaringClass().getName()) + "/" + m.name() + jasminDescriptorOf(m),
-(argCountOf(m) + 1) + sizeOfType(m.returnType()));
}
@Override
public void caseXorExpr(XorExpr v) {
emitValue(v.getOp1());
emitValue(v.getOp2());
v.getType().apply(new TypeSwitch<Object>() {
private void handleIntCase() {
emit("ixor", -1);
}
@Override
public void caseIntType(IntType t) {
handleIntCase();
}
@Override
public void caseBooleanType(BooleanType t) {
handleIntCase();
}
@Override
public void caseShortType(ShortType t) {
handleIntCase();
}
@Override
public void caseCharType(CharType t) {
handleIntCase();
}
@Override
public void caseByteType(ByteType t) {
handleIntCase();
}
@Override
public void caseLongType(LongType t) {
emit("lxor", -2);
}
@Override
public void defaultCase(Type t) {
throw new RuntimeException("Invalid argument type for xor");
}
});
}
});
}
public void emitBooleanBranch(String s) {
int count;
if (s.contains("icmp") || s.contains("acmp")) {
count = -2;
} else {
count = -1;
}
emit(s + " label" + labelCount, count);
emit("iconst_0", 1);
emit("goto label" + labelCount + 1, 0);
emit("label" + labelCount++ + ":");
emit("iconst_1", 1);
emit("label" + labelCount++ + ":");
}
}
| 80,442
| 25.97619
| 123
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/Jimple.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import soot.ArrayType;
import soot.ErroneousType;
import soot.G;
import soot.Immediate;
import soot.Local;
import soot.RefType;
import soot.Singletons;
import soot.SootClass;
import soot.SootFieldRef;
import soot.SootMethod;
import soot.SootMethodRef;
import soot.StmtAddressType;
import soot.Trap;
import soot.Type;
import soot.Unit;
import soot.UnitBox;
import soot.UnknownType;
import soot.Value;
import soot.ValueBox;
import soot.jimple.internal.ConditionExprBox;
import soot.jimple.internal.IdentityRefBox;
import soot.jimple.internal.ImmediateBox;
import soot.jimple.internal.InvokeExprBox;
import soot.jimple.internal.JAddExpr;
import soot.jimple.internal.JAndExpr;
import soot.jimple.internal.JArrayRef;
import soot.jimple.internal.JAssignStmt;
import soot.jimple.internal.JBreakpointStmt;
import soot.jimple.internal.JCastExpr;
import soot.jimple.internal.JCaughtExceptionRef;
import soot.jimple.internal.JCmpExpr;
import soot.jimple.internal.JCmpgExpr;
import soot.jimple.internal.JCmplExpr;
import soot.jimple.internal.JDivExpr;
import soot.jimple.internal.JDynamicInvokeExpr;
import soot.jimple.internal.JEnterMonitorStmt;
import soot.jimple.internal.JEqExpr;
import soot.jimple.internal.JExitMonitorStmt;
import soot.jimple.internal.JGeExpr;
import soot.jimple.internal.JGotoStmt;
import soot.jimple.internal.JGtExpr;
import soot.jimple.internal.JIdentityStmt;
import soot.jimple.internal.JIfStmt;
import soot.jimple.internal.JInstanceFieldRef;
import soot.jimple.internal.JInstanceOfExpr;
import soot.jimple.internal.JInterfaceInvokeExpr;
import soot.jimple.internal.JInvokeStmt;
import soot.jimple.internal.JLeExpr;
import soot.jimple.internal.JLengthExpr;
import soot.jimple.internal.JLookupSwitchStmt;
import soot.jimple.internal.JLtExpr;
import soot.jimple.internal.JMulExpr;
import soot.jimple.internal.JNeExpr;
import soot.jimple.internal.JNegExpr;
import soot.jimple.internal.JNewArrayExpr;
import soot.jimple.internal.JNewExpr;
import soot.jimple.internal.JNewMultiArrayExpr;
import soot.jimple.internal.JNopStmt;
import soot.jimple.internal.JOrExpr;
import soot.jimple.internal.JRemExpr;
import soot.jimple.internal.JRetStmt;
import soot.jimple.internal.JReturnStmt;
import soot.jimple.internal.JReturnVoidStmt;
import soot.jimple.internal.JShlExpr;
import soot.jimple.internal.JShrExpr;
import soot.jimple.internal.JSpecialInvokeExpr;
import soot.jimple.internal.JStaticInvokeExpr;
import soot.jimple.internal.JSubExpr;
import soot.jimple.internal.JTableSwitchStmt;
import soot.jimple.internal.JThrowStmt;
import soot.jimple.internal.JTrap;
import soot.jimple.internal.JUshrExpr;
import soot.jimple.internal.JVirtualInvokeExpr;
import soot.jimple.internal.JXorExpr;
import soot.jimple.internal.JimpleLocal;
import soot.jimple.internal.JimpleLocalBox;
import soot.jimple.internal.RValueBox;
import soot.jimple.internal.StmtBox;
import soot.jimple.internal.VariableBox;
/**
* The Jimple class contains all the constructors for the components of the Jimple grammar for the Jimple body. <br>
* <br>
*
* Immediate -> Local | Constant <br>
* RValue -> Local | Constant | ConcreteRef | Expr<br>
* Variable -> Local | ArrayRef | InstanceFieldRef | StaticFieldRef <br>
*/
public class Jimple {
public Jimple(Singletons.Global g) {
}
public static Jimple v() {
return G.v().soot_jimple_Jimple();
}
public final static String NEWARRAY = "newarray";
public final static String NEWMULTIARRAY = "newmultiarray";
public final static String NOP = "nop";
public final static String RET = "ret";
public final static String SPECIALINVOKE = "specialinvoke";
public final static String DYNAMICINVOKE = "dynamicinvoke";
public final static String STATICINVOKE = "staticinvoke";
public final static String TABLESWITCH = "tableswitch";
public final static String VIRTUALINVOKE = "virtualinvoke";
public final static String NULL_TYPE = "null_type";
public final static String UNKNOWN = "unknown";
public final static String CMP = "cmp";
public final static String CMPG = "cmpg";
public final static String CMPL = "cmpl";
public final static String ENTERMONITOR = "entermonitor";
public final static String EXITMONITOR = "exitmonitor";
public final static String INTERFACEINVOKE = "interfaceinvoke";
public final static String LENGTHOF = "lengthof";
public final static String LOOKUPSWITCH = "lookupswitch";
public final static String NEG = "neg";
public final static String IF = "if";
public final static String ABSTRACT = "abstract";
public final static String BOOLEAN = "boolean";
public final static String BREAK = "break";
public final static String BYTE = "byte";
public final static String CASE = "case";
public final static String CATCH = "catch";
public final static String CHAR = "char";
public final static String CLASS = "class";
public final static String FINAL = "final";
public final static String NATIVE = "native";
public final static String PUBLIC = "public";
public final static String PROTECTED = "protected";
public final static String PRIVATE = "private";
public final static String STATIC = "static";
public final static String SYNCHRONIZED = "synchronized";
public final static String TRANSIENT = "transient";
public final static String VOLATILE = "volatile";
public final static String STRICTFP = "strictfp";
public final static String ENUM = "enum";
public final static String ANNOTATION = "annotation";
public final static String INTERFACE = "interface";
public final static String VOID = "void";
public final static String SHORT = "short";
public final static String INT = "int";
public final static String LONG = "long";
public final static String FLOAT = "float";
public final static String DOUBLE = "double";
public final static String EXTENDS = "extends";
public final static String IMPLEMENTS = "implements";
public final static String BREAKPOINT = "breakpoint";
public final static String DEFAULT = "default";
public final static String GOTO = "goto";
public final static String INSTANCEOF = "instanceof";
public final static String NEW = "new";
public final static String RETURN = "return";
public final static String THROW = "throw";
public final static String THROWS = "throws";
public final static String NULL = "null";
public final static String FROM = "from";
public final static String TO = "to";
public final static String WITH = "with";
public final static String CLS = "cls";
public final static String TRUE = "true";
public final static String FALSE = "false";
public static List<String> jimpleKeywordList() {
List<String> l = new LinkedList<String>();
Collections.addAll(l, NEWARRAY, NEWMULTIARRAY, NOP, RET, SPECIALINVOKE, STATICINVOKE, TABLESWITCH, VIRTUALINVOKE,
NULL_TYPE, UNKNOWN, CMP, CMPG, CMPL, ENTERMONITOR, EXITMONITOR, INTERFACEINVOKE, LENGTHOF, LOOKUPSWITCH, NEG, IF,
ABSTRACT, BOOLEAN, BREAK, BYTE, CASE, CATCH, CHAR, CLASS, FINAL, NATIVE, PUBLIC, PROTECTED, PRIVATE, STATIC,
SYNCHRONIZED, TRANSIENT, VOLATILE, STRICTFP, ENUM, ANNOTATION, INTERFACE, VOID, SHORT, INT, LONG, FLOAT, DOUBLE,
EXTENDS, IMPLEMENTS, BREAKPOINT, DEFAULT, GOTO, INSTANCEOF, NEW, RETURN, THROW, THROWS, NULL, FROM, TO, WITH, CLS,
TRUE, FALSE);
return l;
}
public static boolean isJavaKeywordType(Type t) {
return !(t instanceof StmtAddressType || t instanceof UnknownType || t instanceof RefType
|| (t instanceof ArrayType && (!isJavaKeywordType(((ArrayType) t).baseType))) || t instanceof ErroneousType);
}
public static Value cloneIfNecessary(Value val) {
if (val instanceof Immediate) {
return val;
} else {
return (Value) val.clone();
}
}
/**
* Constructs a XorExpr(Immediate, Immediate) grammar chunk.
*/
public XorExpr newXorExpr(Value op1, Value op2) {
return new JXorExpr(op1, op2);
}
/**
* Constructs a UshrExpr(Immediate, Immediate) grammar chunk.
*/
public UshrExpr newUshrExpr(Value op1, Value op2) {
return new JUshrExpr(op1, op2);
}
/**
* Constructs a SubExpr(Immediate, Immediate) grammar chunk.
*/
public SubExpr newSubExpr(Value op1, Value op2) {
return new JSubExpr(op1, op2);
}
/**
* Constructs a ShrExpr(Immediate, Immediate) grammar chunk.
*/
public ShrExpr newShrExpr(Value op1, Value op2) {
return new JShrExpr(op1, op2);
}
/**
* Constructs a ShlExpr(Immediate, Immediate) grammar chunk.
*/
public ShlExpr newShlExpr(Value op1, Value op2) {
return new JShlExpr(op1, op2);
}
/**
* Constructs a RemExpr(Immediate, Immediate) grammar chunk.
*/
public RemExpr newRemExpr(Value op1, Value op2) {
return new JRemExpr(op1, op2);
}
/**
* Constructs a OrExpr(Immediate, Immediate) grammar chunk.
*/
public OrExpr newOrExpr(Value op1, Value op2) {
return new JOrExpr(op1, op2);
}
/**
* Constructs a NeExpr(Immediate, Immediate) grammar chunk.
*/
public NeExpr newNeExpr(Value op1, Value op2) {
return new JNeExpr(op1, op2);
}
/**
* Constructs a MulExpr(Immediate, Immediate) grammar chunk.
*/
public MulExpr newMulExpr(Value op1, Value op2) {
return new JMulExpr(op1, op2);
}
/**
* Constructs a LeExpr(Immediate, Immediate) grammar chunk.
*/
public LeExpr newLeExpr(Value op1, Value op2) {
return new JLeExpr(op1, op2);
}
/**
* Constructs a GeExpr(Immediate, Immediate) grammar chunk.
*/
public GeExpr newGeExpr(Value op1, Value op2) {
return new JGeExpr(op1, op2);
}
/**
* Constructs a EqExpr(Immediate, Immediate) grammar chunk.
*/
public EqExpr newEqExpr(Value op1, Value op2) {
return new JEqExpr(op1, op2);
}
/**
* Constructs a DivExpr(Immediate, Immediate) grammar chunk.
*/
public DivExpr newDivExpr(Value op1, Value op2) {
return new JDivExpr(op1, op2);
}
/**
* Constructs a CmplExpr(Immediate, Immediate) grammar chunk.
*/
public CmplExpr newCmplExpr(Value op1, Value op2) {
return new JCmplExpr(op1, op2);
}
/**
* Constructs a CmpgExpr(Immediate, Immediate) grammar chunk.
*/
public CmpgExpr newCmpgExpr(Value op1, Value op2) {
return new JCmpgExpr(op1, op2);
}
/**
* Constructs a CmpExpr(Immediate, Immediate) grammar chunk.
*/
public CmpExpr newCmpExpr(Value op1, Value op2) {
return new JCmpExpr(op1, op2);
}
/**
* Constructs a GtExpr(Immediate, Immediate) grammar chunk.
*/
public GtExpr newGtExpr(Value op1, Value op2) {
return new JGtExpr(op1, op2);
}
/**
* Constructs a LtExpr(Immediate, Immediate) grammar chunk.
*/
public LtExpr newLtExpr(Value op1, Value op2) {
return new JLtExpr(op1, op2);
}
/**
* Constructs a AddExpr(Immediate, Immediate) grammar chunk.
*/
public AddExpr newAddExpr(Value op1, Value op2) {
return new JAddExpr(op1, op2);
}
/**
* Constructs a AndExpr(Immediate, Immediate) grammar chunk.
*/
public AndExpr newAndExpr(Value op1, Value op2) {
return new JAndExpr(op1, op2);
}
/**
* Constructs a NegExpr(Immediate, Immediate) grammar chunk.
*/
public NegExpr newNegExpr(Value op) {
return new JNegExpr(op);
}
/**
* Constructs a LengthExpr(Immediate) grammar chunk.
*/
public LengthExpr newLengthExpr(Value op) {
return new JLengthExpr(op);
}
/**
* Constructs a CastExpr(Immediate, Type) grammar chunk.
*/
public CastExpr newCastExpr(Value op1, Type t) {
return new JCastExpr(op1, t);
}
/**
* Constructs a InstanceOfExpr(Immediate, Type) grammar chunk.
*/
public InstanceOfExpr newInstanceOfExpr(Value op1, Type t) {
return new JInstanceOfExpr(op1, t);
}
/**
* Constructs a NewExpr(RefType) grammar chunk.
*/
public NewExpr newNewExpr(RefType type) {
return new JNewExpr(type);
}
/**
* Constructs a NewArrayExpr(Type, Immediate) grammar chunk.
*/
public NewArrayExpr newNewArrayExpr(Type type, Value size) {
return new JNewArrayExpr(type, size);
}
/**
* Constructs a NewMultiArrayExpr(ArrayType, List of Immediate) grammar chunk.
*/
public NewMultiArrayExpr newNewMultiArrayExpr(ArrayType type, List<? extends Value> sizes) {
return new JNewMultiArrayExpr(type, sizes);
}
/**
* Constructs a NewStaticInvokeExpr(ArrayType, List of Immediate) grammar chunk.
*/
public StaticInvokeExpr newStaticInvokeExpr(SootMethodRef method, List<? extends Value> args) {
return new JStaticInvokeExpr(method, args);
}
public StaticInvokeExpr newStaticInvokeExpr(SootMethodRef method, Value... args) {
return newStaticInvokeExpr(method, Arrays.asList(args));
}
public StaticInvokeExpr newStaticInvokeExpr(SootMethodRef method, Value arg) {
return newStaticInvokeExpr(method, Collections.singletonList(arg));
}
public StaticInvokeExpr newStaticInvokeExpr(SootMethodRef method) {
return newStaticInvokeExpr(method, Collections.<Value>emptyList());
}
/**
* Constructs a NewSpecialInvokeExpr(Local base, SootMethodRef method, List of Immediate) grammar chunk.
*/
public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method, List<? extends Value> args) {
return new JSpecialInvokeExpr(base, method, args);
}
/**
* Constructs a NewSpecialInvokeExpr(Local base, SootMethodRef method, List of Immediate) grammar chunk.
*/
public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method, Value... args) {
return newSpecialInvokeExpr(base, method, Arrays.asList(args));
}
public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method, Value arg) {
return newSpecialInvokeExpr(base, method, Collections.<Value>singletonList(arg));
}
public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method) {
return newSpecialInvokeExpr(base, method, Collections.<Value>emptyList());
}
/**
* Constructs a NewDynamicInvokeExpr(SootMethodRef bootstrapMethodRef, List bootstrapArgs, SootMethodRef methodRef, List
* args) grammar chunk.
*/
public DynamicInvokeExpr newDynamicInvokeExpr(SootMethodRef bootstrapMethodRef, List<? extends Value> bootstrapArgs,
SootMethodRef methodRef, List<? extends Value> args) {
return new JDynamicInvokeExpr(bootstrapMethodRef, bootstrapArgs, methodRef, args);
}
/**
* Constructs a NewDynamicInvokeExpr(SootMethodRef bootstrapMethodRef, List bootstrapArgs, SootMethodRef methodRef, List
* args) grammar chunk.
*/
public DynamicInvokeExpr newDynamicInvokeExpr(SootMethodRef bootstrapMethodRef, List<? extends Value> bootstrapArgs,
SootMethodRef methodRef, int tag, List<? extends Value> args) {
return new JDynamicInvokeExpr(bootstrapMethodRef, bootstrapArgs, methodRef, tag, args);
}
/**
* Constructs a NewVirtualInvokeExpr(Local base, SootMethodRef method, List of Immediate) grammar chunk.
*/
public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethodRef method, List<? extends Value> args) {
return new JVirtualInvokeExpr(base, method, args);
}
/**
* Constructs a NewVirtualInvokeExpr(Local base, SootMethodRef method, List of Immediate) grammar chunk.
*/
public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethodRef method, Value... args) {
return newVirtualInvokeExpr(base, method, Arrays.asList(args));
}
public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethodRef method, Value arg) {
return newVirtualInvokeExpr(base, method, Collections.<Value>singletonList(arg));
}
public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethodRef method) {
return newVirtualInvokeExpr(base, method, Collections.<Value>emptyList());
}
/**
* Constructs a NewInterfaceInvokeExpr(Local base, SootMethodRef method, List of Immediate) grammar chunk.
*/
public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethodRef method, List<? extends Value> args) {
return new JInterfaceInvokeExpr(base, method, args);
}
/**
* Constructs a NewInterfaceInvokeExpr(Local base, SootMethodRef method, List of Immediate) grammar chunk.
*/
public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethodRef method, Value... args) {
return newInterfaceInvokeExpr(base, method, Arrays.asList(args));
}
public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethodRef method, Value arg) {
return newInterfaceInvokeExpr(base, method, Collections.<Value>singletonList(arg));
}
public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethodRef method) {
return newInterfaceInvokeExpr(base, method, Collections.<Value>emptyList());
}
/**
* Constructs a ThrowStmt(Immediate) grammar chunk.
*/
public ThrowStmt newThrowStmt(Value op) {
return new JThrowStmt(op);
}
/**
* Constructs a ExitMonitorStmt(Immediate) grammar chunk
*/
public ExitMonitorStmt newExitMonitorStmt(Value op) {
return new JExitMonitorStmt(op);
}
/**
* Constructs a EnterMonitorStmt(Immediate) grammar chunk.
*/
public EnterMonitorStmt newEnterMonitorStmt(Value op) {
return new JEnterMonitorStmt(op);
}
/**
* Constructs a BreakpointStmt() grammar chunk.
*/
public BreakpointStmt newBreakpointStmt() {
return new JBreakpointStmt();
}
/**
* Constructs a GotoStmt(Stmt) grammar chunk.
*/
public GotoStmt newGotoStmt(Unit target) {
return new JGotoStmt(target);
}
public GotoStmt newGotoStmt(UnitBox stmtBox) {
return new JGotoStmt(stmtBox);
}
/**
* Constructs a NopStmt() grammar chunk.
*/
public NopStmt newNopStmt() {
return new JNopStmt();
}
/**
* Constructs a ReturnVoidStmt() grammar chunk.
*/
public ReturnVoidStmt newReturnVoidStmt() {
return new JReturnVoidStmt();
}
/**
* Constructs a ReturnStmt(Immediate) grammar chunk.
*/
public ReturnStmt newReturnStmt(Value op) {
return new JReturnStmt(op);
}
/**
* Constructs a RetStmt(Local) grammar chunk.
*/
public RetStmt newRetStmt(Value stmtAddress) {
return new JRetStmt(stmtAddress);
}
/**
* Constructs a IfStmt(Condition, Stmt) grammar chunk.
*/
public IfStmt newIfStmt(Value condition, Unit target) {
return new JIfStmt(condition, target);
}
/**
* Constructs a IfStmt(Condition, UnitBox) grammar chunk.
*/
public IfStmt newIfStmt(Value condition, UnitBox target) {
return new JIfStmt(condition, target);
}
/**
* Constructs a IdentityStmt(Local, IdentityRef) grammar chunk.
*/
public IdentityStmt newIdentityStmt(Value local, Value identityRef) {
return new JIdentityStmt(local, identityRef);
}
/**
* Constructs a AssignStmt(Variable, RValue) grammar chunk.
*/
public AssignStmt newAssignStmt(Value variable, Value rvalue) {
return new JAssignStmt(variable, rvalue);
}
/**
* Constructs a InvokeStmt(InvokeExpr) grammar chunk.
*/
public InvokeStmt newInvokeStmt(Value op) {
return new JInvokeStmt(op);
}
/**
* Constructs a TableSwitchStmt(Immediate, int, int, List of Unit, Stmt) grammar chunk.
*/
public TableSwitchStmt newTableSwitchStmt(Value key, int lowIndex, int highIndex, List<? extends Unit> targets,
Unit defaultTarget) {
return new JTableSwitchStmt(key, lowIndex, highIndex, targets, defaultTarget);
}
public TableSwitchStmt newTableSwitchStmt(Value key, int lowIndex, int highIndex, List<? extends UnitBox> targets,
UnitBox defaultTarget) {
return new JTableSwitchStmt(key, lowIndex, highIndex, targets, defaultTarget);
}
/**
* Constructs a LookupSwitchStmt(Immediate, List of Immediate, List of Unit, Stmt) grammar chunk.
*/
public LookupSwitchStmt newLookupSwitchStmt(Value key, List<IntConstant> lookupValues, List<? extends Unit> targets,
Unit defaultTarget) {
return new JLookupSwitchStmt(key, lookupValues, targets, defaultTarget);
}
public LookupSwitchStmt newLookupSwitchStmt(Value key, List<IntConstant> lookupValues, List<? extends UnitBox> targets,
UnitBox defaultTarget) {
return new JLookupSwitchStmt(key, lookupValues, targets, defaultTarget);
}
/**
* Constructs a Local with the given name and type.
*/
public Local newLocal(String name, Type t) {
return new JimpleLocal(name, t);
}
/**
* Constructs a new JTrap for the given exception on the given Stmt range with the given Stmt handler.
*/
public Trap newTrap(SootClass exception, Unit beginStmt, Unit endStmt, Unit handlerStmt) {
return new JTrap(exception, beginStmt, endStmt, handlerStmt);
}
public Trap newTrap(SootClass exception, UnitBox beginStmt, UnitBox endStmt, UnitBox handlerStmt) {
return new JTrap(exception, beginStmt, endStmt, handlerStmt);
}
/**
* Constructs a StaticFieldRef(SootFieldRef) grammar chunk.
*/
public StaticFieldRef newStaticFieldRef(SootFieldRef f) {
return new StaticFieldRef(f);
}
/**
* Constructs a ThisRef(RefType) grammar chunk.
*/
public ThisRef newThisRef(RefType t) {
return new ThisRef(t);
}
/**
* Constructs a ParameterRef(SootMethod, int) grammar chunk.
*/
public ParameterRef newParameterRef(Type paramType, int number) {
return new ParameterRef(paramType, number);
}
/**
* Constructs a InstanceFieldRef(Local, SootFieldRef) grammar chunk.
*/
public InstanceFieldRef newInstanceFieldRef(Value base, SootFieldRef f) {
return new JInstanceFieldRef(base, f);
}
/**
* Constructs a CaughtExceptionRef() grammar chunk.
*/
public CaughtExceptionRef newCaughtExceptionRef() {
return new JCaughtExceptionRef();
}
/**
* Constructs a ArrayRef(Local, Immediate) grammar chunk.
*/
public ArrayRef newArrayRef(Value base, Value index) {
return new JArrayRef(base, index);
}
// Note: This is NOT used to create the variable box in JAssignStmt.
public ValueBox newVariableBox(Value value) {
return new VariableBox(value);
}
public ValueBox newLocalBox(Value value) {
return new JimpleLocalBox(value);
}
// Note: This is NOT used to create the rvalue box in JAssignStmt.
public ValueBox newRValueBox(Value value) {
return new RValueBox(value);
}
public ValueBox newImmediateBox(Value value) {
return new ImmediateBox(value);
}
public ValueBox newArgBox(Value value) {
return new ImmediateBox(value);
}
public ValueBox newIdentityRefBox(Value value) {
return new IdentityRefBox(value);
}
public ValueBox newConditionExprBox(Value value) {
return new ConditionExprBox(value);
}
public ValueBox newInvokeExprBox(Value value) {
return new InvokeExprBox(value);
}
public UnitBox newStmtBox(Unit unit) {
return new StmtBox((Stmt) unit);
}
/** Returns an empty JimpleBody associated with method m. */
public JimpleBody newBody(SootMethod m) {
return new JimpleBody(m);
}
/** Returns an empty JimpleBody with no associated method. */
public JimpleBody newBody() {
return new JimpleBody();
}
/*
* Uncomment these stubs to make it compile with old code using Soot that does not know about SootField/MethodRefs.
*/
/*
* public StaticFieldRef newStaticFieldRef(SootField f) { return newStaticFieldRef(f.makeRef()); }
*
* public InstanceFieldRef newInstanceFieldRef(Value base, SootField f) { return newInstanceFieldRef(base, f.makeRef()); }
*
* public StaticInvokeExpr newStaticInvokeExpr(SootMethod method, List args) { return newStaticInvokeExpr(method.makeRef(),
* args); }
*
* public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethod method, List args) { return
* newSpecialInvokeExpr(base, method.makeRef(), args); }
*
* public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethod method, List args) { return
* newVirtualInvokeExpr(base, method.makeRef(), args); }
*
* public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethod method, List args) { return
* newInterfaceInvokeExpr(base, method.makeRef(), args); }
*
* public StaticInvokeExpr newStaticInvokeExpr(SootMethod method) { return newStaticInvokeExpr(method.makeRef()); }
*
* public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethod method) { return newSpecialInvokeExpr(base,
* method.makeRef()); }
*
* public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethod method) { return newVirtualInvokeExpr(base,
* method.makeRef()); }
*
* public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethod method) { return newInterfaceInvokeExpr(base,
* method.makeRef()); }
*
* public StaticInvokeExpr newStaticInvokeExpr(SootMethod method, Value arg) { return newStaticInvokeExpr(method.makeRef(),
* arg); }
*
* public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethod method, Value arg) { return
* newSpecialInvokeExpr(base, method.makeRef(), arg); }
*
* public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethod method, Value arg) { return
* newVirtualInvokeExpr(base, method.makeRef(), arg); }
*
* public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethod method, Value arg) { return
* newInterfaceInvokeExpr(base, method.makeRef(), arg); }
*
* public StaticInvokeExpr newStaticInvokeExpr(SootMethod method, Value arg1, Value arg2) { return
* newStaticInvokeExpr(method.makeRef(), arg1, arg2); }
*
* public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethod method, Value arg1, Value arg2) { return
* newSpecialInvokeExpr(base, method.makeRef(), arg1, arg2); }
*
* public VirtualInvokeExpr newVirtualInvokeExpr(Local base, SootMethod method, Value arg1, Value arg2) { return
* newVirtualInvokeExpr(base, method.makeRef(), arg1, arg2); }
*
* public InterfaceInvokeExpr newInterfaceInvokeExpr(Local base, SootMethod method, Value arg1, Value arg2) { return
* newInterfaceInvokeExpr(base, method.makeRef(), arg1, arg2); }
*/
}
| 26,944
| 32.639201
| 125
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/JimpleBody.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.Body;
import soot.Local;
import soot.PatchingChain;
import soot.RefType;
import soot.SootClass;
import soot.SootMethod;
import soot.Type;
import soot.Unit;
import soot.jimple.validation.FieldRefValidator;
import soot.jimple.validation.IdentityStatementsValidator;
import soot.jimple.validation.IdentityValidator;
import soot.jimple.validation.InvokeArgumentValidator;
import soot.jimple.validation.JimpleTrapValidator;
import soot.jimple.validation.MethodValidator;
import soot.jimple.validation.NewValidator;
import soot.jimple.validation.ReturnStatementsValidator;
import soot.jimple.validation.TypesValidator;
import soot.options.Options;
import soot.util.Chain;
import soot.validation.BodyValidator;
import soot.validation.ValidationException;
/**
* Implementation of the Body class for the Jimple IR.
*/
public class JimpleBody extends StmtBody {
private static final Logger logger = LoggerFactory.getLogger(JimpleBody.class);
/**
* Lazy initialized array containing some validators in order to validate the JimpleBody.
*/
private static class LazyValidatorsSingleton {
static final BodyValidator[] V = new BodyValidator[] { IdentityStatementsValidator.v(), TypesValidator.v(),
ReturnStatementsValidator.v(), InvokeArgumentValidator.v(), FieldRefValidator.v(), NewValidator.v(),
JimpleTrapValidator.v(), IdentityValidator.v(), MethodValidator.v() /* InvokeValidator.v() */ };
private LazyValidatorsSingleton() {
}
}
/**
* Construct an empty JimpleBody
*
* @param m
*/
public JimpleBody(SootMethod m) {
super(m);
if (Options.v().verbose()) {
logger.debug("[" + getMethod().getName() + "] Constructing JimpleBody...");
}
}
/**
* Construct an extremely empty JimpleBody, for parsing into.
*/
public JimpleBody() {
}
/**
* Clones the current body, making deep copies of the contents.
*
* @return
*/
@Override
public Object clone() {
Body b = new JimpleBody(getMethodUnsafe());
b.importBodyContentsFrom(this);
return b;
}
/**
* Make sure that the JimpleBody is well formed. If not, throw an exception. Right now, performs only a handful of checks.
*/
@Override
public void validate() {
final List<ValidationException> exceptionList = new ArrayList<ValidationException>();
validate(exceptionList);
if (!exceptionList.isEmpty()) {
throw exceptionList.get(0);
}
}
/**
* Validates the jimple body and saves a list of all validation errors
*
* @param exceptionList
* the list of validation errors
*/
@Override
public void validate(List<ValidationException> exceptionList) {
super.validate(exceptionList);
final boolean runAllValidators = Options.v().debug() || Options.v().validate();
for (BodyValidator validator : LazyValidatorsSingleton.V) {
if (runAllValidators || validator.isBasicValidator()) {
validator.validate(this, exceptionList);
}
}
}
public void validateIdentityStatements() {
runValidation(IdentityStatementsValidator.v());
}
/**
* Inserts usual statements for handling this & parameters into body.
*/
public void insertIdentityStmts() {
insertIdentityStmts(getMethod().getDeclaringClass());
}
/**
* Inserts usual statements for handling this & parameters into body.
*
* @param declaringClass
* the class, which should be used for this references. Can be null for static methods
*/
public void insertIdentityStmts(SootClass declaringClass) {
final Jimple jimple = Jimple.v();
final PatchingChain<Unit> unitChain = this.getUnits();
final Chain<Local> localChain = this.getLocals();
Unit lastUnit = null;
// add this-ref before everything else
if (!getMethod().isStatic()) {
if (declaringClass == null) {
throw new IllegalArgumentException(
String.format("No declaring class given for method %s", method.getSubSignature()));
}
Local l = jimple.newLocal("this", RefType.v(declaringClass));
Stmt s = jimple.newIdentityStmt(l, jimple.newThisRef((RefType) l.getType()));
localChain.add(l);
unitChain.addFirst(s);
lastUnit = s;
}
int i = 0;
for (Type t : getMethod().getParameterTypes()) {
Local l = jimple.newLocal("parameter" + i, t);
Stmt s = jimple.newIdentityStmt(l, jimple.newParameterRef(l.getType(), i));
localChain.add(l);
if (lastUnit == null) {
unitChain.addFirst(s);
} else {
unitChain.insertAfter(s, lastUnit);
}
lastUnit = s;
i++;
}
}
/**
* Returns the first non-identity stmt in this body.
*
* @return
*/
public Stmt getFirstNonIdentityStmt() {
Unit r = null;
for (Unit u : getUnits()) {
r = u;
if (!(r instanceof IdentityStmt)) {
break;
}
}
if (r == null) {
throw new RuntimeException("no non-id statements!");
}
return (Stmt) r;
}
}
| 5,945
| 28.435644
| 124
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/JimpleMethodSource.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1999 Patrick Lam
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.Body;
import soot.MethodSource;
import soot.PackManager;
import soot.SootMethod;
import soot.jimple.parser.JimpleAST;
import soot.options.Options;
public class JimpleMethodSource implements MethodSource {
private static final Logger logger = LoggerFactory.getLogger(JimpleMethodSource.class);
JimpleAST mJimpleAST;
public JimpleMethodSource(JimpleAST aJimpleAST) {
mJimpleAST = aJimpleAST;
}
public Body getBody(SootMethod m, String phaseName) {
JimpleBody jb = (JimpleBody) mJimpleAST.getBody(m);
if (jb == null) {
throw new RuntimeException("Could not load body for method " + m.getSignature());
}
if (Options.v().verbose()) {
logger.debug("[" + m.getName() + "] Retrieving JimpleBody from AST...");
}
PackManager.v().getPack("jb").apply(jb);
return jb;
}
}
| 1,709
| 29
| 89
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/JimpleToBafContext.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.HashMap;
import java.util.Map;
import soot.Local;
import soot.Unit;
import soot.baf.BafBody;
public class JimpleToBafContext {
private final Map<Local, Local> jimpleLocalToBafLocal;
private BafBody bafBody;
private Unit mCurrentUnit;
/**
* An approximation of the local count is required in order to allocate a reasonably sized hash map.
*/
public JimpleToBafContext(int localCount) {
this.jimpleLocalToBafLocal = new HashMap<Local, Local>(localCount * 2 + 1, 0.7f);
}
public void setCurrentUnit(Unit u) {
this.mCurrentUnit = u;
}
public Unit getCurrentUnit() {
return this.mCurrentUnit;
}
public Local getBafLocalOfJimpleLocal(Local jimpleLocal) {
return this.jimpleLocalToBafLocal.get(jimpleLocal);
}
public void setBafLocalOfJimpleLocal(Local jimpleLocal, Local bafLocal) {
this.jimpleLocalToBafLocal.put(jimpleLocal, bafLocal);
}
public BafBody getBafBody() {
return this.bafBody;
}
public void setBafBody(BafBody bafBody) {
this.bafBody = bafBody;
}
}
| 1,883
| 26.304348
| 102
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/JimpleValueSwitch.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface JimpleValueSwitch extends ExprSwitch, ImmediateSwitch, RefSwitch {
}
| 915
| 32.925926
| 83
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/LeExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface LeExpr extends ConditionExpr {
}
| 879
| 31.592593
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/LengthExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface LengthExpr extends UnopExpr {
}
| 878
| 31.555556
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/LocalStmtPair.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Local;
public class LocalStmtPair {
Local local;
Stmt stmt;
public LocalStmtPair(Local local, Stmt stmt) {
this.local = local;
this.stmt = stmt;
}
public boolean equals(Object other) {
if (other instanceof LocalStmtPair && ((LocalStmtPair) other).local == this.local
&& ((LocalStmtPair) other).stmt == this.stmt) {
return true;
} else {
return false;
}
}
public int hashCode() {
return local.hashCode() * 101 + stmt.hashCode() + 17;
}
}
| 1,343
| 25.88
| 85
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/LongConstant.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.LongType;
import soot.Type;
import soot.util.Switch;
public class LongConstant extends ArithmeticConstant {
private static final long serialVersionUID = 1008501511477295944L;
public final long value;
public static final LongConstant ZERO = new LongConstant(0);
public static final LongConstant ONE = new LongConstant(1);
private LongConstant(long value) {
this.value = value;
}
public static LongConstant v(long value) {
if (value == 0) {
return ZERO;
}
if (value == 1) {
return ONE;
}
return new LongConstant(value);
}
@Override
public boolean equals(Object c) {
return c instanceof LongConstant && ((LongConstant) c).value == this.value;
}
/** Returns a hash code for this DoubleConstant object. */
@Override
public int hashCode() {
return (int) (value ^ (value >>> 32));
}
// PTC 1999/06/28
@Override
public NumericConstant add(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return LongConstant.v(this.value + ((LongConstant) c).value);
}
@Override
public NumericConstant subtract(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return LongConstant.v(this.value - ((LongConstant) c).value);
}
@Override
public NumericConstant multiply(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return LongConstant.v(this.value * ((LongConstant) c).value);
}
@Override
public NumericConstant divide(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return LongConstant.v(this.value / ((LongConstant) c).value);
}
@Override
public NumericConstant remainder(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return LongConstant.v(this.value % ((LongConstant) c).value);
}
@Override
public NumericConstant equalEqual(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return IntConstant.v((this.value == ((LongConstant) c).value) ? 1 : 0);
}
@Override
public NumericConstant notEqual(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return IntConstant.v((this.value != ((LongConstant) c).value) ? 1 : 0);
}
@Override
public boolean isLessThan(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return this.value < ((LongConstant) c).value;
}
@Override
public NumericConstant lessThan(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return IntConstant.v((this.value < ((LongConstant) c).value) ? 1 : 0);
}
@Override
public NumericConstant lessThanOrEqual(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return IntConstant.v((this.value <= ((LongConstant) c).value) ? 1 : 0);
}
@Override
public NumericConstant greaterThan(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return IntConstant.v((this.value > ((LongConstant) c).value) ? 1 : 0);
}
@Override
public NumericConstant greaterThanOrEqual(NumericConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return IntConstant.v((this.value >= ((LongConstant) c).value) ? 1 : 0);
}
public IntConstant cmp(LongConstant c) {
if (this.value > c.value) {
return IntConstant.v(1);
} else if (this.value == c.value) {
return IntConstant.v(0);
} else {
return IntConstant.v(-1);
}
}
@Override
public NumericConstant negate() {
return LongConstant.v(-(this.value));
}
@Override
public ArithmeticConstant and(ArithmeticConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return LongConstant.v(this.value & ((LongConstant) c).value);
}
@Override
public ArithmeticConstant or(ArithmeticConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return LongConstant.v(this.value | ((LongConstant) c).value);
}
@Override
public ArithmeticConstant xor(ArithmeticConstant c) {
if (!(c instanceof LongConstant)) {
throw new IllegalArgumentException("LongConstant expected");
}
return LongConstant.v(this.value ^ ((LongConstant) c).value);
}
@Override
public ArithmeticConstant shiftLeft(ArithmeticConstant c) {
// NOTE CAREFULLY: the RHS of a shift op is not (!)
// of Long type. It is, in fact, an IntConstant.
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return LongConstant.v(this.value << ((IntConstant) c).value);
}
@Override
public ArithmeticConstant shiftRight(ArithmeticConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return LongConstant.v(this.value >> ((IntConstant) c).value);
}
@Override
public ArithmeticConstant unsignedShiftRight(ArithmeticConstant c) {
if (!(c instanceof IntConstant)) {
throw new IllegalArgumentException("IntConstant expected");
}
return LongConstant.v(this.value >>> ((IntConstant) c).value);
}
@Override
public String toString() {
return Long.toString(value) + "L";
}
@Override
public Type getType() {
return LongType.v();
}
@Override
public void apply(Switch sw) {
((ConstantSwitch) sw).caseLongConstant(this);
}
}
| 7,010
| 28.091286
| 79
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/LookupSwitchStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.List;
import soot.Unit;
public interface LookupSwitchStmt extends SwitchStmt {
public void setLookupValues(List<IntConstant> lookupValues);
public void setLookupValue(int index, int value);
public int getLookupValue(int index);
public List<IntConstant> getLookupValues();
public int getTargetCount();
public void setTargets(Unit[] targets);
}
| 1,208
| 27.785714
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/LtExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface LtExpr extends ConditionExpr {
}
| 880
| 30.464286
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/MethodHandle.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 2005 - Jennifer Lhotak
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.Objects;
import org.objectweb.asm.Opcodes;
import soot.RefType;
import soot.SootFieldRef;
import soot.SootMethodRef;
import soot.Type;
import soot.util.Switch;
public class MethodHandle extends Constant {
private static final long serialVersionUID = -7948291265532721191L;
public static enum Kind {
REF_GET_FIELD(Opcodes.H_GETFIELD, "REF_GET_FIELD"),
REF_GET_FIELD_STATIC(Opcodes.H_GETSTATIC, "REF_GET_FIELD_STATIC"),
REF_PUT_FIELD(Opcodes.H_PUTFIELD, "REF_PUT_FIELD"),
REF_PUT_FIELD_STATIC(Opcodes.H_PUTSTATIC, "REF_PUT_FIELD_STATIC"),
REF_INVOKE_VIRTUAL(Opcodes.H_INVOKEVIRTUAL, "REF_INVOKE_VIRTUAL"),
REF_INVOKE_STATIC(Opcodes.H_INVOKESTATIC, "REF_INVOKE_STATIC"),
REF_INVOKE_SPECIAL(Opcodes.H_INVOKESPECIAL, "REF_INVOKE_SPECIAL"),
REF_INVOKE_CONSTRUCTOR(Opcodes.H_NEWINVOKESPECIAL, "REF_INVOKE_CONSTRUCTOR"),
REF_INVOKE_INTERFACE(Opcodes.H_INVOKEINTERFACE, "REF_INVOKE_INTERFACE");
private final int val;
private final String valStr;
private Kind(int val, String valStr) {
this.val = val;
this.valStr = valStr;
}
@Override
public String toString() {
return valStr;
}
public int getValue() {
return val;
}
public static Kind getKind(int kind) {
for (Kind k : Kind.values()) {
if (k.getValue() == kind) {
return k;
}
}
throw new RuntimeException("Error: No method handle kind for value '" + kind + "'.");
}
public static Kind getKind(String kind) {
for (Kind k : Kind.values()) {
if (k.toString().equals(kind)) {
return k;
}
}
throw new RuntimeException("Error: No method handle kind for value '" + kind + "'.");
}
}
protected final SootFieldRef fieldRef;
protected final SootMethodRef methodRef;
protected final int kind;
private MethodHandle(SootMethodRef ref, int kind) {
this.methodRef = ref;
this.kind = kind;
this.fieldRef = null;
}
private MethodHandle(SootFieldRef ref, int kind) {
this.fieldRef = ref;
this.kind = kind;
this.methodRef = null;
}
public static MethodHandle v(SootMethodRef ref, int kind) {
return new MethodHandle(ref, kind);
}
public static MethodHandle v(SootFieldRef ref, int kind) {
return new MethodHandle(ref, kind);
}
@Override
public String toString() {
return "methodhandle: \"" + getKindString() + "\" "
+ (methodRef == null ? Objects.toString(fieldRef) : Objects.toString(methodRef));
}
@Override
public Type getType() {
return RefType.v("java.lang.invoke.MethodHandle");
}
public SootMethodRef getMethodRef() {
return methodRef;
}
public SootFieldRef getFieldRef() {
return fieldRef;
}
public int getKind() {
return kind;
}
public String getKindString() {
return Kind.getKind(kind).toString();
}
public boolean isFieldRef() {
return isFieldRef(kind);
}
public static boolean isFieldRef(int kind) {
return kind == Kind.REF_GET_FIELD.getValue() || kind == Kind.REF_GET_FIELD_STATIC.getValue()
|| kind == Kind.REF_PUT_FIELD.getValue() || kind == Kind.REF_PUT_FIELD_STATIC.getValue();
}
public boolean isMethodRef() {
return isMethodRef(kind);
}
public static boolean isMethodRef(int kind) {
return kind == Kind.REF_INVOKE_VIRTUAL.getValue() || kind == Kind.REF_INVOKE_STATIC.getValue()
|| kind == Kind.REF_INVOKE_SPECIAL.getValue() || kind == Kind.REF_INVOKE_CONSTRUCTOR.getValue()
|| kind == Kind.REF_INVOKE_INTERFACE.getValue();
}
@Override
public void apply(Switch sw) {
((ConstantSwitch) sw).caseMethodHandle(this);
}
@Override
public int hashCode() {
final int prime = 17;
int result = 31;
result = prime * result + Objects.hashCode(methodRef);
result = prime * result + Objects.hashCode(fieldRef);
result = prime * result + kind;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
MethodHandle other = (MethodHandle) obj;
return Objects.equals(this.methodRef, other.methodRef) && Objects.equals(this.fieldRef, other.fieldRef);
}
}
| 5,118
| 26.972678
| 108
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/MethodType.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 2005 - Jennifer Lhotak
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import soot.RefType;
import soot.SootMethod;
import soot.Type;
import soot.util.Switch;
public class MethodType extends Constant {
private static final long serialVersionUID = 3523899677165980823L;
protected Type returnType;
protected List<Type> parameterTypes;
private MethodType(List<Type> parameterTypes, Type returnType) {
this.returnType = returnType;
this.parameterTypes = parameterTypes;
}
public static MethodType v(List<Type> paramaterTypes, Type returnType) {
return new MethodType(paramaterTypes, returnType);
}
@Override
public Type getType() {
return RefType.v("java.lang.invoke.MethodType");
}
@Override
public String toString() {
return "methodtype: " + SootMethod.getSubSignature("__METHODTYPE__", parameterTypes, returnType);
}
public List<Type> getParameterTypes() {
return parameterTypes == null ? Collections.<Type>emptyList() : parameterTypes;
}
public Type getReturnType() {
return returnType;
}
@Override
public void apply(Switch sw) {
((ConstantSwitch) sw).caseMethodType(this);
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(parameterTypes);
result = 31 * result + Objects.hashCode(returnType);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
MethodType other = (MethodType) obj;
return Objects.equals(returnType, other.returnType) && Objects.equals(parameterTypes, other.parameterTypes);
}
}
| 2,537
| 26.290323
| 112
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/MonitorStmt.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Value;
import soot.ValueBox;
public interface MonitorStmt extends Stmt {
public Value getOp();
public void setOp(Value op);
public ValueBox getOpBox();
}
| 1,004
| 27.714286
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/MulExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface MulExpr extends BinopExpr {
}
| 876
| 31.481481
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/NaiveSideEffectTester.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 2000 Patrick Lam
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.Iterator;
import soot.Local;
import soot.SideEffectTester;
import soot.SootMethod;
import soot.Unit;
import soot.Value;
import soot.ValueBox;
/**
* Provides naive side effect information. Relies on no context information; instead, does the least conservative thing
* possible even in the possible presence of badness.
*
* Possible weakness of SideEffectTester: consider a Box. We don't have a name for "what-is-inside-the-box" and so we can't
* ask questions about it. But perhaps we need only ask questions about the box itself; the side effect tester can deal with
* that internally.
*/
// ArrayRef,
// CaughtExceptionRef,
// FieldRef,
// IdentityRef,
// InstanceFieldRef,
// InstanceInvokeExpr,
// Local,
// StaticFieldRef
public class NaiveSideEffectTester implements SideEffectTester {
public void newMethod(SootMethod m) {
}
/**
* Returns true if the unit can read from v. Does not deal with expressions; deals with Refs.
*/
public boolean unitCanReadFrom(Unit u, Value v) {
Stmt s = (Stmt) u;
// This doesn't really make any sense, but we need to return something.
if (v instanceof Constant) {
return false;
}
if (v instanceof Expr) {
throw new RuntimeException("can't deal with expr");
}
// If it's an invoke, then only locals are safe.
if (s.containsInvokeExpr()) {
if (!(v instanceof Local)) {
return true;
}
}
// otherwise, use boxes tell all.
Iterator useIt = u.getUseBoxes().iterator();
while (useIt.hasNext()) {
Value use = (Value) useIt.next();
if (use.equivTo(v)) {
return true;
}
Iterator vUseIt = v.getUseBoxes().iterator();
while (vUseIt.hasNext()) {
if (use.equivTo(vUseIt.next())) {
return true;
}
}
}
return false;
}
public boolean unitCanWriteTo(Unit u, Value v) {
Stmt s = (Stmt) u;
if (v instanceof Constant) {
return false;
}
if (v instanceof Expr) {
throw new RuntimeException("can't deal with expr");
}
// If it's an invoke, then only locals are safe.
if (s.containsInvokeExpr()) {
if (!(v instanceof Local)) {
return true;
}
}
// otherwise, def boxes tell all.
Iterator defIt = u.getDefBoxes().iterator();
while (defIt.hasNext()) {
Value def = ((ValueBox) (defIt.next())).getValue();
Iterator useIt = v.getUseBoxes().iterator();
while (useIt.hasNext()) {
Value use = ((ValueBox) useIt.next()).getValue();
if (def.equivTo(use)) {
return true;
}
}
// also handle the container of all these useboxes!
if (def.equivTo(v)) {
return true;
}
// deal with aliasing - handle case where they
// are a read to the same field, regardless of
// base object.
if (v instanceof InstanceFieldRef && def instanceof InstanceFieldRef) {
if (((InstanceFieldRef) v).getField() == ((InstanceFieldRef) def).getField()) {
return true;
}
}
}
return false;
}
}
| 3,924
| 26.447552
| 124
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/NeExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface NeExpr extends ConditionExpr {
}
| 879
| 31.592593
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/NegExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
public interface NegExpr extends UnopExpr {
}
| 875
| 31.444444
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/NewArrayExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.Type;
import soot.Value;
import soot.ValueBox;
import soot.util.Switch;
public interface NewArrayExpr extends Expr, AnyNewExpr {
public Type getBaseType();
public void setBaseType(Type type);
public ValueBox getSizeBox();
public Value getSize();
public void setSize(Value size);
public Type getType();
public void apply(Switch sw);
}
| 1,196
| 25.6
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/NewExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import soot.RefType;
import soot.Type;
import soot.util.Switch;
public interface NewExpr extends Expr, AnyNewExpr {
public RefType getBaseType();
public void setBaseType(RefType type);
public Type getType();
public void apply(Switch sw);
}
| 1,081
| 27.473684
| 71
|
java
|
soot
|
soot-master/src/main/java/soot/jimple/NewMultiArrayExpr.java
|
package soot.jimple;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
import java.util.List;
import soot.ArrayType;
import soot.Type;
import soot.Value;
import soot.ValueBox;
import soot.util.Switch;
public interface NewMultiArrayExpr extends Expr, AnyNewExpr {
public ArrayType getBaseType();
public void setBaseType(ArrayType baseType);
public ValueBox getSizeBox(int index);
public int getSizeCount();
public Value getSize(int index);
public List<Value> getSizes();
public void setSize(int index, Value size);
public Type getType();
public void apply(Switch sw);
}
| 1,355
| 25.076923
| 71
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.