From 732a161b6770a815f40e9ba96609c50e6f185371 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 22 Jun 2023 02:23:27 -0700 Subject: [PATCH] Minor cleanup --- native/src/boot/dtb.cpp | 4 ++-- native/src/boot/lib.rs | 15 +++++++++------ native/src/boot/main.cpp | 2 +- native/src/core/lib.rs | 6 +++--- native/src/init/lib.rs | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/native/src/boot/dtb.cpp b/native/src/boot/dtb.cpp index 793f57f9a..d648a9016 100644 --- a/native/src/boot/dtb.cpp +++ b/native/src/boot/dtb.cpp @@ -152,7 +152,7 @@ static bool dtb_patch(const char *file) { int len; char *value = (char *) fdt_getprop(fdt, node, "fsmgr_flags", &len); byte_data data(value, len); - patched |= (rust::patch_verity(data) != len); + patched |= (patch_verity(data) != len); } } } @@ -225,7 +225,7 @@ static bool fdt_patch(void *fdt) { int len; const void *value = fdt_getprop(fdt, node, "fsmgr_flags", &len); heap_data copy = byte_view(value, len).clone(); - auto patched_sz = rust::patch_verity(copy); + auto patched_sz = patch_verity(copy); if (patched_sz != len) { modified = true; fdt_setprop(fdt, node, "fsmgr_flags", copy.buf(), patched_sz); diff --git a/native/src/boot/lib.rs b/native/src/boot/lib.rs index 6182b4aa9..174115188 100644 --- a/native/src/boot/lib.rs +++ b/native/src/boot/lib.rs @@ -2,9 +2,9 @@ #![feature(btree_drain_filter)] pub use base; -use cpio::*; -use patch::*; -use payload::*; +use cpio::cpio_commands; +use patch::{hexpatch, patch_encryption, patch_verity}; +use payload::extract_boot_from_payload; mod cpio; mod patch; @@ -21,6 +21,12 @@ pub mod ffi { fn decompress(buf: &[u8], fd: i32) -> bool; } + extern "Rust" { + fn hexpatch(file: &[u8], from: &[u8], to: &[u8]) -> bool; + fn patch_encryption(buf: &mut [u8]) -> usize; + fn patch_verity(buf: &mut [u8]) -> usize; + } + #[namespace = "rust"] extern "Rust" { unsafe fn extract_boot_from_payload( @@ -30,8 +36,5 @@ pub mod ffi { ) -> bool; unsafe fn cpio_commands(argc: i32, argv: *const *const c_char) -> bool; - fn hexpatch(file: &[u8], from: &[u8], to: &[u8]) -> bool; - fn patch_encryption(buf: &mut [u8]) -> usize; - fn patch_verity(buf: &mut [u8]) -> usize; } } diff --git a/native/src/boot/main.cpp b/native/src/boot/main.cpp index 9a43d06a1..30c2230be 100644 --- a/native/src/boot/main.cpp +++ b/native/src/boot/main.cpp @@ -200,7 +200,7 @@ int main(int argc, char *argv[]) { } else if (argc > 2 && str_starts(action, "compress")) { compress(action[8] == '=' ? &action[9] : "gzip", argv[2], argv[3]); } else if (argc > 4 && action == "hexpatch") { - return rust::hexpatch(byte_view(argv[2]), byte_view(argv[3]), byte_view(argv[4])) ? 0 : 1; + return hexpatch(byte_view(argv[2]), byte_view(argv[3]), byte_view(argv[4])) ? 0 : 1; } else if (argc > 2 && action == "cpio"sv) { if (!rust::cpio_commands(argc - 2, argv + 2)) usage(argv[0]); diff --git a/native/src/core/lib.rs b/native/src/core/lib.rs index 6efe5f45a..1431e08d9 100644 --- a/native/src/core/lib.rs +++ b/native/src/core/lib.rs @@ -2,9 +2,9 @@ #![allow(clippy::missing_safety_doc)] use base::Utf8CStr; -use cert::*; -use daemon::*; -use logging::*; +use cert::read_certificate; +use daemon::{daemon_entry, find_apk_path, get_magiskd, zygisk_entry, MagiskD}; +use logging::{android_logging, magisk_logging, zygisk_logging}; mod cert; #[path = "../include/consts.rs"] diff --git a/native/src/init/lib.rs b/native/src/init/lib.rs index 0e761bc3f..7c0aeac2c 100644 --- a/native/src/init/lib.rs +++ b/native/src/init/lib.rs @@ -1,4 +1,4 @@ -pub use logging::*; +use logging::setup_klog; // Has to be pub so all symbols in that crate is included pub use magiskpolicy;