/**
*包装加载时的回调
*/
public void handleLoadPackage(final LoadPackageParam lpparam)
/**
*Xposed提供的Hook方法
*@param className 待Hook的Class
*@param classLoader ClassLoader
*@param methodName 待Hook的Method
*@param paramterTypesAndClassback hook回调
*/
Unhook findAndHookMethod(String className,ClassLoader classLoader,String methodName,Object... parameterTypesAndCallback)
2.创建一个Android Project HookDemo,在项目app目录下创建lib目录(如果将jar包放置到libs目录下,可能会产生错误,估计Xposed作者在其框架内部也引用了BrideApi,这样操作能避免重复),将jar包放置到lib目录(不是项目本身的libs目录)下,选择jar包->右键->Add As Library将这个jar包添加到BuildPATH;
OK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String inPut = Input.getText() + "";
//获取用户输入,并验证是否输入正确
if (isInputOK(inPut)) {
Toast.makeText(MainActivity.this, "Input Success", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Input Faild", Toast.LENGTH_SHORT).show();
}
}
});
… …
private boolean isInputOK(String inPut) {
if ("123456".equals(inPut)) {
return true;
} else {
return false;
}
}
4.在HookDemo项目中,修改AndroidManifest.xml文件中配置插件的名称和Api版本号;
… …
5.创建一个入口类继承并实现IXposedHookLoadPackage接口,使用findAndHookMethod方法Hook输入信息;
public class Main implements IXposedHookLoadPackage {
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (!loadPackageParam.packageName.equals("com.example.pengchengxiang.inputdemo")) {
return;
}
XposedBridge.log("Loaded app:" + loadPackageParam.packageName);
//Hook MainActivity类的isInputOK方法,并将该方法的参数输出至Xposed工具中
findAndHookMethod("com.example.pengchengxiang.inputdemo.MainActivity", loadPackageParam.classLoader, "isInputOK", String.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("hook start");
XposedBridge.log("param1:" + param.args[0]);
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("hook end");
XposedBridge.log("param1:" + param.args[0]);
}
});
}
}
注意:在实际应用过程中,你Hook的方法参数可能是目标程序自定义的类,非Android SDK提供,如"com.example.pengchengxiang.inputdemo.Test"。这里我们可以使用方法XposedHelpers.findClass来获取参数类型的class对象,如下:
XposedHelpers.findAndHookMethod("com.example.pengchengxiang.inputdemo.MainActivity", loadPackageParam.classLoader, "isInputOK", String.class,
XposedHelpers.findClass("com.example.pengchengxiang.inputdemo.Test", loadPackageParam.classLoader), new XC_MethodHook() {...}
6.声明主入口路径,在assets文件夹中创建xposed_init文件,并在其中声明主入口类;
com.example.pengchengxiang.hookdemo.Main
7.完成InputDemo和HookDemo并安装在手机中,在XposedInstaller中启动我们的自己开发的模块;