Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
b14aa178 committed Apr 29, 2021
1 parent 14fb841 commit 9373508
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
30 changes: 20 additions & 10 deletions app/src/main/java/org/lsposed/lspatch/loader/LSPApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import org.lsposed.lspd.nativebridge.SigBypass;
import org.lsposed.lspd.yahfa.hooker.YahfaHooker;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
Expand All @@ -33,7 +36,7 @@
* Created by Windysha
*/
@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_SIGNATURE_ASSET_PATH = "original_signature_info.ini";
private static final String TAG = LSPApplication.class.getSimpleName();
Expand Down Expand Up @@ -207,7 +210,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
});
}

private static void doHook() throws IllegalAccessException, ClassNotFoundException {
private static void doHook() throws IllegalAccessException, ClassNotFoundException, IOException {
hookContextImplSetOuterContext();
hookInstallContentProviders();
hookActivityAttach();
Expand All @@ -216,7 +219,20 @@ private static void doHook() throws IllegalAccessException, ClassNotFoundExcepti
byPassSignature();
}
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);
}
}

Expand All @@ -227,8 +243,7 @@ private static int fetchSigbypassLv() {
return cacheSigbypassLv;
}
for (int i = Constants.SIGBYPASS_LV_DISABLE; i < Constants.SIGBYPASS_LV_MAX; i++) {
try {
context.getAssets().open(Constants.CONFIG_NAME_SIGBYPASSLV + i);
try (InputStream inputStream = context.getAssets().open(Constants.CONFIG_NAME_SIGBYPASSLV + i)) {
cacheSigbypassLv = i;
return i;
}
Expand Down Expand Up @@ -299,16 +314,13 @@ private static Object getActivityThread() {
return activityThread;
}

@Override
protected void attachBaseContext(Context base) {

// 将applicationInfo中保存的applcation class name还原为真实的application class name
if (isApplicationProxied()) {
modifyApplicationInfoClassName();
}

super.attachBaseContext(base);

if (isApplicationProxied()) {
attachOrignalBaseContext(base);
setLoadedApkField(base);
Expand Down Expand Up @@ -339,11 +351,9 @@ private void setLoadedApkField(Context base) {
}
}

@Override
public void onCreate() {
// setLoadedApkField(sOriginalApplication);
// XposedHelpers.setObjectField(sOriginalApplication, "mLoadedApk", XposedHelpers.getObjectField(this, "mLoadedApk"));
super.onCreate();

if (isApplicationProxied()) {
// replaceApplication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public class LSPApplicationStub extends Application {
Log.e(TAG, "create context err");
}
else {
try {
InputStream inputStream = context.getAssets().open("lsploader.dex");
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try (InputStream inputStream = context.getAssets().open("lsploader.dex");
ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {

int nRead;
byte[] data = new byte[16384];
Expand All @@ -37,9 +36,6 @@ public class LSPApplicationStub extends Application {
buffer.write(data, 0, nRead);
}

buffer.flush();
buffer.close();

// loader can load it's own so from app native library dir
String libraryDir = context.getApplicationInfo().nativeLibraryDir;

Expand All @@ -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
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
Expand Down
2 changes: 1 addition & 1 deletion mmp
Submodule mmp updated from efe730 to 41668c
4 changes: 3 additions & 1 deletion patch/src/main/java/org/lsposed/patch/LSPatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -184,7 +185,8 @@ protected void doCommandLine() throws IOException {
}

// 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.
new BuildAndSignApkTask(true, unzipApkFilePath, outputPath).run();
Expand Down

0 comments on commit 9373508

Please sign in to comment.