ksud: replace some utils with rust libraries (#142)

This commit is contained in:
skbeh
2023-01-30 12:57:25 +08:00
committed by GitHub
parent bd6b0d3d12
commit 7785d2a3f8
9 changed files with 525 additions and 178 deletions

View File

@@ -1,7 +1,7 @@
#![allow(dead_code, unused_mut, unused_variables, unused_imports)]
use anyhow::{ensure, Result};
use std::os::unix::process::CommandExt;
use anyhow::{Result, ensure};
const KERNEL_SU_OPTION: u32 = 0xDEADBEEF;
@@ -31,8 +31,7 @@ pub fn grant_root() -> Result<()> {
}
ensure!(result == KERNEL_SU_OPTION, "grant root failed");
std::process::Command::new("/system/bin/sh").exec();
Ok(())
return Err(std::process::Command::new("sh").exec().into());
}
#[cfg(not(target_os = "android"))]
@@ -56,11 +55,7 @@ pub fn get_version() -> i32 {
fn report_event(event: u64) {
#[cfg(target_os = "android")]
unsafe {
libc::prctl(
KERNEL_SU_OPTION as i32,
CMD_REPORT_EVENT,
event,
);
libc::prctl(KERNEL_SU_OPTION as i32, CMD_REPORT_EVENT, event);
}
}
@@ -70,4 +65,4 @@ pub fn report_post_fs_data() {
pub fn report_boot_complete() {
report_event(EVENT_BOOT_COMPLETED);
}
}