mirror of
https://github.com/topjohnwu/Magisk
synced 2025-10-27 04:02:14 +01:00
Compare commits
141 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
8c5f11b7dd | ||
|
|
7f7dda9ec2 | ||
|
|
9c1005ff0c | ||
|
|
5b36b4472c | ||
|
|
a3fcc64aaa | ||
|
|
f3078bc903 | ||
|
|
6072744f7e | ||
|
|
a87ad35a50 | ||
|
|
cf56d7e4ed | ||
|
|
e33a5eb307 | ||
|
|
e5b704eb32 | ||
|
|
56457bd325 | ||
|
|
bdbb3c6657 | ||
|
|
c4d7001489 |
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
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,6 +2,7 @@ obj/
|
||||
libs/
|
||||
*.zip
|
||||
*.jks
|
||||
*.apk
|
||||
|
||||
# Copied binaries
|
||||
# Built binaries
|
||||
ziptools/zipadjust
|
||||
|
||||
12
.gitmodules
vendored
12
.gitmodules
vendored
@@ -1,15 +1,21 @@
|
||||
[submodule "jni/selinux"]
|
||||
path = jni/selinux
|
||||
path = jni/external/selinux
|
||||
url = https://github.com/topjohnwu/selinux.git
|
||||
[submodule "jni/su"]
|
||||
path = jni/su
|
||||
url = https://github.com/topjohnwu/MagiskSU.git
|
||||
[submodule "jni/ndk-compression"]
|
||||
path = jni/ndk-compression
|
||||
path = jni/external/ndk-compression
|
||||
url = https://github.com/topjohnwu/ndk-compression.git
|
||||
[submodule "jni/magiskpolicy"]
|
||||
path = jni/magiskpolicy
|
||||
url = https://github.com/topjohnwu/magiskpolicy.git
|
||||
[submodule "MagiskManager"]
|
||||
path = MagiskManager
|
||||
path = java
|
||||
url = https://github.com/topjohnwu/MagiskManager.git
|
||||
[submodule "jni/busybox"]
|
||||
path = jni/external/busybox
|
||||
url = https://github.com/topjohnwu/ndk-busybox.git
|
||||
[submodule "jni/external/dtc"]
|
||||
path = jni/external/dtc
|
||||
url = https://github.com/dgibson/dtc
|
||||
|
||||
Submodule MagiskManager deleted from 1a69b16d36
61
README.MD
61
README.MD
@@ -4,33 +4,35 @@
|
||||
|
||||
#### Building has been tested on 3 major platforms:
|
||||
|
||||
***macOS 10.12.5***
|
||||
***Ubuntu 17.04 x64***
|
||||
***Windows 10 Creators Update x64***
|
||||
**macOS 10.12**
|
||||
**Ubuntu 17.04 x64**
|
||||
**Windows 10 x64**
|
||||
|
||||
#### Environment Requirements
|
||||
|
||||
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
|
||||
1. A 64-bit machine: `cmake` for Android is only available in 64-bit
|
||||
2. Python 3.5+: to run the build script
|
||||
3. Java Development Kit (JDK) 8: To compile Magisk Manager and sign zips
|
||||
4. C compiler (Unix only): To build `zipadjust`. Windows users can use the pre-built `zipadjust.exe`
|
||||
5. Android SDK: `ANDROID_HOME` environment variable should point to the Android SDK folder
|
||||
6. Android NDK: Install NDK via `sdkmanager`, or via Android SDK Manager in Android Studio
|
||||
|
||||
#### 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.
|
||||
1. The easiest way to setup a working environment is to open Magisk Manager with Android Studio. The IDE will download required components and construct the environment for you. Don't forget to set `ANDROID_HOME` environment variable to the SDK path.
|
||||
2. Windows users: while installing Python 3 on Windows, allow the installer to add Python to `PATH`, or you'll have to add it manually afterwards. By default, the Python executable is setup as `python`, not `python3` like most Unix environment. If you have both Python 2 and Python 3 installed, you'll have to deal with the executable name and `PATH` yourself. To double check the Python version, call `python --version`.
|
||||
3. To run the script, on Windows call `python build.py [args...]`; on Unix call `python3 build.py [args...]`, or simply `./build.py [args...]`. To see the built-in help message, call the script with `-h` as an argument. The `-h` option also works for each supported actions to see the help message for the specific action.
|
||||
4. By default, the script will build binaries and Magisk Manager in debug mode, which will enable verbose debugging messages. If you want to build Magisk Manager in release mode (through the flag `--release`), you will need to place your Java Keystore file in `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).
|
||||
5. 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 use an older Windows version, a quick Google search should provide many workarounds.
|
||||
|
||||
|
||||
## 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 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.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
@@ -39,14 +41,17 @@ 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`)
|
||||
**MagiskManager** (`java`)
|
||||
|
||||
* Copyright 2016-2017, John Wu (@topjohnwu)
|
||||
* All contributors and translators
|
||||
|
||||
**MagiskSU** (`jni/su`)
|
||||
|
||||
* Copyright 2016-2017, John Wu (@topjohnwu)
|
||||
* Copyright 2015, Pierre-Hugues Husson (phh@phh.me)
|
||||
* Copyright 2013, Koushik Dutta (@koush)
|
||||
@@ -54,25 +59,37 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* Copyright 2008, Zinx Verituse (@zinxv)
|
||||
|
||||
**MagiskPolicy** (`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)
|
||||
|
||||
**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
|
||||
* Maintained by many developers in SELinux project
|
||||
|
||||
**ndk-compression** (`jni/ndk-compression`)
|
||||
|
||||
* Makefile for NDK: Copyright 2017, John Wu (@topjohnwu)
|
||||
* Each library has its own copyright message in each directories
|
||||
* Each library has its own copyright message in corresponding directories
|
||||
|
||||
**ndk-busybox** (`jni/busybox`)
|
||||
|
||||
* Makefile for NDK, generated by [ndk-busybox-kitchen](https://github.com/topjohnwu/ndk-busybox-kitchen): Copyright 2017, John Wu (@topjohnwu)
|
||||
* Patches for NDK: Many contributors along the way, all placed in [osm0sis/android-busybox-ndk](https://github.com/osm0sis/android-busybox-ndk)
|
||||
* The copyright message for busybox should be included in its own directory
|
||||
|
||||
**Others Not Mentioned**
|
||||
|
||||
* Copyright 2016-2017, John Wu (@topjohnwu)
|
||||
|
||||
28
docs/README.MD
Normal file
28
docs/README.MD
Normal file
File diff suppressed because one or more lines are too long
166
docs/applets.md
Normal file
166
docs/applets.md
Normal file
File diff suppressed because one or more lines are too long
6
docs/changelog.md
Normal file
6
docs/changelog.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Changelog
|
||||
- 2017.8.16
|
||||
- Initial version for Magisk v13.5
|
||||
- 2017.9.28
|
||||
- Update applets info to Magisk v14.1
|
||||
- Add OTA tips
|
||||
60
docs/details.md
Normal file
60
docs/details.md
Normal file
File diff suppressed because one or more lines are too long
BIN
docs/images/disable_auto_ota.png
Normal file
BIN
docs/images/disable_auto_ota.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 245 KiB |
BIN
docs/images/flashfire.png
Normal file
BIN
docs/images/flashfire.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 224 KiB |
BIN
docs/images/install_second_slot.png
Normal file
BIN
docs/images/install_second_slot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 237 KiB |
BIN
docs/images/ota_step2.png
Normal file
BIN
docs/images/ota_step2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 176 KiB |
BIN
docs/images/repo_description.png
Normal file
BIN
docs/images/repo_description.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
BIN
docs/images/restore_boot.png
Normal file
BIN
docs/images/restore_boot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 258 KiB |
76
docs/module_repo.md
Normal file
76
docs/module_repo.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Magisk Modules and Online Repo
|
||||
## Magisk Module Format
|
||||
The Magisk module is a folder under `magisk`, which has a structure as described below:
|
||||
|
||||
```
|
||||
magisk
|
||||
├── .
|
||||
├── .
|
||||
├── a_module <--- The ID of the module, should match with module.prop
|
||||
│ ├── auto_mount <--- If this file exists, auto mount is enabled
|
||||
│ ├── disable <--- If this file exists, the module is disabled
|
||||
│ ├── module.prop <--- This files stores the indentity and properties of the module
|
||||
│ ├── post-fs-data.sh <--- This script will be executed in post-fs-data
|
||||
│ ├── remove <--- If this file exists, the module will be removed next reboot
|
||||
│ ├── service.sh <--- This script will be executed in late_start service
|
||||
│ ├── system.prop <--- This file will be loaded as system props
|
||||
│ ├── system <--- If auto mount is enabled, Magisk will "Magic Mount" this folder
|
||||
│ │ ├── app
|
||||
│ │ ├── .
|
||||
│ │ └── .
|
||||
│ ├── vendor <--- Auto generated. A symlink to $MODID/system/vendor
|
||||
│ ├── . <--- Any other files/folders are allowed
|
||||
│ └── .
|
||||
├── another_module
|
||||
│ ├── .
|
||||
│ └── .
|
||||
├── .
|
||||
├── .
|
||||
```
|
||||
|
||||
## Magisk Module Template
|
||||
The **Magisk Module Template** is hosted **[here](https://github.com/topjohnwu/magisk-module-template)**.
|
||||
|
||||
It is a template to create a flashable zip to install Magisk Modules. It is created to be simple to use so that anyone can create their own modules easily. The template itself contains minimal scripting for installation; most of the functions are located externally in [util_functions.sh](https://github.com/topjohnwu/Magisk/blob/master/scripts/util_functions.sh), which will be installed along with Magisk, and can be upgraded through a Magisk upgrade without the need of a template update.
|
||||
|
||||
The template should meet most modules' needs. Add files into `system`, which will be cloned into `/system` by Magisk after installing the module, and in addition to module files, `system.prop`, `post-fs-data.sh`, `service.sh` are also installable through this template.
|
||||
|
||||
Here are some files you would want to know:
|
||||
|
||||
- `config.sh`: A simple script used as a configuration file for the actual installation file to correctly install your module. It is the place you can select which features your module needs/disables.
|
||||
- `module.prop`: This file contains your module's indentity and properties, including name and versions etc.. This file will be used to identify your module on an actual device and in the [Magisk Modules Repo](https://github.com/Magisk-Modules-Repo)
|
||||
- `common/*`: These files will be installed to the module with the correspond role
|
||||
- `META-INF/com/google/android/update-binary`: The actual installation script. Modify this file for advanced custom behavior
|
||||
|
||||
## Create a Magisk Module With The Template
|
||||
1. Clone / download [this repo](https://github.com/topjohnwu/magisk-module-template)
|
||||
1. Open `config.sh` and carefully read the fully documented file. Follow the instructions within the script
|
||||
1. You should at least have `config.sh` and `module.prop` modified
|
||||
1. Directly zip all files; the result zip file is a flashable zip that can be used in both Magisk Manager and custom recoveries
|
||||
1. Please check [**Notes**](#notes) for several precautions
|
||||
|
||||
## Submit Your Module to Magisk Modules Repo
|
||||
If you want to share your module with others, you can submit your modules to [Magisk Modules Repo](https://github.com/Magisk-Modules-Repo). You would need some basic `git` knowledge here.
|
||||
|
||||
1. Create a module as stated above, and test if it works properly
|
||||
1. Fork [this repo](https://github.com/topjohnwu/magisk-module-template) to your account
|
||||
1. Commit and push your changes to your forked repo
|
||||
1. Open an issue in [topjohnwu/Magisk_Repo_Central](https://github.com/topjohnwu/Magisk_Repo_Central/issues/new) with your repo link
|
||||
1. I will review your module, and once accepted, your repo should be cloned into [Magisk-Modules-Repo](https://github.com/Magisk-Modules-Repo)
|
||||
1. You should receive an email to become the collaborator so you can edit the repo in the future.
|
||||
|
||||
#### Once your module is live on the Modules Repo, the description of your repo should be the ID of your module. Please do NOT change the description, repeat, do NOT change the description.
|
||||
|
||||

|
||||
|
||||
## Notes
|
||||
- The Module Template depends on external scripts, be aware of the minimal required Magisk version of the template.
|
||||
- **Windows users please check here!!** The line endings of all text files should be in the **Unix format**. Please use advanced text editors like Sublime, Atom, Notepad++ etc. to edit **ALL** text files, **NEVER** use Windows Notepad.
|
||||
- In `module.prop`, `version` can be an arbitrary string, so any fancy version name (e.g. ultra-beta-v1.1.1.1) is allowed. However, `versionCode` **MUST** be an integer. The value is used for version comparison.
|
||||
- Make sure your module ID **does not contain any spaces**.
|
||||
|
||||
## Notes For Repo Developers
|
||||
|
||||
- Magisk Manager monitors all repo's `master` branch. Any changes to the branch `master` will be reflected to all users immediately. If you are working on an update for a module, please work on another branch, make sure it works, then finally merge the changes back to `master`.
|
||||
- Once you finished upgrading your repo, increase at least the `versionCode` in `module.prop`. Magisk Manager uses this value to compare with the local installed module to determine whether an update is availible.
|
||||
- The description of your repo should be the same as your module ID. If you changed your description, Magisk Manager will fail to identify your repo, and cannot relate installed module to the online repo together.
|
||||
11
docs/procedures.html
Normal file
11
docs/procedures.html
Normal file
File diff suppressed because one or more lines are too long
53
docs/tips.md
Normal file
53
docs/tips.md
Normal file
File diff suppressed because one or more lines are too long
1
java
Submodule
1
java
Submodule
Submodule java added at 13bf1b27b4
124
jni/Android.mk
124
jni/Android.mk
@@ -1,29 +1,46 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
# Some handy paths
|
||||
JNI_ROOT := jni
|
||||
SELINUX_PATH := jni/external/selinux
|
||||
COMPRESS_LIB := jni/external/ndk-compression
|
||||
DTC_PATH := jni/external/dtc
|
||||
LIBSELINUX := $(SELINUX_PATH)/libselinux/include
|
||||
LIBSEPOL := $(SELINUX_PATH)/libsepol/include $(SELINUX_PATH)/libsepol/cil/include
|
||||
LIBZ := $(COMPRESS_LIB)/zlib
|
||||
LIBLZMA := $(COMPRESS_LIB)/xz/src/liblzma/api
|
||||
LIBLZ4 := $(COMPRESS_LIB)/lz4/lib
|
||||
LIBBZ2 := $(COMPRESS_LIB)/bzip2
|
||||
LIBFDT := $(DTC_PATH)/libfdt
|
||||
|
||||
########################
|
||||
# Binaries
|
||||
########################
|
||||
|
||||
# magisk main binary
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := magisk
|
||||
LOCAL_STATIC_LIBRARIES := libsepol
|
||||
LOCAL_SHARED_LIBRARIES := libsqlite libselinux
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/utils \
|
||||
$(LOCAL_PATH)/daemon \
|
||||
$(LOCAL_PATH)/resetprop \
|
||||
$(LOCAL_PATH)/magiskpolicy \
|
||||
$(LOCAL_PATH)/external \
|
||||
$(LOCAL_PATH)/selinux/libsepol/include
|
||||
jni/include \
|
||||
jni/external \
|
||||
$(LIBSELINUX) \
|
||||
$(LIBSEPOL)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
main.c \
|
||||
daemon/magisk.c \
|
||||
daemon/daemon.c \
|
||||
daemon/socket_trans.c \
|
||||
daemon/log_monitor.c \
|
||||
daemon/bootstages.c \
|
||||
utils/misc.c \
|
||||
utils/vector.c \
|
||||
utils/xwrap.c \
|
||||
utils/list.c \
|
||||
utils/img.c \
|
||||
daemon/daemon.c \
|
||||
daemon/socket_trans.c \
|
||||
daemon/log_monitor.c \
|
||||
daemon/bootstages.c \
|
||||
utils/file.c \
|
||||
magiskhide/magiskhide.c \
|
||||
magiskhide/proc_monitor.c \
|
||||
magiskhide/hide_utils.c \
|
||||
@@ -36,29 +53,78 @@ LOCAL_SRC_FILES := \
|
||||
su/su.c \
|
||||
su/activity.c \
|
||||
su/db.c \
|
||||
su/misc.c \
|
||||
su/pts.c \
|
||||
su/su_daemon.c \
|
||||
su/su_socket.c
|
||||
|
||||
LOCAL_CFLAGS := -Wno-implicit-exception-spec-mismatch
|
||||
LOCAL_CFLAGS := -Wno-implicit-exception-spec-mismatch -DIS_DAEMON
|
||||
LOCAL_CPPFLAGS := -std=c++11
|
||||
LOCAL_LDLIBS := -llog
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
# External shared libraries, build stub libraries for linking
|
||||
# magiskboot
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := magiskboot
|
||||
LOCAL_STATIC_LIBRARIES := libz liblzma liblz4 libbz2 libfdt
|
||||
LOCAL_C_INCLUDES := \
|
||||
jni/include \
|
||||
$(LIBZ) \
|
||||
$(LIBLZMA) \
|
||||
$(LIBLZ4) \
|
||||
$(LIBBZ2) \
|
||||
$(LIBFDT)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
magiskboot/main.c \
|
||||
magiskboot/bootimg.c \
|
||||
magiskboot/hexpatch.c \
|
||||
magiskboot/compress.c \
|
||||
magiskboot/boot_utils.c \
|
||||
magiskboot/cpio.c \
|
||||
magiskboot/sha1.c \
|
||||
magiskboot/types.c \
|
||||
magiskboot/dtb.c \
|
||||
utils/xwrap.c \
|
||||
utils/vector.c
|
||||
LOCAL_CFLAGS := -DZLIB_CONST
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
# magiskinit
|
||||
ifeq ($(TARGET_ARCH_ABI), arm64-v8a)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := magiskinit
|
||||
LOCAL_STATIC_LIBRARIES := libsepol
|
||||
LOCAL_C_INCLUDES := jni/include $(LIBSEPOL)
|
||||
LOCAL_SRC_FILES := \
|
||||
magiskinit.c \
|
||||
magiskboot/boot_utils.c \
|
||||
utils/file.c \
|
||||
utils/xwrap.c \
|
||||
magiskpolicy/rules.c \
|
||||
magiskpolicy/sepolicy.c \
|
||||
magiskpolicy/api.c
|
||||
LOCAL_CFLAGS := -DNO_SELINUX
|
||||
LOCAL_LDFLAGS := -static
|
||||
include $(BUILD_EXECUTABLE)
|
||||
endif
|
||||
|
||||
# 32-bit static 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
|
||||
|
||||
########################
|
||||
# Externals
|
||||
########################
|
||||
include jni/external/Android.mk
|
||||
|
||||
# libsepol, static library
|
||||
include jni/selinux/libsepol/Android.mk
|
||||
|
||||
#####################################################################
|
||||
# In order to build separate binaries, please comment out everything
|
||||
# above (including the lines for libraries)
|
||||
# Then, uncomment the line you want below
|
||||
#####################################################################
|
||||
# include jni/resetprop/Android.mk
|
||||
# include jni/magiskpolicy/Android.mk
|
||||
|
||||
# Build magiskboot
|
||||
include jni/magiskboot/Android.mk
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
APP_ABI := x86 x86_64 armeabi-v7a arm64-v8a
|
||||
APP_PLATFORM := android-21
|
||||
APP_UNIFIED_HEADERS := true
|
||||
APP_CPPFLAGS += -std=c++11
|
||||
|
||||
83
jni/b64xz.c
Normal file
83
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
@@ -21,13 +21,12 @@
|
||||
#include "utils.h"
|
||||
#include "daemon.h"
|
||||
#include "magiskpolicy.h"
|
||||
#include "resetprop.h"
|
||||
|
||||
pthread_t sepol_patch;
|
||||
int is_restart = 0;
|
||||
|
||||
static void *request_handler(void *args) {
|
||||
// Setup the default error handler for threads
|
||||
err_handler = exit_thread;
|
||||
|
||||
int client = *((int *) args);
|
||||
free(args);
|
||||
client_request req = read_int(client);
|
||||
@@ -40,6 +39,7 @@ static void *request_handler(void *args) {
|
||||
case STOP_MAGISKHIDE:
|
||||
case ADD_HIDELIST:
|
||||
case RM_HIDELIST:
|
||||
case LS_HIDELIST:
|
||||
case POST_FS:
|
||||
case POST_FS_DATA:
|
||||
case LATE_START:
|
||||
@@ -65,6 +65,9 @@ static void *request_handler(void *args) {
|
||||
case RM_HIDELIST:
|
||||
rm_hide_list(client);
|
||||
break;
|
||||
case LS_HIDELIST:
|
||||
ls_hide_list(client);
|
||||
break;
|
||||
case SUPERUSER:
|
||||
su_daemon_receiver(client);
|
||||
break;
|
||||
@@ -96,7 +99,7 @@ static 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, REQUESTOR_DAEMON_PATH_LEN);
|
||||
memcpy(sun->sun_path, REQUESTOR_DAEMON_PATH, sizeof(REQUESTOR_DAEMON_PATH) - 1);
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -110,27 +113,24 @@ static void *large_sepol_patch(void *args) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void start_daemon(int client) {
|
||||
// Launch the daemon, create new session, set proper context
|
||||
if (getuid() != UID_ROOT || getgid() != UID_ROOT) {
|
||||
fprintf(stderr, "Starting daemon requires root: %s\n", strerror(errno));
|
||||
PLOGE("start daemon");
|
||||
}
|
||||
static void *start_magisk_hide(void *args) {
|
||||
launch_magiskhide(-1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
PLOGE("fork");
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
void auto_start_magiskhide() {
|
||||
char *hide_prop = getprop2(MAGISKHIDE_PROP, 1);
|
||||
if (hide_prop == NULL || strcmp(hide_prop, "0") != 0) {
|
||||
pthread_t thread;
|
||||
xpthread_create(&thread, NULL, start_magisk_hide, NULL);
|
||||
pthread_detach(thread);
|
||||
}
|
||||
free(hide_prop);
|
||||
}
|
||||
|
||||
// First close the client, it's useless for us
|
||||
close(client);
|
||||
xsetsid();
|
||||
void start_daemon() {
|
||||
setcon("u:r:su:s0");
|
||||
umask(022);
|
||||
umask(0);
|
||||
int fd = xopen("/dev/null", O_RDWR | O_CLOEXEC);
|
||||
xdup2(fd, STDIN_FILENO);
|
||||
xdup2(fd, STDOUT_FILENO);
|
||||
@@ -142,33 +142,36 @@ void start_daemon(int client) {
|
||||
sepol_med_rules();
|
||||
dump_policydb(SELINUX_LOAD);
|
||||
|
||||
// Continue the larger patch in another thread, we will join later
|
||||
pthread_create(&sepol_patch, NULL, large_sepol_patch, NULL);
|
||||
|
||||
struct sockaddr_un sun;
|
||||
fd = setup_socket(&sun);
|
||||
|
||||
xbind(fd, (struct sockaddr*) &sun, sizeof(sun));
|
||||
if (xbind(fd, (struct sockaddr*) &sun, sizeof(sun)) == -1)
|
||||
exit(1);
|
||||
xlisten(fd, 10);
|
||||
|
||||
if ((is_restart = access(UNBLOCKFILE, F_OK) == 0)) {
|
||||
// Restart stuffs if the daemon is restarted
|
||||
exec_command_sync("logcat", "-b", "all", "-c", NULL);
|
||||
auto_start_magiskhide();
|
||||
start_debug_log();
|
||||
}
|
||||
|
||||
// Start the log monitor
|
||||
monitor_logs();
|
||||
|
||||
// Continue the larger patch in another thread, we will join later
|
||||
xpthread_create(&sepol_patch, NULL, large_sepol_patch, NULL);
|
||||
|
||||
LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n");
|
||||
|
||||
// Change process name
|
||||
strcpy(argv0, "magisk_daemon");
|
||||
// The root daemon should not do anything if an error occurs
|
||||
// It should stay intact under any circumstances
|
||||
err_handler = do_nothing;
|
||||
|
||||
LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n");
|
||||
|
||||
// Unlock all blocks for rw
|
||||
unlock_blocks();
|
||||
|
||||
// Setup links under /sbin
|
||||
xmount(NULL, "/", NULL, MS_REMOUNT, NULL);
|
||||
create_links(NULL, "/sbin");
|
||||
xchmod("/sbin", 0755);
|
||||
xmkdir("/magisk", 0755);
|
||||
xchmod("/magisk", 0755);
|
||||
xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
|
||||
// Notifiy init the daemon is started
|
||||
close(xopen(UNBLOCKFILE, O_RDONLY | O_CREAT));
|
||||
|
||||
// Loop forever to listen for requests
|
||||
while(1) {
|
||||
@@ -185,12 +188,21 @@ void start_daemon(int client) {
|
||||
int connect_daemon() {
|
||||
struct sockaddr_un sun;
|
||||
int fd = setup_socket(&sun);
|
||||
if (connect(fd, (struct sockaddr*) &sun, sizeof(sun))) {
|
||||
/* If we cannot access the daemon, we start the daemon
|
||||
* since there is no clear entry point when the daemon should be started
|
||||
*/
|
||||
LOGD("client: connect fail, try launching new daemon process\n");
|
||||
start_daemon(fd);
|
||||
if (xconnect(fd, (struct sockaddr*) &sun, sizeof(sun))) {
|
||||
// If we cannot access the daemon, we start a daemon in the child process if possible
|
||||
|
||||
if (getuid() != UID_ROOT || getgid() != UID_ROOT) {
|
||||
fprintf(stderr, "No daemon is currently running!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (xfork() == 0) {
|
||||
LOGD("client: connect fail, try launching new daemon process\n");
|
||||
close(fd);
|
||||
xsetsid();
|
||||
start_daemon();
|
||||
}
|
||||
|
||||
do {
|
||||
// Wait for 10ms
|
||||
usleep(10);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* log_monitor.c - New thread to monitor logcat
|
||||
*
|
||||
* Open a new thread to call logcat and get logs with tag "Magisk"
|
||||
* Also, write the logs to a log file for debugging purpose
|
||||
*
|
||||
* 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>
|
||||
@@ -13,34 +13,146 @@
|
||||
|
||||
#include "magisk.h"
|
||||
#include "utils.h"
|
||||
#include "daemon.h"
|
||||
|
||||
int logcat_events[] = { -1, -1, -1 };
|
||||
extern int is_restart;
|
||||
|
||||
#ifdef MAGISK_DEBUG
|
||||
static int debug_log_pid, debug_log_fd;
|
||||
#endif
|
||||
|
||||
static void *logger_thread(void *args) {
|
||||
// Setup error handler
|
||||
err_handler = exit_thread;
|
||||
int log_fd = -1, log_pid;
|
||||
char line[4096];
|
||||
|
||||
rename(LOGFILE, LASTLOG);
|
||||
int log_fd, log_pid;
|
||||
|
||||
log_fd = xopen(LOGFILE, O_WRONLY | O_CREAT | O_CLOEXEC | O_TRUNC, 0644);
|
||||
LOGD("log_monitor: logger start");
|
||||
|
||||
while (1) {
|
||||
// Start logcat
|
||||
char *const command[] = { "logcat", "-s", "Magisk", "-v", "thread", NULL };
|
||||
log_pid = run_command(0, &log_fd, "/system/bin/logcat", command);
|
||||
if (log_pid > 0)
|
||||
waitpid(log_pid, NULL, 0);
|
||||
// For some reason it went here, clear buffer and restart
|
||||
system("logcat -c");
|
||||
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(logcat_events) / sizeof(int)); ++i) {
|
||||
if (logcat_events[i] > 0) {
|
||||
char *s = strdup(line);
|
||||
xwrite(logcat_events[i], &s, sizeof(s));
|
||||
}
|
||||
}
|
||||
if (kill(log_pid, 0))
|
||||
break;
|
||||
}
|
||||
// Clear buffer if restart required
|
||||
exec_command_sync("logcat", "-b", "all", "-c", NULL);
|
||||
}
|
||||
|
||||
// Should never be here, but well...
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Start a new thread to monitor logcat and dump to logfile */
|
||||
static void *magisk_log_thread(void *args) {
|
||||
int have_data = 0;
|
||||
|
||||
// Temp buffer for logs before we have data access
|
||||
struct vector logs;
|
||||
vec_init(&logs);
|
||||
|
||||
FILE *log;
|
||||
int pipefd[2];
|
||||
if (xpipe2(pipefd, O_CLOEXEC) == -1)
|
||||
return NULL;
|
||||
|
||||
// Register our listener
|
||||
logcat_events[LOG_EVENT] = pipefd[1];
|
||||
|
||||
LOGD("log_monitor: magisk log dumper start");
|
||||
|
||||
for (char *line; xxread(pipefd[0], &line, sizeof(line)) > 0; free(line)) {
|
||||
char *ss;
|
||||
if ((ss = strstr(line, " Magisk")) && (ss[-1] != 'D') && (ss[-1] != 'V')) {
|
||||
if (!have_data) {
|
||||
if ((have_data = check_data())) {
|
||||
// Dump buffered logs to file
|
||||
if (!is_restart)
|
||||
rename(LOGFILE, LASTLOG);
|
||||
log = xfopen(LOGFILE, "a");
|
||||
setbuf(log, NULL);
|
||||
char *tmp;
|
||||
vec_for_each(&logs, tmp) {
|
||||
fprintf(log, "%s", tmp);
|
||||
free(tmp);
|
||||
}
|
||||
vec_destroy(&logs);
|
||||
} else {
|
||||
vec_push_back(&logs, strdup(line));
|
||||
}
|
||||
}
|
||||
if (have_data)
|
||||
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
|
||||
logcat_events[DEBUG_EVENT] = pipefd[1];
|
||||
|
||||
for (char *line; xxread(pipefd[0], &line, sizeof(line)) > 0; free(line)) {
|
||||
char *ss;
|
||||
if ((ss = strstr(line, "Magisk")))
|
||||
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);
|
||||
pthread_t thread;
|
||||
// Start debug thread
|
||||
xpthread_create(&thread, NULL, debug_magisk_log_thread, NULL);
|
||||
pthread_detach(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,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "magisk.h"
|
||||
@@ -11,57 +12,62 @@
|
||||
char *argv0;
|
||||
|
||||
char *applet[] =
|
||||
{ "su", "resetprop", "magiskpolicy", "supolicy", "sepolicy-inject", "magiskhide", NULL };
|
||||
{ "su", "resetprop", "magiskpolicy", "supolicy", "magiskhide", NULL };
|
||||
|
||||
int (*applet_main[]) (int, char *[]) =
|
||||
{ su_client_main, resetprop_main, magiskpolicy_main, magiskpolicy_main, magiskpolicy_main, magiskhide_main, NULL };
|
||||
{ su_client_main, resetprop_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 availible 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"
|
||||
"\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];
|
||||
@@ -132,6 +138,15 @@ 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], "--daemon") == 0) {
|
||||
// Start daemon, this process won't return
|
||||
start_daemon();
|
||||
} else if (strcmp(argv[1], "--post-fs") == 0) {
|
||||
int fd = connect_daemon();
|
||||
write_int(fd, POST_FS);
|
||||
31
jni/external/Android.mk
vendored
31
jni/external/Android.mk
vendored
@@ -1,13 +1,40 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
EXTERNAL := $(LOCAL_PATH)
|
||||
|
||||
# libsqlite.so (stub)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:= libsqlite
|
||||
LOCAL_SRC_FILES := sqlite3_stub.c
|
||||
LOCAL_SRC_FILES := stubs/sqlite3_stub.c
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
# libselinux.so (stub)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE:= libselinux
|
||||
LOCAL_SRC_FILES := selinux_stub.c
|
||||
LOCAL_C_INCLUDES := $(LIBSELINUX)
|
||||
LOCAL_SRC_FILES := stubs/selinux_stub.c
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
# libfdt
|
||||
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)
|
||||
|
||||
# libsepol, static library
|
||||
include $(SELINUX_PATH)/libsepol/Android.mk
|
||||
|
||||
# Compression libraries for magiskboot
|
||||
include $(COMPRESS_LIB)/zlib/Android.mk
|
||||
include $(COMPRESS_LIB)/xz/src/liblzma/Android.mk
|
||||
include $(COMPRESS_LIB)/lz4/lib/Android.mk
|
||||
include $(COMPRESS_LIB)/bzip2/Android.mk
|
||||
|
||||
1
jni/external/busybox
vendored
Submodule
1
jni/external/busybox
vendored
Submodule
Submodule jni/external/busybox added at 90c9c4fd96
1
jni/external/dtc
vendored
Submodule
1
jni/external/dtc
vendored
Submodule
Submodule jni/external/dtc added at fe50bd1ecc
1
jni/external/ndk-compression
vendored
Submodule
1
jni/external/ndk-compression
vendored
Submodule
Submodule jni/external/ndk-compression added at b5cefe452b
1
jni/external/selinux
vendored
Submodule
1
jni/external/selinux
vendored
Submodule
Submodule jni/external/selinux added at 2fefdfc40f
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user