java - Intercepting all Android Activity onCreate -
been trying hook android byte-buddy having issues goal; goal being intercept oncreate, , add log.d(tag, "message") activities getting created.
updated imports
package he.herpa.autoloader; import android.app.application; import android.content.context; import android.util.log; import net.bytebuddy.bytebuddy; import net.bytebuddy.classfileversion; import net.bytebuddy.android.androidclassloadingstrategy; import net.bytebuddy.implementation.methoddelegation; import net.bytebuddy.implementation.bind.annotation.supercall; import net.bytebuddy.matcher.elementmatchers; import net.bytebuddy.utility.randomstring; import java.io.file; import java.io.ioexception; import java.util.concurrent.callable; public class app extends application { private static final string tag = "test"; @override public void oncreate() { super.oncreate(); bytebuddy bytebuddy; bytebuddy = new bytebuddy(classfileversion.java_v6); try { file file = this.getdir(randomstring.make(), context.mode_private); if (!file.isdirectory()) { throw new ioexception("not directory: " + file); } try { bytebuddy .redefine(activity.class) .method(elementmatchers.named("oncreate")) .intercept(methoddelegation.to(interceptor.class)) .make() .load(activity.class.getclassloader(), new androidclassloadingstrategy(file)); } catch (throwable e) { log.w(tag, e); return; } } catch (throwable e) { log.w(tag, e); } } @override public void onterminate() { super.onterminate(); } public static class interceptor { public static void intercept(@supercall callable<void> zuper) throws exception { log.d("test", "should have placed log in oncreates"); return zuper.call(); } } first issue class activity not seem found.
edit java.lang.illegalargumentexception: cannot locate class file class he.herpa.autoloader.activity using classfilelocator.forclassloader
second issue is, on right track?
byte buddy not support redefinition or rebasement on android. can during build time runtime android not provide standardized access java byte code.
Comments
Post a Comment