ksud: add su
This commit is contained in:
@@ -58,6 +58,9 @@ enum Debug {
|
||||
apk: String,
|
||||
},
|
||||
|
||||
/// Root Shell
|
||||
Su,
|
||||
|
||||
/// Get kernel version
|
||||
Version,
|
||||
|
||||
@@ -129,6 +132,7 @@ pub fn run() -> Result<()> {
|
||||
println!("Kernel Version: {}", crate::ksu::get_version());
|
||||
Ok(())
|
||||
}
|
||||
Debug::Su => crate::ksu::grant_root(),
|
||||
Debug::Test => todo!(),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
#![allow(dead_code, unused_mut, unused_variables)]
|
||||
#![allow(dead_code, unused_mut, unused_variables, unused_imports)]
|
||||
|
||||
use std::os::unix::process::CommandExt;
|
||||
use anyhow::{Result, ensure};
|
||||
|
||||
const KERNEL_SU_OPTION: u32 = 0xDEADBEEF;
|
||||
|
||||
// const CMD_GRANT_ROOT: u64 = 0;
|
||||
const CMD_GRANT_ROOT: u64 = 0;
|
||||
// const CMD_BECOME_MANAGER: u64 = 1;
|
||||
const CMD_GET_VERSION: u64 = 2;
|
||||
// const CMD_ALLOW_SU: u64 = 3;
|
||||
@@ -13,19 +17,23 @@ const CMD_REPORT_EVENT: u64 = 7;
|
||||
const EVENT_POST_FS_DATA: u64 = 1;
|
||||
const EVENT_BOOT_COMPLETED: u64 = 2;
|
||||
|
||||
// pub fn grant_root() -> bool {
|
||||
// let mut result: i32 = 0;
|
||||
// unsafe {
|
||||
// libc::prctl(
|
||||
// KERNEL_SU_OPTION as i32,
|
||||
// CMD_GRANT_ROOT,
|
||||
// 0,
|
||||
// 0,
|
||||
// &mut result as *mut _ as *mut libc::c_void,
|
||||
// );
|
||||
// }
|
||||
// return result as u32 == KERNEL_SU_OPTION;
|
||||
// }
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn grant_root() -> Result<()> {
|
||||
let mut result: u32 = 0;
|
||||
unsafe {
|
||||
libc::prctl(
|
||||
KERNEL_SU_OPTION as i32,
|
||||
CMD_GRANT_ROOT,
|
||||
0,
|
||||
0,
|
||||
&mut result as *mut _ as *mut libc::c_void,
|
||||
);
|
||||
}
|
||||
|
||||
ensure!(result == KERNEL_SU_OPTION, "grant root failed");
|
||||
std::process::Command::new("/system/bin/sh").exec();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_version() -> i32 {
|
||||
let mut result: i32 = 0;
|
||||
|
||||
Reference in New Issue
Block a user