DEV Community

Stone
Stone

Posted on

Simple demo of Android reverse /hook

what is xposed

Xposed is a special Android application. By replacing the files such as app_process witch under system\bin\Process to control the zygote process, so as to control all the app processes on the mobile phone; the disadvantage is that it can't hook the functions in the so application

how to install xposed

refer to Install xposed for Android phone

a demo for xposed

  1. create a new Android project
  2. modify(alter, change? I dont konw..)the AndroidManifest,xml
<!-- Whether it is an xposed module. Xposed judges whether it is a module based on this
        <meta-data
            android:name="xposedmodule"
            android:value="true" />

        <!-- The module description -->
        <meta-data
            android:name="xposeddescription"
            android:value="xposed demo" />

        <!-- The minimum version supported is 30-->
        <meta-data
            android:name="xposedminversion"
            android:value="30" />
Enter fullscreen mode Exit fullscreen mode

3.add dependency
open buile.gradle (module:app)File, add the following code in it:

 compileOnly 'de.robv.android.xposed:api:82'
 compileOnly 'de.robv.android.xposed:api:82:sources'
Enter fullscreen mode Exit fullscreen mode
  1. IXposedHookLoadPackage
    Create a new Java class(MainIntercept) and implements Ixposedhookloadpackage and override the handleloadpackage method

  2. xposed_init
    Create an assets under Src/Mian, add xposed_init under it,, the code inside is your hook class package name + class name

  3. Rewrite the Mainactivity code as follows:

 public class MainActivity extends BaseActivity

    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ............
        textView.setText(getText());
        ............
    }

    private String getText(){
          return "-----ha ha !!-----";
    }

}
Enter fullscreen mode Exit fullscreen mode

6.change the code in MainIntercept:

public class MainIntercept implements IXposedHookLoadPackage {

    @Override
     public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
    if(!lpparam.packageName.equals("com.xxx.xxx")) return;

  XposedHelpers.findAndHookMethod("com.xxx.xxx.xxx.MainActivity", lpparam.classLoader, "getText", new XC_MethodHook() {

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                param.setResult("----I was changed-----");
            }

        });

    }
}
Enter fullscreen mode Exit fullscreen mode

7.Rebuild, select the app in xposedinstaller and restart it

image
image
image

8.after restart the app,When this method is executed,you will see the result is '----I was changed-----' instead of '-----ha ha !!-----'

Oldest comments (0)