企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 话不多说,直接上代码 ## MainActivity.class ~~~ package com.gyk.xposedmodule; import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import de.robv.android.xposed.XposedBridge; public class MainActivity extends AppCompatActivity { private EditText editText1; private EditText editText2; private EditText editText3; private String kapai1 = "J"; private String kapai2 = "Q"; private String kapai3 = "K"; private Button button; public static Context context = null; private static String[] kapais = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); context = getApplicationContext(); editText1 = (EditText) findViewById(R.id.editText1); editText2 = (EditText)findViewById(R.id.editText2); editText3 = (EditText)findViewById(R.id.editText3); editText1.setText(kapai1); editText2.setText(kapai2); editText3.setText(kapai3); button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { kapai1 = editText1.getText().toString(); kapai2 = editText2.getText().toString(); kapai3 = editText3.getText().toString(); kapai1 = kapai1.trim().toUpperCase(); kapai2 = kapai2.trim().toUpperCase(); kapai3 = kapai3.trim().toUpperCase(); editText1.setText(kapai1); editText2.setText(kapai2); editText3.setText(kapai3); List<String> list = new ArrayList<>(Arrays.asList(kapais)); int i1 = list.indexOf(kapai1) + 10; int i2 = list.indexOf(kapai2) + 10; int i3 = list.indexOf(kapai3) + 10; String strNums = i1 + "," + i2 + "," + i3; String path =""; // 获取到当前环境的存储路径 path = context.getFilesDir().getAbsolutePath(); boolean flag = saveFile(path,strNums); String toastMsg = ""; if(flag) { toastMsg = "卡牌已经保存,地址为" + path; } else { toastMsg = "卡牌保存失败!"; } Toast t = Toast.makeText(getApplicationContext(),toastMsg , Toast.LENGTH_LONG); t.show(); } }); } // 保存文件 public static boolean saveFile(String path,String strNums){ FileOutputStream outputStream; try{ outputStream = new FileOutputStream(new File(path + "/puke.txt")); outputStream.write(strNums.getBytes()); outputStream.flush(); outputStream.close(); return true; }catch (Exception e) { e.printStackTrace(); } return false; } } ~~~ ## HookClass.class ~~~ package com.gyk.xposedmodule; import android.app.Application; import android.content.Context; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.List; 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 HookClass implements IXposedHookLoadPackage { @Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable { XposedBridge.log("========hook到包:" + lpparam.packageName + "============"); String weNeedPackage = "com.ify.dd"; if (lpparam.packageName.equals(weNeedPackage)) { XposedBridge.log("=====hook到了我们要的包:" + lpparam.packageName); // hook我们需要的类,由于是多dex,所以需要特殊处理 XposedHelpers.findAndHookMethod(Application.class, "attach", Context.class, new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { final Context context = (Context) param.args[0]; ClassLoader cl = (context.getClassLoader()); Class<?> hookclass = null; Class<?> argClass = null; try { hookclass = cl.loadClass("com.tongdaxing.xchat_core.room.face.FaceCoreImpl"); argClass = cl.loadClass("com.tongdaxing.xchat_core.room.face.FaceInfo"); } catch (Exception e) { XposedBridge.log("jyy寻找xxx.xxx.xxx报错"); return; } XposedBridge.log("寻找xxx.xxx.xxx成功"); XposedHelpers.findAndHookMethod(hookclass, "generateRandomNumber", int.class, argClass, new XC_MethodHook(){ //进行hook操作 @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { XposedBridge.log("=====hook方法前====="); if(param != null && param.args.length > 0){ XposedBridge.log("查看参数"); for (int i = 0; i < param.args.length; i++) { XposedBridge.log("arg:" + param.args[i]); } XposedBridge.log("========拦截前完毕====="); } } @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); XposedBridge.log("=====hook方法后====="); Object obj = param.getResultOrThrowable(); String text = readData(); String[] strPukes = text.split(","); Integer[] pukeIds = new Integer[3]; for (int i = 0; i < strPukes.length; i++) { pukeIds[i] = Integer.parseInt(strPukes[i]); } List<Integer> list = Arrays.asList(pukeIds); XposedBridge.log("========"+ pukeIds[2] +"=========="); param.setResult(list); } }); } }); } } // 读取文件信息 public static String readData() { // 由于无法获取到MainActivity的content,所以路径手写 String path = "/data/user/0/io.va.exposed/virtual/data/user/0/com.gyk.xposedmodule/files/puke.txt"; File file = new File(path); try { FileInputStream fis = new FileInputStream(file); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); StringBuilder sb = new StringBuilder(""); String line = null; while((line = br.readLine()) != null) { sb.append(line); } return sb.toString(); } catch (Exception e) { e.printStackTrace(); } return "真sb"; } } ~~~