mirror of
				https://github.com/topjohnwu/Magisk
				synced 2025-10-31 10:40:52 +01:00 
			
		
		
		
	Compare commits
	
		
			209 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | d8bb3af06b | ||
|   | e139e8777b | ||
|   | d52d7cfbd9 | ||
|   | 4f74a259e3 | ||
|   | 74da6e1dc0 | ||
|   | 84ffdf0ed5 | ||
|   | 022b18c8ce | ||
|   | b92b1dcddb | ||
|   | 1472dbb291 | ||
|   | d58a8dc868 | ||
|   | e94be0b70e | ||
|   | f6ae7e1bf1 | ||
|   | f7b4935677 | ||
|   | a3c49de6a5 | ||
|   | e8dd1b292f | ||
|   | d21264d01b | ||
|   | b0567eadfd | ||
|   | 5fc2058336 | ||
|   | d0567d29d2 | ||
|   | 4db0ad32f0 | ||
|   | d065040321 | ||
|   | 17f0fea3fc | ||
|   | 8ca1e43533 | ||
|   | bd01c314dc | ||
|   | e404476609 | ||
|   | 942c870981 | ||
|   | baff9256c5 | ||
|   | b4c0a255fc | ||
|   | 9f6a27c20d | ||
|   | 742dc137ed | ||
|   | 39a6bd33ce | ||
|   | 4672a5fad6 | ||
|   | e649b0a2df | ||
|   | fd8dbe3eff | ||
|   | bb97cc594d | ||
|   | 70a322263e | ||
|   | c6f144d482 | ||
|   | 3709489b3a | ||
|   | 145ef32e28 | ||
|   | 2212800a23 | ||
|   | 2e25431bb6 | ||
|   | 32c8e7522f | ||
|   | a5e4f3cc6b | ||
|   | a30777bd9f | ||
|   | e989195a68 | ||
|   | 997d58932e | ||
|   | b4015f877f | ||
|   | d15fff95b9 | ||
|   | 687e3b13ea | ||
|   | 8c6bb383b7 | ||
|   | bc592c1d13 | ||
|   | 968bd8be67 | ||
|   | d8b8adb88c | ||
|   | f42d820891 | ||
|   | bc21a1fb71 | ||
|   | 3bc31374ac | ||
|   | 858e7bae2b | ||
|   | 8c02d120a2 | ||
|   | 07e353f4ff | ||
|   | bb33d9e600 | ||
|   | 68eb0bdec9 | ||
|   | 32ee8e462c | ||
|   | e79aa54b70 | ||
|   | 9a95652034 | ||
|   | 912c188b53 | ||
|   | e9d0f615ba | ||
|   | 9136573596 | ||
|   | 2487ec94e6 | ||
|   | 811489f157 | ||
|   | b438cc9335 | ||
|   | 1d3d30fa45 | ||
|   | 72b5985398 | ||
|   | 2db60e0a6b | ||
|   | e710848345 | ||
|   | 8d6f3c2450 | ||
|   | f863d127e7 | ||
|   | a831110816 | ||
|   | e97bdb53f4 | ||
|   | fe1439fbac | ||
|   | 2bc30e5c22 | ||
|   | 7244c02a0d | ||
|   | 6c229ffa68 | ||
|   | cdc5d983f3 | ||
|   | 96688e4dac | ||
|   | 28a945fee9 | ||
|   | c7e777255a | ||
|   | 2dd4cf040e | ||
|   | d1b9eca5eb | ||
|   | 594a67fe28 | ||
|   | cddeaffada | ||
|   | 2a8898e7c3 | ||
|   | ce3f3b09b4 | ||
|   | fe4b3df7e9 | ||
|   | 25bdbcf526 | ||
|   | df7eaa5598 | ||
|   | bb7099376b | ||
|   | 0327fd9710 | ||
|   | e645c6e465 | ||
|   | 78a3d36ccc | ||
|   | 3942858ccd | ||
|   | 03c8d716cc | ||
|   | 60181c4fcb | ||
|   | c215447405 | ||
|   | 89330b89d8 | ||
|   | a8f3718ed0 | ||
|   | a78ba44709 | ||
|   | ff110e3513 | ||
|   | cfae6c63b5 | ||
|   | dbfe49c56f | ||
|   | 98e21f9f5b | ||
|   | 83af0497e4 | ||
|   | 6ce37b44db | ||
|   | 9cb1cf756f | ||
|   | ffa005e4ab | ||
|   | af102e47f1 | ||
|   | 73064a816d | ||
|   | 9b4ae8fcc5 | ||
|   | a1a2c52409 | ||
|   | 9a0b26e0b0 | ||
|   | b805b96e16 | ||
|   | 590e7f7724 | ||
|   | 4d61e5e319 | ||
|   | 8c8a63ebfb | ||
|   | e5e34797a8 | ||
|   | 8516ebe6f5 | ||
|   | 9f6205f47f | ||
|   | 8b2ec23a89 | ||
|   | 1816ca6b02 | ||
|   | 7394ff9346 | ||
|   | bb5a6a1c28 | ||
|   | b614b06736 | ||
|   | 7a376c9efc | ||
|   | 518f3d229f | ||
|   | 46c91f923d | ||
|   | 3a2262dfb3 | ||
|   | ff7c38f8e9 | ||
|   | 4229ba364f | ||
|   | ba8e7a211a | ||
|   | 6b41653a32 | ||
|   | 59c1125e72 | ||
|   | b536046720 | ||
|   | 619b805894 | ||
|   | 8662537883 | ||
|   | 717890395b | ||
|   | b7b4164f4f | ||
|   | 7e65296470 | ||
|   | cd5f5d702f | ||
|   | 44b93e7cc4 | ||
|   | 0eb79e5acd | ||
|   | eceba26894 | ||
|   | 0bf404f75e | ||
|   | cd8dd65a65 | ||
|   | 50c56f8b50 | ||
|   | 9e9f8ca8f3 | ||
|   | f63af0601c | ||
|   | 189c671ce2 | ||
|   | bb39a01361 | ||
|   | 764999704a | ||
|   | ecfa4aafc1 | ||
|   | a1e33c4d2f | ||
|   | 7f8ba74dac | ||
|   | e3df62d812 | ||
|   | 1913125881 | ||
|   | e8e58f3fed | ||
|   | 1ca9ec384b | ||
|   | 9522255e3a | ||
|   | 2a22fa694e | ||
|   | 1591f5a0ca | ||
|   | 3bc4e9a724 | ||
|   | f7a6bb0723 | ||
|   | e9c17a3ef7 | ||
|   | 29bb5840b5 | ||
|   | c9d8d860f6 | ||
|   | cc18096882 | ||
|   | 15f2a664d1 | ||
|   | 70b4f62ddc | ||
|   | e1023fdfaf | ||
|   | 5e9648387a | ||
|   | 2ba8b4df67 | ||
|   | 3a084c5d7b | ||
|   | f7200e39c3 | ||
|   | a7dfc20967 | ||
|   | 6eb7c0b5d6 | ||
|   | 0b3c078aeb | ||
|   | 750872cc37 | ||
|   | 29895ff474 | ||
|   | 44adccc147 | ||
|   | 2a7e2c70b5 | ||
|   | 8d431b6762 | ||
|   | 273849c0c8 | ||
|   | 5cc14405c7 | ||
|   | f0cfd60e62 | ||
|   | d6547f0701 | ||
|   | 3b68905037 | ||
|   | eae611c54d | ||
|   | b37bad35c2 | ||
|   | 5fab15fee5 | ||
|   | 10c8ea17aa | ||
|   | 7058c8ff5a | ||
|   | 64e85da59f | ||
|   | f79fad64aa | ||
|   | cb70eebb08 | ||
|   | edaf8787d1 | ||
|   | 24164c8580 | ||
|   | 9fca7011aa | ||
|   | b13eb3fd40 | ||
|   | b7986a351c | ||
|   | ce87591c62 | ||
|   | 25c289ad3e | 
							
								
								
									
										2
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							| @@ -8,9 +8,11 @@ | ||||
|  | ||||
| # Declare files that will always have CRLF line endings on checkout. | ||||
| *.cmd text eol=crlf | ||||
| *.bat text eol=crlf | ||||
|  | ||||
| # Denote all files that are truly binary and should not be modified. | ||||
| chromeos/** binary | ||||
| *.jar binary | ||||
| *.exe binary | ||||
| *.apk binary | ||||
| *.png binary | ||||
|   | ||||
							
								
								
									
										15
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,7 +1,16 @@ | ||||
| obj/ | ||||
| libs/ | ||||
| out | ||||
| *.zip | ||||
| *.jks | ||||
| *.apk | ||||
|  | ||||
| # Copied binaries | ||||
| # Built binaries | ||||
| ziptools/zipadjust | ||||
|  | ||||
| # Android Studio / Gradle | ||||
| *.iml | ||||
| .gradle | ||||
| /local.properties | ||||
| /.idea | ||||
| /build | ||||
| /captures | ||||
| .externalNativeBuild | ||||
|   | ||||
							
								
								
									
										26
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										26
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							| @@ -1,15 +1,27 @@ | ||||
| [submodule "jni/selinux"] | ||||
| 	path = jni/selinux | ||||
| 	path = core/jni/external/selinux | ||||
| 	url = https://github.com/topjohnwu/selinux.git | ||||
| [submodule "jni/su"] | ||||
| 	path = jni/su | ||||
| 	path = core/jni/su | ||||
| 	url = https://github.com/topjohnwu/MagiskSU.git | ||||
| [submodule "jni/ndk-compression"] | ||||
| 	path = jni/ndk-compression | ||||
| 	url = https://github.com/topjohnwu/ndk-compression.git | ||||
| [submodule "jni/magiskpolicy"] | ||||
| 	path = jni/magiskpolicy | ||||
| 	path = core/jni/magiskpolicy | ||||
| 	url = https://github.com/topjohnwu/magiskpolicy.git | ||||
| [submodule "MagiskManager"] | ||||
| 	path = MagiskManager | ||||
| 	path = app | ||||
| 	url = https://github.com/topjohnwu/MagiskManager.git | ||||
| [submodule "jni/busybox"] | ||||
| 	path = core/jni/external/busybox | ||||
| 	url = https://github.com/topjohnwu/ndk-busybox.git | ||||
| [submodule "jni/external/dtc"] | ||||
| 	path = core/jni/external/dtc | ||||
| 	url = https://github.com/dgibson/dtc | ||||
| [submodule "jni/external/lz4"] | ||||
| 	path = core/jni/external/lz4 | ||||
| 	url = https://github.com/lz4/lz4.git | ||||
| [submodule "jni/external/bzip2"] | ||||
| 	path = core/jni/external/bzip2 | ||||
| 	url = https://github.com/nemequ/bzip2.git | ||||
| [submodule "jni/external/xz"] | ||||
| 	path = core/jni/external/xz | ||||
| 	url = https://github.com/xz-mirror/xz.git | ||||
|   | ||||
 Submodule MagiskManager deleted from 3550d1e61c
									
								
							
							
								
								
									
										79
									
								
								README.MD
									
									
									
									
									
								
							
							
						
						
									
										79
									
								
								README.MD
									
									
									
									
									
								
							| @@ -2,35 +2,33 @@ | ||||
|  | ||||
| ## How to build Magisk | ||||
|  | ||||
| #### Building has been tested on 3 major platforms: | ||||
| #### Building has been tested on 3 major platforms: macOS, Ubuntu, Windows 10 | ||||
|  | ||||
| ***macOS 10.12.5***   | ||||
| ***Ubuntu 17.04 x64***   | ||||
| ***Windows 10 Creators Update x64***   | ||||
| ### Environment Requirements | ||||
|  | ||||
| #### Environment Requirements | ||||
| 1. A 64-bit machine: `cmake` for Android is only available in 64-bit | ||||
| 2. Python 3.5+: run `build.py` script | ||||
| 3. Java Development Kit (JDK) 8: Compile Magisk Manager and sign zips | ||||
| 4. Latest Android SDK: `ANDROID_HOME` environment variable should point to the Android SDK folder | ||||
| 5. Android NDK: Install NDK along with SDK (`$ANDROID_HOME/ndk-bundle`), or specify custom path `ANDROID_NDK` | ||||
| 6. (Windows Only) Python package Colorama: Install with `pip install colorama`, used for ANSI color codes | ||||
| 7. (Unix only) C compiler: Build `zipadjust`. Windows users can use the pre-built `zipadjust.exe` | ||||
|  | ||||
| 1. Python 3 **(>= 3.5)**: `python3` (or in some cases `python`) should be accessible   | ||||
| 2. Java runtime: `java` should be accessible   | ||||
| 3. (Unix only) C compiler: `gcc` should be accessible   | ||||
| 4. Android SDK: `ANDROID_HOME` environment variable should point to the Android SDK folder   | ||||
| 5. NDK: Install NDK using `sdkmanager`, or through Android SDK Manager   | ||||
| 6. Android build-tools: Should have build-tools version matching `MagiskManager/app/build.gradle` installed   | ||||
| ### Instructions and Notes | ||||
| 1. Magisk can be built with the latest NDK (r16 as of writing), however binaries released officially will be built with NDK r10e due to ELF incompatibilities with the binaries built from the newer NDKs. | ||||
| 2. The easiest way to setup the environment is by importing this folder as an Android Studio project. The IDE will download required components and construct the environment for you. You still have to set the `ANDROID_HOME` environment variable to point to the SDK path. | ||||
| 3. Run `build.py` with argument `-h` to see the built-in help message. The `-h` option also works for each supported actions, e.g. `./build.py binary -h` | ||||
| 4. Build everything with `build.py`, don't directly call `gradlew` or `ndk-build`, since most requires special setup / dependencies. | ||||
| 5. By default, `build.py` will build binaries and Magisk Manager in debug mode. If you want to build Magisk Manager in release mode (through the flag `--release`), you will need to place a Java Keystore file at `release_signature.jks` to sign Magisk Manager's APK. For more information, check out [Google's Official Documentation](https://developer.android.com/studio/publish/app-signing.html#signing-manually). | ||||
|  | ||||
| #### Instructions and Notes | ||||
|  | ||||
| 1. The python build script uses ANSI color codes to change the color of the terminal output. For Windows, this **only** works on Windows 10, as previous Windows console do not support them. If you insist to use an older Windows version, a quick Google search should provide many workarounds   | ||||
| 2. After installing the latest Python 3 on Windows (allow the installer to add Python to PATH, or you'll have to manually set the environment), instead of calling `python3` like most Unix environment, you should call `python` in shell (cmd or Powershell both OK). You can double check the version by `python --version`   | ||||
| 3. The build script will do several checks, it will refuse to run if the environment doesn't meet the requirements   | ||||
| 4. For further instructions, please check the built in help message by `python3 build.py -h`   | ||||
| (Unix users can simply `./build.py -h`, Windows users, as mentioned, call `python` instead)   | ||||
| 5. Each action has its own help message, access them by commands like `python3 build.py all -h`   | ||||
| 6. To build Magisk for release (enabled through the `--release` flag, the script builds in debug mode by default), you will need to provide a Java keystore file, and place it in `release_signature.jks` to sign Magisk Manager APK for release builds. For more information, check out [Google's Official Documentation](https://developer.android.com/studio/publish/app-signing.html#signing-manually) | ||||
| 7. To properly setup the Android SDK environment, the easiest way is to use Android Studio and open Magisk Manager. If gradle sync passed, your build-tools etc. should be set properly. You can also access SDK Manager GUI within Android Studio to download NDK. Don't forget to add Android Studio's SDK path into environment variable ANDROID_HOME.   | ||||
|  | ||||
| ## License | ||||
|  | ||||
| Magisk, including all subprojects (git submodule) is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||||
| ``` | ||||
| Magisk, including all git submodules are free software: | ||||
| you can redistribute it and/or modify it under the terms of the  | ||||
| GNU General Public License as published by the Free Software Foundation,  | ||||
| either version 3 of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| @@ -39,40 +37,45 @@ GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
| ``` | ||||
|  | ||||
| ## Credits | ||||
|  | ||||
| **MagiskManager** (`MagiskManager`) | ||||
| * Copyright 2016-2017, John Wu (@topjohnwu) | ||||
| * All contributors and translators | ||||
| **MagiskManager** (`app`) | ||||
|  | ||||
| * Copyright 2016-2017, John Wu (@topjohnwu) | ||||
| * All contributors and translators on Github | ||||
|  | ||||
| **MagiskSU** (`core/jni/su`) | ||||
|  | ||||
| **MagiskSU** (`jni/su`) | ||||
| * Copyright 2016-2017, John Wu (@topjohnwu) | ||||
| * Copyright 2015, Pierre-Hugues Husson (phh@phh.me) | ||||
| * Copyright 2013, Koushik Dutta (@koush) | ||||
| * Copyright 2010, Adam Shanks (@ChainsDD) | ||||
| * Copyright 2008, Zinx Verituse (@zinxv) | ||||
|  | ||||
| **MagiskPolicy** (`jni/magiskpolicy`) | ||||
| **MagiskPolicy** (`core/jni/magiskpolicy`) | ||||
|  | ||||
| * Copyright 2016-2017, John Wu (@topjohnwu) | ||||
| * Copyright 2015, Pierre-Hugues Husson (phh@phh.me) | ||||
| * Copyright 2015, Joshua Brindle (@joshua_brindle) | ||||
|  | ||||
| **MagiskHide** (`jni/magiskhide`) | ||||
| * Copyright 2016-2017, John Wu (@topjohnwu) | ||||
| * Copyright 2016, Pierre-Hugues Husson (phh@phh.me) (original hidesu) | ||||
| **MagiskHide** (`core/jni/magiskhide`) | ||||
|  | ||||
| * Copyright 2016-2017, John Wu (@topjohnwu) | ||||
| * Copyright 2016, Pierre-Hugues Husson (phh@phh.me) | ||||
|  | ||||
| **resetprop** (`core/jni/resetprop`) | ||||
|  | ||||
| **resetprop** (`jni/resetprop`) | ||||
|  * Copyright 2016-2017 John Wu (@topjohnwu) | ||||
|  * Copyright 2016 nkk71 (nkk71x@gmail.com) | ||||
|   | ||||
| **SELinux** (`jni/selinux`) | ||||
| * Makefile for NDK: Copyright 2016-2017, John Wu (@topjohnwu) | ||||
| * It is maintained by many developers in SELinux project, copyright belongs to them | ||||
|  | ||||
| **ndk-compression** (`jni/ndk-compression`) | ||||
| * Makefile for NDK: Copyright 2017, John Wu (@topjohnwu) | ||||
| * Each library has its own copyright message in each directories | ||||
| **External Dependencies** (`core/jni/external`) | ||||
|  | ||||
| * Makefile for busybox, generated by [ndk-busybox-kitchen](https://github.com/topjohnwu/ndk-busybox-kitchen) | ||||
| * Each dependencies has its own license/copyright information in each subdirectory.   | ||||
| All of them are either GPL or GPL compatible. | ||||
|  | ||||
| **Others Not Mentioned** | ||||
|  | ||||
| * Copyright 2016-2017, John Wu (@topjohnwu) | ||||
|   | ||||
							
								
								
									
										1
									
								
								app
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								app
									
									
									
									
									
										Submodule
									
								
							 Submodule app added at 1adf331268
									
								
							
							
								
								
									
										27
									
								
								build.gradle
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								build.gradle
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| // Top-level build file where you can add configuration options common to all sub-projects/modules. | ||||
|  | ||||
| buildscript { | ||||
|      | ||||
|     repositories { | ||||
|         google() | ||||
|         jcenter() | ||||
|     } | ||||
|     dependencies { | ||||
|         classpath 'com.android.tools.build:gradle:3.0.1' | ||||
|          | ||||
|  | ||||
|         // NOTE: Do not place your application dependencies here; they belong | ||||
|         // in the individual module build.gradle files | ||||
|     } | ||||
| } | ||||
|  | ||||
| allprojects { | ||||
|     repositories { | ||||
|         google() | ||||
|         jcenter() | ||||
|     } | ||||
| } | ||||
|  | ||||
| task clean(type: Delete) { | ||||
|     delete rootProject.buildDir | ||||
| } | ||||
							
								
								
									
										3
									
								
								core/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								core/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| /build | ||||
| obj | ||||
| libs | ||||
							
								
								
									
										20
									
								
								core/build.gradle
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								core/build.gradle
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| apply plugin: 'com.android.library' | ||||
|  | ||||
| android { | ||||
|     compileSdkVersion 27 | ||||
|  | ||||
|     externalNativeBuild { | ||||
|         ndkBuild { | ||||
|             path 'jni/Android.mk' | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     defaultConfig { | ||||
|         externalNativeBuild { | ||||
|             ndkBuild { | ||||
|                 // Passes an optional argument to ndk-build. | ||||
|                 arguments "GRADLE=true" | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										138
									
								
								core/jni/Android.mk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								core/jni/Android.mk
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,138 @@ | ||||
| LOCAL_PATH := $(call my-dir) | ||||
|  | ||||
| # Some handy paths | ||||
| EXT_PATH := jni/external | ||||
| SE_PATH := $(EXT_PATH)/selinux | ||||
| LIBSELINUX := $(SE_PATH)/libselinux/include | ||||
| LIBSEPOL := $(SE_PATH)/libsepol/include $(SE_PATH)/libsepol/cil/include | ||||
| LIBLZMA := $(EXT_PATH)/xz/src/liblzma/api | ||||
| LIBLZ4 := $(EXT_PATH)/lz4/lib | ||||
| LIBBZ2 := $(EXT_PATH)/bzip2 | ||||
| LIBFDT := $(EXT_PATH)/dtc/libfdt | ||||
| UTIL_SRC := utils/cpio.c \ | ||||
|             utils/file.c \ | ||||
|             utils/img.c \ | ||||
|             utils/list.c \ | ||||
|             utils/misc.c \ | ||||
|             utils/pattern.c \ | ||||
|             utils/vector.c \ | ||||
|             utils/xwrap.c | ||||
|  | ||||
| ######################## | ||||
| # Binaries | ||||
| ######################## | ||||
|  | ||||
| ifneq "$(or $(PRECOMPILE), $(GRADLE))" "" | ||||
|  | ||||
| # magisk main binary | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE := magisk | ||||
| LOCAL_SHARED_LIBRARIES := libsqlite libselinux | ||||
|  | ||||
| LOCAL_C_INCLUDES := \ | ||||
| 	jni/include \ | ||||
| 	jni/external/include \ | ||||
| 	$(LIBSELINUX) | ||||
|  | ||||
| LOCAL_SRC_FILES := \ | ||||
| 	core/magisk.c \ | ||||
| 	core/daemon.c \ | ||||
| 	core/log_monitor.c \ | ||||
| 	core/bootstages.c \ | ||||
| 	core/socket.c \ | ||||
| 	magiskhide/magiskhide.c \ | ||||
| 	magiskhide/proc_monitor.c \ | ||||
| 	magiskhide/hide_utils.c \ | ||||
| 	resetprop/resetprop.cpp \ | ||||
| 	resetprop/system_properties.cpp \ | ||||
| 	su/su.c \ | ||||
| 	su/activity.c \ | ||||
| 	su/db.c \ | ||||
| 	su/pts.c \ | ||||
| 	su/su_daemon.c \ | ||||
| 	su/su_socket.c \ | ||||
| 	$(UTIL_SRC) | ||||
|  | ||||
| LOCAL_CFLAGS := -DIS_DAEMON -DSELINUX | ||||
| LOCAL_LDLIBS := -llog | ||||
| include $(BUILD_EXECUTABLE) | ||||
|  | ||||
| endif | ||||
|  | ||||
| ifndef PRECOMPILE | ||||
|  | ||||
| # magiskinit | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE := magiskinit | ||||
| LOCAL_STATIC_LIBRARIES := libsepol liblzma | ||||
| LOCAL_C_INCLUDES := \ | ||||
| 	jni/include \ | ||||
| 	jni/magiskpolicy \ | ||||
| 	../out/$(TARGET_ARCH_ABI) \ | ||||
| 	$(LIBSEPOL) \ | ||||
| 	$(LIBLZMA) | ||||
|  | ||||
| LOCAL_SRC_FILES := \ | ||||
| 	core/magiskinit.c \ | ||||
| 	core/socket.c \ | ||||
| 	magiskpolicy/api.c \ | ||||
| 	magiskpolicy/magiskpolicy.c \ | ||||
| 	magiskpolicy/rules.c \ | ||||
| 	magiskpolicy/sepolicy.c \ | ||||
| 	$(UTIL_SRC) | ||||
|  | ||||
| LOCAL_LDFLAGS := -static | ||||
| include $(BUILD_EXECUTABLE) | ||||
|  | ||||
| # magiskboot | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE := magiskboot | ||||
| LOCAL_STATIC_LIBRARIES := liblzma liblz4 libbz2 libfdt | ||||
| LOCAL_C_INCLUDES := \ | ||||
| 	jni/include \ | ||||
| 	jni/external/include \ | ||||
| 	$(LIBLZMA) \ | ||||
| 	$(LIBLZ4) \ | ||||
| 	$(LIBBZ2) \ | ||||
| 	$(LIBFDT) | ||||
|  | ||||
| LOCAL_SRC_FILES := \ | ||||
| 	external/sha1/sha1.c \ | ||||
| 	magiskboot/main.c \ | ||||
| 	magiskboot/bootimg.c \ | ||||
| 	magiskboot/hexpatch.c \ | ||||
| 	magiskboot/compress.c \ | ||||
| 	magiskboot/types.c \ | ||||
| 	magiskboot/dtb.c \ | ||||
| 	magiskboot/ramdisk.c \ | ||||
| 	$(UTIL_SRC) | ||||
|  | ||||
| LOCAL_CFLAGS := -DXWRAP_EXIT | ||||
| LOCAL_LDLIBS := -lz | ||||
| include $(BUILD_EXECUTABLE) | ||||
|  | ||||
| # 32-bit static binaries | ||||
| ifndef GRADLE  # Do not run gradle sync on these binaries | ||||
| ifneq ($(TARGET_ARCH_ABI), x86_64) | ||||
| ifneq ($(TARGET_ARCH_ABI), arm64-v8a) | ||||
| # b64xz | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE := b64xz | ||||
| LOCAL_STATIC_LIBRARIES := liblzma | ||||
| LOCAL_C_INCLUDES := $(LIBLZMA) | ||||
| LOCAL_SRC_FILES := b64xz.c | ||||
| LOCAL_LDFLAGS := -static | ||||
| include $(BUILD_EXECUTABLE) | ||||
| # Busybox | ||||
| include jni/external/busybox/Android.mk | ||||
| endif | ||||
| endif | ||||
| endif | ||||
|  | ||||
| # Precompile | ||||
| endif | ||||
|  | ||||
| ######################## | ||||
| # Externals | ||||
| ######################## | ||||
| include jni/external/Android.mk | ||||
| @@ -1,4 +1,4 @@ | ||||
| APP_ABI := x86 x86_64 armeabi-v7a arm64-v8a | ||||
| APP_PLATFORM := android-21 | ||||
| APP_UNIFIED_HEADERS := true | ||||
| APP_CPPFLAGS += -std=c++11 | ||||
| APP_CFLAGS := $(MAGISK_FLAGS) -std=gnu99 | ||||
| APP_CPPFLAGS := -std=c++11 | ||||
							
								
								
									
										83
									
								
								core/jni/b64xz.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								core/jni/b64xz.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | ||||
| /* b64xz.c - Base64-XZ Extractor | ||||
|  * | ||||
|  * This program expects data from stdin. The data should be compressed with xz and | ||||
|  * then encoded into base64 format. What b64xz does is basically the reverse of the | ||||
|  * mentioned process: decode base64 to uint8_ts, decompress xz, then dump to stdout | ||||
|  * | ||||
|  * The compiled binary will be hex-dumped into update-binary | ||||
|  * Busybox will be xz-compressed, base64 encoded and dumped into update-binary | ||||
|  * This program is to recover busybox for Magisk installation environment | ||||
|  * | ||||
|  * I intentionally removed stdio. This will result in a smaller binary size because | ||||
|  * all I/O are handled by system calls (read/write) instead of libc wrappers | ||||
|  */ | ||||
|  | ||||
| #include <unistd.h> | ||||
| #include <lzma.h> | ||||
|  | ||||
| #define BUFSIZE 8192 | ||||
|  | ||||
| static const char trans_tbl[] = | ||||
| 		"|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq"; | ||||
|  | ||||
| static void decodeblock(uint8_t* in, uint8_t* out) { | ||||
| 	out[0] = (uint8_t)(in[0] << 2 | in[1] >> 4); | ||||
| 	out[1] = (uint8_t)(in[1] << 4 | in[2] >> 2); | ||||
| 	out[2] = (uint8_t)(((in[2] << 6) & 0xc0) | in[3]); | ||||
| } | ||||
|  | ||||
| static int unxz(lzma_stream *strm, void *buf, size_t size) { | ||||
| 	lzma_ret ret = 0; | ||||
| 	uint8_t out[BUFSIZE]; | ||||
| 	strm->next_in = buf; | ||||
| 	strm->avail_in = size; | ||||
| 	do { | ||||
| 		strm->next_out = out; | ||||
| 		strm->avail_out = sizeof(out); | ||||
| 		ret = lzma_code(strm, LZMA_RUN); | ||||
| 		write(STDOUT_FILENO, out, sizeof(out) - strm->avail_out); | ||||
| 	} while (strm->avail_out == 0 && ret == LZMA_OK); | ||||
|  | ||||
| 	if (ret != LZMA_OK && ret != LZMA_STREAM_END) | ||||
| 		write(STDERR_FILENO, "LZMA error!\n", 13); | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| int main(int argc, char const* argv[]) { | ||||
| 	if (argc > 1) | ||||
| 		return 0; | ||||
|  | ||||
| 	uint8_t in[4], buf[BUFSIZE]; | ||||
| 	int len = 0, pos = 0; | ||||
| 	char c; | ||||
|  | ||||
| 	// Setup lzma stream | ||||
| 	lzma_stream strm = LZMA_STREAM_INIT; | ||||
| 	if (lzma_auto_decoder(&strm, UINT64_MAX, 0) != LZMA_OK) { | ||||
| 		write(STDERR_FILENO, "Unable to init lzma stream\n", 28); | ||||
| 		return 1; | ||||
| 	} | ||||
|  | ||||
| 	while (read(STDIN_FILENO, &c, sizeof(c)) == 1) { | ||||
| 		c = ((c < 43 || c > 122) ? -1 : (trans_tbl[c - 43] == '$' ? -1 : trans_tbl[c - 43] - 62)); | ||||
| 		if (c >= 0) | ||||
| 			in[len++] = c; | ||||
| 		if (len < 4) | ||||
| 			continue; | ||||
| 		len = 0; | ||||
| 		decodeblock(in, buf + pos); | ||||
| 		pos += 3; | ||||
| 		if (pos > sizeof(buf) - 3) { | ||||
| 			// Buffer is full, unxz | ||||
| 			if (unxz(&strm, buf, pos)) | ||||
| 				return 1; | ||||
| 			pos = 0; | ||||
| 		} | ||||
| 	} | ||||
| 	if (pos) { | ||||
| 		if (unxz(&strm, buf, pos)) | ||||
| 			return 1; | ||||
| 	} | ||||
| 	lzma_end(&strm); | ||||
| 	return 0; | ||||
| } | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										318
									
								
								core/jni/core/daemon.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										318
									
								
								core/jni/core/daemon.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										178
									
								
								core/jni/core/log_monitor.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										178
									
								
								core/jni/core/log_monitor.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,178 @@ | ||||
| /* log_monitor.c - New thread to monitor logcat | ||||
|  * | ||||
|  * A universal logcat monitor for many usages. Add listeners to the list, | ||||
|  * and the pointer of the new log line will be sent through pipes to trigger | ||||
|  * asynchronous events without polling | ||||
|  */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <pthread.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/wait.h> | ||||
|  | ||||
| #include "magisk.h" | ||||
| #include "utils.h" | ||||
|  | ||||
| extern int is_daemon_init; | ||||
|  | ||||
| static int am_proc_start_filter(const char *log) { | ||||
| 	return strstr(log, "am_proc_start") != NULL; | ||||
| } | ||||
|  | ||||
| static int magisk_log_filter(const char *log) { | ||||
| 	char *ss; | ||||
| 	return (ss = strstr(log, " Magisk")) && (ss[-1] != 'D') && (ss[-1] != 'V'); | ||||
| } | ||||
|  | ||||
| static int magisk_debug_log_filter(const char *log) { | ||||
| 	return strstr(log, "Magisk") != NULL; | ||||
| } | ||||
|  | ||||
| struct log_listener log_events[] = { | ||||
| 	{	/* HIDE_EVENT */ | ||||
| 		.fd = -1, | ||||
| 		.filter = am_proc_start_filter | ||||
| 	}, | ||||
| 	{	/* LOG_EVENT */ | ||||
| 		.fd = -1, | ||||
| 		.filter = magisk_log_filter | ||||
| 	}, | ||||
| 	{	/* DEBUG_EVENT */ | ||||
| 		.fd = -1, | ||||
| 		.filter = magisk_debug_log_filter | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| #ifdef MAGISK_DEBUG | ||||
| static int debug_log_pid, debug_log_fd; | ||||
| #endif | ||||
|  | ||||
| static void *logger_thread(void *args) { | ||||
| 	int log_fd = -1, log_pid; | ||||
| 	char line[4096]; | ||||
|  | ||||
| 	LOGD("log_monitor: logger start"); | ||||
|  | ||||
| 	while (1) { | ||||
| 		// Start logcat | ||||
| 		log_pid = exec_command(0, &log_fd, NULL, "logcat", "-b", "all" , "-v", "threadtime", "-s", "am_proc_start", "Magisk", NULL); | ||||
| 		while (fdgets(line, sizeof(line), log_fd)) { | ||||
| 			for (int i = 0; i < (sizeof(log_events) / sizeof(struct log_listener)); ++i) { | ||||
| 				if (log_events[i].fd > 0 && log_events[i].filter(line)) { | ||||
| 					char *s = strdup(line); | ||||
| 					xwrite(log_events[i].fd, &s, sizeof(s)); | ||||
| 				} | ||||
| 			} | ||||
| 			if (kill(log_pid, 0)) | ||||
| 				break; | ||||
| 		} | ||||
|  | ||||
| 		// Cleanup | ||||
| 		close(log_fd); | ||||
| 		log_fd = -1; | ||||
| 		kill(log_pid, SIGTERM); | ||||
| 		waitpid(log_pid, NULL, 0); | ||||
|  | ||||
| 		// Clear buffer before restart | ||||
| 		exec_command_sync("logcat", "-b", "all", "-c", NULL); | ||||
| 	} | ||||
|  | ||||
| 	// Should never be here, but well... | ||||
| 	return NULL; | ||||
| } | ||||
|  | ||||
| static void *magisk_log_thread(void *args) { | ||||
| 	// Buffer logs before we have data access | ||||
| 	struct vector logs; | ||||
| 	vec_init(&logs); | ||||
|  | ||||
| 	int pipefd[2]; | ||||
| 	if (xpipe2(pipefd, O_CLOEXEC) == -1) | ||||
| 		return NULL; | ||||
|  | ||||
| 	// Register our listener | ||||
| 	log_events[LOG_EVENT].fd = pipefd[1]; | ||||
|  | ||||
| 	LOGD("log_monitor: magisk log dumper start"); | ||||
|  | ||||
| 	FILE *log = NULL; | ||||
| 	for (char *line; xxread(pipefd[0], &line, sizeof(line)) > 0; free(line)) { | ||||
| 		if (!is_daemon_init) { | ||||
| 			vec_push_back(&logs, strdup(line)); | ||||
| 		} else { | ||||
| 			if (log == NULL) { | ||||
| 				// Dump buffered logs to file | ||||
| 				log = xfopen(LOGFILE, "w"); | ||||
| 				setbuf(log, NULL); | ||||
| 				char *tmp; | ||||
| 				vec_for_each(&logs, tmp) { | ||||
| 					fprintf(log, "%s", tmp); | ||||
| 					free(tmp); | ||||
| 				} | ||||
| 				vec_destroy(&logs); | ||||
| 			} | ||||
| 			fprintf(log, "%s", line); | ||||
| 		} | ||||
| 	} | ||||
| 	return NULL; | ||||
| } | ||||
|  | ||||
| static void *debug_magisk_log_thread(void *args) { | ||||
| 	FILE *log = xfopen(DEBUG_LOG, "a"); | ||||
| 	setbuf(log, NULL); | ||||
| 	int pipefd[2]; | ||||
| 	if (xpipe2(pipefd, O_CLOEXEC) == -1) | ||||
| 		return NULL; | ||||
|  | ||||
| 	LOGD("log_monitor: debug log dumper start"); | ||||
|  | ||||
| 	// Register our listener | ||||
| 	log_events[DEBUG_EVENT].fd = pipefd[1]; | ||||
|  | ||||
| 	for (char *line; xxread(pipefd[0], &line, sizeof(line)) > 0; free(line)) | ||||
| 		fprintf(log, "%s", line); | ||||
|  | ||||
| 	return NULL; | ||||
| } | ||||
|  | ||||
| /* Start new threads to monitor logcat and dump to logfile */ | ||||
| void monitor_logs() { | ||||
| 	pthread_t thread; | ||||
|  | ||||
| 	// Start log file dumper before monitor | ||||
| 	xpthread_create(&thread, NULL, magisk_log_thread, NULL); | ||||
| 	pthread_detach(thread); | ||||
|  | ||||
| 	// Start logcat monitor | ||||
| 	xpthread_create(&thread, NULL, logger_thread, NULL); | ||||
| 	pthread_detach(thread); | ||||
|  | ||||
| } | ||||
|  | ||||
| void start_debug_full_log() { | ||||
| #ifdef MAGISK_DEBUG | ||||
| 	// Log everything initially | ||||
| 	debug_log_fd = xopen(DEBUG_LOG, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644); | ||||
| 	debug_log_pid = exec_command(0, &debug_log_fd, NULL, "logcat", "-v", "threadtime", NULL); | ||||
| 	close(debug_log_fd); | ||||
| #endif | ||||
| } | ||||
|  | ||||
| void stop_debug_full_log() { | ||||
| #ifdef MAGISK_DEBUG | ||||
| 	// Stop recording the boot logcat after every boot task is done | ||||
| 	kill(debug_log_pid, SIGTERM); | ||||
| 	waitpid(debug_log_pid, NULL, 0); | ||||
| 	// Start debug thread | ||||
| 	start_debug_log(); | ||||
| #endif | ||||
| } | ||||
|  | ||||
| void start_debug_log() { | ||||
| #ifdef MAGISK_DEBUG | ||||
| 	pthread_t thread; | ||||
| 	// Start debug thread | ||||
| 	xpthread_create(&thread, NULL, debug_magisk_log_thread, NULL); | ||||
| 	pthread_detach(thread); | ||||
| #endif | ||||
| } | ||||
| @@ -3,6 +3,8 @@ | ||||
|  | ||||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| #include <unistd.h> | ||||
| #include <libgen.h> | ||||
|  | ||||
| #include "utils.h" | ||||
| #include "magisk.h" | ||||
| @@ -10,65 +12,64 @@ | ||||
|  | ||||
| char *argv0; | ||||
|  | ||||
| char *applet[] = | ||||
| 	{ "su", "resetprop", "magiskpolicy", "supolicy", "sepolicy-inject", "magiskhide", NULL }; | ||||
| int (*applet_main[]) (int, char *[]) = { su_client_main, resetprop_main, magiskhide_main, NULL }; | ||||
|  | ||||
| int (*applet_main[]) (int, char *[]) = | ||||
| 	{ su_client_main, resetprop_main, magiskpolicy_main, magiskpolicy_main, magiskpolicy_main, magiskhide_main, NULL }; | ||||
|  | ||||
| // Global error hander function | ||||
| // Should be changed each thread/process | ||||
| __thread void (*err_handler)(void); | ||||
| int create_links(const char *bin, const char *path) { | ||||
| 	char self[PATH_MAX], linkpath[PATH_MAX]; | ||||
| 	if (bin == NULL) { | ||||
| 		xreadlink("/proc/self/exe", self, sizeof(self)); | ||||
| 		bin = self; | ||||
| 	} | ||||
| 	int ret = 0; | ||||
| 	for (int i = 0; applet[i]; ++i) { | ||||
| 		snprintf(linkpath, sizeof(linkpath), "%s/%s", path, applet[i]); | ||||
| 		unlink(linkpath); | ||||
| 		ret |= symlink(bin, linkpath); | ||||
| 	} | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| static void usage() { | ||||
| 	fprintf(stderr, | ||||
| 		"Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") (by topjohnwu) multi-call binary\n" | ||||
| 		"\n" | ||||
| 		"Usage: %s [applet [arguments]...]\n" | ||||
| 		"   or: %s --install [SOURCE] <DIR> \n" | ||||
| 		"   or: %s --list\n" | ||||
| 		"   or: %s --createimg <PATH> <SIZE>\n" | ||||
| 		"       create ext4 image, SIZE is interpreted in MB\n" | ||||
| 		"   or: %s --imgsize <PATH>\n" | ||||
| 		"   or: %s --resizeimg <PATH> <SIZE>\n" | ||||
| 		"       SIZE is interpreted in MB\n" | ||||
| 		"   or: %s --mountimg <IMG> <PATH>\n" | ||||
| 		"       Prints out the loop device\n" | ||||
| 		"   or: %s --umountimg <PATH> <LOOP>\n" | ||||
| 		"   or: %s --[boot stage]\n" | ||||
| 		"       start boot stage service\n" | ||||
| 		"   or: %s [options]\n" | ||||
| 		"   or: applet [arguments]...\n" | ||||
| 		"\n" | ||||
| 		"Supported boot stages:\n" | ||||
| 		"       post-fs, post-fs-data, service\n" | ||||
| 		"   or: %s [options]...\n" | ||||
| 		"\n" | ||||
| 		"Options:\n" | ||||
| 		"       -c            print client version\n" | ||||
| 		"       -v            print daemon version\n" | ||||
| 		"       -V            print daemon version code\n" | ||||
| 		"   -c                        print current binary version\n" | ||||
| 		"   -v                        print running daemon version\n" | ||||
| 		"   -V                        print running daemon version code\n" | ||||
| 		"   --list                    list all available applets\n" | ||||
| 		"   --install [SOURCE] DIR    symlink all applets to DIR. SOURCE is optional\n" | ||||
| 		"   --createimg IMG SIZE      create ext4 image. SIZE is interpreted in MB\n" | ||||
| 		"   --imgsize IMG             report ext4 image used/total size\n" | ||||
| 		"   --resizeimg IMG SIZE      resize ext4 image. SIZE is interpreted in MB\n" | ||||
| 		"   --mountimg IMG PATH       mount IMG to PATH and prints the loop device\n" | ||||
| 		"   --umountimg PATH LOOP     unmount PATH and delete LOOP device\n" | ||||
| 		"   --[init service]          start init service\n" | ||||
| 		"   --unlock-blocks           set BLKROSET flag to OFF for all block devices\n" | ||||
| 		"   --restorecon              fix selinux context on Magisk files and folders\n" | ||||
| 		"   --clone-attr SRC DEST     clone permission, owner, and selinux context\n" | ||||
| 		"\n" | ||||
| 		"Supported init services:\n" | ||||
| 		"   daemon, post-fs, post-fs-data, service\n" | ||||
| 		"\n" | ||||
| 		"Supported applets:\n" | ||||
| 	, argv0, argv0, argv0, argv0, argv0, argv0, argv0, argv0, argv0, argv0); | ||||
| 	, argv0, argv0); | ||||
|  | ||||
| 	for (int i = 0; applet[i]; ++i) { | ||||
| 		fprintf(stderr, i ? ", %s" : "       %s", applet[i]); | ||||
| 	} | ||||
| 	fprintf(stderr, "\n"); | ||||
| 	for (int i = 0; applet[i]; ++i) | ||||
| 		fprintf(stderr, i ? ", %s" : "    %s", applet[i]); | ||||
| 	fprintf(stderr, "\n\n"); | ||||
| 	exit(1); | ||||
| } | ||||
|  | ||||
| int main(int argc, char *argv[]) { | ||||
| 	argv0 = argv[0]; | ||||
| 	// Exit the whole app if error occurs by default | ||||
| 	err_handler = exit_proc; | ||||
| 	char * arg = strrchr(argv[0], '/'); | ||||
| 	if (arg) ++arg; | ||||
| 	else arg = argv[0]; | ||||
| 	if (strcmp(arg, "magisk") == 0) { | ||||
| 	if (strcmp(basename(argv[0]), "magisk") == 0) { | ||||
| 		if (argc < 2) usage(); | ||||
| 		if (strcmp(argv[1], "-c") == 0) { | ||||
| 			printf("%s\n", MAGISK_VER_STR); | ||||
| 			printf("%s (%d)\n", MAGISK_VER_STR, MAGISK_VER_CODE); | ||||
| 			return 0; | ||||
| 		} else if (strcmp(argv[1], "-v") == 0) { | ||||
| 			int fd = connect_daemon(); | ||||
| @@ -132,6 +133,20 @@ int main(int argc, char *argv[]) { | ||||
| 			if (argc < 4) usage(); | ||||
| 			umount_image(argv[2], argv[3]); | ||||
| 			return 0; | ||||
| 		} else if (strcmp(argv[1], "--unlock-blocks") == 0) { | ||||
| 			unlock_blocks(); | ||||
| 			return 0; | ||||
| 		} else if (strcmp(argv[1], "--restorecon") == 0) { | ||||
| 			fix_filecon(); | ||||
| 			return 0; | ||||
| 		} else if (strcmp(argv[1], "--clone-attr") == 0) { | ||||
| 			if (argc < 4) usage(); | ||||
| 			clone_attr(argv[2], argv[3]); | ||||
| 			return 0; | ||||
| 		} else if (strcmp(argv[1], "--daemon") == 0) { | ||||
| 			if (xfork() == 0) | ||||
| 				start_daemon(); | ||||
| 			return 0; | ||||
| 		} else if (strcmp(argv[1], "--post-fs") == 0) { | ||||
| 			int fd = connect_daemon(); | ||||
| 			write_int(fd, POST_FS); | ||||
| @@ -148,16 +163,15 @@ int main(int argc, char *argv[]) { | ||||
| 			// It's calling applets | ||||
| 			--argc; | ||||
| 			++argv; | ||||
| 			arg = argv[0]; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// Applets | ||||
| 	for (int i = 0; applet[i]; ++i) { | ||||
| 		if (strcmp(arg, applet[i]) == 0) | ||||
| 		if (strcmp(basename(argv[0]), applet[i]) == 0) | ||||
| 			return (*applet_main[i])(argc, argv); | ||||
| 	} | ||||
|  | ||||
| 	fprintf(stderr, "%s: applet not found\n", arg); | ||||
| 	fprintf(stderr, "%s: applet not found\n", basename(argv[0])); | ||||
| 	return 1; | ||||
| } | ||||
							
								
								
									
										528
									
								
								core/jni/core/magiskinit.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										528
									
								
								core/jni/core/magiskinit.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,18 +1,22 @@ | ||||
| /* socket_trans.c - Functions to transfer data through socket | ||||
| /* socket.c - All socket related operations | ||||
|  */ | ||||
|  | ||||
| #include <unistd.h> | ||||
| #include <string.h> | ||||
| #include <stdlib.h> | ||||
| #include <limits.h> | ||||
| #include <fcntl.h> | ||||
| #include <errno.h> | ||||
| #include <sys/types.h> | ||||
| #include <sys/socket.h> | ||||
|  | ||||
| #include "magisk.h" | ||||
| #include "utils.h" | ||||
| #include "daemon.h" | ||||
| #include "logging.h" | ||||
| #include "utils.h" | ||||
| #include "magisk.h" | ||||
|  | ||||
| /* Setup the address and return socket fd */ | ||||
| int setup_socket(struct sockaddr_un *sun) { | ||||
|     int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); | ||||
|     memset(sun, 0, sizeof(*sun)); | ||||
|     sun->sun_family = AF_LOCAL; | ||||
|     memcpy(sun->sun_path, REQUESTOR_DAEMON_PATH, sizeof(REQUESTOR_DAEMON_PATH) - 1); | ||||
|     return fd; | ||||
| } | ||||
|  | ||||
|  | ||||
| /* | ||||
|  * Receive a file descriptor from a Unix socket. | ||||
							
								
								
									
										158
									
								
								core/jni/external/Android.mk
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										158
									
								
								core/jni/external/Android.mk
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,158 @@ | ||||
| LOCAL_PATH:= $(call my-dir) | ||||
|  | ||||
| # libsqlite.so (stub) | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE:= libsqlite | ||||
| LOCAL_C_INCLUDES := jni/external/include | ||||
| LOCAL_SRC_FILES := stubs/sqlite3_stub.c | ||||
| include $(BUILD_SHARED_LIBRARY) | ||||
|  | ||||
| # libselinux.so (stub) | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE:= libselinux | ||||
| LOCAL_C_INCLUDES := $(LIBSELINUX) | ||||
| LOCAL_SRC_FILES := stubs/selinux_stub.c | ||||
| include $(BUILD_SHARED_LIBRARY) | ||||
|  | ||||
| # libfdt.a | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE:= libfdt | ||||
| LOCAL_C_INCLUDES := $(LIBFDT) | ||||
| LOCAL_SRC_FILES := \ | ||||
| 	dtc/libfdt/fdt.c \ | ||||
| 	dtc/libfdt/fdt_addresses.c \ | ||||
| 	dtc/libfdt/fdt_empty_tree.c \ | ||||
| 	dtc/libfdt/fdt_overlay.c \ | ||||
| 	dtc/libfdt/fdt_ro.c \ | ||||
| 	dtc/libfdt/fdt_rw.c \ | ||||
| 	dtc/libfdt/fdt_strerror.c \ | ||||
| 	dtc/libfdt/fdt_sw.c \ | ||||
| 	dtc/libfdt/fdt_wip.c | ||||
| include $(BUILD_STATIC_LIBRARY) | ||||
|  | ||||
| # liblz4.a | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE := liblz4 | ||||
| LOCAL_C_INCLUDES += $(LIBLZ4) | ||||
| LOCAL_SRC_FILES := \ | ||||
| 	lz4/lib/lz4.c \ | ||||
| 	lz4/lib/lz4frame.c \ | ||||
| 	lz4/lib/lz4hc.c \ | ||||
| 	lz4/lib/xxhash.c | ||||
| include $(BUILD_STATIC_LIBRARY) | ||||
|  | ||||
| # libbz2.a | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE := libbz2 | ||||
| LOCAL_C_INCLUDES += $(LIBBZ2) | ||||
| LOCAL_SRC_FILES := \ | ||||
| 	bzip2/blocksort.c  \ | ||||
| 	bzip2/huffman.c    \ | ||||
| 	bzip2/crctable.c   \ | ||||
| 	bzip2/randtable.c  \ | ||||
| 	bzip2/compress.c   \ | ||||
| 	bzip2/decompress.c \ | ||||
| 	bzip2/bzlib.c | ||||
| include $(BUILD_STATIC_LIBRARY) | ||||
|  | ||||
| # liblzma.a | ||||
| include $(CLEAR_VARS) | ||||
| LOCAL_MODULE := liblzma | ||||
| LOCAL_C_INCLUDES += \ | ||||
| 	$(EXT_PATH)/include/xz_config \ | ||||
| 	$(EXT_PATH)/xz/src/common \ | ||||
| 	$(EXT_PATH)/xz/src/liblzma/api \ | ||||
| 	$(EXT_PATH)/xz/src/liblzma/check \ | ||||
| 	$(EXT_PATH)/xz/src/liblzma/common \ | ||||
| 	$(EXT_PATH)/xz/src/liblzma/delta \ | ||||
| 	$(EXT_PATH)/xz/src/liblzma/lz \ | ||||
| 	$(EXT_PATH)/xz/src/liblzma/lzma \ | ||||
| 	$(EXT_PATH)/xz/src/liblzma/rangecoder \ | ||||
| 	$(EXT_PATH)/xz/src/liblzma/simple \ | ||||
| 	$(EXT_PATH)/xz/src/liblzma | ||||
| LOCAL_SRC_FILES := \ | ||||
| 	xz/src/common/tuklib_cpucores.c \ | ||||
| 	xz/src/common/tuklib_exit.c \ | ||||
| 	xz/src/common/tuklib_mbstr_fw.c \ | ||||
| 	xz/src/common/tuklib_mbstr_width.c \ | ||||
| 	xz/src/common/tuklib_open_stdxxx.c \ | ||||
| 	xz/src/common/tuklib_physmem.c \ | ||||
| 	xz/src/common/tuklib_progname.c \ | ||||
| 	xz/src/liblzma/check/check.c \ | ||||
| 	xz/src/liblzma/check/crc32_fast.c \ | ||||
| 	xz/src/liblzma/check/crc32_table.c \ | ||||
| 	xz/src/liblzma/check/crc64_fast.c \ | ||||
| 	xz/src/liblzma/check/crc64_table.c \ | ||||
| 	xz/src/liblzma/check/sha256.c \ | ||||
| 	xz/src/liblzma/common/alone_decoder.c \ | ||||
| 	xz/src/liblzma/common/alone_encoder.c \ | ||||
| 	xz/src/liblzma/common/auto_decoder.c \ | ||||
| 	xz/src/liblzma/common/block_buffer_decoder.c \ | ||||
| 	xz/src/liblzma/common/block_buffer_encoder.c \ | ||||
| 	xz/src/liblzma/common/block_decoder.c \ | ||||
| 	xz/src/liblzma/common/block_encoder.c \ | ||||
| 	xz/src/liblzma/common/block_header_decoder.c \ | ||||
| 	xz/src/liblzma/common/block_header_encoder.c \ | ||||
| 	xz/src/liblzma/common/block_util.c \ | ||||
| 	xz/src/liblzma/common/common.c \ | ||||
| 	xz/src/liblzma/common/easy_buffer_encoder.c \ | ||||
| 	xz/src/liblzma/common/easy_decoder_memusage.c \ | ||||
| 	xz/src/liblzma/common/easy_encoder.c \ | ||||
| 	xz/src/liblzma/common/easy_encoder_memusage.c \ | ||||
| 	xz/src/liblzma/common/easy_preset.c \ | ||||
| 	xz/src/liblzma/common/filter_buffer_decoder.c \ | ||||
| 	xz/src/liblzma/common/filter_buffer_encoder.c \ | ||||
| 	xz/src/liblzma/common/filter_common.c \ | ||||
| 	xz/src/liblzma/common/filter_decoder.c \ | ||||
| 	xz/src/liblzma/common/filter_encoder.c \ | ||||
| 	xz/src/liblzma/common/filter_flags_decoder.c \ | ||||
| 	xz/src/liblzma/common/filter_flags_encoder.c \ | ||||
| 	xz/src/liblzma/common/hardware_cputhreads.c \ | ||||
| 	xz/src/liblzma/common/hardware_physmem.c \ | ||||
| 	xz/src/liblzma/common/index.c \ | ||||
| 	xz/src/liblzma/common/index_decoder.c \ | ||||
| 	xz/src/liblzma/common/index_encoder.c \ | ||||
| 	xz/src/liblzma/common/index_hash.c \ | ||||
| 	xz/src/liblzma/common/outqueue.c \ | ||||
| 	xz/src/liblzma/common/stream_buffer_decoder.c \ | ||||
| 	xz/src/liblzma/common/stream_buffer_encoder.c \ | ||||
| 	xz/src/liblzma/common/stream_decoder.c \ | ||||
| 	xz/src/liblzma/common/stream_encoder.c \ | ||||
| 	xz/src/liblzma/common/stream_encoder_mt.c \ | ||||
| 	xz/src/liblzma/common/stream_flags_common.c \ | ||||
| 	xz/src/liblzma/common/stream_flags_decoder.c \ | ||||
| 	xz/src/liblzma/common/stream_flags_encoder.c \ | ||||
| 	xz/src/liblzma/common/vli_decoder.c \ | ||||
| 	xz/src/liblzma/common/vli_encoder.c \ | ||||
| 	xz/src/liblzma/common/vli_size.c \ | ||||
| 	xz/src/liblzma/delta/delta_common.c \ | ||||
| 	xz/src/liblzma/delta/delta_decoder.c \ | ||||
| 	xz/src/liblzma/delta/delta_encoder.c \ | ||||
| 	xz/src/liblzma/lz/lz_decoder.c \ | ||||
| 	xz/src/liblzma/lz/lz_encoder.c \ | ||||
| 	xz/src/liblzma/lz/lz_encoder_mf.c \ | ||||
| 	xz/src/liblzma/lzma/fastpos_table.c \ | ||||
| 	xz/src/liblzma/lzma/fastpos_tablegen.c \ | ||||
| 	xz/src/liblzma/lzma/lzma2_decoder.c \ | ||||
| 	xz/src/liblzma/lzma/lzma2_encoder.c \ | ||||
| 	xz/src/liblzma/lzma/lzma_decoder.c \ | ||||
| 	xz/src/liblzma/lzma/lzma_encoder.c \ | ||||
| 	xz/src/liblzma/lzma/lzma_encoder_optimum_fast.c \ | ||||
| 	xz/src/liblzma/lzma/lzma_encoder_optimum_normal.c \ | ||||
| 	xz/src/liblzma/lzma/lzma_encoder_presets.c \ | ||||
| 	xz/src/liblzma/rangecoder/price_table.c \ | ||||
| 	xz/src/liblzma/rangecoder/price_tablegen.c \ | ||||
| 	xz/src/liblzma/simple/arm.c \ | ||||
| 	xz/src/liblzma/simple/armthumb.c \ | ||||
| 	xz/src/liblzma/simple/ia64.c \ | ||||
| 	xz/src/liblzma/simple/powerpc.c \ | ||||
| 	xz/src/liblzma/simple/simple_coder.c \ | ||||
| 	xz/src/liblzma/simple/simple_decoder.c \ | ||||
| 	xz/src/liblzma/simple/simple_encoder.c \ | ||||
| 	xz/src/liblzma/simple/sparc.c \ | ||||
| 	xz/src/liblzma/simple/x86.c | ||||
| LOCAL_CFLAGS += -DHAVE_CONFIG_H -std=c99 | ||||
| include $(BUILD_STATIC_LIBRARY) | ||||
|  | ||||
| # libsepol.a | ||||
| include $(SE_PATH)/libsepol/Android.mk | ||||
							
								
								
									
										1
									
								
								core/jni/external/busybox
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								core/jni/external/busybox
									
									
									
									
										vendored
									
									
										Submodule
									
								
							 Submodule core/jni/external/busybox added at e3a1a4d91f
									
								
							
							
								
								
									
										1
									
								
								core/jni/external/bzip2
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								core/jni/external/bzip2
									
									
									
									
										vendored
									
									
										Submodule
									
								
							 Submodule core/jni/external/bzip2 added at 67d818584d
									
								
							
							
								
								
									
										1
									
								
								core/jni/external/dtc
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								core/jni/external/dtc
									
									
									
									
										vendored
									
									
										Submodule
									
								
							 Submodule core/jni/external/dtc added at 22a65c5331
									
								
							
							
								
								
									
										498
									
								
								core/jni/external/include/xz_config/config.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										498
									
								
								core/jni/external/include/xz_config/config.h
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1
									
								
								core/jni/external/lz4
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								core/jni/external/lz4
									
									
									
									
										vendored
									
									
										Submodule
									
								
							 Submodule core/jni/external/lz4 added at c10863b98e
									
								
							
							
								
								
									
										1
									
								
								core/jni/external/selinux
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								core/jni/external/selinux
									
									
									
									
										vendored
									
									
										Submodule
									
								
							 Submodule core/jni/external/selinux added at 8e849a5639
									
								
							| @@ -1,10 +1,11 @@ | ||||
| #include <stdbool.h> | ||||
| #include "selinux/avc.h" | ||||
| #include "selinux/context.h" | ||||
| #include "selinux/get_context_list.h" | ||||
| #include "selinux/get_default_type.h" | ||||
| #include "selinux/restorecon.h" | ||||
| #include "selinux/selinux.h" | ||||
| #include <selinux/avc.h> | ||||
| #include <selinux/context.h> | ||||
| #include <selinux/get_context_list.h> | ||||
| #include <selinux/get_default_type.h> | ||||
| #include <selinux/label.h> | ||||
| #include <selinux/restorecon.h> | ||||
| #include <selinux/selinux.h> | ||||
| int is_selinux_enabled(void) { return 0; } | ||||
| int is_selinux_mls_enabled(void) { return 0; } | ||||
| void freecon(char * con) { } | ||||
| @@ -225,7 +226,7 @@ int selinux_raw_to_trans_context(const char * raw, | ||||
| int selinux_raw_context_to_color(const char * raw, | ||||
| 					char **color_str) { return 0; } | ||||
| int getseuserbyname(const char *linuxuser, char **seuser, char **level) { return 0; } | ||||
| int getseuser(const char *username, const char *service,  | ||||
| int getseuser(const char *username, const char *service, | ||||
| 			char **r_seuser, char **r_level) { return 0; } | ||||
| int selinux_file_context_cmp(const char * a, | ||||
| 				const char * b) { return 0; } | ||||
							
								
								
									
										1
									
								
								core/jni/external/xz
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								core/jni/external/xz
									
									
									
									
										vendored
									
									
										Submodule
									
								
							 Submodule core/jni/external/xz added at 3d566cd519
									
								
							Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user