Class DexRewriter

  • All Implemented Interfaces:
    Rewriters

    public class DexRewriter
    extends java.lang.Object
    implements Rewriters
    Out-of-the box, this class does nothing except make a picture-perfect copy of a dex file. However, it provides many points where you can hook into this process and selectively modify the dex file. For example, If you want to rename all instances (including definitions and references) of the class Lorg/blah/MyBlah; to Lorg/blah/YourBlah;
     
     DexRewriter rewriter = new DexRewriter(new RewriterModule() {
         public Rewriter<String> getTypeRewriter(Rewriters rewriters) {
             return new Rewriter<String>() {
                 public String rewrite(String value) {
                     if (value.equals("Lorg/blah/MyBlah;")) {
                         return "Lorg/blah/YourBlah;";
                     }
                     return value;
                 }
             };
         }
     });
     DexFile rewrittenDexFile = rewriter.rewriteDexFile(dexFile);