use of soot.Body in project soot by Sable.
the class JimpleBasedInterproceduralCFG method initializeUnitToOwner.
public void initializeUnitToOwner(SootMethod m) {
if (m.hasActiveBody()) {
Body b = m.getActiveBody();
PatchingChain<Unit> units = b.getUnits();
for (Unit unit : units) {
unitToOwner.put(unit, b);
}
}
}
use of soot.Body in project soot by Sable.
the class ReflectionTraceInfo method inferSource.
private Set<SootMethod> inferSource(String source, int lineNumber) {
String className = source.substring(0, source.lastIndexOf("."));
String methodName = source.substring(source.lastIndexOf(".") + 1);
if (!Scene.v().containsClass(className)) {
Scene.v().addBasicClass(className, SootClass.BODIES);
Scene.v().loadBasicClasses();
if (!Scene.v().containsClass(className)) {
throw new RuntimeException("Trace file refers to unknown class: " + className);
}
}
SootClass sootClass = Scene.v().getSootClass(className);
Set<SootMethod> methodsWithRightName = new LinkedHashSet<SootMethod>();
for (SootMethod m : sootClass.getMethods()) {
if (m.isConcrete() && m.getName().equals(methodName)) {
methodsWithRightName.add(m);
}
}
if (methodsWithRightName.isEmpty()) {
throw new RuntimeException("Trace file refers to unknown method with name " + methodName + " in Class " + className);
} else if (methodsWithRightName.size() == 1) {
return Collections.singleton(methodsWithRightName.iterator().next());
} else {
// more than one method with that name
for (SootMethod sootMethod : methodsWithRightName) {
if (coversLineNumber(lineNumber, sootMethod)) {
return Collections.singleton(sootMethod);
}
if (sootMethod.isConcrete()) {
if (!sootMethod.hasActiveBody())
sootMethod.retrieveActiveBody();
Body body = sootMethod.getActiveBody();
if (coversLineNumber(lineNumber, body)) {
return Collections.singleton(sootMethod);
}
for (Unit u : body.getUnits()) {
if (coversLineNumber(lineNumber, u)) {
return Collections.singleton(sootMethod);
}
}
}
}
// be conservative and return all method that we found
return methodsWithRightName;
}
}
use of soot.Body in project soot by Sable.
the class FieldRenamer method setBooleanTo.
protected void setBooleanTo(SootClass sc, SootField f, boolean value) {
if (!value && f.getType() instanceof IntegerType && Rand.getInt() % 2 > 0) {
return;
}
RefType boolRef = Scene.v().getRefType(booleanClassName);
Body body;
boolean newInit = false;
if (!sc.declaresMethodByName(SootMethod.staticInitializerName)) {
SootMethod m = Scene.v().makeSootMethod(SootMethod.staticInitializerName, emptyList(), VoidType.v(), Modifier.STATIC);
sc.addMethod(m);
body = Jimple.v().newBody(m);
m.setActiveBody(body);
newInit = true;
} else {
SootMethod m = sc.getMethodByName(SootMethod.staticInitializerName);
body = m.getActiveBody();
}
PatchingChain<Unit> units = body.getUnits();
if (f.getType() instanceof IntegerType) {
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(f.makeRef()), IntConstant.v(value ? 1 : 0)));
} else {
Local bool = Jimple.v().newLocal("boolLcl", boolRef);
body.getLocals().add(bool);
SootMethod boolInit = boolRef.getSootClass().getMethod("void <init>(boolean)");
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(f.makeRef()), bool));
units.addFirst(Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(bool, boolInit.makeRef(), IntConstant.v(value ? 1 : 0))));
units.addFirst(Jimple.v().newAssignStmt(bool, Jimple.v().newNewExpr(boolRef)));
}
if (newInit) {
units.addLast(Jimple.v().newReturnVoidStmt());
}
}
use of soot.Body in project soot by Sable.
the class ClassRenamer method internalTransform.
@Override
protected void internalTransform(String phaseName, Map<String, String> options) {
if (isVerbose()) {
logger.debug("Transforming Class Names...");
}
BodyBuilder.retrieveAllBodies();
BodyBuilder.retrieveAllNames();
final SootClass mainClass = getMainClassSafely();
// iterate through application classes, rename classes with junk
for (SootClass sootClass : Scene.v().getApplicationClasses()) {
final String className = sootClass.getName();
if (sootClass.equals(mainClass) || oldToNewClassNames.containsValue(className) || soot.jbco.Main.getWeight(phaseName, className) == 0) {
continue;
}
String newClassName = oldToNewClassNames.get(className);
if (newClassName == null) {
newClassName = getNewName(getPackageName(className), className);
}
sootClass.setName(newClassName);
RefType crt = RefType.v(newClassName);
crt.setSootClass(sootClass);
sootClass.setRefType(crt);
sootClass.setResolvingLevel(SootClass.BODIES);
// will this fix dangling classes?
// scene.addRefType(sootClass.getType());
newNameToClass.put(newClassName, sootClass);
if (isVerbose()) {
logger.info("\tRenaming " + className + " to " + newClassName);
}
}
Scene.v().releaseActiveHierarchy();
Scene.v().setFastHierarchy(new FastHierarchy());
if (isVerbose()) {
logger.info("\r\tUpdating bytecode class references");
}
for (SootClass sootClass : Scene.v().getApplicationClasses()) {
for (SootMethod sootMethod : sootClass.getMethods()) {
if (!sootMethod.isConcrete()) {
continue;
}
if (isVerbose()) {
logger.info("\t\t" + 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());
}
use of soot.Body in project soot by Sable.
the class JimpleBody method clone.
/**
* Clones the current body, making deep copies of the contents.
*/
@Override
public Object clone() {
Body b = new JimpleBody(getMethod());
b.importBodyContentsFrom(this);
return b;
}
Aggregations