环境:
andriod studio2023.1.1
jdk17
gradle8.2
流程:
1.新建项目,选empty views activity即可(其他也可)
2.语言选java,其他路径名称等暗战自己需要随便改,然后点击finish
3.修改AndroidManifest.xml,加入以下代码:
<meta-dataandroid:name="xposedmodule"android:value="true" /><meta-dataandroid:name="xposeddescription"android:value="xposed" /><meta-dataandroid:name="xposedminversion"android:value="53" />
4.MainActivity修改
public class MainActivity extends AppCompatActivity {private Button button;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button = (Button) findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {public void onClick(View v) {Toast.makeText(MainActivity.this, toastMessage(), Toast.LENGTH_SHORT).show();}});}public String toastMessage() {return "没结果";}
}
5.在主页面activity_main.xml页面加一个按钮
<Buttonandroid:id="@+id/button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="别点我,没结果"tools:ignore="MissingConstraints"tools:layout_editor_absoluteX="132dp"tools:layout_editor_absoluteY="286dp" />
6.添加xposed依赖,将api-82.jar文件添加到libs文件夹中
这里要注意一下,直接点击api-82.jar右键,会出现
implementation(files(“libs/api-82.jar”))
我们在build.gradle文件中直接手动改成
compileOnly(files("libs/api-82.jar"))
然后sync一下
7.编写hook文件,添加一个java文件,比如Dain等
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;public class Dain implements IXposedHookLoadPackage {public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {if (loadPackageParam.packageName.equals("com.tencent.aaa")) {XposedBridge.log(" has Hooked!");Class<?> clazz = loadPackageParam.classLoader.loadClass("com.tencent.aaa.MainActivity");XposedHelpers.findAndHookMethod(clazz, "toastMessage", new XC_MethodHook() {protected void beforeHookedMethod(MethodHookParam param) throws Throwable {super.beforeHookedMethod(param);//XposedBridge.log(" has Hooked!");}protected void afterHookedMethod(MethodHookParam param) throws Throwable {param.setResult("hooker1.0");}});}}
}
8.右键Main文件夹,新建assets
在里面新建xposed_init
里面写hook入口文件
com.tencent.aaa.Dain
然后build,安装到手机,点击按钮,如果出现了hooker1.0,说明配置完成,如果显示没结果,查一下是不是漏掉了哪一步。
至此,一个简单的xposed插件就开发完成了。