Open source fully obfuscated stub

This commit is contained in:
topjohnwu
2021-09-02 21:31:33 -07:00
parent a967afc629
commit 9c09ad3b62
67 changed files with 535 additions and 184 deletions

View File

@@ -7,6 +7,9 @@ import android.content.res.Configuration;
import java.lang.reflect.Method;
import io.michaelrocks.paranoid.Obfuscate;
@Obfuscate
public class DelegateApplication extends Application {
static boolean dynLoad = false;

View File

@@ -1,5 +1,14 @@
package com.topjohnwu.magisk;
import static android.R.string.no;
import static android.R.string.ok;
import static android.R.string.yes;
import static com.topjohnwu.magisk.DelegateApplication.dynLoad;
import static com.topjohnwu.magisk.A.string.dling;
import static com.topjohnwu.magisk.A.string.no_internet_msg;
import static com.topjohnwu.magisk.A.string.relaunch_app;
import static com.topjohnwu.magisk.A.string.upgrade_msg;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
@@ -16,17 +25,22 @@ import com.topjohnwu.magisk.utils.APKInstall;
import org.json.JSONException;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import static android.R.string.no;
import static android.R.string.ok;
import static android.R.string.yes;
import static com.topjohnwu.magisk.DelegateApplication.dynLoad;
import static com.topjohnwu.magisk.R.string.dling;
import static com.topjohnwu.magisk.R.string.no_internet_msg;
import static com.topjohnwu.magisk.R.string.relaunch_app;
import static com.topjohnwu.magisk.R.string.upgrade_msg;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import io.michaelrocks.paranoid.Obfuscate;
@Obfuscate
public class DownloadActivity extends Activity {
private static final String APP_NAME = "Magisk";
@@ -41,6 +55,9 @@ public class DownloadActivity extends Activity {
super.onCreate(savedInstanceState);
themed = new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault);
// Inject resources
loadResources();
if (Networking.checkNetworkStatus(this)) {
if (apkLink == null) {
fetchCanary();
@@ -111,4 +128,26 @@ public class DownloadActivity extends Activity {
});
}
private void loadResources() {
File apk = new File(getCacheDir(), "res.apk");
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKey key = new SecretKeySpec(Bytes.key(), "AES");
IvParameterSpec iv = new IvParameterSpec(Bytes.iv());
cipher.init(Cipher.DECRYPT_MODE, key, iv);
InputStream is = new CipherInputStream(new ByteArrayInputStream(Bytes.res()), cipher);
try (InputStream gzip = new GZIPInputStream(is);
OutputStream out = new FileOutputStream(apk)) {
byte[] buf = new byte[4096];
for (int read; (read = gzip.read(buf)) >= 0;) {
out.write(buf, 0, read);
}
}
DynAPK.addAssetPath(getResources().getAssets(), apk.getPath());
} catch (Exception e) {
// Should not happen
e.printStackTrace();
}
}
}

View File

@@ -17,6 +17,9 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import io.michaelrocks.paranoid.Obfuscate;
@Obfuscate
public class InjectAPK {
static Object componentFactory;

View File

@@ -1,43 +0,0 @@
package com.topjohnwu.magisk;
import com.topjohnwu.magisk.dummy.DummyReceiver;
import java.util.HashMap;
import java.util.Map;
/**
* These are just some random class names hardcoded as an example.
* For the actual release builds, these mappings will be auto generated.
*/
public class Mapping {
private static final Map<String, String> map = new HashMap<>();
public static final Map<String, Class<?>> internalMap = new HashMap<>();
public static final Map<String, String> inverseMap;
static {
map.put("a.Q", "com.topjohnwu.magisk.core.App");
map.put("f.u7", "com.topjohnwu.magisk.core.SplashActivity");
map.put("fxQ.lk", "com.topjohnwu.magisk.core.Provider");
map.put("yy.E", "com.topjohnwu.magisk.core.Receiver");
map.put("xt.R", "com.topjohnwu.magisk.ui.MainActivity");
map.put("lt5.a", "com.topjohnwu.magisk.ui.surequest.SuRequestActivity");
map.put("d.s", "com.topjohnwu.magisk.core.download.DownloadService");
map.put("w.d", "androidx.work.impl.background.systemjob.SystemJobService");
internalMap.put("a.Q", DelegateApplication.class);
internalMap.put("f.u7", DownloadActivity.class);
internalMap.put("fxQ.lk", FileProvider.class);
internalMap.put("yy.E", DummyReceiver.class);
inverseMap = new HashMap<>(map.size());
for (Map.Entry<String, String> e : map.entrySet()) {
inverseMap.put(e.getValue(), e.getKey());
}
}
public static String get(String name) {
String n = map.get(name);
return n != null ? n : name;
}
}

View File

@@ -10,6 +10,9 @@ import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import io.michaelrocks.paranoid.Obfuscate;
@Obfuscate
public class Networking {
private static final int READ_TIMEOUT = 15000;

View File

@@ -20,6 +20,9 @@ import java.net.HttpURLConnection;
import java.util.Scanner;
import java.util.concurrent.Executor;
import io.michaelrocks.paranoid.Obfuscate;
@Obfuscate
public class Request implements Closeable {
private HttpURLConnection conn;
private Executor executor = null;