Commit Graph
890 Commits
Author SHA1 Message Date
xAstroBoy 8903cf7f22 zygisk: make built-in Zygisk work on Meta Quest (lazy per-trust partition zygotes)
Meta Quest (Horizon OS) does not start the zygote the normal way: ro.zygote=
zygote64_stub32 launches /system/bin/stub_zygote, which forks a separate
app_process64 zygote PER security partition (system/trusted vs untrusted-app),
driven by hzos_security_zygote_partitioning_policy. The untrusted-app partition
zygote -- the one that forks 3rd-party apps and the Magisk manager -- is spawned
LAZILY, after boot-complete.

magiskd sets ro.dalvik.vm.native.bridge=libzygisk.so during boot but clears it
again at boot-complete (ZygiskState::reset). On a normal device every zygote has
already started by then, so clearing it is harmless. On Quest the untrusted-app
partition zygote reads the (now cleared) property when it finally execve's
app_process64, never loads libzygisk.so, so 3rd-party apps + the Magisk manager
are never injected -> "Zygisk: N/A".

Fix (daemon.rs): on the boot-complete reset(restore=true) path, reset the crash
counter but KEEP native.bridge set (set_prop) instead of clearing it
(restore_prop); only the >3-crash rollback path still clears. The lazily-spawned
partition zygotes then load the loader when they start.

Also (hook.cpp), robustness fixes the loader needs on this device:
 - Wrap hook_zygote_jni()'s JNI locals in PushLocalFrame(64)/PopLocalFrame so
   leaking locals can't trip ART's "non-empty local reference table" abort, and
   bail if GetEnv returns no env.
 - Make the strdup(ZygoteInit) trigger a substring match + add an idempotency
   guard so the zygote hooks install exactly once per process.

Verified on Quest 3 (Android 14): system_server + every app fork is intercepted
and LSPosed loads end-to-end.
2026-08-27 05:38:45 +00:00
Wang Han 5a28d2fcfc Backup original sepolicy db for LD_PRELOAD strategy 2026-08-27 05:38:01 +00:00
Bela Schaum 3c411abc34 Fix slice copy range for 'want' in dtb.rs 2026-08-25 21:09:16 +00:00
topjohnwu 15062974a3 magiskboot: allow free zImage piggy payload size
Support dynamic zImage piggy payload sizes during repacking by updating
the zImage decompressor stub headers, symbol tables, and GOT entries.

Previously, magiskboot padded repacked zImage files to preserve the
exact original file size. For non-gzip compressed zImages (such as XZ),
repacking with a different payload size broke stub symbol resolution
and resulted in ununpackable or unbootable images.

Key changes:
- Encapsulate zImage parsing and patching in a dedicated struct ZImage
  in Rust with CXX FFI, new_head, and new_tail methods.
- Locate piggy_end using table references or GOT table entries bounded
  by LC0.
- Relocate LC0 table entries, LC1 table, and GOT table entries with
  4-byte padding/alignment when payload size changes.
- Relocate R_ARM_GOTPC PC-relative literal pools in decompressor .text.
- Append uncompressed size for non-gzip algorithms per size_append.
- Remove zopfli compression support across magiskboot as dynamic zImage
  piggy sizing supersedes the need for exact size matching.

Fix #9880

Assisted-by: Gemini 3.7 Flash
2026-08-25 19:09:29 +00:00
topjohnwu de60431a0d magiskboot: port find_dtb_offset to Rust
Port find_dtb_offset from C++ to Rust in dtb.rs, using the fdt crate
for header parsing and root node validation.

Key changes:
- Upgrade fdt crate to 0.2.0-alpha2 and adapt dtb.rs to updated APIs.
- Implement find_dtb_offset using Fdt::new_unaligned_fallible.
- Define MIN_NON_EMPTY_DTB_SIZE (0x48) per Linux kernel ARM zImage
  specification to ignore empty or false positive DTB headers.
- Expose find_dtb_offset to C++ via CXX bridge and clean up legacy
  structs and declarations.

Assisted-by: Gemini 3.7 Flash
2026-08-25 19:09:29 +00:00
topjohnwu c02705d969 magiskboot: migrate check_fmt to Rust
Migrate check_fmt and guess_lzma to Rust in format.rs.

Assisted-by: Gemini 3.6 Flash
2026-08-25 19:09:29 +00:00
Michael Jauregui a19666d884 magiskboot: Lower the compression presets for XZ & LZMA
magiskboot: Lower the compression presets for XZ & LZMA

The compression routine always uses the maximum compression preset for all formats.
This is problematic with XZ and LZMA because they use far more memory than the other formats, while just providing a very marginal advantage in the resulting file size.
The compression preset was changed from 9 to 6, which is often the default value and provides more than enough compression.
Tested on Samsung Galaxy Fame (512MB RAM, perfect for this).
2026-08-23 21:46:25 +00:00
lsx 0675a18a3a init: check charger mode before force_normal_boot
b55f597c ("Skip loading magisk in charger mode") aborts when
androidboot.mode=charger, but the check sits after the force_normal_boot
branch. Devices that set androidboot.force_normal_boot=1 during off-mode
charging (e.g. some Motorola models) take force_normal_boot -> first_stage()
and never reach the charger check, so Magisk still loads in charger mode and
bumps the never-reset bootloop counter until safe mode trips.

Move the charger check ahead of skip_initramfs/force_normal_boot so charger
boots abort regardless, matching AOSP treating charger mode first.

Fixes #9967.
2026-08-18 18:38:55 +00:00
topjohnwu 3bdffe695d Generate shorty in comments and reorder jni_hooks 2026-08-12 23:49:37 +00:00
Wang Han 65aa82516f Update jni hook signatures for A17 QPR2 2026-08-11 20:14:03 -07:00
Bela Schaum 72dfc7b9a8 Update condition to check for newline and comma 2026-08-05 11:17:01 -07:00
kousuandClaude Sonnet 4.6 d9a9b02c27 Update AVB hash header image_size to match unpacked original_image_size.
Fixes https://github.com/topjohnwu/Magisk/issues/8389

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-08-05 10:32:24 -07:00
Wang Han 2c98b6ccf2 Update resetprop to support --compact 2026-08-04 12:07:38 -07:00
topjohnwu 0b0ee5611e Update libcxx 2026-08-03 19:22:52 -07:00
topjohnwu fd0cb66b6b Cargo fmt 2026-07-31 22:57:41 -07:00
topjohnwu a581038608 Update cargo dependencies 2026-07-31 22:57:41 -07:00
topjohnwu bffc9108bc Address new clippy warnings 2026-07-31 22:57:41 -07:00
topjohnwu d04635478a Fix clippy warnings across native codebase
Address clippy warnings including collapsible match statements in
bootstages, daemon, su daemon, and db modules, as well as iterator
loops in files.rs.

Assisted-by: Gemini 3.6 Flash
2026-07-31 22:57:41 -07:00
topjohnwu 05099cce89 sepolicy: use pure token-based xperm parsing
Update extract_token to only split hyphens when preceding a valid
hex xperm. Revert parse_xperm and parse_xperms to pure token-based
AST parsing without inspecting ID strings.

Assisted-by: Gemini 3.6 Flash
2026-07-31 22:57:41 -07:00
topjohnwu 9d4befe06d sepolicy: add unit tests for statement parsing
Add unit tests covering all PolicyStatement variants, brace set
expansion, xperm ranges/complements, spacing corner cases, and error
cases.

Assisted-by: Gemini 3.6 Flash
2026-07-31 22:57:41 -07:00
topjohnwu 896b78cdd5 sepolicy: parse statements into PolicyStatement enum
Parse tokens into intermediate PolicyStatement enums with meaningful
field names before executing them on SePolicy.

Assisted-by: Gemini 3.6 Flash
2026-07-31 22:57:41 -07:00
Wang Han 1b9f69b4b8 Update zygisk sepolicy for A17 QPR1 Beta 4
Mainline kernel starts to use dedicated memfd_file type for memfd,
which makes zygote cannot open memfd created by magiskd.
2026-07-27 18:49:19 -07:00
Wang Han 14ea5cfb4a Fix sepolicy parsing for hyphenated identifiers 2026-05-05 02:15:16 +08:00
topjohnwu 9d0b5298af Update to ONDK r30.0 2026-04-20 01:36:36 -07:00
topjohnwu 2f4bb0149e Update cargo dependencies 2026-04-08 05:29:57 +00:00
topjohnwu 74ead75ce8 Update cargo dependencies 2026-02-22 14:39:46 -08:00
Wang Han ee25db0627 Add jni hooks signature for nubia 2026-02-22 13:20:08 -08:00
topjohnwu 9ee6a6b3d7 Update to ONDK r29.5 2026-02-06 16:32:25 -08:00
Wang Han e872fafd8b Update getModuleDir() API doc 2026-02-05 13:12:34 -08:00
topjohnwu dd3798905f Update libsepol to upstream Android 16 QPR2 2026-02-05 12:51:21 -08:00
Ephemera42 0d39b10889 Optimize preinit finding and add klogdump partition
* Use major number check to filter out device-mapper devices while preserving virtio-blk compatibility.
* Introduce `klogdump` partition support for Smartisan devices as a valid preinit target.
2026-02-04 21:10:25 -08:00
vvb2060 628b4d4715 Allow reacquiring capabilities if not explicitly cleared
- Old behavior: Switching to a non-zero UID was implicitly interpreted as a request to drop capabilities, thereby preventing subsequent reacquisition  via `su`.
- New behavior: Switching to a non-zero UID now requires the `--drop-cap` argument to explicitly prevent the reacquisition of capabilities.
2026-02-04 11:35:24 -08:00
LoveSy be5246aef5 Reorder positional arguments in Backup and Remove 2026-02-04 11:35:12 -08:00
LoveSy b55f597ccf Skip loading magisk in charger mode 2026-02-03 15:55:53 -08:00
Wang Han e729eec636 Remove unnecessary file system permissions
Removed permissions for mounting loop devices, mirrors, and tmpfs.
2026-02-02 11:15:33 -08:00
LoveSy 5f13a8f8f7 support sony's init.real 2026-01-31 13:54:34 -08:00
canyie ac8d4200e1 Add nativeSpecializeAppProcess signature for XR devices running 14
Build fingerprint: google/gms_sdk_xr64_x86_64/emulator64_x86_64:14/UP1A.231005.007.A1/13953962:userdebug/test-keys
2026-01-31 13:51:41 -08:00
Wang Han e590ffbdcb Fix formatting and update comments in bootimg.cpp 2026-01-31 13:50:36 -08:00
Wang Han 97138f1e91 magiskboot: Fix tail offset calculation 2026-01-31 13:50:36 -08:00
LoveSy bea50fafba Fix magiskboot cpio ls -r 2026-01-31 13:50:13 -08:00
Pzqqt 0919db6b11 magiskboot: Avoid implicit type conversion
Fix #9607
2026-01-19 23:33:00 +08:00
topjohnwu 01cb75eaef Code cleanup 2025-12-13 22:12:30 -08:00
topjohnwu 33eaa7c5eb Update cargo dependencies 2025-12-12 11:42:45 -08:00
topjohnwu 8734423cb0 Update to ONDK r29.4 2025-12-12 11:42:45 -08:00
topjohnwu ff4ca74cfe Ban all unwrap usage in codebase 2025-12-08 23:31:04 -08:00
topjohnwu 200665c48a Make jni_hooks.hpp a normal C++ header
[skip ci]
2025-12-07 02:44:19 -08:00
topjohnwu dd42aa99ea Refactor gen_jni_hooks.py
[skip ci]
2025-12-07 02:25:50 -08:00
Wang Han 0936cdb192 Update nativeForkAndSpecialize signature for A16 QPR2
https://android.googlesource.com/platform/frameworks/base.git/+/67a4b1b2fee385f798d75ad02d016b80fc79f075
2025-12-07 00:18:50 -08:00
topjohnwu a510554b21 Disable Zygisk upon incomplete JNI hook
Do not enable Zygisk unless ALL replacements are hooked properly.
This allow Zygisk tests to fail when new signature is introduced.
2025-12-07 00:18:50 -08:00
南宫雪珊 b5138a4af0 Update unpack boot image help message 2025-12-05 11:14:45 -08:00