[Soot-list] Loading class and support: problem instrumenting bytecode

Luca Cavallaro mitch_ing at yahoo.it
Fri Jun 13 11:36:02 EDT 2008


Dear all,
I have a question about loading classes with soot at run time. 
I am trying to instrument bytecode using an external helper static method. 
Actually I want to add the call to this method after some statements are 
executed.
I am trying to implement this thing in a body transformer which I want to 
insert in the jtp pack. 
The problem is that whe I try to load the class that contains the method I 
want to call I get this exception:

java.lang.RuntimeException: This operation requires resolving level SIGNATURES 
but instrumenter.utils.UnitInstrumentation is at resolving level HIERARCHY
	at soot.SootClass.checkLevel(SootClass.java:126)
	at soot.SootClass.addMethod(SootClass.java:581)
	at soot.coffi.Util.resolveFromClassFile(Util.java:252)
	at soot.CoffiClassSource.resolve(CoffiClassSource.java:37)
	at soot.SootResolver.bringToHierarchy(SootResolver.java:148)
	at soot.SootResolver.bringToSignatures(SootResolver.java:172)
	at soot.SootResolver.bringToBodies(SootResolver.java:214)
	at soot.SootResolver.processResolveWorklist(SootResolver.java:100)
	at soot.SootResolver.resolveClass(SootResolver.java:89)
	at soot.Scene.loadClass(Scene.java:329)
	at soot.Scene.loadClassAndSupport(Scene.java:314)
	at 
instrumenter.transformation.MethodInstrumenter.internalTransform(MethodInstrumenter.java:30)
	at soot.BodyTransformer.transform(BodyTransformer.java:51)
	at soot.Transform.apply(Transform.java:104)
	at soot.BodyPack.internalApply(BodyPack.java:50)
	at soot.Pack.apply(Pack.java:120)
	at soot.PackManager.runBodyPacks(PackManager.java:681)
	at soot.PackManager.runBodyPacks(PackManager.java:396)
	at soot.PackManager.runBodyPacks(PackManager.java:340)
	at soot.PackManager.runPacks(PackManager.java:335)
	at soot.Main.run(Main.java:203)
	at soot.Main.main(Main.java:146)
	at instrumenter.transformation.Main.main(Main.java:21)


Here is the code I am trying to use for instrumentation:
protected void internalTransform(Body b, String phaseName, Map options) {
		
		SootClass sc = 
Scene.v().loadClassAndSupport("instrumenter.utils.UnitInstrumentation");
		SootMethod unitInstrumenter = sc.getMethodByName("myMethod");
		SootMethod m = b.getMethod();
		ExceptionalUnitGraph eg = new ExceptionalUnitGraph(b);
		List<Unit> methodHeads = eg.getHeads();
		PatchingChain units = m.getActiveBody().getUnits();
		for(Unit head: methodHeads){
			instrumentUnit(eg, units, head, unitInstrumenter);
		}
		
		Iterator<Unit> overMethodUnits = units.snapshotIterator();
		while(overMethodUnits.hasNext()){
			Unit next = overMethodUnits.next();
		
			if(next instanceof IfStmt || next instanceof ThrowStmt || next instanceof 
GotoStmt||next instanceof ReturnStmt||next instanceof ThrowStmt){
				instrumentUnit(eg, units, next, unitInstrumenter);

			}

		}

	}
	
	private void instrumentUnit(ExceptionalUnitGraph eg, PatchingChain units,
			Unit next, SootMethod unitInstrumenter) {
		
		Vector<Unit> v = new Vector<Unit>();
		List<Unit> l = eg.getSuccsOf(next);
		for(Unit u : l){
			
			v.add(u);
			InvokeExpr expr = 
Jimple.v().newStaticInvokeExpr(unitInstrumenter.makeRef(),v);
			Stmt incStmt = Jimple.v().newInvokeStmt(expr);
			units.insertAfter(incStmt, u);;
		}
	}

These are the options I am trying to pass to soot.Main:
-p cg.spark on  -cp ${soot-cp2}:
${instrumentationcp}:/usr/lib/jvm/java-1.5.0-sun-1.5.0.11/jre/lib//jce.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.11/jre/lib/rt.jar:/home/luca/universita/dottorato/minore/eclipse/plugins/org.aspectj.runtime_1.6.0.20081300000002/aspectjrt.jar -f 
jimple -w -i instrumenter --app examples.lollypop.Factory --output-dir 
jimpleout

Naturally the class whose method I want to invoke has been included in soot 
class path, as wellas the Factory class (that is the one I want to 
instrument).

Anyone has a hint?
Thank you very much
Luca


More information about the Soot-list mailing list