use of soot.SootFieldRef in project soot by Sable.
the class FieldRenamer method internalTransform.
protected void internalTransform(String phaseName, Map<String, String> options) {
if (output) {
if (rename_fields) {
out.println("Transforming Field Names and Adding Opaque Predicates...");
} else {
out.println("Adding Opaques...");
}
}
RefType boolRef = Scene.v().getRefType(booleanClassName);
BodyBuilder.retrieveAllBodies();
BodyBuilder.retrieveAllNames();
for (SootClass sc : Scene.v().getApplicationClasses()) {
String className = sc.getName();
if (className.contains(".")) {
className = className.substring(className.lastIndexOf(".") + 1, className.length());
}
oldToNewFieldNames.put(className, className);
if (rename_fields) {
if (output) {
out.println("\tClassName: " + className);
}
// rename all the fields in the class
for (SootField f : sc.getFields()) {
int weight = soot.jbco.Main.getWeight(phaseName, f.getName());
if (weight > 0) {
renameField(className, f);
}
}
}
// skip interfaces - they can only hold final fields
if (sc.isInterface()) {
continue;
}
// add one opaq predicate for true and one for false to each class
String bool = "opPred1";
Type t = Rand.getInt() % 2 == 0 ? BooleanType.v() : boolRef;
while (oldToNewFieldNames.containsKey(bool)) {
bool += "_";
}
SootField f = Scene.v().makeSootField(bool, t, Modifier.PUBLIC | Modifier.STATIC);
renameField(className, f);
opaquePreds1ByClass.put(sc, f);
sc.addField(f);
setBooleanTo(sc, f, true);
bool = "opPred2";
t = t == BooleanType.v() ? boolRef : BooleanType.v();
while (oldToNewFieldNames.containsKey(bool)) {
bool += "_";
}
f = Scene.v().makeSootField(bool, t, Modifier.PUBLIC | Modifier.STATIC);
renameField(className, f);
opaquePreds2ByClass.put(sc, f);
sc.addField(f);
if (t == boolRef) {
setBooleanTo(sc, f, false);
}
}
buildOpaquePairings();
if (!rename_fields) {
return;
}
if (output) {
out.println("\r\tUpdating field references in bytecode");
}
for (SootClass sc : Scene.v().getApplicationClasses()) {
for (SootMethod m : sc.getMethods()) {
if (!m.isConcrete()) {
continue;
}
if (!m.hasActiveBody()) {
m.retrieveActiveBody();
}
for (Unit unit : m.getActiveBody().getUnits()) {
for (ValueBox box : unit.getUseAndDefBoxes()) {
Value value = box.getValue();
if (value instanceof FieldRef) {
FieldRef fieldRef = (FieldRef) value;
SootFieldRef sootFieldRef = fieldRef.getFieldRef();
if (sootFieldRef.declaringClass().isLibraryClass()) {
continue;
}
String oldName = sootFieldRef.name();
String fullName = sootFieldRef.declaringClass().getName() + '.' + oldName;
String newName = oldToNewFieldNames.get(oldName);
if (newName == null || namesToNotRename.contains(fullName)) {
continue;
}
if (newName.equals(oldName)) {
System.out.println("Strange.. Should not find a field with the same old and new name.");
}
sootFieldRef = Scene.v().makeFieldRef(sootFieldRef.declaringClass(), newName, sootFieldRef.type(), sootFieldRef.isStatic());
fieldRef.setFieldRef(sootFieldRef);
try {
sootFieldRef.resolve();
} catch (Exception e) {
System.err.println("********ERROR Updating " + sootFieldRef.name() + " to " + newName);
System.err.println("Fields of " + sootFieldRef.declaringClass().getName() + ": " + sootFieldRef.declaringClass().getFields());
throw new RuntimeException(e);
}
}
}
}
}
}
}
use of soot.SootFieldRef in project soot by Sable.
the class Walker method outASigFieldRef.
public void outASigFieldRef(ASigFieldRef node) {
SootFieldRef field = (SootFieldRef) mProductions.removeLast();
field = Scene.v().makeFieldRef(field.declaringClass(), field.name(), field.type(), true);
mProductions.addLast(Jimple.v().newStaticFieldRef(field));
}
use of soot.SootFieldRef in project soot by Sable.
the class Walker method outALocalFieldRef.
/*
* field_ref = {local} local_name dot field_signature | {sig}
* field_signature;
*/
public void outALocalFieldRef(ALocalFieldRef node) {
SootFieldRef field = (SootFieldRef) mProductions.removeLast();
String local = (String) mProductions.removeLast();
Local l = mLocals.get(local);
if (l == null)
throw new RuntimeException("did not find local: " + local);
mProductions.addLast(Jimple.v().newInstanceFieldRef(l, field));
}
use of soot.SootFieldRef in project soot by Sable.
the class Walker method outAFieldSignature.
/*
* field_signature = cmplt [class_name]:class_name [first]:colon type
* [field_name]:name cmpgt;
*/
public void outAFieldSignature(AFieldSignature node) {
String className, fieldName;
Type t;
fieldName = (String) mProductions.removeLast();
t = (Type) mProductions.removeLast();
className = (String) mProductions.removeLast();
SootClass cl = mResolver.makeClassRef(className);
SootFieldRef field = Scene.v().makeFieldRef(cl, fieldName, t, false);
mProductions.addLast(field);
}
Aggregations