xposed 如何主动调用java层类中的方

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xposed 如何主动调用java层类中的方相关的知识,希望对你有一定的参考价值。

final Class <?> test = XposedHelpers.findClass("com.debug.xposed.xposedtest.test", lpparam.classLoader);
final Class <?> testndk = XposedHelpers.findClass("com.debug.xposed.xposedtest.testndk", lpparam.classLoader);
findAndHookMethod("com.debug.xposed.xposedtest.MainActivity", lpparam.classLoader, "testbtn", View.class, new XC_MethodHook()

@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
XposedBridge.log("Hook之前");
//getSign


@Override
//函数执行后
protected void afterHookedMethod(MethodHookParam param) throws Throwable

XposedBridge.log("Hook之后");
try
String str1 = (String) XposedHelpers.callMethod(param.thisObject, "test1");
Log.i("debug","mainactivity test1 return "+str1);
String str2 = (String) XposedHelpers.callMethod(param.thisObject, "test2","xposed input main test2");
Log.i("debug","mainactivity test2 return "+str2);

Object testObject = test.newInstance();
String str3 = (String) XposedHelpers.callMethod(testObject,"test1");
Log.i("debug","test test1 return= "+str3);
String str4 = (String) XposedHelpers.callMethod(testObject, "test2", "hello ", "txmg");
Log.i("debug","test test2 return= "+str4);

Object testndkobject = testndk.newInstance();
Method myteststr = XposedHelpers.findMethodBestMatch(testndkobject.getClass(), "teststr");
String str5 = (String) myteststr.invoke(testndkobject);
Log.i("debug","ndk teststr return= "+str5);

Method mytest = XposedHelpers.findMethodBestMatch(testndkobject.getClass(), "mytest"," gggg");
String str6 = (String) mytest.invoke(testndkobject,"mytest input test ");
Log.i("debug","ndk mytest return= "+str6);
catch (Exception e)

e.printStackTrace();
参考技术A XposedHelpers.callMethod
XposedHelpers.callStaticMethod

以上是关于xposed 如何主动调用java层类中的方的主要内容,如果未能解决你的问题,请参考以下文章

四. Java继承和多态2. Java super关键字

JAVA和Android的回调机制

C#中怎么调用WebService

在Java接口的实现类中如何调用这个接口中定义的变量?

Java中如何调用枚举类中的数组

Android 中如何在java类中调用activity 中的一个方法?