document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*  AVANT:
  2.     public class HelloWorldActivity extends Activity {
  3.         public void onCreate(Bundle savedInstanceState) {
  4.             super.onCreate(savedInstanceState);
  5.             setContentView(R.layout.main);
  6.         }
  7.     }
  8. */
  9. Dex dex = Dex.Load("helloworld.dex");
  10.  
  11. // Recherche de la classe puis de la methode a modifier
  12. ClassDefinition cdef = dex.GetClass("org.dexer.HelloWorldActivity");
  13. MethodDefinition mdef = cdef.GetMethod("onCreate");
  14.  
  15. // Creation d\'une reference sur une methode a appeler
  16. TypeReference parameterType = dex.Import(new ClassReference("java.lang.CharSequence"));
  17. TypeReference returnType = dex.Import(PrimitiveType.Void);
  18. Prototype prototype = new Prototype(returnType, new Parameter(parameterType));
  19. MethodReference mref = dex.Import(new MethodReference(cdef, "setTitle", prototype));
  20.  
  21. // Ajout d\'instructions
  22. var regs = mdef.Body.Registers; // ici, regs[1] : \'this\', l\'instance
  23. var instructions = mdef.Body.Instructions;
  24. Instruction inscst = new Instruction(OpCodes.Const_string, "Hello World from Dexer!", regs[0]);
  25. Instruction insinv = new Instruction(OpCodes.Invoke_virtual, mref, regs[1], regs[0]);
  26.  
  27. // instructions[0] invoke-super: on conserve pour l\'appel a l\'ancetre
  28. instructions.Insert(1, inscst);
  29. instructions.Insert(2, insinv);
  30.  
  31. /*  APRES:
  32.     public class HelloWorldActivity extends Activity {
  33.         public void onCreate(Bundle savedInstanceState) {
  34.             super.onCreate(savedInstanceState);
  35.             >>>> setTitle("Hello World from Dexer!");  <<<<
  36.             setContentView(R.layout.main);
  37.         }
  38.     }
  39. */
');