[Soot-list] instrument interface class causes dexopt failed error
Steven Arzt
Steven.Arzt at cased.de
Thu Apr 2 10:48:55 EDT 2015
Hi Zipeng,
Did you mark the “Instrument” class and the interface as application classes? Only application classes will be written out to the new dex file.
Best regards,
Steven
Von: soot-list-bounces at CS.McGill.CA [mailto:soot-list-bounces at CS.McGill.CA] Im Auftrag von fox tiny
Gesendet: Donnerstag, 2. April 2015 15:01
An: soot-list at CS.McGill.CA
Betreff: [Soot-list] instrument interface class causes dexopt failed error
Hi all,
While instrumentation of android apps, if the injected class contains an interface, the instrumented apk cannot be installed in Android successfully, a dexopt error is reported.
my instrumentation code is shown below. It replaces the startActivity statement with a static function f() defined in class Instrument
protected void internalTransform(final Body body, String s, Map<String, String> stringStringMap) {
final PatchingChain units = body.getUnits();
for (Iterator<Unit> iter = units.snapshotIterator(); iter.hasNext(); ) {
final Unit u = iter.next();
u.apply(new AbstractStmtSwitch() {
@Override
public void caseInvokeStmt(InvokeStmt stmt) {
InvokeExpr invokeExpr = stmt.getInvokeExpr();
if (invokeExpr instanceof InstanceInvokeExpr &&
invokeExpr.getMethod().getName().equals("startActivity")) {
SootClass instrumentClass = Scene.v().getSootClass("Instrument");
SootMethod instrumentMethod = instrumentClass.getMethodByName("f");
List<Value> args = new ArrayList<Value>();
Unit insertStmt = Jimple.v().newInvokeStmt(
Jimple.v().newStaticInvokeExpr(instrumentMethod.makeRef(),args)
);
units.insertBefore(insertStmt, stmt);
units.remove(stmt);
body.validate();
}
}
});
}
}
The Instrument.java is defined below:
import A;
public class Instrument {
public static int f() {
A a = A.Stub.asInterface();
return a.f();
}
}
and class A is defined as an interface
public interface A {
public int f();
public static abstract class Stub implements A {
public static A asInterface() {
return new AImpl();
}
}
}
class AImpl implements A {
@Override
public int f() {
return 0;
}
}
Is the interface class output into the apk incorrectly?
Thanks a lot!
Zipeng Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20150402/1dde12ed/attachment-0001.html
More information about the Soot-list
mailing list