Android Hook with xposed

Source: Internet
Author: User

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:


  1. Public class Main implements Ixposedhookloadpackage {
  2. /** 
  3. * Callback when package is loaded
  4. */
  5. public void Handleloadpackage (final Loadpackageparam Lpparam) throws Throwable {
  6. //Remove the application with the package name not Com.example.login
  7. if (!lpparam.packagename.equals ("Com.example.login"))
  8. return;
  9. XposedBridge.log ("Loaded app:" + lpparam.packagename);
  10. }
  11. }

. 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
  1. Import static De.robv.android.xposed.XposedHelpers.findAndHookMethod;
  2. Public class Main implements Ixposedhookloadpackage {
  3. /** 
  4. * Callback when package is loaded
  5. */
  6. public void Handleloadpackage (final Loadpackageparam Lpparam) throws Throwable {
  7. //Remove the application with the package name not Com.example.login
  8. if (!lpparam.packagename.equals ("Com.example.login"))
  9. return;
  10. XposedBridge.log ("Loaded app:" + lpparam.packagename);
  11. //Hook mainactivity in Iscorrectinfo (string,string) method
  12. Findandhookmethod ("com.example.login.MainActivity", Lpparam.classloader, "Iscorrectinfo", String. Class,
  13. String. class, new Xc_methodhook () {
  14. @Override
  15. protected void Beforehookedmethod (Methodhookparam param) throws throwable {
  16. XposedBridge.log ("Start hijacking ~");
  17. XposedBridge.log ("Parameter 1 =" + param.args[0]);
  18. XposedBridge.log ("Parameter 2 =" + param.args[1]);
  19. }
  20. @Override
  21. protected void Afterhookedmethod (Methodhookparam param) throws throwable {
  22. XposedBridge.log ("hijacking ended ~");
  23. XposedBridge.log ("Parameter 1 =" + param.args[0]);
  24. XposedBridge.log ("Parameter 2 =" + param.args[1]);
  25. }
  26. });
  27. }

Android Hook with xposed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.