细节调整

pull/1/head
Milk 4 years ago
parent d082886725
commit 6bd50258cf
  1. 1
      Bcore/black-fake/src/main/java/mirror/android/app/LoadedApk.java
  2. 3
      Bcore/src/main/aidl/top/niunaijun/blackbox/entity/pm/InstalledModule.aidl
  3. 23
      Bcore/src/main/java/top/niunaijun/blackbox/BlackBoxCore.java
  4. 22
      Bcore/src/main/java/top/niunaijun/blackbox/app/BActivityThread.java
  5. 72
      Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/InstalledModule.java
  6. 61
      Bcore/src/main/java/top/niunaijun/blackbox/entity/pm/XposedConfig.java
  7. 13
      app/src/main/java/top/niunaijun/blackdex/MainActivity.java

@ -9,6 +9,7 @@ public class LoadedApk {
public static final MirrorReflection REF = MirrorReflection.on("android.app.LoadedApk"); public static final MirrorReflection REF = MirrorReflection.on("android.app.LoadedApk");
public static MirrorReflection.FieldWrapper<ApplicationInfo> mApplicationInfo = REF.field("mApplicationInfo"); public static MirrorReflection.FieldWrapper<ApplicationInfo> mApplicationInfo = REF.field("mApplicationInfo");
public static MirrorReflection.MethodWrapper<Application> makeApplication = REF.method("makeApplication", boolean.class, Instrumentation.class); public static MirrorReflection.MethodWrapper<Application> makeApplication = REF.method("makeApplication", boolean.class, Instrumentation.class);
public static MirrorReflection.MethodWrapper<ClassLoader> getClassloader = REF.method("getClassloader");
public static MirrorReflection.FieldWrapper<Boolean> mSecurityViolation = REF.field("mSecurityViolation"); public static MirrorReflection.FieldWrapper<Boolean> mSecurityViolation = REF.field("mSecurityViolation");
} }

@ -1,3 +0,0 @@
package top.niunaijun.blackbox.entity.pm;
parcelable InstalledModule;

@ -109,9 +109,6 @@ public class BlackBoxCore extends ClientConfiguration {
} }
public void doCreate() { public void doCreate() {
// fix contentProvider
if (isVirtualProcess()) {
}
if (!isServerProcess()) { if (!isServerProcess()) {
initService(); initService();
} }
@ -143,7 +140,25 @@ public class BlackBoxCore extends ClientConfiguration {
return BStorageManager.get(); 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); Intent launchIntentForPackage = getBPackageManager().getLaunchIntentForPackage(packageName, USER_ID);
if (launchIntentForPackage == null) { if (launchIntentForPackage == null) {
return false; return false;

@ -26,6 +26,7 @@ import top.niunaijun.blackbox.core.IBActivityThread;
import top.niunaijun.blackbox.core.VMCore; import top.niunaijun.blackbox.core.VMCore;
import top.niunaijun.blackbox.entity.AppConfig; import top.niunaijun.blackbox.entity.AppConfig;
import top.niunaijun.blackbox.core.IOCore; import top.niunaijun.blackbox.core.IOCore;
import top.niunaijun.blackbox.utils.Slog;
import top.niunaijun.blackbox.utils.compat.ContextCompat; import top.niunaijun.blackbox.utils.compat.ContextCompat;
import top.niunaijun.blackbox.BlackBoxCore; import top.niunaijun.blackbox.BlackBoxCore;
@ -170,22 +171,27 @@ public class BActivityThread extends IBActivityThread.Stub {
mBoundApplication = bindData; mBoundApplication = bindData;
Application application; Application application = null;
BlackBoxCore.get().getAppLifecycleCallback().beforeCreateApplication(packageName, processName, packageContext); BlackBoxCore.get().getAppLifecycleCallback().beforeCreateApplication(packageName, processName, packageContext);
try {
try { try {
application = LoadedApk.makeApplication.call(loadedApk, false, null); application = LoadedApk.makeApplication.call(loadedApk, false, null);
} catch (Throwable e) {
Slog.e(TAG, "Unable to makeApplication");
e.printStackTrace();
}
mInitialApplication = application; mInitialApplication = application;
ActivityThread.mInitialApplication.set(BlackBoxCore.mainThread(), mInitialApplication);
ContextCompat.fix((Context) ActivityThread.getSystemContext.call(BlackBoxCore.mainThread()));
ContextCompat.fix(mInitialApplication);
if (Objects.equals(packageName, processName)) { 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) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("Unable to makeApplication", e);
} finally { } finally {
BlackBoxCore.get().uninstallPackage(packageName); BlackBoxCore.get().uninstallPackage(packageName);
} }

@ -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<InstalledModule> CREATOR = new Creator<InstalledModule>() {
@Override
public InstalledModule createFromParcel(Parcel source) {
return new InstalledModule(source);
}
@Override
public InstalledModule[] newArray(int size) {
return new InstalledModule[size];
}
};
}

@ -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<String, Boolean> 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<String, Boolean> 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<String, Boolean>(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<XposedConfig> CREATOR = new Parcelable.Creator<XposedConfig>() {
@Override
public XposedConfig createFromParcel(Parcel source) {
return new XposedConfig(source);
}
@Override
public XposedConfig[] newArray(int size) {
return new XposedConfig[size];
}
};
}

@ -1,14 +1,9 @@
package top.niunaijun.blackdex; package top.niunaijun.blackdex;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import java.io.File; import java.io.File;
import top.niunaijun.blackbox.BlackBoxCore; import top.niunaijun.blackbox.BlackBoxCore;
import top.niunaijun.blackbox.entity.pm.InstallResult;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
public static final String TAG = "MainActivity"; public static final String TAG = "MainActivity";
@ -18,13 +13,7 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
findViewById(R.id.btn_click).setOnClickListener(v -> { findViewById(R.id.btn_click).setOnClickListener(v -> {
String hlx = "com.huluxia.gametools"; BlackBoxCore.get().dumpDex(new File("/sdcard/huluxia.apk"));
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);
}); });
} }
} }
Loading…
Cancel
Save