Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* AVANT:
- public class HelloWorldActivity extends Activity {
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- }
- */
- Dex dex = Dex.Load("helloworld.dex");
- // Recherche de la classe puis de la methode a modifier
- ClassDefinition cdef = dex.GetClass("org.dexer.HelloWorldActivity");
- MethodDefinition mdef = cdef.GetMethod("onCreate");
- // Creation d'une reference sur une methode a appeler
- TypeReference parameterType = dex.Import(new ClassReference("java.lang.CharSequence"));
- TypeReference returnType = dex.Import(PrimitiveType.Void);
- Prototype prototype = new Prototype(returnType, new Parameter(parameterType));
- MethodReference mref = dex.Import(new MethodReference(cdef, "setTitle", prototype));
- // Ajout d'instructions
- var regs = mdef.Body.Registers; // ici, regs[1] : 'this', l'instance
- var instructions = mdef.Body.Instructions;
- Instruction inscst = new Instruction(OpCodes.Const_string, "Hello World from Dexer!", regs[0]);
- Instruction insinv = new Instruction(OpCodes.Invoke_virtual, mref, regs[1], regs[0]);
- // instructions[0] invoke-super: on conserve pour l'appel a l'ancetre
- instructions.Insert(1, inscst);
- instructions.Insert(2, insinv);
- /* APRES:
- public class HelloWorldActivity extends Activity {
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- >>>> setTitle("Hello World from Dexer!"); <<<<
- setContentView(R.layout.main);
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement