[Soot-list] instrument interface class causes dexopt failed error

fox tiny zpzhang266 at gmail.com
Thu Apr 2 09:01:29 EDT 2015


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/e4765311/attachment.html 


More information about the Soot-list mailing list