Compare commits
4 Commits
9e65012c99
...
aaf27a3db8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aaf27a3db8 | ||
|
|
b9d8da3415 | ||
|
|
f8a3a3aaf2 | ||
|
|
ed7b41545a |
@@ -8,7 +8,9 @@ use android_logger::Config;
|
||||
use log::LevelFilter;
|
||||
|
||||
use crate::boot_patch::{BootPatchArgs, BootRestoreArgs};
|
||||
use crate::{apk_sign, assets, debug, defs, init_event, ksucalls, module, module_config, utils};
|
||||
use crate::{
|
||||
apk_sign, assets, debug, defs, init_event, ksucalls, module, module_config, susfs, utils,
|
||||
};
|
||||
|
||||
/// KernelSU userspace cli
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -35,6 +37,12 @@ enum Commands {
|
||||
/// Trigger `boot-complete` event
|
||||
BootCompleted,
|
||||
|
||||
/// Susfs
|
||||
Susfs {
|
||||
#[command(subcommand)]
|
||||
command: Susfs,
|
||||
},
|
||||
|
||||
/// Install KernelSU userspace component to system
|
||||
Install {
|
||||
#[arg(long, default_value = None)]
|
||||
@@ -432,6 +440,16 @@ mod kpm_cmd {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(clap::Subcommand, Debug)]
|
||||
enum Susfs {
|
||||
/// Get SUSFS Status
|
||||
Status,
|
||||
/// Get SUSFS Version
|
||||
Version,
|
||||
/// Get SUSFS enable Features
|
||||
Features,
|
||||
}
|
||||
|
||||
#[derive(clap::Subcommand, Debug)]
|
||||
enum Umount {
|
||||
/// Add custom umount path
|
||||
@@ -496,7 +514,16 @@ pub fn run() -> Result<()> {
|
||||
init_event::on_boot_completed();
|
||||
Ok(())
|
||||
}
|
||||
Commands::Susfs { command } => {
|
||||
match command {
|
||||
Susfs::Version => println!("{}", susfs::get_susfs_version()),
|
||||
|
||||
Susfs::Status => println!("{}", susfs::get_susfs_status()),
|
||||
|
||||
Susfs::Features => println!("{}", susfs::get_susfs_features()),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Commands::Module { command } => {
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@ mod profile;
|
||||
mod restorecon;
|
||||
mod sepolicy;
|
||||
mod su;
|
||||
mod susfs;
|
||||
#[cfg(target_os = "android")]
|
||||
mod uid_scanner;
|
||||
mod umount_manager;
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
use anyhow::{Context, Ok, Result, bail};
|
||||
use getopts::Options;
|
||||
use libc::c_int;
|
||||
use log::{error, warn};
|
||||
use log::error;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::{
|
||||
@@ -75,7 +75,6 @@ fn set_identity(uid: u32, gid: u32, groups: &[u32]) {
|
||||
fn wrap_tty(fd: c_int) {
|
||||
let inner_fn = move || -> Result<()> {
|
||||
if unsafe { libc::isatty(fd) != 1 } {
|
||||
warn!("not a tty: {fd}");
|
||||
return Ok(());
|
||||
}
|
||||
let new_fd = get_wrapped_fd(fd).context("get_wrapped_fd")?;
|
||||
|
||||
79
userspace/ksud/src/susfs.rs
Normal file
79
userspace/ksud/src/susfs.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
#![allow(clippy::unreadable_literal)]
|
||||
use libc::SYS_reboot;
|
||||
|
||||
const SUSFS_MAX_VERSION_BUFSIZE: usize = 16;
|
||||
const SUSFS_ENABLED_FEATURES_SIZE: usize = 8192;
|
||||
const ERR_CMD_NOT_SUPPORTED: i32 = 126;
|
||||
const KSU_INSTALL_MAGIC1: u32 = 0xDEADBEEF;
|
||||
const CMD_SUSFS_SHOW_VERSION: u32 = 0x555e1;
|
||||
const CMD_SUSFS_SHOW_ENABLED_FEATURES: u32 = 0x555e2;
|
||||
const SUSFS_MAGIC: u32 = 0xFAFAFAFA;
|
||||
|
||||
#[repr(C)]
|
||||
struct SusfsVersion {
|
||||
susfs_version: [u8; SUSFS_MAX_VERSION_BUFSIZE],
|
||||
err: i32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct SusfsFeatures {
|
||||
enabled_features: [u8; SUSFS_ENABLED_FEATURES_SIZE],
|
||||
err: i32,
|
||||
}
|
||||
|
||||
pub fn get_susfs_version() -> String {
|
||||
let mut cmd = SusfsVersion {
|
||||
susfs_version: [0; SUSFS_MAX_VERSION_BUFSIZE],
|
||||
err: ERR_CMD_NOT_SUPPORTED,
|
||||
};
|
||||
|
||||
let ret = unsafe {
|
||||
libc::syscall(
|
||||
SYS_reboot,
|
||||
KSU_INSTALL_MAGIC1,
|
||||
SUSFS_MAGIC,
|
||||
CMD_SUSFS_SHOW_VERSION,
|
||||
&mut cmd,
|
||||
)
|
||||
};
|
||||
|
||||
if ret < 0 {
|
||||
return "unsupport".to_string();
|
||||
}
|
||||
|
||||
let ver = cmd.susfs_version.iter().position(|&b| b == 0).unwrap_or(16);
|
||||
String::from_utf8(cmd.susfs_version[..ver].to_vec()).unwrap_or_else(|_| "<invalid>".to_string())
|
||||
}
|
||||
|
||||
pub fn get_susfs_status() -> bool {
|
||||
get_susfs_version() != "unsupport"
|
||||
}
|
||||
|
||||
pub fn get_susfs_features() -> String {
|
||||
let mut cmd = SusfsFeatures {
|
||||
enabled_features: [0; SUSFS_ENABLED_FEATURES_SIZE],
|
||||
err: ERR_CMD_NOT_SUPPORTED,
|
||||
};
|
||||
|
||||
let ret = unsafe {
|
||||
libc::syscall(
|
||||
SYS_reboot,
|
||||
KSU_INSTALL_MAGIC1,
|
||||
SUSFS_MAGIC,
|
||||
CMD_SUSFS_SHOW_ENABLED_FEATURES,
|
||||
&mut cmd,
|
||||
)
|
||||
};
|
||||
|
||||
if ret < 0 {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
let features = cmd
|
||||
.enabled_features
|
||||
.iter()
|
||||
.position(|&b| b == 0)
|
||||
.unwrap_or(16);
|
||||
String::from_utf8(cmd.enabled_features[..features].to_vec())
|
||||
.unwrap_or_else(|_| "<invalid>".to_string())
|
||||
}
|
||||
Reference in New Issue
Block a user