StringTokenizer st = new StringTokenizer(extDirs, File.pathSeparatorChar+"");
while(st.hasMoreTokens()) {
String goo = st.nextToken();
- System.out.println("goo " + goo);
File f = new File(goo);
if (!f.exists() || !f.isDirectory()) continue;
String[] jars = f.list();
// Set up the Arena zero-arg constructor
SootClass arena = getArenaForGladiator(sc);
- SootMethod arenaInitMethod = arena.getMethod("<init>", new LinkedList());
+ SootMethod arenaInitMethod = null;
+ for(Iterator it = arena.getMethods().iterator(); it.hasNext();) {
+ SootMethod m = (SootMethod)it.next();
+ if (m.getName().equals("<init>")) {
+ if (arenaInitMethod != null) throw new Error("class " + arena.getName() + " has two constructors");
+ arenaInitMethod = m;
+ }
+ }
JimpleBody arenaInitBody = (JimpleBody)arenaInitMethod.getActiveBody();
SootField maxField = new SootField(getGladiatorName(sc) + "$$max", IntType.v());
for(Iterator it = sc.getMethods().iterator(); it.hasNext();) {
SootMethod m = (SootMethod)it.next();
- if (!m.isConcrete()) continue;
+ if (!m.isConcrete() || !m.hasActiveBody()) continue;
boolean doremove = true;
Body mincBody = m.getActiveBody();
if (implementsGladiator(m.getDeclaringClass()) && m.getName().equals("<init>")) {
+ System.out.println("processing ctor " + sc.getName() + "." + m.getSignature());
doremove = false;
SootClass c = m.getDeclaringClass();
- String name = /*c.getShortName().substring(c.getShortName().lastIndexOf('$')+1) + */"$init";
+ String name = "$init";
List li = m.getParameterTypes();
c.removeMethod(m);
SootMethod nm = new SootMethod(name, li, implementsGladiator(m.getReturnType()) ? IntType.v() : m.getReturnType());
nm.setActiveBody(bod);
m = nm;
mincBody = bod;
- mincBody.getUnits().remove(((JimpleBody)mincBody).getFirstNonIdentityStmt());
- mincBody.getUnits().remove(((JimpleBody)mincBody).getFirstNonIdentityStmt());
+
+ for(Iterator it2 = mincBody.getUnits().snapshotIterator(); it2.hasNext(); ) {
+ Unit u = (Unit)it2.next();
+ if (u instanceof DefinitionStmt) {
+ DefinitionStmt ds = (DefinitionStmt)u;
+ if (ds.getLeftOp() instanceof ThisRef)
+ mincBody.getUnits().remove(u);
+ else if (ds.getLeftOp() instanceof FieldRef) {
+ if (((FieldRef)ds.getLeftOp()).getFieldRef().name().endsWith("this$0"))
+ mincBody.getUnits().remove(u);
+ }
+ } else if (u instanceof InvokeStmt) {
+ InvokeExpr ie = ((InvokeStmt)u).getInvokeExpr();
+ SootMethodRef meth = ie.getMethodRef();
+ if (meth.declaringClass().getName().equals("java.lang.Object") && meth.name().equals("<init>"))
+ mincBody.getUnits().remove(u);
+ }
+ }
+
} else {
System.out.println("examining " + sc.getName() + "." + m.getSignature());
m.retrieveActiveBody();
List list = new LinkedList();
list.addAll(m.getParameterTypes());
list.add(IntType.v());
- for(Iterator i = list.iterator(); i.hasNext();) System.out.println(i.next());
SootMethod m2 = new SootMethod(name, list, m.getReturnType());
getArenaForGladiator(sc).addMethod(m2);
}
*/
if (vb.getValue() instanceof ThisRef) {
- System.out.println(s);
vb.setValue(loc);
}
}
body = b2;
}
Chain units = body.getUnits();
- System.out.println("processBody("+body.getMethod()+")");
for(Iterator it = body.getLocals().snapshotIterator(); it.hasNext();) {
Local l = (Local)it.next();
if (implementsGladiator(l.getType())) l.setType(IntType.v());
}
+ if (!smeth.isStatic())
+ body.getThisLocal().setType(ownerClass.getType());
for(int qq=0; qq<2; qq++) for(Iterator stmtIt = units.snapshotIterator(); stmtIt.hasNext();) {
Stmt s = (Stmt) stmtIt.next();
if (s instanceof DefinitionStmt) {
if (((ReturnStmt)s).getOp().getType() instanceof NullType)
((ReturnStmt)s).getOpBox().setValue(IntConstant.v(-1));
List l = s.getUseAndDefBoxes();
- for(Iterator it = l.iterator(); it.hasNext();) {
+ List l2l = new LinkedList();
+ l2l.addAll(l);
+ for(Iterator it = l2l.iterator(); it.hasNext();) {
Object o = it.next();
if (o instanceof ValueBox) {
ValueBox vb = (ValueBox)o;
Local ll = viaLocal(invokeExpr, body, s);
vb.setValue(ll);
v = ll;
- continue;
+ qq = 0;
+ break;
}
} else
//pl.remove(0);
}
pl.add(IntType.v());
- li.add(viaLocal(iie.getBase(),body,s));
+ li.add(/*viaLocal(*/iie.getBase()/*,body,s)*/);
SootClass sc = mr.declaringClass();
name = sc.getShortName().substring(sc.getShortName().lastIndexOf('$')+1) + "$$" + name;
mr = Scene.v().makeMethodRef(getArenaForGladiator(sc),
break;
}
- } else if (v instanceof InstanceFieldRef) {
- InstanceFieldRef ifr = (InstanceFieldRef)v;
+ } else if (v instanceof FieldRef) {
+ FieldRef ifr = (FieldRef)v;
SootFieldRef fr = ifr.getFieldRef();
Type t = fr.type();
if (implementsGladiator(fr.declaringClass()) && fr.name().equals("this$0")) {
- System.out.println("******************");
vb.setValue(body.getThisLocal());
- System.out.println("s is " + s);
} else if (implementsGladiator(fr.declaringClass())) {
SootClass arena = getArenaForGladiator(fr.declaringClass());
- InstanceFieldRef sfr = newIFR(body, getSliceForField(fr));
- vb.setValue(Jimple.v().newArrayRef(viaLocal(sfr, body, s), ifr.getBase()));
+ if (fr.isStatic()) {
+ vb.setValue(newIFR(body, getSliceForField(fr)));
+ } else {
+ InstanceFieldRef sfr = newIFR(body, getSliceForField(fr));
+ vb.setValue(Jimple.v().newArrayRef(viaLocal(sfr, body, s), ((InstanceFieldRef)ifr).getBase()));
+ }
}
if ((t instanceof RefType) && implementsGladiator(((RefType)t).getSootClass())) {
SootClass tc = ((RefType)t).getSootClass();
SootClass arena = getArenaForGladiator(tc);
- ifr.setFieldRef(Scene.v().makeFieldRef(arena, fr.name(), IntType.v(), false));
+ ifr.setFieldRef(Scene.v().makeFieldRef(arena, fr.name(), IntType.v(), fr.isStatic()));
+ } else if (t instanceof ArrayType) {
+ ArrayType at = (ArrayType)t;
+ Type et = at.getElementType();
+ if (et instanceof RefType && implementsGladiator(((RefType)et).getSootClass()))
+ ifr.setFieldRef(Scene.v().makeFieldRef(fr.declaringClass(),
+ fr.name(),
+ IntType.v().makeArrayType(),
+ fr.isStatic()));
}
}