From 6bd50258cf0d7ac7eec46edf0c5e84fbf64d6e05 Mon Sep 17 00:00:00 2001 From: Milk <1871357815@qq.com> Date: Sat, 22 May 2021 20:55:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/mirror/android/app/LoadedApk.java | 1 + .../blackbox/entity/pm/InstalledModule.aidl | 3 - .../top/niunaijun/blackbox/BlackBoxCore.java | 23 ++++-- .../blackbox/app/BActivityThread.java | 24 ++++--- .../blackbox/entity/pm/InstalledModule.java | 72 ------------------- .../blackbox/entity/pm/XposedConfig.java | 61 ---------------- .../top/niunaijun/blackdex/MainActivity.java | 15 +--- 7 files changed, 37 insertions(+), 162 deletions(-) delete mode 100644 Bcore/src/main/aidl/top/niunaijun/blackbox/entity/pm/InstalledModule.aidl delete mode 100644 Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/InstalledModule.java delete mode 100644 Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/XposedConfig.java diff --git a/Bcore/black-fake/src/main/java/mirror/android/app/LoadedApk.java b/Bcore/black-fake/src/main/java/mirror/android/app/LoadedApk.java index da79ac5..9362031 100644 --- a/Bcore/black-fake/src/main/java/mirror/android/app/LoadedApk.java +++ b/Bcore/black-fake/src/main/java/mirror/android/app/LoadedApk.java @@ -9,6 +9,7 @@ public class LoadedApk { public static final MirrorReflection REF = MirrorReflection.on("android.app.LoadedApk"); public static MirrorReflection.FieldWrapper mApplicationInfo = REF.field("mApplicationInfo"); public static MirrorReflection.MethodWrapper makeApplication = REF.method("makeApplication", boolean.class, Instrumentation.class); + public static MirrorReflection.MethodWrapper getClassloader = REF.method("getClassloader"); public static MirrorReflection.FieldWrapper mSecurityViolation = REF.field("mSecurityViolation"); } \ No newline at end of file diff --git a/Bcore/src/main/aidl/top/niunaijun/blackbox/entity/pm/InstalledModule.aidl b/Bcore/src/main/aidl/top/niunaijun/blackbox/entity/pm/InstalledModule.aidl deleted file mode 100644 index 1fd84cb..0000000 --- a/Bcore/src/main/aidl/top/niunaijun/blackbox/entity/pm/InstalledModule.aidl +++ /dev/null @@ -1,3 +0,0 @@ -package top.niunaijun.blackbox.entity.pm; - -parcelable InstalledModule; \ No newline at end of file diff --git a/Bcore/src/main/java/top/niunaijun/blackbox/BlackBoxCore.java b/Bcore/src/main/java/top/niunaijun/blackbox/BlackBoxCore.java index af774e7..40f8985 100644 --- a/Bcore/src/main/java/top/niunaijun/blackbox/BlackBoxCore.java +++ b/Bcore/src/main/java/top/niunaijun/blackbox/BlackBoxCore.java @@ -109,9 +109,6 @@ public class BlackBoxCore extends ClientConfiguration { } public void doCreate() { - // fix contentProvider - if (isVirtualProcess()) { - } if (!isServerProcess()) { initService(); } @@ -143,7 +140,25 @@ public class BlackBoxCore extends ClientConfiguration { return BStorageManager.get(); } - public boolean launchApk(String packageName) { + public boolean dumpDex(String packageName) { + InstallResult installResult = installPackage(packageName); + if (installResult.success) { + return launchApk(packageName); + } else { + return false; + } + } + + public boolean dumpDex(File file) { + InstallResult installResult = installPackage(file); + if (installResult.success) { + return launchApk(installResult.packageName); + } else { + return false; + } + } + + private boolean launchApk(String packageName) { Intent launchIntentForPackage = getBPackageManager().getLaunchIntentForPackage(packageName, USER_ID); if (launchIntentForPackage == null) { return false; diff --git a/Bcore/src/main/java/top/niunaijun/blackbox/app/BActivityThread.java b/Bcore/src/main/java/top/niunaijun/blackbox/app/BActivityThread.java index 3b45921..9f7ec06 100644 --- a/Bcore/src/main/java/top/niunaijun/blackbox/app/BActivityThread.java +++ b/Bcore/src/main/java/top/niunaijun/blackbox/app/BActivityThread.java @@ -26,6 +26,7 @@ import top.niunaijun.blackbox.core.IBActivityThread; import top.niunaijun.blackbox.core.VMCore; import top.niunaijun.blackbox.entity.AppConfig; import top.niunaijun.blackbox.core.IOCore; +import top.niunaijun.blackbox.utils.Slog; import top.niunaijun.blackbox.utils.compat.ContextCompat; import top.niunaijun.blackbox.BlackBoxCore; @@ -170,22 +171,27 @@ public class BActivityThread extends IBActivityThread.Stub { mBoundApplication = bindData; - Application application; + Application application = null; BlackBoxCore.get().getAppLifecycleCallback().beforeCreateApplication(packageName, processName, packageContext); try { - application = LoadedApk.makeApplication.call(loadedApk, false, null); - + try { + application = LoadedApk.makeApplication.call(loadedApk, false, null); + } catch (Throwable e) { + Slog.e(TAG, "Unable to makeApplication"); + e.printStackTrace(); + } mInitialApplication = application; - ActivityThread.mInitialApplication.set(BlackBoxCore.mainThread(), mInitialApplication); - ContextCompat.fix((Context) ActivityThread.getSystemContext.call(BlackBoxCore.mainThread())); - ContextCompat.fix(mInitialApplication); - if (Objects.equals(packageName, processName)) { - VMCore.dumpDex(mInitialApplication.getClassLoader(), processName); + ClassLoader loader; + if (application == null) { + loader = LoadedApk.getClassloader.call(loadedApk); + } else { + loader = application.getClassLoader(); + } + VMCore.dumpDex(loader, processName); } } catch (Throwable e) { e.printStackTrace(); - throw new RuntimeException("Unable to makeApplication", e); } finally { BlackBoxCore.get().uninstallPackage(packageName); } diff --git a/Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/InstalledModule.java b/Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/InstalledModule.java deleted file mode 100644 index 0559e16..0000000 --- a/Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/InstalledModule.java +++ /dev/null @@ -1,72 +0,0 @@ -package top.niunaijun.blackbox.entity.pm; - -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.os.Parcel; -import android.os.Parcelable; - -import top.niunaijun.blackbox.BlackBoxCore; -import top.niunaijun.blackbox.core.system.user.BUserHandle; - -/** - * Created by Milk on 5/2/21. - * * ∧_∧ - * (`・ω・∥ - * 丶 つ0 - * しーJ - * 此处无Bug - */ -public class InstalledModule implements Parcelable { - public String packageName; - public String name; - public String desc; - public String main; - public boolean enable; - - public InstalledModule() { - } - - - public ApplicationInfo getApplication() { - return BlackBoxCore.getBPackageManager().getApplicationInfo(packageName, PackageManager.GET_META_DATA, BUserHandle.USER_XPOSED); - } - - public PackageInfo getPackageInfo() { - return BlackBoxCore.getBPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA, BUserHandle.USER_XPOSED); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(this.packageName); - dest.writeString(this.name); - dest.writeString(this.desc); - dest.writeString(this.main); - dest.writeByte(this.enable ? (byte) 1 : (byte) 0); - } - - protected InstalledModule(Parcel in) { - this.packageName = in.readString(); - this.name = in.readString(); - this.desc = in.readString(); - this.main = in.readString(); - this.enable = in.readByte() != 0; - } - - public static final Creator CREATOR = new Creator() { - @Override - public InstalledModule createFromParcel(Parcel source) { - return new InstalledModule(source); - } - - @Override - public InstalledModule[] newArray(int size) { - return new InstalledModule[size]; - } - }; -} diff --git a/Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/XposedConfig.java b/Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/XposedConfig.java deleted file mode 100644 index 9e16175..0000000 --- a/Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/XposedConfig.java +++ /dev/null @@ -1,61 +0,0 @@ -package top.niunaijun.blackbox.entity.pm; - -import android.os.Parcel; -import android.os.Parcelable; - -import java.util.HashMap; -import java.util.Map; - -/** - * Created by Milk on 5/2/21. - * * ∧_∧ - * (`・ω・∥ - * 丶 つ0 - * しーJ - * 此处无Bug - */ -public class XposedConfig implements Parcelable { - public boolean enable; - public Map moduleState = new HashMap<>(); - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeByte(this.enable ? (byte) 1 : (byte) 0); - dest.writeInt(this.moduleState.size()); - for (Map.Entry entry : this.moduleState.entrySet()) { - dest.writeString(entry.getKey()); - dest.writeValue(entry.getValue()); - } - } - - public XposedConfig() { - } - - public XposedConfig(Parcel in) { - this.enable = in.readByte() != 0; - int mModuleStateSize = in.readInt(); - this.moduleState = new HashMap(mModuleStateSize); - for (int i = 0; i < mModuleStateSize; i++) { - String key = in.readString(); - Boolean value = (Boolean) in.readValue(Boolean.class.getClassLoader()); - this.moduleState.put(key, value); - } - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public XposedConfig createFromParcel(Parcel source) { - return new XposedConfig(source); - } - - @Override - public XposedConfig[] newArray(int size) { - return new XposedConfig[size]; - } - }; -} diff --git a/app/src/main/java/top/niunaijun/blackdex/MainActivity.java b/app/src/main/java/top/niunaijun/blackdex/MainActivity.java index 0f543e1..5c60e62 100644 --- a/app/src/main/java/top/niunaijun/blackdex/MainActivity.java +++ b/app/src/main/java/top/niunaijun/blackdex/MainActivity.java @@ -1,14 +1,9 @@ package top.niunaijun.blackdex; import androidx.appcompat.app.AppCompatActivity; - import android.os.Bundle; -import android.util.Log; - import java.io.File; - import top.niunaijun.blackbox.BlackBoxCore; -import top.niunaijun.blackbox.entity.pm.InstallResult; public class MainActivity extends AppCompatActivity { public static final String TAG = "MainActivity"; @@ -18,13 +13,7 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.btn_click).setOnClickListener(v -> { - String hlx = "com.huluxia.gametools"; - boolean installed = BlackBoxCore.get().isInstalled(hlx); - if (!installed) { - InstallResult installResult = BlackBoxCore.get().installPackage(new File("/sdcard/huluxia.apk")); - Log.d(TAG, "onClick: " + installResult.toString()); - } - BlackBoxCore.get().launchApk(hlx); + BlackBoxCore.get().dumpDex(new File("/sdcard/huluxia.apk")); }); } -} \ No newline at end of file +}