The main thing is to use two more important methods in xposed, Handleloadpackage get the callback of the package load and get the corresponding Classloader;findandhookmethod to hook the method of the specified class.
/**
* Callback when package is loaded
*/
public void Handleloadpackage (final loadpackageparam Lpparam)
/**
* Hook method provided by xposed
*
* @param className to hook class
* @param classLoader ClassLoader
* @param the method methodName to hook
* @param parametertypesandcallback Hook callback
* @return
*/
Unhook Findandhookmethod (String className, ClassLoader ClassLoader, String methodName, Object ...) Parametertypesandcallback)
<application
Android:allowbackup= "true"
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name"
Android:theme= "@style/apptheme" >
<meta-data
Android:name= "Xposedmodule"
Android:value= "true"/>
<!--module Description--
<meta-data
Android:name= "Xposeddescription"
Android:value= "A sample of landing hijacking"/>
<!--minimum version number--
<meta-data
Android:name= "Xposedminversion"
Android:value= "/>"
</application>
Create a new entry class and inherit and implement the Ixposedhookloadpackage interface
The following actions, We created a new class of Com.example.loginhook.Main and implemented the Handleloadpackage method in the Ixposedhookloadpackage interface, filtering out the application of the non-Com.example.login package name, that is, we only operate the package name For the application of Com.example.login. As shown below:
- Public class Main implements Ixposedhookloadpackage {
- /**
- * Callback when package is loaded
- */
- public void Handleloadpackage (final Loadpackageparam Lpparam) throws Throwable {
- //Remove the application with the package name not Com.example.login
- if (!lpparam.packagename.equals ("Com.example.login"))
- return;
- XposedBridge.log ("Loaded app:" + lpparam.packagename);
- }
- }
. Declaring the main entry path
You need to create a new Xposed_init file in the Assets folder and declare the main entry class in it. For example, our main entry class is Com.example.loginhook.Main.
Use the Findandhookmethod method to hijack the login information
This is one of the most important steps that we have previously analyzed that need to be done in this step. As we have previously analyzed the login process, we need to hijack, is the need to hook its com.example.login.MainActivity in the Iscorrectinfo method. We use the Findandhookmethod provided by Xposed to perform methodhook operations directly (similar to Cydia). Use the XposedBridge.log method in its hook callback to print the login password information to the xposed log. The operation is as follows:
[Java]View Plaincopy
- Import static De.robv.android.xposed.XposedHelpers.findAndHookMethod;
- Public class Main implements Ixposedhookloadpackage {
- /**
- * Callback when package is loaded
- */
- public void Handleloadpackage (final Loadpackageparam Lpparam) throws Throwable {
- //Remove the application with the package name not Com.example.login
- if (!lpparam.packagename.equals ("Com.example.login"))
- return;
- XposedBridge.log ("Loaded app:" + lpparam.packagename);
- //Hook mainactivity in Iscorrectinfo (string,string) method
- Findandhookmethod ("com.example.login.MainActivity", Lpparam.classloader, "Iscorrectinfo", String. Class,
- String. class, new Xc_methodhook () {
- @Override
- protected void Beforehookedmethod (Methodhookparam param) throws throwable {
- XposedBridge.log ("Start hijacking ~");
- XposedBridge.log ("Parameter 1 =" + param.args[0]);
- XposedBridge.log ("Parameter 2 =" + param.args[1]);
- }
- @Override
- protected void Afterhookedmethod (Methodhookparam param) throws throwable {
- XposedBridge.log ("hijacking ended ~");
- XposedBridge.log ("Parameter 1 =" + param.args[0]);
- XposedBridge.log ("Parameter 2 =" + param.args[1]);
- }
- });
- }
Android Hook with xposed