Xposed Hook (Android)

Source: Internet
Author: User

First write a test program get ID

public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //控件        TextView test = findViewById(R.id.test);        Context context = getApplicationContext();        //权限        //<uses-permission android:name="android.permission.READ_PHONE_STATE" />        if (context.getPackageManager().checkPermission(Manifest.permission.READ_PHONE_STATE,                context.getPackageName()) == PackageManager.PERMISSION_GRANTED)        {            String  Imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).getDeviceId();            Log.e("soho",Imei);            test.setText(Imei);        }        else        {            Log.e("soho","no permission");        }    }}


Start Hook
Create a new project
Adding module descriptions in application

 <meta-data android:name= "Xposedmodule" android:value= "true" ></meta-data> <meta-data android:name= "x Poseddescription "android:value=" xposed plugin "></meta-data> <meta-data android:name=" Xposedminversion "and Roid:value= "></meta-data>/////////////////////////////////////////////////////////////<?xml"    Version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.liuhailong.hook" > <application android:allowbackup= "true" android:icon= "@mipma P/ic_launcher "android:label=" @string/app_name "android:roundicon=" @mipmap/ic_launcher_round "Android : Supportsrtl= "true" android:theme= "@style/apptheme" > <activity android:name= ". Mainactivity "> <intent-filter> <action android:name=" Android.intent.action.MAIN "/&G                T <category android:name= "Android.intent.category.LAUNCHER "/> </intent-filter> </activity> <meta-data android:name=" Xposedmodule "Andro Id:value= "true" ></meta-data> <meta-data android:name= "xposeddescription" android:value= "xposed plug-in" > </meta-data> <meta-data android:name= "xposedminversion" android:value= "si" ></meta-data> </a Pplication></manifest>

Import xposed jar
Creates a new folder in the app and must be named Lib (in Project view)

Copy module in

Open module Dependency

Add

Modify scope to


Load or run not restart as
will appear 3 directory description loading successful

Creating a class name must be the main implementation Ixposedhookloadpackage interface

Implementation method

declaring the primary portal Classpath
in the main folder The assets folder must be named Assets
Create a new Xposed_init file name within the assets folder
Declare the entry class name in the file

use Findandhookmethod

    Package Com.example.liuhailong.hook;import Android.telephony.telephonymanager;import De.robv.android.xposed.ixposedhookloadpackage;import De.robv.android.xposed.xc_methodreplacement;import De.robv.android.xposed.xposedbridge;import De.robv.android.xposed.xposedhelpers;import De.robv.android.xposed.callbacks.xc_loadpackage;public class Main implements Ixposedhookloadpackage {@Override Publ IC void Handleloadpackage (Xc_loadpackage.loadpackageparam loadpackageparam) throws Throwable {//First to determine the package to hook is that a PP if (!loadpackageparam.packagename.equals ("Com.example.liuhailong")) {//print log This print on the APK xpose            DBridge.log (Loadpackageparam.packagename);        Return }//Hit the corresponding method to replace Replacehookedmethod replacement method//Parameter 1: Name parameter 2: Method name parameter 3: Implement Listener override Method Xposedhelpers.findandhookme            Thod (Telephonymanager.class, "Getdeviceid", new Xc_methodreplacement () {@Override Protected Object Replacehookedmethod(Methodhookparam Argmethodhookparam) throws Throwable {return "I'm the serial number!            ";    }        }        ); }}

Installing the hook Frame
de.robv.android.xposed.installer_v32_de4f0d.apk

Prompts you to install the hook

Click Frame

Click Install it will ask you to restart
Start hook when reboot is complete

Click Module

Reboot will be done as long as the hooktest will be hook (hook do not start generally write not meet I was to debug)

Main.java Complete code

Package Com.bluelesson.xposed24;import Android.telephony.telephonymanager;import De.robv.android.xposed.ixposedhookloadpackage;import De.robv.android.xposed.xc_methodhook;import De.robv.android.xposed.xposedbridge;import De.robv.android.xposed.xposedhelpers;import De.robv.android.xposed.callbacks.xc_loadpackage;public class Main implements Ixposedhookloadpackage {@Override Publ IC void Handleloadpackage (Xc_loadpackage.loadpackageparam argloadpackageparam) throws Throwable {//Judging is not to hook the package, not        is to return directly if (!argloadpackageparam.packagename.equals ("Com.bluelesson.testphoneinfo")) {return;                }//Xposedhelpers.findandhookmethod (//telephonymanager.class,//"Getdeviceid",// New Xc_methodreplacement () {//@Override//protected Object Replacehooke Dmethod (Methodhookparam argmethodhookparam) throws Throwable {//return "I'm the serial number! ";//                    }//               }//        ); Xposedhelpers.findandhookmethod (Telephonymanager.class, "Getdeviceid", New X C_methodhook () {@Override protected void Beforehookedmethod (Methodhookparam param)                        Throws Throwable {super.beforehookedmethod (param);                    XposedBridge.log ("Beforehookedmethod");  } @Override protected void Afterhookedmethod (Methodhookparam param) throws Throwable                        {Super.afterhookedmethod (param);                        XposedBridge.log ("Afterhookedmethod");                    Param.setresult ("I am serial number");    }                }        ); }}

Xposed Hook (Android)

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.