Commit Graph
175 Commits
Author SHA1 Message Date
topjohnwu 9ee6a6b3d7 Update to ONDK r29.5 2026-02-06 16:32:25 -08:00
LoveSy b55f597ccf Skip loading magisk in charger mode 2026-02-03 15:55:53 -08:00
LoveSy 5f13a8f8f7 support sony's init.real 2026-01-31 13:54:34 -08:00
topjohnwu 01cb75eaef Code cleanup 2025-12-13 22:12:30 -08:00
topjohnwu ff4ca74cfe Ban all unwrap usage in codebase 2025-12-08 23:31:04 -08:00
南宫雪珊 9a776c22d9 Revert "Use rootfs for magisktmp if possible" 2025-12-01 11:45:34 -08:00
topjohnwu 5d6b703622 Move occupy and unoccupy out of base crate 2025-11-29 00:13:41 -08:00
topjohnwu f7ce9c38e1 Run through clippy and rustfmt 2025-11-29 00:13:41 -08:00
LoveSy bdbfb40383 Use rootfs for magisktmp if possible 2025-11-29 00:13:41 -08:00
topjohnwu 5bcb55b7fc Format Rust imports with rustfmt 2025-10-19 17:15:30 -07:00
topjohnwu 0dc8231585 Make all dependencies workspace = true 2025-10-19 17:15:30 -07:00
topjohnwu 0222527a1e Use bitflags macro 2025-09-11 01:17:34 -07:00
topjohnwu 312bfe1bab Do not leak base::ffi to external crates 2025-09-11 01:17:34 -07:00
topjohnwu c8caaa98f5 Enable mount for nix 2025-09-09 20:17:09 -07:00
topjohnwu ef4e230258 Use nix for libc functions 2025-09-08 23:59:29 -07:00
topjohnwu bc89c60977 Run cargo fmt 2025-09-02 22:06:08 -07:00
topjohnwu 484d53ef7e Update to ONDK r29.2 2025-08-28 16:15:59 -07:00
topjohnwu 2e4fa6864c Make Utf8CStr a first class citizen in C++ codebase
Utf8CStr is in many cases a better string view class than
std::string_view, because it provides "view" access to a string buffer
that is guaranteed to be null terminated. It also has the additional
benefit of being UTF-8 verified and can seemlessly cross FFI boundaries.

We would want to start use more Utf8CStr in our existing C++ codebase.
2025-08-27 22:48:48 -07:00
topjohnwu b861671391 Cleanup libbase 2025-08-25 01:31:47 -07:00
topjohnwu e91fc75d86 Consolidate for_each implementation into Rust 2025-08-25 01:31:47 -07:00
topjohnwu fd193c3cae Simplify ResultExt implementation
Also introduce OptionExt
2025-08-22 12:03:47 -07:00
Wang Han 8dc23d0ead Avoid triggering magisk --zygote-restart twice
We have already used on restart keyword to inject zygote restart, so
triggering it here on prop is not needed.
2025-08-20 12:34:39 -07:00
topjohnwu 7961be5cfa Migrate prepare_modules to Rust 2025-08-05 11:24:55 -07:00
topjohnwu 1460317ebd Cleanup C++ headers 2025-06-16 02:25:38 -07:00
topjohnwu d8cf42af16 Reduce unstable feature usage 2025-05-30 11:11:36 -07:00
topjohnwu dc0acea47c Remove C++ I/O streams 2025-05-20 03:26:00 -07:00
topjohnwu 527bbc0368 Migrate module mounting to Rust 2025-05-20 03:24:43 -07:00
topjohnwu 4f4b1ff885 Add sepolicy.rule patching tests 2025-05-13 14:08:54 -07:00
topjohnwu 9684a35cab Use rust::String::c_str to ensure nil termination 2025-05-09 16:02:46 -07:00
Wang Han a20a2a8fa0 Recognize Samsung custom policy version path 2025-05-09 11:03:58 -07:00
topjohnwu 3327fc668e Remove FsPath and FsPathMnt trait
Directly use Utf8CStr
2025-04-28 17:22:14 -07:00
topjohnwu 610945ac54 Remove open_fd macro 2025-04-28 17:22:14 -07:00
topjohnwu e02b5f7868 Rename cstr_buf to cstr::buf 2025-04-22 03:21:00 -07:00
topjohnwu ab2e5d1e7e Make FsPathBuf a trait and rename to FsPathBuilder 2025-04-22 03:21:00 -07:00
topjohnwu f3fef7bfe4 Make FsPath a trait 2025-04-22 03:21:00 -07:00
topjohnwu 7a207d4ccf Only accept UTF-8 directory entries 2025-04-15 10:26:22 -07:00
topjohnwu 084d89fcce Create Utf8CStrBuffer type 2025-04-15 10:26:22 -07:00
topjohnwu 7bd901273c Provide richer error messages
Make sure most syscall/libc calls results are mapped to OsResult
that can produce more detailed error messages.
2025-04-15 00:18:48 -07:00
topjohnwu 9c7d359093 Optimize and format imports
[skip ci]
2025-04-08 09:57:09 -07:00
topjohnwu d4a0286e13 Migrate magiskinit selinux.cpp to Rust 2025-04-08 02:33:52 -07:00
topjohnwu 50af14f2a3 Move all MagiskInit entrypoints into init.rs 2025-03-24 17:26:03 -07:00
topjohnwu e0a356b319 Introduce mount helper methods 2025-03-24 17:26:03 -07:00
topjohnwu c09a792958 Reorganize magiskinit code 2025-03-24 17:26:03 -07:00
topjohnwu 0bbfe7f44d Fix 2SI on legacy SAR devices 2025-03-24 17:26:03 -07:00
topjohnwu 6ff82c4e86 Introduce FsPathFollow
Make sure all operations of FsPath do not follow symlinks, and provide
a way to explicitly switch over to a set of operations that DO follow
symlinks by FsPath::follow_link.
2025-03-07 15:51:51 -08:00
LoveSy c64de35375 Move magiskpolicy cli to argh 2025-03-07 14:29:30 -08:00
topjohnwu c90e73ccec Migration to Edition 2024 2025-03-07 02:35:25 -08:00
topjohnwu a43c1267d8 Update Cargo.toml 2025-03-07 02:35:25 -08:00
topjohnwu c6c1a17ae6 Address several clippy warnings 2025-03-03 02:15:14 -08:00
topjohnwu c9eac0c438 Introduce new sepolicy strategy for legacy devices
The existing sepolicy patching strategy looks like this:

1. 2SI: use LD_PRELOAD to hijack `security_load_policy`
2. Split policy: devices using split policy implies it also needs to
   do early mount, which means fstab is stored in device tree.
   So we do the following:
   - Hijack the fstab node in the device tree in sysfs
   - Wait for init to mount selinuxfs for us
   - Hijack selinuxfs to intercept sepolicy loading
3. Monolithic policy: directly patch `/sepolicy`

Method #1 and #2 both has the magiskinit pre-init daemon handling
the sepolicy patching and loading process, while method #3 gives us
zero control over sepolicy loading process. Downsides:

a. Pre-init daemon bypasses the need to guess which sepolicy init
   will load, because the original init will literally send the stock
   sepolicy file directly to us with this approach.
b. If we want to add more features/functionalities during the sepolicy
   patching process, we will leave out devices using method #3

In order to solve these issues, we completely redesign the sepolicy
patching strategy for non-2SI devices. Instead of limiting usage of
pre-init daemon to early mount devices, we always intercept the
sepolicy loading process regardless of the Android version and device
setup. This will give us a unified implementation for sepolicy patching,
and will make it easier to develop further new features down the line.
2025-02-28 09:39:10 -08:00