minor fix

This commit is contained in:
327135569 2021-04-28 20:24:47 +08:00
parent 14fb841a53
commit 9373508fda
4 changed files with 40 additions and 18 deletions

View File

@ -19,7 +19,10 @@ import org.lsposed.lspatch.share.Constants;
import org.lsposed.lspd.nativebridge.SigBypass; import org.lsposed.lspd.nativebridge.SigBypass;
import org.lsposed.lspd.yahfa.hooker.YahfaHooker; import org.lsposed.lspd.yahfa.hooker.YahfaHooker;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
@ -33,7 +36,7 @@ import de.robv.android.xposed.XposedInit;
* Created by Windysha * Created by Windysha
*/ */
@SuppressLint("UnsafeDynamicallyLoadedCode") @SuppressLint("UnsafeDynamicallyLoadedCode")
public class LSPApplication extends Application { public class LSPApplication {
private static final String ORIGINAL_APPLICATION_NAME_ASSET_PATH = "original_application_name.ini"; private static final String ORIGINAL_APPLICATION_NAME_ASSET_PATH = "original_application_name.ini";
private static final String ORIGINAL_SIGNATURE_ASSET_PATH = "original_signature_info.ini"; private static final String ORIGINAL_SIGNATURE_ASSET_PATH = "original_signature_info.ini";
private static final String TAG = LSPApplication.class.getSimpleName(); private static final String TAG = LSPApplication.class.getSimpleName();
@ -207,7 +210,7 @@ public class LSPApplication extends Application {
}); });
} }
private static void doHook() throws IllegalAccessException, ClassNotFoundException { private static void doHook() throws IllegalAccessException, ClassNotFoundException, IOException {
hookContextImplSetOuterContext(); hookContextImplSetOuterContext();
hookInstallContentProviders(); hookInstallContentProviders();
hookActivityAttach(); hookActivityAttach();
@ -216,7 +219,20 @@ public class LSPApplication extends Application {
byPassSignature(); byPassSignature();
} }
if (fetchSigbypassLv() >= Constants.SIGBYPASS_LV_PM_OPENAT) { if (fetchSigbypassLv() >= Constants.SIGBYPASS_LV_PM_OPENAT) {
SigBypass.enableOpenatHook(); File apk = new File(context.getCacheDir(), "lspatchapk.so");
if (!apk.exists()) {
try (InputStream inputStream = context.getAssets().open("origin_apk.bin");
FileOutputStream buffer = new FileOutputStream(apk)) {
int nRead;
byte[] data = new byte[16384];
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
}
}
SigBypass.enableOpenatHook(context.getApplicationInfo().packageName);
} }
} }
@ -227,8 +243,7 @@ public class LSPApplication extends Application {
return cacheSigbypassLv; return cacheSigbypassLv;
} }
for (int i = Constants.SIGBYPASS_LV_DISABLE; i < Constants.SIGBYPASS_LV_MAX; i++) { for (int i = Constants.SIGBYPASS_LV_DISABLE; i < Constants.SIGBYPASS_LV_MAX; i++) {
try { try (InputStream inputStream = context.getAssets().open(Constants.CONFIG_NAME_SIGBYPASSLV + i)) {
context.getAssets().open(Constants.CONFIG_NAME_SIGBYPASSLV + i);
cacheSigbypassLv = i; cacheSigbypassLv = i;
return i; return i;
} }
@ -299,7 +314,6 @@ public class LSPApplication extends Application {
return activityThread; return activityThread;
} }
@Override
protected void attachBaseContext(Context base) { protected void attachBaseContext(Context base) {
// 将applicationInfo中保存的applcation class name还原为真实的application class name // 将applicationInfo中保存的applcation class name还原为真实的application class name
@ -307,8 +321,6 @@ public class LSPApplication extends Application {
modifyApplicationInfoClassName(); modifyApplicationInfoClassName();
} }
super.attachBaseContext(base);
if (isApplicationProxied()) { if (isApplicationProxied()) {
attachOrignalBaseContext(base); attachOrignalBaseContext(base);
setLoadedApkField(base); setLoadedApkField(base);
@ -339,11 +351,9 @@ public class LSPApplication extends Application {
} }
} }
@Override
public void onCreate() { public void onCreate() {
// setLoadedApkField(sOriginalApplication); // setLoadedApkField(sOriginalApplication);
// XposedHelpers.setObjectField(sOriginalApplication, "mLoadedApk", XposedHelpers.getObjectField(this, "mLoadedApk")); // XposedHelpers.setObjectField(sOriginalApplication, "mLoadedApk", XposedHelpers.getObjectField(this, "mLoadedApk"));
super.onCreate();
if (isApplicationProxied()) { if (isApplicationProxied()) {
// replaceApplication(); // replaceApplication();

View File

@ -26,9 +26,8 @@ public class LSPApplicationStub extends Application {
Log.e(TAG, "create context err"); Log.e(TAG, "create context err");
} }
else { else {
try { try (InputStream inputStream = context.getAssets().open("lsploader.dex");
InputStream inputStream = context.getAssets().open("lsploader.dex"); ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead; int nRead;
byte[] data = new byte[16384]; byte[] data = new byte[16384];
@ -37,9 +36,6 @@ public class LSPApplicationStub extends Application {
buffer.write(data, 0, nRead); buffer.write(data, 0, nRead);
} }
buffer.flush();
buffer.close();
// loader can load it's own so from app native library dir // loader can load it's own so from app native library dir
String libraryDir = context.getApplicationInfo().nativeLibraryDir; String libraryDir = context.getApplicationInfo().nativeLibraryDir;
@ -57,6 +53,20 @@ public class LSPApplicationStub extends Application {
} }
} }
@Override
public void onCreate() {
super.onCreate();
if (realLSPApplication != null) {
try {
realLSPApplication.getClass().getDeclaredMethod("onCreate").invoke(realLSPApplication);
}
catch (Exception e) {
throw new IllegalStateException("wtf", e);
}
}
}
@Override @Override
protected void attachBaseContext(Context base) { protected void attachBaseContext(Context base) {
super.attachBaseContext(base); super.attachBaseContext(base);

2
mmp

@ -1 +1 @@
Subproject commit efe7306fed1bcf5bde7ff8d45f2316ddc81e4e4b Subproject commit 41668cd0ad080e18b527ad70db4b8828059e3257

View File

@ -19,6 +19,7 @@ import org.lsposed.patch.util.ManifestParser;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -184,7 +185,8 @@ public class LSPatch extends BaseCommand {
} }
// save lspatch config to asset.. // save lspatch config to asset..
fuckIfFail(new File(unzipApkFilePath, "assets/" + Constants.CONFIG_NAME_SIGBYPASSLV + sigbypassLevel).createNewFile()); org.apache.commons.io.FileUtils.write(new File(unzipApkFilePath, "assets" + File.separator + Constants.CONFIG_NAME_SIGBYPASSLV + sigbypassLevel), "lspatch",
Charset.defaultCharset());
// compress all files into an apk and then sign it. // compress all files into an apk and then sign it.
new BuildAndSignApkTask(true, unzipApkFilePath, outputPath).run(); new BuildAndSignApkTask(true, unzipApkFilePath, outputPath).run();