When writing the Cydia hook plugin using the Cydia framework, because the Initialize method is a static method with no parameters, it cannot get the context so many things can not be done directly in the Initialize method, such as Toast, send broadcast, etc. Because hooks are the result of changing the API execution of other classes. So you can use the hook's class to get the context so that you can use toast and so on.
Way:
1Ms.hookmethod (arg0, Toast,NewMS. Methodalteration () {2 3 @Override4 Publicobject invoked (object arg0, Object ... arg1)5 throwsThrowable {6Toast.maketext ((Activity) arg0). Getapplicationcontext (), "test", Toast.length_long). Show ();7Invoke (arg0, "hook before");8 Invoke (arg0, arg1);9Invoke (arg0, "Hook End"); Ten return NULL; One } A});
Parameter arg0 is an example of the last hook class, using her to get the method inside her, because I hook the class is activity type, so can get the context.
Cydia for Android2