Commit Graph

153 Commits

Author SHA1 Message Date
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
topjohnwu b6b34f7612 Fix overlay.d context preservation 2025-02-27 01:57:25 -08:00
topjohnwu 363410e1c0 Introduce cstr_buf helper functions 2025-02-17 11:32:21 -08:00
topjohnwu fc2ef21660 Introduce path! macro for FsPath 2025-02-17 01:46:19 -08:00
topjohnwu 3c7c46307a Partially cleanup MagiskInit code 2025-02-15 18:27:45 -08:00
LoveSy 9a74e19117 Add log_ok() for log().ok() 2025-02-14 14:24:13 -08:00
LoveSy b1e17706a4 Format code 2025-02-14 14:24:13 -08:00
LoveSy caad129d69 Move MagiskInit::patch_sepolicy to rust 2025-02-14 14:24:13 -08:00
LoveSy da58571ce5 Remove redundant rust export 2025-02-14 14:24:13 -08:00
LoveSy 2aa7f1c094 Move MagiskInit::check_two_stage to rust 2025-02-14 14:24:13 -08:00
LoveSy 823e31a91b Use linker to link vfprintf as tiny_vfprintf 2025-02-14 14:24:13 -08:00
LoveSy fb926ae302 Move MagiskInit::redirect_second_stage to rust 2025-02-14 14:24:13 -08:00
LoveSy e0489eeffd Move MagiskInit::first_stage to rust 2025-02-14 14:24:13 -08:00
LoveSy dc9d5a4cac Move MagiskInit::second_stage to rust 2025-02-14 14:24:13 -08:00
LoveSy 143743d0b0 Refactor init.cpp to init.rs 2025-02-14 14:24:13 -08:00
LoveSy 563f0d5ad5 Move BootConfig::print to rust 2025-02-14 14:24:13 -08:00
LoveSy c99f4a591b Move MagiskInit::exec_init to rust 2025-02-14 14:24:13 -08:00
LoveSy 449204e380 Move MagiskInit::prepare_data to rust 2025-02-14 14:24:13 -08:00
LoveSy a85c4c6528 Move MagiskInit::MagiskInit to rust 2025-02-14 14:24:13 -08:00
LoveSy d203a6fff6 Move MagiskInit to rust 2025-02-14 14:24:13 -08:00
LoveSy 6c612d66d7 Move BootConfig to rust 2025-02-14 14:24:13 -08:00
topjohnwu b7ca73f431 Remove an additional unique_ptr indirection 2025-02-05 14:18:16 +08:00
LoveSy 3981c9665e Replace rust inner functions to try blocks 2025-02-02 22:09:55 +08:00