Class FillArrayTransformer

  • All Implemented Interfaces:
    Transformer

    public class FillArrayTransformer
    extends StatedTransformer
    require SSA, usually run after ConstTransformer 1. array is fixed size. 2. array object init and use once, (exclude the element assignment) 3. all elements are init with fixed index before use. 4. the array is not in PhiExpr 5. and for array object init at A, use at B; A and B must in same loop/path, so G(A->B), G(A->C->B), G(A->C, A->D,C->B,D->B), G(A->C,C->D,D->C,C->B) and G(A->C,C->A,C->B) is ok to transform, but for G(A->C,C->B, B->D,D->C), B is in a loop (B->D->C->B), should not transformed.

    transform

         a=new String[3]
         a[0]="123"
         a[2]="1234"
         a[1]="12345"
         return a
     

    to

         return new String[3] { "123", "12345", "1234" }
     

    1. This Transformer is useful when cleanup the tool-injected reflection code

         // before transform
         ...
         Class a[]=new Class[2]
         a[0]=String.class
         a[1]=int.class
         Method m=x.getMethod("methodA",a)
         Object b[]=new Object[2]
         b[0]="123";
         b[1]=Integer.valueOf(1);
         m.invoke(c,b)
         // after transform
         Method m=x.getMethod("methodA", new Class[2] { String.class ,int.class });
         m.invoke(b,new Object[]{"123",Integer.valueOf(1)})
     

    2. Suggest decompilers generate better code

         // for following code, before transform, the decompiler generate same source
         Object[]a=new Object[2];
         a[0]=b;
         a[1]=c
         String.format("b is %s, c is %s",a)
         // after transform, then decompile generate the following source
         String.format("b is %s, c is %s",b,c)
     

    FIXME also handle not full filled array

     int a[] = new int[5];
     // a[0]=0;
     a[1] = 1;
     a[2] = 3;
     a[3] = 4;
     a[4] = 7;
     
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void main​(java.lang.String... args)  
      protected java.util.Set<com.googlecode.dex2jar.ir.ts.array.FillArrayTransformer.ArrayObjectValue> markUsed​(java.util.Collection<com.googlecode.dex2jar.ir.ts.array.FillArrayTransformer.ArrayObjectValue> values)  
      boolean transformReportChanged​(IrMethod method)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FillArrayTransformer

        public FillArrayTransformer()
    • Method Detail

      • main

        public static void main​(java.lang.String... args)
      • markUsed

        protected java.util.Set<com.googlecode.dex2jar.ir.ts.array.FillArrayTransformer.ArrayObjectValue> markUsed​(java.util.Collection<com.googlecode.dex2jar.ir.ts.array.FillArrayTransformer.ArrayObjectValue> values)