Commit Graph

1596 Commits

Author SHA1 Message Date
topjohnwu
e13775ec2c Directly use memmem in contains 2023-06-07 16:52:52 -07:00
topjohnwu
ee4dad7a13 Bridge C++ bytes with Rust &[u8] 2023-06-07 16:49:40 -07:00
topjohnwu
5e2ef1b7f4 Better bytes support in C++ 2023-06-06 17:11:42 -07:00
topjohnwu
305e8b3d14 Improve bootimg const correctness 2023-06-03 05:10:22 -07:00
topjohnwu
2a654e5d7f Improve byte_data const correctness 2023-06-03 03:16:03 -07:00
topjohnwu
57afae3425 Cleanup cpio codebase 2023-06-03 00:31:20 -07:00
topjohnwu
feb44f875e Migrate PREINITDEVICE in recovery mode
Close #6917
2023-06-02 16:49:04 -07:00
topjohnwu
9ea9f01933 Resolve clippy errors and warnings 2023-05-31 01:08:33 -07:00
topjohnwu
c30fbdf145 Simplify logging code 2023-05-29 01:27:40 -07:00
topjohnwu
f12951bd1d Fix typo 2023-05-29 00:30:55 -07:00
topjohnwu
f2846694e1 Cleanup some code 2023-05-28 23:50:52 -07:00
topjohnwu
d77a368176 Move dependency version into workspace 2023-05-28 17:30:33 -07:00
topjohnwu
5b8b48ccc1 Properly support streamable input 2023-05-26 14:07:11 -07:00
topjohnwu
659b9c6fee Support extracting any partition from payload.bin 2023-05-26 13:36:47 -07:00
LoveSy
ec31cab5a7 Add zip and payload.bin support to Magisk app 2023-05-26 13:36:47 -07:00
vvb2060
dd93556ad8 Faster get magisk tmpfs path 2023-05-25 01:03:27 -07:00
topjohnwu
533aeadd38 Update cstr macro 2023-05-25 01:03:04 -07:00
topjohnwu
18d0cedbe2 Parse rule files with Rust 2023-05-24 19:11:56 -07:00
topjohnwu
5a94ef9106 Fix init rust code setup 2023-05-23 21:50:13 -07:00
topjohnwu
8e8f01f8b5 Move project common code into include 2023-05-23 21:30:30 -07:00
topjohnwu
47d2d4e3a5 Update su cmdline parsing 2023-05-23 20:51:23 -07:00
topjohnwu
69144942e3 Fix fortify
Close #7009, fix #7003
2023-05-23 16:31:24 -07:00
topjohnwu
5627053b74 Move su folder into core 2023-05-23 01:36:25 -07:00
topjohnwu
0f666de5e6 Organize headers 2023-05-22 21:36:15 -07:00
LoveSy
eddc862fa3 Use POSIX format 2023-05-22 18:14:59 -07:00
LoveSy
4327682120 Add mnt ns attach support for su 2023-05-22 18:14:59 -07:00
LoveSy
af5bdee78f Reimplement su -z 2023-05-22 18:14:59 -07:00
LoveSy
0e36e86dbf Support settings gids of su 2023-05-22 18:14:59 -07:00
LoveSy
f95478f1f1 Truncate file only if needed 2023-05-22 00:51:42 -07:00
topjohnwu
9fe8741a02 Export get_prop to Rust 2023-05-21 23:51:30 -07:00
topjohnwu
a5768e02ea Cleanup byte_channel implementation 2023-05-20 14:19:40 -07:00
topjohnwu
f5aaff2b1e Cleanup filter_out_stream implementation 2023-05-20 01:28:10 -07:00
topjohnwu
655f778171 Better cxx binding codegen 2023-05-19 15:59:40 -07:00
topjohnwu
2bcf2e76f1 Generate cxx binding in build.rs 2023-05-19 15:16:54 -07:00
topjohnwu
57bd450798 Split input and output streams 2023-05-19 04:19:43 -07:00
topjohnwu
582cad1b8d Cleanup libc hacks 2023-05-19 03:23:43 -07:00
topjohnwu
6ca2a3d841 Update libsystemproperties 2023-05-19 03:22:50 -07:00
topjohnwu
91773c3311 Support only read properties from storage 2023-05-19 01:53:40 -07:00
topjohnwu
dc61033b2c Support persist props bypassing property_service 2023-05-18 23:36:46 -07:00
topjohnwu
f8d62a4b6c Move resetprop under core 2023-05-18 22:15:49 -07:00
topjohnwu
1d2145b1b7 Improve argument parsing and help message 2023-05-18 21:54:54 -07:00
topjohnwu
1f7f84b74a Remove unnecessary class 2023-05-18 20:38:33 -07:00
topjohnwu
cd7a335d0f Cleanup implementation 2023-05-18 20:26:20 -07:00
topjohnwu
17569005a4 Remove sysprop fallback
The library now supports mapping as ro
2023-05-18 15:47:50 -07:00
topjohnwu
f36b21bae5 Support get property context
Co-authored-by: canyie <a1364259@163.com>
Co-authored-by: vvb2060 <vvb2060@gmail.com>
2023-05-18 14:46:36 -07:00
topjohnwu
fe1ca52f6d Simplify prop_cb 2023-05-16 02:41:39 -07:00
topjohnwu
1be647a279 Put all FFI into same module 2023-05-16 02:41:39 -07:00
topjohnwu
a8c1ed8795 Update development docs 2023-05-13 02:38:03 -07:00
topjohnwu
22d05ca399 Update time handling code 2023-05-13 02:38:03 -07:00
LoveSy
b9e6937996 Make magisk node ro as well 2023-05-10 00:13:18 -07:00
topjohnwu
583ffc8177 Reduce cpp logging overhead 2023-05-09 19:14:08 -07:00
topjohnwu
7518092ad2 Implement logging purely in Rust 2023-05-09 18:54:38 -07:00
topjohnwu
d364554425 Remove unused code 2023-05-06 01:48:47 -07:00
vvb2060
726ffdcd98 Fix meizu rootfs type 2023-05-06 00:06:59 -07:00
vvb2060
f9d22cf8ee New magisk tmp dir: /debug_ramdisk
Co-authored-by: LoveSy <shana@zju.edu.cn>
2023-05-06 00:04:11 -07:00
vvb2060
ee50da566f Cancel recursive bind 2023-05-06 00:04:11 -07:00
vvb2060
9f7d410959 Use pathname local socket 2023-05-06 00:04:11 -07:00
vvb2060
bc94ea4334 Update SELinux policy 2023-05-06 00:04:11 -07:00
topjohnwu
c0c9204848 Add ResultExt 2023-05-05 23:57:34 -07:00
topjohnwu
c0d1bf63bc Clean up logging on C++ side 2023-05-05 01:14:56 -07:00
topjohnwu
7b5ff99cd1 Reorganize code 2023-05-04 21:37:08 -07:00
topjohnwu
21ddb26db8 Perform proto codegen in build script 2023-05-04 21:37:08 -07:00
LoveSy
7bf2e3875f Support extract boot image from payload.bin 2023-05-04 21:37:08 -07:00
topjohnwu
b136aba1e2 Implement magiskinit logging in Rust 2023-05-02 16:49:43 -07:00
topjohnwu
1c5a435e1f Update cxx-rs 2023-05-01 14:53:07 -07:00
topjohnwu
f7de649a36 Update ODNK requirement to r25.3 2023-04-29 15:12:04 -07:00
topjohnwu
0cf0d2b821 Move avd_hack boolean out of init class 2023-04-25 23:34:45 -07:00
vvb2060
68c2817d40 Enable avd hack for debug build 2023-04-25 23:00:59 -07:00
LoveSy
52a98cbd51 Temp workaround for module file context 2023-04-10 19:30:37 -07:00
topjohnwu
b4ae3493a6 Use ext4 partitions for preinit first
Fix #6841, close #6847
2023-04-08 20:30:40 -07:00
残页
1a16004b20
Add help message for magisk --preinit-device 2023-04-08 18:32:34 -07:00
topjohnwu
cc5ff36165 Revert "Cancel recursive bind"
This reverts commit a18a440236.
2023-04-05 10:47:13 -07:00
topjohnwu
18b1ef6c29 Only restore JNIEnv in constructor 2023-04-05 10:13:50 -07:00
LoveSy
7fe012347a Restore JNIEnv in advance for clean env to modules 2023-04-05 09:29:59 -07:00
vvb2060
5c165c9bb0 Fix avd hack 2023-04-05 04:01:32 -07:00
topjohnwu
6c3519923d Make things more obvious 2023-04-05 04:01:07 -07:00
topjohnwu
9ea859810d Update api.hpp copyright notice 2023-04-05 01:54:56 -07:00
vvb2060
9279f30e89 Upload mapping and native debug symbols 2023-04-05 00:14:51 -07:00
LoveSy
b505819ca2 Fix a typo 2023-04-04 12:28:08 -07:00
vvb2060
69529ac59c Fix restorecon 2023-04-04 02:34:16 -07:00
vvb2060
a18a440236 Cancel recursive bind 2023-04-04 02:12:07 -07:00
LoveSy
aa7846c1c0 No need to mount ROOTMIR if tmp_dir != /sbin 2023-04-04 02:12:07 -07:00
topjohnwu
24ba4ab95b Better AVD support 2023-04-04 02:04:49 -07:00
topjohnwu
762b70ba9d Better string split implementation 2023-04-03 18:50:36 -07:00
topjohnwu
41b77e4f25 Make base as template argument for optimization 2023-04-03 18:32:11 -07:00
topjohnwu
2087e47300 Get random separately 2023-04-03 18:32:11 -07:00
vvb2060
46ce765860 Use stable random seed 2023-04-03 18:32:11 -07:00
LoveSy
15cab86152 Make module mirror read only 2023-04-02 22:03:02 -07:00
LoveSy
97731a519a Update zygisk API to avoid mem leak 2023-04-02 03:54:33 -07:00
LoveSy
4ff60ef9a9 No more patching libc.a on 64bit platforms 2023-04-01 03:51:57 -07:00
topjohnwu
23b1b69110 Consolidate zygisk cleanup routines 2023-04-01 03:37:17 -07:00
LoveSy
3a4fe53f27 New way to unload zygisk
Co-authored-by: 残页 <a1364259@163.com>
2023-04-01 03:37:17 -07:00
LoveSy
04324a7ebe Upgrade LSPlt to bypass a bionic bug 2023-03-23 20:56:35 -07:00
vvb2060
f54daa3469 Force ramdisk format to lz4_legacy for v4 2023-03-23 20:50:27 -07:00
LoveSy
07c22ccd39 Use app_dir to detect systemui instead
uid may be shared by other apps (e.g., in MIUI, systemui's uid
is 1000 and shared by many system apps).
2023-03-23 16:17:13 -07:00
LoveSy
e893c13cf1 Unlink preinit device if bind mount fails 2023-03-23 00:40:13 -07:00
LoveSy
dba5020e4f Refactor magiskrc 2023-03-22 17:53:15 -07:00
LoveSy
87e036a190 Update LSPlt to avoid crash when hooking libc 2023-03-22 12:02:33 -07:00
topjohnwu
4417997749 Make sure ro mmap region is not overwritten 2023-03-21 15:50:43 -07:00
LoveSy
2eef542054 Add amonet microloader support 2023-03-21 15:50:43 -07:00
LoveSy
b9d0a3b3d4 Use partition name or devpath's name 2023-03-21 00:40:11 -07:00
topjohnwu
76405bd984 Add more comments 2023-03-21 00:40:11 -07:00
topjohnwu
4e2b88b3d0 Rename rules to preinit
It is possible that we will allow more preinit files for modules.
Rename the partition and folders from rules to preinit.
2023-03-21 00:40:11 -07:00
LoveSy
7048aa1014 Rename sepolicy.rules -> rules 2023-03-21 00:40:11 -07:00
LoveSy
1c2fcd14b5 Mount sepolicy.rules for migration 2023-03-21 00:40:11 -07:00
vvb2060
362eea741f Refactor sepolicy.rules resolve native
Co-authored-by: LoveSy <shana@zju.edu.cn>
2023-03-21 00:40:11 -07:00
LoveSy
03cee0b8d4 Remove meaningless umount in magiskinit
This is no longer required since we redirect to /data/magiskinit
2023-03-19 23:35:18 -07:00
LoveSy
54ecc001f4 Clean up more codes 2023-03-19 23:20:19 -07:00
topjohnwu
af054e4e31 Bump minSdk to 23 2023-03-17 04:24:26 -07:00
LoveSy
d9f0aed571 Fix unpack -n and repack -n of ZIMAGE kernel 2023-03-17 02:00:46 -07:00
LoveSy
98813c24fb Drop trailing garbage of gzip decompress
I previously refered to minigzip from libz which copies all trailing
data to the output when decompressing. However, gzip, on the other
hand, drop trailing garbage by default. Consider ZIMAGE append
the kernel size with zero padding, we should drop trailing garbage
as well.
2023-03-17 02:00:25 -07:00
LoveSy
1a1646795f Support untrusted_app_32 2023-03-09 02:17:30 -08:00
南宫雪珊
4709a32641
Fix mkdir
Co-authored-by: LoveSy <shana@zju.edu.cn>
2023-03-07 01:47:26 -08:00
LoveSy
981ccabbef No support for partitions w/o symlink in /system 2023-03-06 05:23:40 -08:00
vvb2060
9e07eb592c Fix make private before remount 2023-03-06 05:18:16 -08:00
LoveSy
9555380818 Replace parse_mnt with parse_mount_info 2023-03-06 05:09:12 -08:00
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
LoveSy
1aade8f8a8 No greedy match to find parent mount point
This fixes /sys is considered as a parent mount point of /system
2023-03-03 11:09:03 -08:00
LoveSy
b6ea5b8984 Fix SYSTEM_ROOT not passed to boot patch 2023-03-02 23:39:50 -08:00
LoveSy
f59fbd5dca Filter duplicate mount points
This prevents umounting existing overlay mount points
2023-03-02 14:33:50 -08:00
LoveSy
da36e5bcd5 Make worker private 2023-03-02 02:25:44 -08:00
南宫雪珊
3726eb6032
Deny init relabel to adb_data_file
Co-authored-by: 残页 <a1364259@163.com>
Co-authored-by: LoveSy <shana@zju.edu.cn>
2023-03-02 02:20:38 -08:00
vvb2060
4772868d6a Move REMOUNT_ROOT 2023-03-02 02:05:38 -08:00
vvb2060
7dbfba76bf Umount by tmpfs id 2023-02-26 14:23:11 -08:00
vvb2060
2a4aa95a6f Identify tmpfs used by magisk 2023-02-26 14:23:11 -08:00
LoveSy
a1a87c9956 Get rid of vtable hook 2023-02-26 04:59:21 -08:00
vvb2060
2c53356bfd Remove unexpected files 2023-02-26 03:47:38 -08:00
topjohnwu
85d9756f62 Update Zygisk API documentation 2023-02-26 03:16:13 -08:00
LoveSy
d7158131e4 No need to manually parse mount flags 2023-02-26 01:15:18 -08:00
topjohnwu
3d3082bc82 Minor optimizations 2023-02-26 01:14:10 -08:00
topjohnwu
744ebca206 Don't let inter_node upgrade to module_node 2023-02-25 22:05:50 -08:00
topjohnwu
92077ebe53 Refactor module and node implementation 2023-02-25 18:19:46 -08:00
LoveSy
78ca682bc5 Always mount tmpfs for dirs
https://android-review.googlesource.com/c/platform/system/core/+/928592
2023-02-25 18:19:46 -08:00
LoveSy
af01a36296 Refactor magic mount to support overlayfs
Previously, magic mount creates its own mirror devices and mount
mirror mount points. With these mirror mount points, magic mount
can get the original files and directory trees. However, some
devices use overlayfs to modify some mount points, and thus after
magic mount, the overlayed files are missing because the mirror
mount points do not contain the overlayed files. To address this
issue and make magic mount more compatible, this patch refactors
how magic mount works.

The new workflows are as follows:
1. make MAGISKTMP a private mount point so that we can create the
   private mount points there
2. for mirror mount points, we instead of creating our own mirror
   devices and mount the mirror mount points, we "copy" the
   original mount points by recursively mounting /
3. to prevent magic mount affecting the mirror mount points, we
   recursively set the mirror mount points private
4. to trace the mount points we created for reverting mounts, we
   again make the mirror mount points shared, and by this way we
   create a new peer group for each mirror mount points
5. as for tracing the newly created tmpfs mount point by magic
   mount, we create a dedicated tmpfs mount point for them, namely
   worker mount point, and obviously, it is shared as in a newly
   created peer group for tracing
6. when reverting mount points by magic mount, we can then trace
   the peer group id and unmount the mount points whose peer group
   ids are created by us

The advantages are as follows:
1. it is more compatible, (e.g., with overlayfs, fix #2359)
2. it can mount more partitions for which previous implementation
   cannot create mirror mount points (fix #3338)
2023-02-25 18:19:46 -08:00
LoveSy
97ed1b16d0 Fix gzip decompression 2023-02-20 18:26:04 -08:00
残页
ae34659b26
No kernel repack if it isn't patched at all
It turns out that decompressing and recompressing the kernel is enough to break booting on many devices that use MT6763.
Fix #5124, fix #6204, fix #6566 

Co-authored-by: LoveSy <shana@zju.edu.cn>
Co-authored-by: 南宫雪珊 <vvb2060@gmail.com>
2023-02-17 15:00:14 -08:00
LoveSy
79a85f5937 Use mountinfo for revert unmount 2023-02-17 12:36:19 -08:00
LoveSy
b249832571 Use statfs to check rootfs
This helps support adb remount
2023-02-12 22:49:27 -08:00
LoveSy
577b5912af Fix SKIP_FD_SANITIZATION false positive
Fix #6523
2023-02-12 00:40:09 -08:00
LoveSy
9e8c68af12
Refactor sepolicy.rules resolve
We resolve available partitions for sepolicy.rules when patching
boot and bind mount the partition by magiskinit.

For older devices, the previous logic won't work because the part name
is never readable.

Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2023-02-12 00:36:38 -08:00
shìwēi nguyen
03418ddcbf
run module uninstall.sh on Magisk uninstallation 2023-02-09 20:36:58 -08:00
LoveSy
220a1c84ce Zygisk v4 module's plt commit should not use regex 2023-02-09 20:19:53 -08:00
vvb2060
7a9e6d2ad2 Remove unexpected /sbin/overlay.d 2023-02-09 20:08:59 -08:00
canyie
6ecc04a4df Fix auto install stub 2023-01-23 01:55:28 +08:00
LoveSy
0329f00129 Upgrade LSPlt
Fix #6533
2023-01-20 19:29:55 +08:00
topjohnwu
cd8a2edefb Reduce unnecessary formatting 2023-01-20 14:41:34 +08:00
LoveSy
4318ab5cd2 Reuse tmpfs for magic mount
As we already have a tmpfs (magisktmp), we can reuse them for
magic mount
2023-01-20 03:49:40 +08:00
topjohnwu
3517e6d752 Handle nullptr char* in Rust 2023-01-20 03:45:16 +08:00
LoveSy
67845f9c21
Clear sepolicy rules when disable/remove modules
Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2023-01-19 04:25:44 +08:00
Kian-Meng Ang
f562710438 Fix typos
Found via `codespell -S *.xml,*.kt,./native/src/external -L crate,bu`
2023-01-18 16:35:37 +08:00