use of soot.SootField in project soot by Sable.
the class ConstantValueToInitializerTransformer method transformClass.
public void transformClass(SootClass sc) {
SootMethod smInit = null;
Set<SootField> alreadyInitialized = new HashSet<SootField>();
for (SootField sf : sc.getFields()) {
// different constructors might assign different values.
if (!sf.isStatic() || !sf.isFinal())
continue;
// generate a second one
if (alreadyInitialized.contains(sf))
continue;
// Look for constant values
for (Tag t : sf.getTags()) {
Stmt initStmt = null;
if (t instanceof DoubleConstantValueTag) {
double value = ((DoubleConstantValueTag) t).getDoubleValue();
initStmt = Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(sf.makeRef()), DoubleConstant.v(value));
} else if (t instanceof FloatConstantValueTag) {
float value = ((FloatConstantValueTag) t).getFloatValue();
initStmt = Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(sf.makeRef()), FloatConstant.v(value));
} else if (t instanceof IntegerConstantValueTag) {
int value = ((IntegerConstantValueTag) t).getIntValue();
initStmt = Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(sf.makeRef()), IntConstant.v(value));
} else if (t instanceof LongConstantValueTag) {
long value = ((LongConstantValueTag) t).getLongValue();
initStmt = Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(sf.makeRef()), LongConstant.v(value));
} else if (t instanceof StringConstantValueTag) {
String value = ((StringConstantValueTag) t).getStringValue();
initStmt = Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(sf.makeRef()), StringConstant.v(value));
}
if (initStmt != null) {
if (smInit == null)
smInit = getOrCreateInitializer(sc, alreadyInitialized);
if (smInit != null)
smInit.getActiveBody().getUnits().addFirst(initStmt);
}
}
}
if (smInit != null) {
Chain<Unit> units = smInit.getActiveBody().getUnits();
if (units.isEmpty() || !(units.getLast() instanceof ReturnVoidStmt))
units.add(Jimple.v().newReturnVoidStmt());
}
}
use of soot.SootField in project soot by Sable.
the class BadFields method handleMethod.
private void handleMethod(SootMethod m) {
if (!m.isConcrete())
return;
for (Iterator<ValueBox> bIt = m.retrieveActiveBody().getUseAndDefBoxes().iterator(); bIt.hasNext(); ) {
final ValueBox b = bIt.next();
Value v = b.getValue();
if (!(v instanceof StaticFieldRef))
continue;
StaticFieldRef sfr = (StaticFieldRef) v;
SootField f = sfr.getField();
if (!f.getDeclaringClass().getName().equals("java.lang.System"))
continue;
if (f.getName().equals("err")) {
logger.debug("" + "Use of System.err in " + m);
}
if (f.getName().equals("out")) {
logger.debug("" + "Use of System.out in " + m);
}
}
for (Iterator<Unit> sIt = m.getActiveBody().getUnits().iterator(); sIt.hasNext(); ) {
final Stmt s = (Stmt) sIt.next();
if (!s.containsInvokeExpr())
continue;
InvokeExpr ie = s.getInvokeExpr();
SootMethod target = ie.getMethod();
if (target.getDeclaringClass().getName().equals("java.lang.System") && target.getName().equals("exit")) {
warn("" + m + " calls System.exit");
}
}
if (m.getName().equals("<clinit>")) {
for (Iterator<Unit> sIt = m.getActiveBody().getUnits().iterator(); sIt.hasNext(); ) {
final Stmt s = (Stmt) sIt.next();
for (Iterator<ValueBox> bIt = s.getUseBoxes().iterator(); bIt.hasNext(); ) {
final ValueBox b = bIt.next();
Value v = b.getValue();
if (v instanceof FieldRef) {
warn(m.getName() + " reads field " + v);
}
}
if (!s.containsInvokeExpr())
continue;
InvokeExpr ie = s.getInvokeExpr();
SootMethod target = ie.getMethod();
calls(target);
}
}
}
use of soot.SootField in project soot by Sable.
the class BadFields method handleClass.
private void handleClass(SootClass cl) {
for (Iterator<SootField> fIt = cl.getFields().iterator(); fIt.hasNext(); ) {
final SootField f = fIt.next();
if (!f.isStatic())
continue;
String typeName = f.getType().toString();
if (typeName.equals("java.lang.Class"))
continue;
if (f.isFinal()) {
if (f.getType() instanceof PrimType)
continue;
if (typeName.equals("java.io.PrintStream"))
continue;
if (typeName.equals("java.lang.String"))
continue;
if (typeName.equals("java.lang.Object"))
continue;
if (typeName.equals("java.lang.Integer"))
continue;
if (typeName.equals("java.lang.Boolean"))
continue;
}
warn("Bad field " + f);
}
}
use of soot.SootField in project soot by Sable.
the class PointsToAnalysis method main.
public static void main(String[] args) {
loadClass("Item", false);
loadClass("Container", false);
SootClass c = loadClass(args[1], true);
soot.Scene.v().loadNecessaryClasses();
soot.Scene.v().setEntryPoints(EntryPoints.v().all());
if (args[0].equals("paddle"))
setPaddlePointsToAnalysis();
else if (args[0].equals("spark"))
setSparkPointsToAnalysis();
SootField f = getField("Container", "item");
Map /*<Local>*/
ls = getLocals(c, args[2], "Container");
printLocalIntersects(ls);
printFieldIntersects(ls, f);
}
use of soot.SootField in project soot by Sable.
the class DexField method makeSootField.
/**
* @return the Soot equivalent of a field
*/
public static SootField makeSootField(Field f) {
String name = f.getName();
Type type = DexType.toSoot(f.getType());
int flags = f.getAccessFlags();
SootField sf = Scene.v().makeSootField(name, type, flags);
if (Modifier.isFinal(flags))
DexField.addConstantTag(sf, f);
return sf;
}
Aggregations