ControlFlowBuilder cfg = new ControlFlowBuilder(wrapper);
cfg.moveToStatement(wrapper.getEntry());
// create a variable holding any string
Variable anyVar = application.createVariable(VariableType.STRING);
Statement assignAny = new StringInit(anyVar, Basic.makeAnyString());
cfg.addStatement(assignAny);
// create a variable holding the null string
Variable nullVar = application.createVariable(VariableType.STRING);
Statement assignNull = new StringInit(nullVar, Automatons.getNull());
cfg.addStatement(assignNull);
// initialize externally visible field variables to anything
// and set string fields to "null"
for (SootClass ac : getApplicationClasses()) {
for (SootField field : ac.getFields()) {
// String fields should be assigned to "null" because they are
// exempt from the
// null-pointer analysis we use for other objects
if (field.getType().equals(RefType.v("java.lang.String"))) {
FieldAssignment assignment = new FieldAssignment(
variableManager.getField(field), nullVar);
cfg.addStatement(assignment);
}
// corrupt externally visible fields
if (ext.isExternallyVisibleField(field)) {
VariableType type = fromSootType(field
.getType());
if (type == VariableType.NONE)
continue;
Variable fieldInit;
switch (type) {
case OBJECT:
case STRING:
case PRIMITIVE:
fieldInit = anyVar;
break;
case STRINGBUFFER: {
fieldInit = application.createVariable(VariableType.STRINGBUFFER);
Statement s = new StringBufferCorrupt(fieldInit);
cfg.addStatement(s);
break;
}
case ARRAY: {
fieldInit = application.createVariable(VariableType.ARRAY);
Statement s = new ArrayCorrupt(fieldInit);
cfg.addStatement(s);
break;
}
default:
throw new RuntimeException("Unknown field type " + type);
}// switch
FieldAssignment assignment = new FieldAssignment(variableManager.getField(field), fieldInit);
cfg.addStatement(assignment);
}
}
}
// split control here, and call a random externally visible method
cfg.startBranch();
// call externally visible methods
for (SootClass ac : getApplicationClasses()) {
for (SootMethod sm : ac.getMethods()) {
if (ext.isExternallyVisibleMethod(sm)) {
Method m = sms_m.get(sm.getSignature());
Variable[] params = m.getEntry().params;
Variable[] args = new Variable[params.length];
for (int i = 0; i < params.length; i++) {
Variable arg = application.createVariable(params[i].getType());
args[i] = arg;
Statement s;
switch (arg.getType()) {
case STRING:
s = new StringInit(arg, Basic.makeAnyString());
break;
case STRINGBUFFER: