Xposed如何实现类中函数的调用
生活随笔
收集整理的這篇文章主要介紹了
Xposed如何实现类中函数的调用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
0x01前言
之前學(xué)習(xí)了Xposed如何實現(xiàn)不重新打包APP的條件下,實現(xiàn)函數(shù)的Hook,在使用過程中,除了方法的hook,比如我要實現(xiàn)某些函數(shù)額調(diào)用,不同類中的函數(shù)和Native方法的調(diào)用。
0x02 測試環(huán)境
1.待測試的APP,這里寫了一個測試APP,Mainactivity實現(xiàn)界面,定義兩個函數(shù):
public String test1() Public String test2(String str)2.新建一個Class為test,并定義兩個函數(shù) ,和mainactivity一樣,test1()和test2(String str),
3.新建一個testNdk的class,實現(xiàn)native方法,并定義兩個函數(shù),
public native String teststr(); public native String mytest(String str);一個帶參數(shù)和一個沒有參數(shù)。
0x03 Xposed 實現(xiàn)方法的調(diào)用
這里我們hook mainactivity的btntest方法,
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() {@Overrideprotected void beforeHookedMethod(MethodHookParam param) throws Throwable {XposedBridge.log("Hook之前");//getSign}@Override//函數(shù)執(zhí)行后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();}Log輸出:
原文地址:?https://www.ijiza.cn/2016/02/14/xposed%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E7%B1%BB%E4%B8%AD%E5%87%BD%E6%95%B0%E7%9A%84%E8%B0%83%E7%94%A8/
總結(jié)
以上是生活随笔為你收集整理的Xposed如何实现类中函数的调用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用xposed绕过安卓SSL证书的强校
- 下一篇: android中SO文件动态调试