Commit Graph

537 Commits

Author SHA1 Message Date
topjohnwu
6d79de7d71 Initial crt0 implementation
Builds but cannot link, missing a lot of symbols
2024-02-22 21:22:27 -08:00
topjohnwu
18c45ae289 Update cxx and Rust dependencies 2024-02-02 14:35:30 -08:00
LoveSy
356ee1febd Code clean up 2024-01-30 11:07:37 -08:00
LoveSy
cc044ccc4c Fix zygisk unload 2024-01-30 11:07:37 -08:00
LoveSy
9c638cc463 Remove rust workaround 2024-01-29 15:07:21 -08:00
topjohnwu
308c9999fa Properly detect package changes 2024-01-28 00:42:43 -08:00
topjohnwu
930bb8687f Minor zygisk refactoring 2024-01-25 00:17:47 -08:00
topjohnwu
f2c4288d2d Run pthread_atfork only once
Close #7704
2024-01-25 00:17:05 -08:00
残页
94d3daeadf Fix Sony init.real check 2024-01-17 16:09:50 -08:00
LoveSy
79334b7702 One stage zygisk loading 2024-01-11 16:19:39 -08:00
LoveSy
df66458db6 Check full path of init.rc instead of its dir
Some devices has `/system/etc/init/hw` but has no init.rc in it.
2024-01-11 16:18:57 -08:00
LoveSy
97705704e2 install or uninstall apk asynchronously 2024-01-11 16:16:36 -08:00
topjohnwu
65207f96c8 Create custom cxx binding to Utf8CStr 2023-12-26 23:10:55 +08:00
topjohnwu
1057cb3e3c Set serial on Rust binding 2023-12-24 04:36:58 +08:00
topjohnwu
2dd23b2518 Update system_properties 2023-12-24 04:36:58 +08:00
topjohnwu
48b1c26dc8 Prevent race condition in wait 2023-12-23 06:33:12 +08:00
topjohnwu
f1e0bc3e4a Use platform implementation if possible 2023-12-23 06:24:20 +08:00
topjohnwu
38527cd58f Slightly change wait usage and API 2023-12-23 06:23:29 +08:00
LoveSy
e94d65b4b2 Add resetprop -w for waiting property change
It's very easy to wait for property change both in Java and C++,
but it's not the case in shell script. With this patch, developers
can now easily to wait for property change, just like what we have
in `.rc` files, and to wait for boot complete.
2023-12-23 00:12:42 +08:00
LoveSy
27ece3c7df Keep mirror shared before magic mount
This allows mounting during post-fs-data be kept after magic mount
2023-12-22 21:39:03 +08:00
LoveSy
06687abffc Fix magisk --stop by making mirror shared
Previously mirror is private and then unshared to zygote, which
makes magisk --stop cannot propagate umount mirror to zygote.
2023-12-22 21:39:03 +08:00
vvb2060
deedb462a0 Hide magisk internal mount point 2023-12-22 21:38:15 +08:00
Wang Han
1ef3f6e13b Remove useless rule for prctl PR_SET_MM
* There is no use-case for it now.
2023-12-22 00:36:06 +08:00
topjohnwu
e30bda6c8d Rebase libsepol to AOSP main 2023-12-21 19:23:02 +08:00
vvb2060
00e9d76a5a Revert "Avoid doing any unmounts for SysUI" 2023-12-20 17:23:17 +08:00
LoveSy
f41994cb52 Skip svc for ro properties
ro properties' triggers should only be triggered once, otherwise it
may undefined behaviour.
This patch avoids triggering ro properties' actions again when using
resetprop to modify them.

Co-authored-by: 5ec1cff <ewtqyqyewtqyqy@gmail.com>
2023-12-18 16:21:08 +08:00
topjohnwu
a003336497 Update system_properties for pre Android 10 2023-12-18 16:21:08 +08:00
LoveSy
401090d6fe Avoid zygiskd restarts when boot-complete 2023-12-18 16:21:08 +08:00
LoveSy
90dcc1cd30 Do not always zero initialize for rust resize vec 2023-12-18 16:21:08 +08:00
LoveSy
2ac464b186 Only compress regular file 2023-12-18 16:21:08 +08:00
LoveSy
8b7fae278b Support compressing during cpio backup 2023-12-18 16:21:08 +08:00
LoveSy
98861f0b5a Clone dir attr for tmpfs in advance 2023-12-13 03:28:30 +08:00
topjohnwu
e35925d520 Properly version zygisk APIs 2023-12-13 03:27:38 +08:00
Kieron Quinn
685a2d2101 Fixes for Android 14 QPR2 B2
Added new method signatures and arguments
2023-12-13 00:16:54 +08:00
LoveSy
f7e471616d Fix clone_attr for newly created dirs 2023-12-10 23:37:47 +08:00
canyie
1fe9ede940 Update selinux to disable validation for policydb 2023-12-08 16:50:45 +08:00
LoveSy
1fd49e4987 Make tmpfs mount of magic mount atomic
This avoid system libraries disappear temporarily during magic mount,
which causes some dynamic executables fails to run during post-fs-data.
2023-12-08 13:59:02 +08:00
LoveSy
d49b02b274 Fix zygiskd not restart when zygote restarts 2023-12-07 20:44:44 +08:00
topjohnwu
1dcf325547 Minor cleanup 2023-12-03 19:32:58 +08:00
LoveSy
58aded31c2 Enable iter_intersperse 2023-11-29 23:47:51 +08:00
LoveSy
6f6b0ade06 Correct cpio's norm_path 2023-11-29 23:47:51 +08:00
topjohnwu
c7083659aa Directly guard boot state with mutex 2023-11-27 17:40:58 +08:00
canyie
68442f38ac Misc changes
- actions: Update all actions/checkout references to v4
- magiskboot: Add missing new line to dtb help message
- docs: Update documents, fix some errors and remove outdated info
2023-11-17 13:58:41 -08:00
topjohnwu
8d5b9e5329 C++/Rust 2 way binding for MagiskD 2023-11-17 13:35:50 -08:00
topjohnwu
6c0966b795 Move some global state into Rust 2023-11-16 15:38:38 -08:00
topjohnwu
7c2e93d266 Introduce owned_fd 2023-11-16 15:38:38 -08:00
topjohnwu
49f241b77c Allow running scripts with incomplete env 2023-11-10 00:55:05 -08:00
topjohnwu
cfb20b0f86 Zygisk refactoring part 2 2023-11-09 20:55:58 -08:00
topjohnwu
6d6f14fcb3 Use bitflags 2023-11-09 14:35:49 -08:00
topjohnwu
977c981265 Make sure native bridge is restored on daemon restart 2023-11-08 17:55:25 -08:00
topjohnwu
ef48abf19d Reorganize zygisk code 2023-11-08 17:46:39 -08:00
topjohnwu
65c18f9c09 Restructure project files 2023-11-08 01:46:02 -08:00
残页
ecb31eed40
Prevent Zygisk from closing new fds created by Zygote itself 2023-11-08 00:34:38 -08:00
topjohnwu
a80cadf587 Refactor hookJniNativeMethods
Utilize NativeBridgeRuntimeCallbacks we obtained from native bridge
to directly fetch and modify registered native JNI methods.
By doing so, we do not need to keep a copy of every single
JNINativeMethod registered in order to provide JNI hooking
functionality.

Co-authored-by: LoveSy <shana@zju.edu.cn>
2023-11-07 23:57:55 -08:00
LoveSy
fce1bf2365 Obtain NativeBridgeRuntimeCallbacks for future use
NativeBridgeRuntimeCallbacks can be used for better JNI method hooking

Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2023-11-07 16:56:40 -08:00
LoveSy
cbc6d40b2c Clean up codes 2023-11-07 14:25:57 -08:00
LoveSy
9fbd079560 Refactor zygisk to use native bridge to inject
Co-authored-by: vvb2060 <vvb2060@gmail.com>
Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2023-11-07 14:25:57 -08:00
LoveSy
42eb928054 Inject zygisk.rc for sync --zygisk-restart 2023-11-06 15:39:48 -08:00
topjohnwu
75e37be6f3 Do not need to check pkg in magisk_env 2023-11-05 23:02:40 -08:00
topjohnwu
ac5ceb18c8 Guard log FIFO with SELinux 2023-11-04 23:59:11 -07:00
topjohnwu
72b39594d3 Always close logd_fd during fork 2023-11-04 02:36:14 -07:00
topjohnwu
16ae4aedf1 Remove usage of MAGISKTMP 2023-11-02 15:50:36 -07:00
topjohnwu
489100c755 Fix fd sanitization 2023-11-01 02:01:29 -07:00
topjohnwu
da766f2a4e Do not go through magiskd for getting the log pipe 2023-11-01 02:01:18 -07:00
topjohnwu
c81d7ff76c Remove unnecessary RefCell usage 2023-10-31 18:22:48 -07:00
topjohnwu
a6e50d3648 Make log pipe a FIFO instead of anonymous pipe 2023-10-31 18:05:22 -07:00
topjohnwu
a177846044 Better logging in recv_fds 2023-10-31 17:40:59 -07:00
topjohnwu
19a4e11645 Make tmpfs path static strings 2023-10-29 00:47:28 -07:00
topjohnwu
67cc36268e Simplify zygisk log pipe 2023-10-26 18:13:56 -07:00
LoveSy
9088b584f6 Use official argh 2023-10-25 15:14:16 -07:00
topjohnwu
985454afd4 Better logging 2023-10-24 16:41:49 -07:00
topjohnwu
1eeb2a34a1 Don't support alternative binary paths
The Magisk app will guide users through repair setup
2023-10-19 05:11:43 -07:00
topjohnwu
91c92051f1 Simplify C++ SELinux routines 2023-10-17 16:04:59 -07:00
topjohnwu
4b8a0388e7 Make SELinux support a feature 2023-10-17 13:29:15 -07:00
topjohnwu
66788dc58c Cleanup SELinux support 2023-10-16 17:38:44 -07:00
topjohnwu
36de62873a Fix error logging on the C++ side 2023-10-13 16:59:54 -07:00
topjohnwu
51e37880c6 Add repr(transparent) to guarantee soundness 2023-10-12 18:59:16 -07:00
topjohnwu
4b83c1e76c Cleanup messy error messages 2023-10-12 18:54:09 -07:00
topjohnwu
6d1e8d86cb Cleaner cstr code 2023-10-11 23:53:55 -07:00
topjohnwu
eda8c70a80 Borrow value instead of moving in FsPath::from()
When accepting a value of AsRef<Utf8CStr> in FsPath::from(), the
existing code will move a value of Utf8CStrBufArr, creating a reference
that lives longer than the borrowing value, causing undefined behavior.

The issue is only visible on release builds, as more advanced
optimizations will be more aggressive re-using the stack of variables
that no longer lives.

Fix #7408
2023-10-11 23:48:54 -07:00
topjohnwu
e774408782 Allow AVD hacks on release builds 2023-10-11 14:17:31 -07:00
topjohnwu
6076b52c48 Update libcxx 2023-10-03 17:22:25 -07:00
topjohnwu
79a1c39b30 Simplify fd sanitization 2023-09-28 20:38:16 -07:00
topjohnwu
5c92d39498 Enable Zygisk by default in emulators
Make sure CI tests Zygisk
2023-09-28 20:25:26 -07:00
topjohnwu
6e7a995716 Introduce UtfCString 2023-09-27 15:21:24 -07:00
topjohnwu
a55d570213 Move more I/O operations into Rust 2023-09-27 02:28:43 -07:00
topjohnwu
5d07d0b964 Do not support systems without SELinux 2023-09-27 02:28:43 -07:00
Wang Han
ec115cd7e3 Don't skip fd sanitization if fds_to_ignore does not exist 2023-09-25 09:45:03 -07:00
topjohnwu
a3f5918d25 Fix bug in libsepol
Fix #7308
2023-09-23 22:34:51 -07:00
topjohnwu
b28326198c Use crates for cpio code 2023-09-22 01:39:21 -07:00
topjohnwu
46275b90c2 Generalize unxz 2023-09-21 05:47:21 -07:00
topjohnwu
15e13a8d8b Organize logging code 2023-09-19 03:02:30 -07:00
topjohnwu
b750c89c87 Address clippy warnings 2023-09-19 01:11:50 -07:00
LoveSy
8d7c7c3dfb Refactor dtb in rust 2023-09-19 00:41:42 -07:00
topjohnwu
8e1a91509c Remove readlink_unsafe 2023-09-19 00:06:21 -07:00
LoveSy
927cd571f8 Fix read_cert crash when receive fd = -1 2023-09-18 22:32:32 -07:00
LoveSy
5fbd3e5c65 Fix buf len update of read_link to Utf8CStrBuf 2023-09-18 22:31:12 -07:00
topjohnwu
dda8cc85c9 Use bytemuck 2023-09-14 13:10:09 -07:00
topjohnwu
6a59939d9a Remove for_all_file 2023-09-13 18:09:16 -07:00
topjohnwu
9aa466c773 Fix genfscon and filename_trans
Fix #7329
2023-09-12 21:31:31 -07:00
LoveSy
0243610c09 No trailing zeros if the signed boot img is larger 2023-09-12 18:09:20 -07:00
topjohnwu
0a2a590ab7 Use Utf8CStr for logging 2023-09-12 17:35:20 -07:00
topjohnwu
89aee6ffa7 Add more to the Utf8CStr family
Better C strings with path operations
2023-09-12 17:35:01 -07:00
topjohnwu
4eaf701cb7 Address clippy warnings 2023-09-06 21:45:12 -07:00
topjohnwu
4fff2aa7d8 Fix proto read and write 2023-09-06 20:45:59 -07:00
topjohnwu
35b3c8ba5c Cleanup persist props code 2023-09-06 15:52:14 -07:00
topjohnwu
1d7cff7703 Update Cargo dependencies 2023-09-06 13:57:43 -07:00
LoveSy
8d81bd0e33 resetprop: replace nanopb with quick-protobuf for persist 2023-09-05 22:20:57 -07:00
topjohnwu
4c45775131 Update BusyBox 2023-09-02 05:45:18 -07:00
LoveSy
c072b4254d Wrap rename and renameat 2023-09-02 04:24:24 -07:00
topjohnwu
2dbb812126 Disable stack protector on x86 static executables
Close #7274
2023-09-01 23:04:19 -07:00
topjohnwu
0c28a916be Use cxx_name 2023-08-24 00:50:38 -07:00
topjohnwu
275208e81b Update Rust dependencies 2023-08-17 21:24:29 -07:00
topjohnwu
41226c12b8 Update to ONDK r25.7 2023-08-15 17:10:20 -07:00
topjohnwu
b5b14ce343 Use cxx_name instead of rust_name 2023-08-10 21:22:53 -07:00
topjohnwu
f924ffcbf3 Merge files 2023-08-08 00:57:58 -07:00
vvb2060
c6efb51f61 sulog: add more info 2023-08-02 21:18:05 -07:00
topjohnwu
17ba5cba3e Print permissive rules 2023-08-02 09:11:22 -07:00
topjohnwu
f2e109ad7d Update libselinux and libsepol 2023-08-01 18:07:53 -07:00
topjohnwu
c83e141a1c Support dumping sepolicy rules 2023-08-01 18:03:54 -07:00
topjohnwu
6089cc36de Update xperm parsing 2023-07-31 09:28:27 -07:00
topjohnwu
9638dc0a66 Fix perror 2023-07-25 21:03:04 -07:00
Andrew Gunnerson
b191a14a23 magiskpolicy: Fix old xperms being cleared when adding new xperms
This commit updates sepol_impl::add_xperm_rule() so that it loads the
current xperm bits from the existing avtab entry before setting or
clearing xperm bits. This fixes new allowxperm rules causing old xperm
rules within the same xperm specified/driver to be removed.

Fixes: #7176

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-07-24 23:52:28 -07:00
topjohnwu
7ad77a14ae Remove unused line 2023-07-17 21:43:09 -07:00
topjohnwu
af65d07456 Support AVB1.0 signing and verification in magiskboot 2023-07-17 18:57:50 -07:00
topjohnwu
c97ab690b6 Segment memory mapped boot image region 2023-07-13 21:01:49 -07:00
LoveSy
0a07018fec No need to use submodule for argh 2023-07-06 15:28:39 -07:00
LoveSy
64c82e1f2c Refine cpio argh
we can use argh to handle `--help` now
2023-07-06 15:07:06 -07:00
topjohnwu
e8e8afa6c2 Properly handle visibility 2023-07-06 11:12:27 -07:00
LoveSy
af2207433d Fix error logging
ok_or will unconditionally creates a LoggedResult, which prints
an error even it successes. Use ok_or_else which lazily creates
a LoggedResult only if it fails.
2023-07-06 11:01:57 -07:00
LoveSy
606d97ae4d Trace location from LoggedError
Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2023-07-05 18:55:23 -07:00
topjohnwu
d778b0b0a7 Custom help message when using argh
Help messages generated from argh is nearly useless and very hard to
customize. Fork argh and disable all code for generating help messages.

Use a closure to print the help message when handling EarlyExit.
2023-07-05 17:05:39 -07:00
topjohnwu
5ee6daf126 Handle cpio commands properly 2023-07-03 21:57:28 -07:00
topjohnwu
ee943afbc9 Cleanup SHA hash implementation 2023-06-30 15:50:52 -07:00
LoveSy
1f7c3e9f14 Use rust to calculate sha 2023-06-30 14:06:02 -07:00
LoveSy
a470ee6f93 Fix mmap block device 2023-06-30 01:06:51 -07:00
topjohnwu
4ee4cbada6 Standardize logging and error handling
- Introduce new types: LoggedResult and LoggedError
- Introduce new extension methods to log and add additional msgs
- Never exit when logging error messages in Rust (all errors should be
  handled by using Result and Rust's error propagation)
- Remove all usages of anyhow as it doesn't fit Magisk's use cases
2023-06-29 17:14:53 -07:00
topjohnwu
a8c4a33e91 Avoid using trait object 2023-06-23 02:32:29 -07:00
topjohnwu
279f955a84 Minor changes 2023-06-23 01:50:33 -07:00
topjohnwu
dc26ad7125 Address clippy warnings 2023-06-22 02:36:31 -07:00
LoveSy
24b1c607f3 Replace clap with argh 2023-06-22 02:36:31 -07:00
topjohnwu
732a161b67 Minor cleanup 2023-06-22 02:23:27 -07:00
topjohnwu
9c7cf340a1 Move pattern matching to Rust 2023-06-21 16:47:20 -07:00
topjohnwu
399b9e5eba Move hexpatch to Rust 2023-06-20 18:17:26 -07:00
topjohnwu
a6b1149b9f Minor cleanup 2023-06-20 14:36:07 -07:00
LoveSy
51e985ae7f Use quick-protobuf 2023-06-20 14:36:07 -07:00
vvb2060
9929b25339 Move su request path to magisk tmp 2023-06-20 03:29:06 -07:00
topjohnwu
2359cfc480 Small refactor 2023-06-20 00:21:51 -07:00
topjohnwu
81493475f9 Directly use rust::Vec 2023-06-20 00:21:51 -07:00
topjohnwu
8abcccc262 Fix typo 2023-06-16 01:49:44 -07:00
LoveSy
a9c89cbbbb Read certificate in Rust
Co-authored-by: topjohnwu <topjohnwu@gmail.com>
2023-06-16 01:49:44 -07:00
LoveSy
53257b6ea1 Fix find_apk_path 2023-06-15 04:09:45 -07:00
LoveSy
c874391be4 Box CpioEntry 2023-06-15 04:09:17 -07:00
LoveSy
7e8e013832 Fix two typo 2023-06-15 04:09:17 -07:00
topjohnwu
037f46f7f0 Fix copy_cstr 2023-06-15 04:00:32 -07:00
topjohnwu
d3e1c496ca Upgrade ONDK to r25.6 2023-06-15 01:26:54 -07:00
topjohnwu
d7d0a44693 Remove randomness from Magisk 2023-06-14 17:05:49 -07:00
topjohnwu
9d6f6764cb Use Metadata instead of direct stat syscall 2023-06-12 14:58:13 -07:00
topjohnwu
cb3ab63815 Replace all CStr usage to Utf8CStr 2023-06-12 13:57:15 -07:00
topjohnwu
caae932117 Remove unnecessary lifetime markers 2023-06-12 13:56:20 -07:00
LoveSy
e9cf27eb5a Fix map_file 2023-06-12 13:55:58 -07:00
LoveSy
d15017b777 Add arg requirement for cpio extract 2023-06-12 02:40:50 -07:00
LoveSy
a9387e63e1 Fix Utf8CStr::as_ref() -> OsStr 2023-06-12 02:40:50 -07:00
topjohnwu
23c1f0111b Improve Rust implementation
- Move mmap_file implementation into Rust
- Introduce Utf8CStr as the better c-string type to use
2023-06-12 02:40:50 -07:00
LoveSy
866386e21f Use to_string instead of to_owned 2023-06-12 02:40:50 -07:00
LoveSy
bf10496fa9 Add log for restore 2023-06-12 02:40:50 -07:00
LoveSy
607e6547a7 No check rm -r 2023-06-12 02:40:50 -07:00
topjohnwu
6b21091fe2 Fix compile errors and cleanup 2023-06-12 02:40:50 -07:00
topjohnwu
e58f98e844 Update cargo files 2023-06-12 02:40:50 -07:00
LoveSy
b8cb9cd84d Refactor magiskboot cpio 2023-06-12 02:40:50 -07:00
LoveSy
c1038ac6f9 Remove permissve update_engine 2023-06-10 13:17:37 -07:00
LoveSy
bf6359abaa Fix release build 2023-06-10 13:10:54 -07:00
topjohnwu
d1621845b8 Fix typo 2023-06-10 01:50:18 -07:00
topjohnwu
f33f1d25d0 Move find_apk_path to Rust 2023-06-10 01:40:45 -07:00
topjohnwu
40f25f4d56 Introduce directory traversal 2023-06-09 02:00:37 -07:00
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