Hook 一个方法
创建一个实现 IXposedHookLoadPackage
的新类并实现 handleLoadPackage
方法:
public class MultiPatcher implements IXposedHookLoadPackage
{
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable
{
}
}
在方法内部,你可以检查 loadPackageParam.packageName
以获取要挂钩的应用程序的包名称:
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable
{
if (!loadPackageParam.packageName.equals("other.package.name"))
{
return;
}
}
现在,你可以挂钩你的方法,并在运行代码之前或之后操作它:
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable
{
if (!loadPackageParam.packageName.equals("other.package.name"))
{
return;
}
XposedHelpers.findAndHookMethod(
"other.package.name",
loadPackageParam.classLoader,
"otherMethodName",
YourFirstParameter.class,
YourSecondParameter.class,
new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
{
Object[] args = param.args;
args[0] = true;
args[1] = "example string";
args[2] = 1;
Object thisObject = param.thisObject;
// Do something with the instance of the class
}
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable
{
Object result = param.getResult();
param.setResult(result + "example string");
}
});
}