refine code

This commit is contained in:
327135569 2021-04-11 16:15:29 +08:00
parent f97f52dc8c
commit 49e6d32fc5
9 changed files with 23 additions and 152 deletions

View File

@ -1,19 +1,15 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
compileSdkVersion rootProject.ext.androidCompileSdkVersion
defaultConfig {
applicationId "com.storm.wind.xposed"
minSdkVersion 27
targetSdkVersion 28
versionCode version_code as Integer
versionName version_name
applicationId "org.lsposed.lspatch"
minSdkVersion rootProject.ext.androidMinSdkVersion
targetSdkVersion rootProject.ext.androidTargetSdkVersion
versionCode rootProject.ext.verCode
versionName rootProject.ext.verName
multiDexEnabled false
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
buildTypes {
debug {
@ -65,6 +61,5 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation("androidx.core:core:1.3.2")
implementation project(path: ':lspcore')
}

View File

@ -1,41 +1,23 @@
package com.storm.wind.xposed;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.core.app.ActivityCompat;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
//import android.support.v4.app.ActivityCompat;
public class MainActivity extends Activity {
private static final int REQUEST_PERMISSION_CODE = 1;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, REQUEST_PERMISSION_CODE);
}
}
XposedHelpers.findAndHookMethod(this.getClass(), "checkXposed", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

View File

@ -182,6 +182,7 @@ public class MMPLoader {
boolean configFileExist = configFileExist();
// todo: Android 11
for (PackageInfo pkg : pm.getInstalledPackages(PackageManager.GET_META_DATA)) {
ApplicationInfo app = pkg.applicationInfo;
if (!app.enabled) {
@ -228,7 +229,7 @@ public class MMPLoader {
return modulePathList;
}
// sd卡中加载指定文件以加载指定的xposed module
// sd 卡中加载指定文件以加载指定的 xposed module
private static List<String> loadPackageNameListFromFile(boolean loadActivedPackages) {
File moduleFile = new File(DIR_BASE, XPOSED_MODULE_FILE_PATH);
if (!moduleFile.exists()) {
@ -236,11 +237,8 @@ public class MMPLoader {
}
List<String> modulePackageList = new ArrayList<>();
FileInputStream fileInputStream = null;
BufferedReader bufferedReader = null;
try {
fileInputStream = new FileInputStream(moduleFile);
bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
try (FileInputStream fileInputStream = new FileInputStream(moduleFile);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream))) {
String modulePackageName;
while ((modulePackageName = bufferedReader.readLine()) != null) {
modulePackageName = modulePackageName.trim();
@ -263,10 +261,6 @@ public class MMPLoader {
e.printStackTrace();
return null;
}
finally {
closeStream(fileInputStream);
closeStream(bufferedReader);
}
return modulePackageList;
}
@ -282,12 +276,8 @@ public class MMPLoader {
throw new IllegalStateException("create " + XPOSED_MODULE_FILE_PATH + " err");
}
}
FileOutputStream outputStream = null;
BufferedWriter writer = null;
try {
outputStream = new FileOutputStream(moduleFile, true);
writer = new BufferedWriter(new OutputStreamWriter(outputStream));
try (FileOutputStream outputStream = new FileOutputStream(moduleFile, true);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream))) {
for (Pair<String, String> packageInfo : packageNameList) {
String packageName = packageInfo.first;
String appName = packageInfo.second;
@ -300,10 +290,6 @@ public class MMPLoader {
catch (Exception e) {
e.printStackTrace();
}
finally {
closeStream(outputStream);
closeStream(writer);
}
}
private static boolean configFileExist() {

View File

@ -21,15 +21,15 @@ public class FileUtils {
public static boolean isSdcardPermissionGranted(Context context) {
int pid = android.os.Process.myPid();
int uid = Process.myUid();
return context.checkPermission(PERMISSIONS_STORAGE[0], pid, uid) == PackageManager.PERMISSION_GRANTED && context.checkPermission(PERMISSIONS_STORAGE[1], pid, uid) == PackageManager.PERMISSION_GRANTED;
return context.checkPermission(PERMISSIONS_STORAGE[0], pid, uid) == PackageManager.PERMISSION_GRANTED && context.checkPermission(PERMISSIONS_STORAGE[1], pid,
uid) == PackageManager.PERMISSION_GRANTED;
}
public static String readTextFromAssets(Context context, String assetsFileName) {
if (context == null) {
throw new IllegalStateException("context null");
}
try {
InputStream is = context.getAssets().open(assetsFileName);
try (InputStream is = context.getAssets().open(assetsFileName)) {
return readTextFromInputStream(is);
}
catch (Exception e) {

View File

@ -1,93 +0,0 @@
package com.wind.xposed.entry.util;
import static android.os.Build.VERSION.SDK_INT;
import android.os.Build;
import android.util.Log;
import java.lang.reflect.Method;
/**
* @author Windysha
*/
public class ReflectionApiCheck {
private static final String TAG = ReflectionApiCheck.class.getSimpleName();
private static final int ERROR_EXEMPT_FAILED = -21;
private static Object sVmRuntime;
private static Method setHiddenApiExemptions;
static {
if (SDK_INT >= Build.VERSION_CODES.P) {
try {
Method forName = Class.class.getDeclaredMethod("forName", String.class);
Method getDeclaredMethod = Class.class.getDeclaredMethod("getDeclaredMethod", String.class, Class[].class);
Class<?> vmRuntimeClass = (Class<?>) forName.invoke(null, "dalvik.system.VMRuntime");
Method getRuntime = (Method) getDeclaredMethod.invoke(vmRuntimeClass, "getRuntime", null);
if (getRuntime == null) {
throw new IllegalStateException("getRuntime method null");
}
setHiddenApiExemptions = (Method) getDeclaredMethod.invoke(vmRuntimeClass, "setHiddenApiExemptions", new Class[]{String[].class});
sVmRuntime = getRuntime.invoke(null);
}
catch (Throwable e) {
Log.e(TAG, "reflect bootstrap failed:", e);
}
}
}
public static int unseal() {
if (SDK_INT < 28) {
// Below Android P, ignore
return 0;
}
// try exempt API first.
if (exemptAll()) {
return 0;
}
else {
return ERROR_EXEMPT_FAILED;
}
}
/**
* make the method exempted from hidden API check.
*
* @param method the method signature prefix.
* @return true if success.
*/
public static boolean exempt(String method) {
return exempt(new String[]{method});
}
/**
* make specific methods exempted from hidden API check.
*
* @param methods the method signature prefix, such as "Ldalvik/system", "Landroid" or even "L"
* @return true if success
*/
public static boolean exempt(String... methods) {
if (sVmRuntime == null || setHiddenApiExemptions == null) {
return false;
}
try {
setHiddenApiExemptions.invoke(sVmRuntime, new Object[]{methods});
return true;
}
catch (Throwable e) {
return false;
}
}
/**
* Make all hidden API exempted.
*
* @return true if success.
*/
public static boolean exemptAll() {
return exempt(new String[]{"L"});
}
}

View File

@ -10,7 +10,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class XpatchUtils {
final static String TAG = "MMP" + XpatchUtils.class.getSimpleName();
final static String TAG = "LSP" + XpatchUtils.class.getSimpleName();
public static Context createAppContext() {
try {

View File

@ -7,8 +7,8 @@
<TextView
android:id="@+id/msg"
android:textSize="50sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Hello World!" />
</RelativeLayout>

View File

@ -9,20 +9,21 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-alpha14'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32"
}
}
// sync from https://github.com/LSPosed/LSPosed/blob/master/build.gradle.kts
ext {
androidCompileSdkVersion = 30
androidCompileNdkVersion = "22.1.7171670"
androidBuildToolsVersion = "30.0.3"
androidMinSdkVersion = 27
androidTargetSdkVersion = 28
androidTargetSdkVersion = 30
verCode = 1
verName = "mmpatch"
verName = "lspatch"
apiCode = 93
defaultManagerPackageName = "org.github.mmpatch"
defaultManagerPackageName = "org.lsposed.lspatch"
androidSourceCompatibility = JavaVersion.VERSION_11
androidTargetCompatibility = JavaVersion.VERSION_11
zipPathMagiskReleasePath = project(":lspcore").projectDir.path + "/build/tmp/release/magisk/"

View File

@ -1,5 +1,5 @@
include ':app'
rootProject.name='MMPLoader'
rootProject.name='LSPatch'
include ':lspcore'
project(':lspcore').projectDir = new File('mmp/core')
include ':hiddenapi-stubs'