Answer the question
In order to leave comments, you need to log in
How can I change (add) the code to the .dex file on Android?
Good day!) I am writing a code compiler program for android. With the javassist library, I can add or change the function code of my dex file like this:
final ClassPool pool = ClassPool.getDefault();
pool.appendClassPath(new LoaderClassPath(getClass().getClassLoader()));
pool.appendClassPath("./android.jar");
final CtClass compiledClass = pool.get(targetClass);
final CtMethod method = compiledClass.getDeclaredMethod(targetMethod);
method.insertBefore("{ java.lang.System#out.println(\"doA() is called.\");}");
compiledClass.writeFile(targetFolder);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question