add pmmtool switch

master
wlt233 1 year ago
parent 804fc6d0d8
commit 6120bee512

@ -1,6 +1,9 @@
package moe.tqlwsl.aicemu
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Build
@ -8,9 +11,11 @@ import android.os.Bundle
import android.util.Log
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
import org.lsposed.hiddenapibypass.HiddenApiBypass
import java.lang.reflect.Method
class SettingActivity : AppCompatActivity() {
private var isHCEFSupported: Boolean = false
private var isHCEFUnlocked: Boolean = false
@ -34,8 +39,8 @@ class SettingActivity : AppCompatActivity() {
textHCEF.setTextColor(Color.RED)
}
val textUnlocker = findViewById<TextView>(R.id.unlocker_work_text)
if (isHCEFSupported) {
val textUnlocker = findViewById<TextView>(R.id.unlocker_work_text)
try {
val globalVar = this.applicationContext as GlobalVar
isHCEFUnlocked = globalVar.isHCEFUnlocked
@ -67,6 +72,15 @@ class SettingActivity : AppCompatActivity() {
// textPmmtool.setTextColor(Color.GREEN)
// }
val pmmtoolSwitch = findViewById<SwitchCompat>(R.id.pmmtool_switch)
pmmtoolSwitch.setOnCheckedChangeListener { _, isChecked ->
var prefs: SharedPreferences =
applicationContext.getSharedPreferences("AICEmu", Context.MODE_WORLD_READABLE)
val editor = prefs.edit()
editor.putBoolean("loadPmmtool", isChecked)
editor.apply()
Runtime.getRuntime().exec(arrayOf("su", "-c", "kill -9 $(su -c pidof com.android.nfc)"))
}
}
}

@ -1,9 +1,14 @@
package moe.tqlwsl.aicemu;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import java.util.List;
@ -11,6 +16,7 @@ import java.util.List;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
@ -24,7 +30,6 @@ public class xp implements IXposedHookLoadPackage {
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
XposedBridge.log("In " + lpparam.packageName);
if (lpparam.packageName.equals("com.android.nfc")) {
XposedHelpers.findAndHookMethod("android.nfc.cardemulation.NfcFCardEmulation", lpparam.classLoader,
@ -36,45 +41,47 @@ public class xp implements IXposedHookLoadPackage {
});
// XposedHelpers.findAndHookMethod("com.android.nfc.NfcApplication",
// lpparam.classLoader, "onCreate", new XC_MethodHook() {
// @Override
// protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
// XposedBridge.log("Inside com.android.nfc.NfcApplication#onCreate");
// super.beforeHookedMethod(param);
// Application application = (Application) param.thisObject;
// mcontext = application.getApplicationContext();
// XposedBridge.log("Got context");
// }
// });
XposedHelpers.findAndHookMethod("com.android.nfc.NfcApplication",
lpparam.classLoader, "onCreate", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
XposedBridge.log("Inside com.android.nfc.NfcApplication#onCreate");
super.beforeHookedMethod(param);
Application application = (Application) param.thisObject;
mcontext = application.getApplicationContext();
XposedBridge.log("Got context");
}
});
XposedHelpers.findAndHookMethod("android.nfc.cardemulation.NfcFCardEmulation",
lpparam.classLoader, "isValidSystemCode", String.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
XposedBridge.log("Inside android.nfc.cardemulation.NfcFCardEmulation#isValidSystemCode");
// mclassloader = mcontext.getClassLoader();
// XposedBridge.log("Got classloader");
// String path = getSoPath();
// XposedBridge.log("So path = " + path);
// int version = android.os.Build.VERSION.SDK_INT;
// try {
// if (!path.equals("")) {
// XposedBridge.log("Start injecting libpmm.so");
// if (version >= 28) {
// XposedHelpers.callMethod(Runtime.getRuntime(), "nativeLoad", path, mclassloader);
// } else {
// XposedHelpers.callMethod(Runtime.getRuntime(), "doLoad", path, mclassloader);
// }
// XposedBridge.log("Injected libpmm.so");
// }
// } catch (Exception e) {
// XposedBridge.log(e);
// e.printStackTrace();
// }
mclassloader = mcontext.getClassLoader();
XposedBridge.log("Got classloader");
String path = getSoPath();
XposedBridge.log("So path = " + path);
try {
Boolean needLoadPmmtool = false;
XSharedPreferences pref = getPref();
if (pref != null) {
needLoadPmmtool = pref.getBoolean("loadPmmtool", false);
} else {
XposedBridge.log("Cannot load pref for AICEmu properly");
}
XposedBridge.log("loadPmmtool: " + needLoadPmmtool.toString());
if (needLoadPmmtool && !path.equals("")) {
XposedBridge.log("Start injecting libpmm.so");
XposedHelpers.callMethod(Runtime.getRuntime(), "nativeLoad", path, mclassloader);
XposedBridge.log("Injected libpmm.so");
}
} catch (Exception e) {
XposedBridge.log(e);
e.printStackTrace();
}
// Unlocker
param.setResult(true);
@ -84,7 +91,10 @@ public class xp implements IXposedHookLoadPackage {
XposedBridge.log("Hook succeeded!!!");
}
}
private static XSharedPreferences getPref() {
XSharedPreferences pref = new XSharedPreferences("moe.tqlwsl.aicemu", "AICEmu");
return pref.getFile().canRead() ? pref : null;
}
private String getSoPath() {
try {
String text = "";

@ -40,5 +40,38 @@
app:layout_constraintTop_toBottomOf="@+id/unlocker_work_text"
android:visibility="gone"/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/pmmtool_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pmmtool_work_text"
android:text="@string/pmmtool_switch"/>
<TextView
android:id="@+id/version_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:textSize="20sp"
android:text="@string/version_info"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/author_text"/>
<TextView
android:id="@+id/author_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:textSize="16sp"
android:text="@string/author_info"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -25,4 +25,6 @@
<string name="mode_compatible">兼容模式</string>
<string name="mode_commmon">正常模式</string>
<string name="add_test_card">添加测试卡</string>
<string name="apdu_service_desc">模拟AIC卡</string>
<string name="pmmtool_switch">用 Pmmtool 修改 PMm</string>
</resources>

@ -31,4 +31,8 @@
<string name="mode_commmon">Common</string>
<string name="mode_compatible">Compatible</string>
<string name="add_test_card">Add test card</string>
<string name="apdu_service_desc">Emulate AIC Card</string>
<string name="pmmtool_switch">Change PMm with Pmmtool</string>
<string name="author_info" translatable="false">made by wlt233 with ❤\ntqlwsl.moe | 2709684396</string>
<string name="version_info" translatable="false">1.0-Beta4 (2023.09.01)</string>
</resources>
Loading…
Cancel
Save