Remove busybox dependency

This commit is contained in:
topjohnwu 2016-11-29 13:24:48 +08:00
parent bb878a1ccf
commit 24ef80351c
18 changed files with 110 additions and 108 deletions

View File

@ -1,8 +1,4 @@
# Magisk Manager
The project can only be compiled on Android Studio Version 2.2.0+
I use Java 8 features, which requires Jack compiler and that's only available 2.2.0+
# Prebuild Binaries
### libbusybox.so
Static BusyBox binary by @yashdsaraf
Link and source: http://forum.xda-developers.com/showthread.php?t=3348543
I use Java 8 features, which requires Jack compiler and that's only available in 2.2.0+
Also, you need to install CMake and NDK to build the zipadjust library for zip preprocessing

View File

@ -15,8 +15,7 @@ android {
}
ndk {
moduleName 'zipadjust'
// abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
abiFilters 'x86', 'x86_64', 'armeabi'
abiFilters 'x86', 'x86_64', 'armeabi', 'arm64-v8a'
}
}

View File

@ -23,6 +23,7 @@ import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ZipUtils;
import java.io.File;
import java.util.List;
@ -77,6 +78,19 @@ public class MagiskFragment extends Fragment {
@Override
public void task(Uri uri) {
new Async.FlashZIP(mContext, uri, mFilename) {
@Override
protected boolean unzipAndCheck() {
publishProgress(mContext.getString(R.string.zip_install_unzip_zip_msg));
// We might not have busybox yet, unzip with Java
// We will have complete busybox after Magisk installation
ZipUtils.unzip(mCachedFile, new File(mCachedFile.getParent(), "magisk"));
Shell.su(
"mkdir -p " + Async.TMP_FOLDER_PATH + "/magisk",
"cp -af " + mCachedFile.getParent() + "/magisk/. " + Async.TMP_FOLDER_PATH + "/magisk"
);
return super.unzipAndCheck();
}
@Override
protected void done() {
Shell.su("setprop magisk.version " + String.valueOf(remoteMagiskVersion));
@ -110,14 +124,16 @@ public class MagiskFragment extends Fragment {
appLink,
"MagiskManager-v" + remoteAppVersion + ".apk");
static {
updateMagiskVersion();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.magisk_fragment, container, false);
ButterKnife.bind(this, v);
updateMagiskVersion();
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
mSwipeRefreshLayout.setOnRefreshListener(() -> {
@ -167,7 +183,7 @@ public class MagiskFragment extends Fragment {
prefs.unregisterOnSharedPreferenceChangeListener(listener);
}
private void updateMagiskVersion() {
private static void updateMagiskVersion() {
List<String> ret = Shell.sh("getprop magisk.version");
if (ret.get(0).length() == 0) {
magiskVersion = -1;
@ -178,6 +194,16 @@ public class MagiskFragment extends Fragment {
// Custom version don't need to receive updates
magiskVersion = Double.POSITIVE_INFINITY;
}
}
private void updateUI() {
String theme = prefs.getString("theme", "");
if (theme.equals("Dark")) {
builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(getActivity());
}
if (magiskVersion == -1) {
magiskStatusContainer.setBackgroundColor(colorNeutral);
@ -192,16 +218,6 @@ public class MagiskFragment extends Fragment {
magiskVersionText.setText(getString(R.string.magisk_version, magiskVersionString));
magiskVersionText.setTextColor(colorOK);
}
}
private void updateUI() {
String theme = prefs.getString("theme", "");
if (theme.equals("Dark")) {
builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialog_dh);
} else {
builder = new AlertDialog.Builder(getActivity());
}
if (remoteMagiskVersion == -1) {
appCheckUpdatesContainer.setBackgroundColor(colorWarn);

View File

@ -91,8 +91,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
navigationView.setNavigationItemSelectedListener(this);
checkHideSection();
}
@Override
@ -104,13 +102,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(SELECTED_ITEM_ID, mSelectedId);
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
@ -123,18 +119,21 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
mSelectedId = menuItem.getItemId();
mDrawerHandler.removeCallbacksAndMessages(null);
mDrawerHandler.postDelayed(() -> navigate(menuItem.getItemId()), 250);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private void checkHideSection() {
Menu menu = navigationView.getMenu();
if (PreferenceManager.getDefaultSharedPreferences(getApplication()).getBoolean("magiskhide", false)) {
menu.findItem(R.id.magiskhide).setVisible(true);
} else {
if (MagiskFragment.magiskVersion == -1) {
menu.findItem(R.id.magiskhide).setVisible(false);
menu.findItem(R.id.modules).setVisible(false);
menu.findItem(R.id.downloads).setVisible(false);
} else {
menu.findItem(R.id.modules).setVisible(true);
menu.findItem(R.id.downloads).setVisible(true);
menu.findItem(R.id.magiskhide).setVisible(
PreferenceManager.getDefaultSharedPreferences(this).getBoolean("magiskhide", false));
}
}

View File

@ -37,7 +37,7 @@ public class SplashActivity extends AppCompatActivity {
.apply();
new Async.CheckUpdates(prefs).exec();
new Async.ConstructEnv(getApplicationInfo()).exec();
// new Async.ConstructEnv(getApplicationInfo()).exec();
new Async.LoadModules(prefs) {
@Override

View File

@ -21,15 +21,10 @@ import android.widget.TextView;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.receivers.DownloadReceiver;
import com.topjohnwu.magisk.receivers.RepoDlReceiver;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.Utils.ByteArrayInOutStream;
import com.topjohnwu.magisk.utils.WebWindow;
import com.topjohnwu.magisk.utils.ZipUtils;
import java.io.OutputStream;
import java.util.List;
import butterknife.BindView;

View File

@ -4,7 +4,6 @@ import android.net.Uri;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.Utils.ByteArrayInOutStream;
import com.topjohnwu.magisk.utils.ZipUtils;

View File

@ -3,7 +3,6 @@ package com.topjohnwu.magisk.utils;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
@ -45,46 +44,7 @@ public class Async {
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
public static final String MAGISK_HIDE_PATH = "/magisk/.core/magiskhide/";
public static class ConstructEnv extends NormalTask<Void, Void, Void> {
ApplicationInfo mInfo;
public ConstructEnv(ApplicationInfo info) {
mInfo = info;
}
@Override
protected Void doInBackground(Void... voids) {
String toolPath = mInfo.dataDir + "/tools";
String busybox = mInfo.dataDir + "/lib/libbusybox.so";
if (!Utils.itemExist(false, toolPath)) {
Shell.sh(
"mkdir " + toolPath,
"chmod 755 " + toolPath,
"cd " + toolPath,
"ln -s " + busybox + " busybox",
"for tool in $(./busybox --list); do",
"ln -s " + busybox + " $tool",
"done",
"rm -f su sh"
);
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
new RootTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
Shell.su("PATH=" + mInfo.dataDir + "/tools:$PATH");
return null;
}
}.exec();
}
}
public static final String TMP_FOLDER_PATH = "/dev/tmp";
public static class CheckUpdates extends NormalTask<Void, Void, Void> {
@ -226,6 +186,12 @@ public class Async {
}
}
protected boolean unzipAndCheck() {
ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android");
return Utils.readFile(mCachedFile.getParent() + "/META-INF/com/google/android/updater-script")
.get(0).contains("#MAGISK");
}
@Override
protected void onPreExecute() {
progress = new ProgressDialog(mContext);
@ -249,27 +215,22 @@ public class Async {
e.printStackTrace();
return -1;
}
if (!unzipAndCheck()) return 0;
publishProgress(mContext.getString(R.string.zip_install_progress_msg, mFilename));
if (Shell.rootAccess()) {
ret = Shell.su(
"unzip -o " + mCachedFile.getPath() + " META-INF/com/google/android/* -d " + mCachedFile.getParent(),
"if [ \"$(cat " + mCachedFile.getParent() + "/META-INF/com/google/android/updater-script)\" = \"#MAGISK\" ]; then echo true; else echo false; fi"
);
if (! Boolean.parseBoolean(ret.get(ret.size() - 1))) {
return 0;
}
ret = Shell.su(
"BOOTMODE=true sh " + mCachedFile.getParent() + "/META-INF/com/google/android/update-binary dummy 1 "+ mCachedFile.getPath(),
"BOOTMODE=true sh " + mCachedFile.getParent() +
"/META-INF/com/google/android/update-binary dummy 1 " + mCachedFile.getPath(),
"if [ $? -eq 0 ]; then echo true; else echo false; fi"
);
Shell.su("rm -rf " + mCachedFile.getParent() + "/META-INF");
Logger.dev("FlashZip: Console log:");
for (String line : ret) {
Logger.dev(line);
}
}
if (mCachedFile != null && mCachedFile.exists() && !mCachedFile.delete()) {
Utils.removeItem(mCachedFile.getPath());
Shell.su(
"rm -rf " + mCachedFile.getParent() + "/*",
"rm -rf " + TMP_FOLDER_PATH
);
}
if (ret != null && Boolean.parseBoolean(ret.get(ret.size() - 1))) {
return 1;
@ -284,7 +245,9 @@ public class Async {
progress.dismiss();
switch (result) {
case -1:
Toast.makeText(mContext, mContext.getString(R.string.manual_install, mUri.getPath()), Toast.LENGTH_LONG).show();
Toast.makeText(mContext, mContext.getString(R.string.install_error), Toast.LENGTH_LONG).show();
Toast.makeText(mContext, mContext.getString(R.string.manual_install_1, mUri.getPath()), Toast.LENGTH_LONG).show();
Toast.makeText(mContext, mContext.getString(R.string.manual_install_2), Toast.LENGTH_LONG).show();
break;
case 0:
Toast.makeText(mContext, mContext.getString(R.string.invalid_zip), Toast.LENGTH_LONG).show();

View File

@ -39,8 +39,9 @@ public class Shell {
rootSTDOUT = new StreamGobbler(rootShell.getInputStream(), rootOutList, true);
rootSTDOUT.start();
// Setup umask
// Setup umask and PATH
su("umask 022");
su("PATH=/data/busybox:$PATH");
List<String> ret = su("echo -BOC-", "id");

View File

@ -25,6 +25,7 @@ import org.spongycastle.util.encoders.Base64;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -48,6 +49,7 @@ import java.security.spec.PKCS8EncodedKeySpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
@ -98,7 +100,7 @@ public class ZipUtils {
byte buffer[] = new byte[4096];
while ((entry = source.getNextJarEntry()) != null) {
// Remove the top directory from the path
path = entry.toString().substring(entry.toString().indexOf("/") + 1);
path = entry.getName().substring(entry.getName().indexOf("/") + 1);
// If it's the top folder, ignore it
if (path.isEmpty())
continue;
@ -118,6 +120,44 @@ public class ZipUtils {
}
}
public static void unzip(File file, File folder) {
unzip(file, folder, "");
}
public static void unzip(File file, File folder, String path) {
try {
int count;
FileOutputStream out;
File dest;
InputStream is;
JarEntry entry;
byte data[] = new byte[4096];
JarFile zipfile = new JarFile(file);
Enumeration e = zipfile.entries();
while(e.hasMoreElements()) {
entry = (JarEntry) e.nextElement();
if (!entry.getName().contains(path)) {
continue;
}
Logger.dev("Extracting: " + entry);
is = zipfile.getInputStream(entry);
dest = new File(folder, entry.getName());
if (dest.getParentFile().mkdirs()) {
dest.createNewFile();
}
out = new FileOutputStream(dest);
while ((count = is.read(data, 0, 4096)) != -1) {
out.write(data, 0, count);
}
out.flush();
out.close();
is.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
public static void signZip(Context context, InputStream inputStream,
OutputStream outputStream, boolean signWholeFile) {
JarMap inputJar;

View File

@ -1,7 +1,5 @@
<resources>
<!--Universal-->
<string name="app_name" translatable="false">Magisk Manager</string>
<string name="magisk" translatable="false">Magisk</string>
<!--Welcome Activity-->
<string name="navigation_drawer_open">Navigationsleiste öffnen</string>
@ -70,7 +68,7 @@
<string name="download_install">Herunterladen und Installieren</string>
<string name="download_file_error">Fehler beim Herunterladen</string>
<string name="install_error">Fehler beim Installieren!</string>
<string name="manual_install">Fehler beim Flashen. Datei in %1$s abgelegt\n Bitte in recovery manuell flashen</string>
<string name="manual_install_1">Fehler beim Flashen. Datei in %1$s abgelegt\n Bitte in recovery manuell flashen</string>
<string name="invalid_zip">Diese Datei ist kein Magisk Modul!!</string>
<string name="reboot_title">Installation erfolgreich!</string>
<string name="reboot_msg">Wollen Sie jetzt neu starten?</string>

View File

@ -1,7 +1,5 @@
<resources>
<!--Universal-->
<string name="app_name" translatable="false">Magisk Manager</string>
<string name="magisk" translatable="false">Magisk</string>
<!--Welcome Activity-->
<string name="navigation_drawer_open">Abrir menú lateral</string>
@ -72,7 +70,7 @@
<string name="download_install">Descargar e instalar</string>
<string name="download_file_error">Error descargando fichero</string>
<string name="install_error">¡Error en la instalación!</string>
<string name="manual_install">Error flasheando fichero, zip colocado en %1$s\nFlashear manualmente desde recovery</string>
<string name="manual_install_1">Error flasheando fichero, zip colocado en %1$s\nFlashear manualmente desde recovery</string>
<string name="invalid_zip">¡El zip no es un Módulo Magisk!</string>
<string name="reboot_title">¡Instalación correcta!</string>
<string name="reboot_msg">¿Deseas reiniciar ahora?</string>

View File

@ -1,7 +1,5 @@
<resources>
<!--Universal-->
<string name="app_name" translatable="false">Magisk Manager</string>
<string name="magisk" translatable="false">Magisk</string>
<!--Welcome Activity-->
<string name="navigation_drawer_open">Apri drawer di navigazione</string>
@ -70,7 +68,7 @@
<string name="download_install">Scarica e installa</string>
<string name="download_file_error">Errore nel download del file</string>
<string name="install_error">Errore di installazione!</string>
<string name="manual_install">Errore nel flash del file, il file zip è in %1$s\nFlash esegui il flash manuale</string>
<string name="manual_install_1">Errore nel flash del file, il file zip è in %1$s\nFlash esegui il flash manuale</string>
<string name="invalid_zip">Lo zip non è un Modulo Magisk!!</string>
<string name="reboot_title">Installazione completata</string>
<string name="reboot_msg">Vuoi riavviare ora?</string>

View File

@ -1,7 +1,5 @@
<resources>
<!--Universal-->
<string name="app_name" translatable="false">Magisk Manager</string>
<string name="magisk" translatable="false">Magisk</string>
<!--Welcome Activity-->
<string name="navigation_drawer_open">Open navigatie</string>
@ -70,7 +68,7 @@
<string name="download_install">Downloaden en installeren</string>
<string name="download_file_error">Er is een fout opgetreden bij het downloaden van het bestand</string>
<string name="install_error">Er is een fout opgetreden in de installatie</string>
<string name="manual_install">Er is een fout opgetreden in het flashen van het bestand. Het zip bestand is opgeslagen in %1$s\nFlash het handmatig in recovery modus.</string>
<string name="manual_install_1">Er is een fout opgetreden in het flashen van het bestand. Het zip bestand is opgeslagen in %1$s\nFlash het handmatig in recovery modus.</string>
<string name="invalid_zip">Zip bestand is geen Magisk Module!</string>
<string name="reboot_title">Installatie succesvol!</string>
<string name="reboot_msg">Wilt u nu rebooten?</string>

View File

@ -66,7 +66,7 @@
<string name="download_install">Baixar e instalar</string>
<string name="download_file_error">Erro ao baixar o arquivo</string>
<string name="install_error">Erro na instalação!</string>
<string name="manual_install">Erro ao flashear o arquivo, arquivo zip colocado em %1$s\nFlashear isto na recuperação manualmente</string>
<string name="manual_install_1">Erro ao flashear o arquivo, arquivo zip colocado em %1$s\nFlashear isto na recuperação manualmente</string>
<string name="invalid_zip">O zip não é um Módulo Magisk!!</string>
<string name="reboot_title">Instalação bem-sucedida!</string>
<string name="reboot_msg">Você quer reiniciar agora?</string>

View File

@ -72,13 +72,15 @@
<string name="download_install">Download and install</string>
<string name="download_file_error">Error downloading file</string>
<string name="install_error">Installation error!</string>
<string name="manual_install">Error in flashing file, zip file placed in %1$s\nFlash it in recovery manually</string>
<string name="manual_install_1">Zip file placed in %1$s</string>
<string name="manual_install_2">Flash it in recovery manually</string>
<string name="invalid_zip">The zip is not a Magisk Module!!</string>
<string name="reboot_title">Installation succeeded!</string>
<string name="reboot_msg">Do you want to reboot now?</string>
<string name="reboot">Reboot</string>
<string name="zip_install_progress_title">Installing</string>
<string name="zip_install_process_zip_msg">Processing zip file ...</string>
<string name="zip_install_unzip_zip_msg">Unzipping zip file …</string>
<string name="zip_install_process_zip_msg">Processing zip file …</string>
<string name="zip_install_progress_msg">"Installing %1$s …"</string>
<string name="no_magisk_title">No Magisk Installed!</string>
<string name="no_magisk_msg">Do you want to download and install Magisk?</string>