mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-27 13:29:40 +00:00
Add hide Magisk Manager feature
This commit is contained in:
@@ -35,6 +35,7 @@ import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
||||
import com.topjohnwu.magisk.receivers.ManagerUpdate;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -288,4 +289,25 @@ public class Utils {
|
||||
|
||||
return locales;
|
||||
}
|
||||
|
||||
public static String genPackageName(String prefix, int length) {
|
||||
StringBuilder builder = new StringBuilder(length);
|
||||
builder.append(prefix);
|
||||
length -= prefix.length();
|
||||
SecureRandom random = new SecureRandom();
|
||||
String base = "abcdefghijklmnopqrstuvwxyz";
|
||||
String alpha = base + base.toUpperCase();
|
||||
String full = alpha + "0123456789..........";
|
||||
char next, prev = '\0';
|
||||
for (int i = 0; i < length; ++i) {
|
||||
if (prev == '.' || i == length - 1 || i == 0) {
|
||||
next = alpha.charAt(random.nextInt(alpha.length()));
|
||||
} else {
|
||||
next = full.charAt(random.nextInt(full.length()));
|
||||
}
|
||||
builder.append(next);
|
||||
prev = next;
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.bouncycastle.asn1.ASN1InputStream;
|
||||
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
||||
@@ -65,6 +66,7 @@ public class ZipUtils {
|
||||
// File name in assets
|
||||
private static final String PUBLIC_KEY_NAME = "public.certificate.x509.pem";
|
||||
private static final String PRIVATE_KEY_NAME = "private.key.pk8";
|
||||
private static final String UNHIDE_NAME = "unhide.apk";
|
||||
|
||||
private static final String CERT_SF_NAME = "META-INF/CERT.SF";
|
||||
private static final String CERT_SIG_NAME = "META-INF/CERT.%s";
|
||||
@@ -82,6 +84,45 @@ public class ZipUtils {
|
||||
|
||||
public native static void zipAdjust(String filenameIn, String filenameOut);
|
||||
|
||||
public static String generateUnhide(Context context, File output) {
|
||||
File temp = new File(context.getCacheDir(), "temp.apk");
|
||||
String pkg = "";
|
||||
try {
|
||||
JarInputStream source = new JarInputStream(context.getAssets().open(UNHIDE_NAME));
|
||||
JarOutputStream dest = new JarOutputStream(new FileOutputStream(temp));
|
||||
JarEntry entry;
|
||||
int size;
|
||||
byte buffer[] = new byte[4096];
|
||||
while ((entry = source.getNextJarEntry()) != null) {
|
||||
dest.putNextEntry(new JarEntry(entry.getName()));
|
||||
if (TextUtils.equals(entry.getName(), "AndroidManifest.xml")) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
while((size = source.read(buffer)) != -1) {
|
||||
baos.write(buffer, 0, size);
|
||||
}
|
||||
byte xml[] = baos.toByteArray();
|
||||
pkg = Utils.genPackageName("com.", 20);
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
xml[424 + i] = (byte) pkg.charAt(i);
|
||||
}
|
||||
dest.write(xml);
|
||||
} else {
|
||||
while((size = source.read(buffer)) != -1) {
|
||||
dest.write(buffer, 0, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
source.close();
|
||||
dest.close();
|
||||
signZip(context, temp, output, false);
|
||||
temp.delete();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return pkg;
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
||||
public static void removeTopFolder(InputStream in, File output) throws IOException {
|
||||
try {
|
||||
JarInputStream source = new JarInputStream(in);
|
||||
@@ -102,7 +143,7 @@ public class ZipUtils {
|
||||
continue;
|
||||
}
|
||||
dest.putNextEntry(new JarEntry(path));
|
||||
while((size = source.read(buffer, 0, 2048)) != -1) {
|
||||
while((size = source.read(buffer)) != -1) {
|
||||
dest.write(buffer, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user