The Magic Mask for Android
Go to file
topjohnwu a1ce6f5f12 Fix race condition when switching root manager
Before this change, the root manager package name is only written into
the database after the repackaged APK is installed. In the time between
the repackaged APK being installed and the package name being written
into the database, if some operation calls `get_manager`, the Magisk
daemon will cache this result and ignore the repackaged APK, even if
the package name is set afterwards, because the cache won't be
invalidated. The result is that the repackaged manager APK will not be
recognized as the root manager, breaking the hide manager feature.

This race condition is more likely to happen when Zygisk is enabled,
because `get_manager` is called with a very high frequency in that case.

To fix the issue, we have to set the new package name into the database
BEFORE installing the repackaged APK. We also stop pruning the
database if the repackaged manager is not found, moving this logic into
the Magisk app. By doing so, we can guarantee that the instant after
the repackaged manager APK is installed, the Magisk daemon will
immediately pick it up and treat it as the root manager.

Another small optimization: when the requester is root, simply bypass
the whole database + manager package check. Since the Magisk app hiding
APK installation proces will call `su` several times to run `pm` under
different UIDs, doing this opimization will reduce the amount of
unnecessary database query + filesystem traversals.
2023-03-06 03:58:58 -08:00
.github CI uses java 17 2022-12-13 14:13:25 -08:00
app Fix race condition when switching root manager 2023-03-06 03:58:58 -08:00
buildSrc Fix gradle cache 2023-03-03 02:39:22 -08:00
docs Update ota.md (#6374) 2023-03-02 02:23:19 -08:00
gradle/wrapper Upgrade gradle 2023-02-20 00:08:23 -08:00
native Fix race condition when switching root manager 2023-03-06 03:58:58 -08:00
scripts Skip copy old rule 2023-03-02 02:05:38 -08:00
stub Build script adjustments 2023-03-02 20:32:46 -08:00
tools Set version comment in apk 2022-06-17 11:53:16 -07:00
.gitattributes Small native code reorganization 2020-03-09 01:50:30 -07:00
.gitignore Open source fully obfuscated stub 2021-09-02 21:31:33 -07:00
.gitmodules Add inode plt hook APIs 2023-01-10 02:42:45 +08:00
build.gradle.kts Move config to buildSrc 2021-09-09 01:37:20 -07:00
build.py Fix build script 2023-03-02 03:02:10 -08:00
config.prop.sample Cleanup scripts 2021-01-24 07:24:13 -08:00
gradle.properties Release new canary build 2023-03-02 21:35:14 -08:00
gradlew Upgrade gradle 2023-02-20 00:08:23 -08:00
gradlew.bat Update deps 2022-12-26 17:16:26 -08:00
LICENSE Use GPL v3 license and update copyright messages 2017-04-22 17:12:54 +08:00
README.MD Remove obsolete link 2023-02-20 17:25:32 -08:00
settings.gradle.kts Move config to buildSrc 2021-09-09 01:37:20 -07:00

Downloads

This is not an officially supported Google product

Introduction

Magisk is a suite of open source software for customizing Android, supporting devices higher than Android 5.0.
Some highlight features:

  • MagiskSU: Provide root access for applications
  • Magisk Modules: Modify read-only partitions by installing modules
  • MagiskBoot: The most complete tool for unpacking and repacking Android boot images
  • Zygisk: Run code in every Android applications' processes

Downloads

Github is the only source where you can get official Magisk information and downloads.

Bug Reports

Only bug reports from Debug builds will be accepted.

For installation issues, upload both boot image and install logs.
For Magisk issues, upload boot logcat or dmesg.
For Magisk app crashes, record and upload the logcat when the crash occurs.

Building and Development

  • Magisk builds on any OS Android Studio supports. Install Android Studio and do the initial setups.
  • Clone sources: git clone --recurse-submodules https://github.com/topjohnwu/Magisk.git
  • Install Python 3.8+
    (Windows only: select 'Add Python to PATH' in installer, and run pip install colorama after install)
  • Configure to use the JDK bundled in Android Studio:
    • macOS: export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
    • Linux: export PATH="/path/to/androidstudio/jre/bin:$PATH"
    • Windows: Add C:\Path\To\Android Studio\jre\bin to environment variable PATH
  • Set environment variable ANDROID_SDK_ROOT to the Android SDK folder (can be found in Android Studio settings)
  • Run ./build.py ndk to let the script download and install NDK for you
  • To start building, run build.py to see your options.
    For each action, use -h to access help (e.g. ./build.py all -h)
  • To start development, open the project with Android Studio. The IDE can be used for both app (Kotlin/Java) and native sources.
  • Optionally, set custom configs with config.prop. A sample config.prop.sample is provided.

Signing and Distribution

  • The certificate of the key used to sign the final Magisk APK product is also directly embedded into some executables. In release builds, Magisk's root daemon will enforce this certificate check and reject and forcefully uninstall any non-matching Magisk apps to protect users from malicious and unverified Magisk APKs.
  • To do any development on Magisk itself, switch to an official debug build and reinstall Magisk to bypass the signature check.
  • To distribute your own Magisk builds signed with your own keys, set your signing configs in config.prop.
  • Check Google's Documentation for more details on generating your own key.

Translation Contributions

Default string resources for the Magisk app and its stub APK are located here:

  • app/src/main/res/values/strings.xml
  • stub/src/main/res/values/strings.xml

Translate each and place them in the respective locations ([module]/src/main/res/values-[lang]/strings.xml).

License

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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
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/>.