You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
ksud: rust FMT
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{Result, ensure};
|
use anyhow::{ensure, Result};
|
||||||
use std::io::{Read, Seek, SeekFrom};
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
|
|
||||||
pub fn get_apk_signature(apk: &str) -> Result<(u32, String)> {
|
pub fn get_apk_signature(apk: &str) -> Result<(u32, String)> {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ use std::path::PathBuf;
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use anyhow::Result;
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use anyhow::ensure;
|
use anyhow::ensure;
|
||||||
|
use anyhow::Context;
|
||||||
|
use anyhow::Result;
|
||||||
use regex_lite::Regex;
|
use regex_lite::Regex;
|
||||||
use which::which;
|
use which::which;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ pub fn get_current_kmi() -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result<String> {
|
fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result<String> {
|
||||||
use std::fs::{File, copy};
|
use std::fs::{copy, File};
|
||||||
use std::io::{BufReader, Read};
|
use std::io::{BufReader, Read};
|
||||||
let kernel_path = workdir.join("kernel");
|
let kernel_path = workdir.join("kernel");
|
||||||
copy(kernel, &kernel_path).context("Failed to copy kernel")?;
|
copy(kernel, &kernel_path).context("Failed to copy kernel")?;
|
||||||
@@ -200,11 +200,7 @@ fn is_magisk_patched_vendor(magiskboot: &Path, workdir: &Path) -> Result<bool> {
|
|||||||
.current_dir(workdir)
|
.current_dir(workdir)
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
.args([
|
.args(["cpio", vendor_ramdisk_cpio.to_str().unwrap(), "test"])
|
||||||
"cpio",
|
|
||||||
vendor_ramdisk_cpio.to_str().unwrap(),
|
|
||||||
"test",
|
|
||||||
])
|
|
||||||
.status()?;
|
.status()?;
|
||||||
|
|
||||||
// 0: stock, 1: magisk
|
// 0: stock, 1: magisk
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{Context, Ok, Result, ensure};
|
use anyhow::{ensure, Context, Ok, Result};
|
||||||
use std::{
|
use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::module::{handle_updated_modules, prune_modules};
|
|||||||
use crate::{assets, defs, ksucalls, restorecon, utils};
|
use crate::{assets, defs, ksucalls, restorecon, utils};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use rustix::fs::{MountFlags, mount};
|
use rustix::fs::{mount, MountFlags};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn on_post_data_fs() -> Result<()> {
|
pub fn on_post_data_fs() -> Result<()> {
|
||||||
|
|||||||
@@ -4,20 +4,20 @@ use crate::defs::{
|
|||||||
use crate::magic_mount::NodeFileType::{Directory, RegularFile, Symlink, Whiteout};
|
use crate::magic_mount::NodeFileType::{Directory, RegularFile, Symlink, Whiteout};
|
||||||
use crate::restorecon::{lgetfilecon, lsetfilecon};
|
use crate::restorecon::{lgetfilecon, lsetfilecon};
|
||||||
use crate::utils::ensure_dir_exists;
|
use crate::utils::ensure_dir_exists;
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{bail, Context, Result};
|
||||||
use extattr::lgetxattr;
|
use extattr::lgetxattr;
|
||||||
use rustix::fs::{
|
use rustix::fs::{
|
||||||
Gid, MetadataExt, Mode, MountFlags, MountPropagationFlags, Uid, UnmountFlags, bind_mount,
|
bind_mount, chmod, chown, mount, move_mount, unmount, Gid, MetadataExt, Mode, MountFlags,
|
||||||
chmod, chown, mount, move_mount, unmount,
|
MountPropagationFlags, Uid, UnmountFlags,
|
||||||
};
|
};
|
||||||
use rustix::mount::mount_change;
|
use rustix::mount::mount_change;
|
||||||
use rustix::path::Arg;
|
use rustix::path::Arg;
|
||||||
use std::cmp::PartialEq;
|
use std::cmp::PartialEq;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::{DirEntry, FileType, create_dir, create_dir_all, read_dir, read_link};
|
use std::fs::{create_dir, create_dir_all, read_dir, read_link, DirEntry, FileType};
|
||||||
use std::os::unix::fs::{FileTypeExt, symlink};
|
use std::os::unix::fs::{symlink, FileTypeExt};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
const REPLACE_DIR_XATTR: &str = "trusted.overlay.opaque";
|
const REPLACE_DIR_XATTR: &str = "trusted.overlay.opaque";
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::{
|
|||||||
sepolicy,
|
sepolicy,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result, anyhow, bail, ensure};
|
use anyhow::{anyhow, bail, ensure, Context, Result};
|
||||||
use const_format::concatcp;
|
use const_format::concatcp;
|
||||||
use is_executable::is_executable;
|
use is_executable::is_executable;
|
||||||
use java_properties::PropertiesIter;
|
use java_properties::PropertiesIter;
|
||||||
@@ -16,7 +16,7 @@ use std::fs::{copy, rename};
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
env::var as env_var,
|
env::var as env_var,
|
||||||
fs::{File, Permissions, remove_dir_all, remove_file, set_permissions},
|
fs::{remove_dir_all, remove_file, set_permissions, File, Permissions},
|
||||||
io::Cursor,
|
io::Cursor,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::path::Path;
|
|||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use anyhow::{Context, Ok};
|
use anyhow::{Context, Ok};
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use extattr::{Flags as XattrFlags, lsetxattr};
|
use extattr::{lsetxattr, Flags as XattrFlags};
|
||||||
|
|
||||||
pub const SYSTEM_CON: &str = "u:object_r:system_file:s0";
|
pub const SYSTEM_CON: &str = "u:object_r:system_file:s0";
|
||||||
pub const ADB_CON: &str = "u:object_r:adb_data_file:s0";
|
pub const ADB_CON: &str = "u:object_r:adb_data_file:s0";
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use anyhow::{Result, bail};
|
use anyhow::{bail, Result};
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use nom::{
|
use nom::{
|
||||||
AsChar, IResult, Parser,
|
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::{tag, take_while, take_while_m_n, take_while1},
|
bytes::complete::{tag, take_while, take_while1, take_while_m_n},
|
||||||
character::complete::{space0, space1},
|
character::complete::{space0, space1},
|
||||||
combinator::map,
|
combinator::map,
|
||||||
|
AsChar, IResult, Parser,
|
||||||
};
|
};
|
||||||
use std::{ffi, path::Path, vec};
|
use std::{ffi, path::Path, vec};
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use crate::{
|
|||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use rustix::{
|
use rustix::{
|
||||||
process::getuid,
|
process::getuid,
|
||||||
thread::{Gid, Uid, set_thread_res_gid, set_thread_res_uid},
|
thread::{set_thread_res_gid, set_thread_res_uid, Gid, Uid},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use anyhow::{Context, Error, Ok, Result, bail};
|
use anyhow::{bail, Context, Error, Ok, Result};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{File, OpenOptions, create_dir_all, remove_file, write},
|
fs::{create_dir_all, remove_file, write, File, OpenOptions},
|
||||||
io::{
|
io::{
|
||||||
ErrorKind::{AlreadyExists, NotFound},
|
ErrorKind::{AlreadyExists, NotFound},
|
||||||
Write,
|
Write,
|
||||||
@@ -11,7 +11,7 @@ use std::{
|
|||||||
|
|
||||||
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
|
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use std::fs::{Permissions, set_permissions};
|
use std::fs::{set_permissions, Permissions};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::prelude::PermissionsExt;
|
use std::os::unix::prelude::PermissionsExt;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ use std::path::PathBuf;
|
|||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use rustix::{
|
use rustix::{
|
||||||
process,
|
process,
|
||||||
thread::{LinkNameSpaceType, move_into_link_name_space},
|
thread::{move_into_link_name_space, LinkNameSpaceType},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn ensure_clean_dir(dir: impl AsRef<Path>) -> Result<()> {
|
pub fn ensure_clean_dir(dir: impl AsRef<Path>) -> Result<()> {
|
||||||
@@ -125,7 +125,7 @@ pub fn get_zip_uncompressed_size(zip_path: &str) -> Result<u64> {
|
|||||||
pub fn switch_mnt_ns(pid: i32) -> Result<()> {
|
pub fn switch_mnt_ns(pid: i32) -> Result<()> {
|
||||||
use rustix::{
|
use rustix::{
|
||||||
fd::AsFd,
|
fd::AsFd,
|
||||||
fs::{Mode, OFlags, open},
|
fs::{open, Mode, OFlags},
|
||||||
};
|
};
|
||||||
let path = format!("/proc/{pid}/ns/mnt");
|
let path = format!("/proc/{pid}/ns/mnt");
|
||||||
let fd = open(path, OFlags::RDONLY, Mode::from_raw_mode(0))?;
|
let fd = open(path, OFlags::RDONLY, Mode::from_raw_mode(0))?;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{Result, ensure};
|
use anyhow::{ensure, Result};
|
||||||
use std::io::{Read, Seek, SeekFrom};
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
|
|
||||||
pub fn get_apk_signature(apk: &str) -> Result<(u32, String)> {
|
pub fn get_apk_signature(apk: &str) -> Result<(u32, String)> {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ use std::path::PathBuf;
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use anyhow::Result;
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use anyhow::ensure;
|
use anyhow::ensure;
|
||||||
|
use anyhow::Context;
|
||||||
|
use anyhow::Result;
|
||||||
use regex_lite::Regex;
|
use regex_lite::Regex;
|
||||||
use which::which;
|
use which::which;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ pub fn get_current_kmi() -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result<String> {
|
fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result<String> {
|
||||||
use std::fs::{File, copy};
|
use std::fs::{copy, File};
|
||||||
use std::io::{BufReader, Read};
|
use std::io::{BufReader, Read};
|
||||||
let kernel_path = workdir.join("kernel");
|
let kernel_path = workdir.join("kernel");
|
||||||
copy(kernel, &kernel_path).context("Failed to copy kernel")?;
|
copy(kernel, &kernel_path).context("Failed to copy kernel")?;
|
||||||
@@ -200,11 +200,7 @@ fn is_magisk_patched_vendor(magiskboot: &Path, workdir: &Path) -> Result<bool> {
|
|||||||
.current_dir(workdir)
|
.current_dir(workdir)
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
.args([
|
.args(["cpio", vendor_ramdisk_cpio.to_str().unwrap(), "test"])
|
||||||
"cpio",
|
|
||||||
vendor_ramdisk_cpio.to_str().unwrap(),
|
|
||||||
"test",
|
|
||||||
])
|
|
||||||
.status()?;
|
.status()?;
|
||||||
|
|
||||||
// 0: stock, 1: magisk
|
// 0: stock, 1: magisk
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{Context, Ok, Result, ensure};
|
use anyhow::{ensure, Context, Ok, Result};
|
||||||
use std::{
|
use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{bail, Context, Result};
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use std::{collections::HashMap, path::Path};
|
use std::{collections::HashMap, path::Path};
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::{
|
|||||||
sepolicy, utils,
|
sepolicy, utils,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result, anyhow, bail, ensure};
|
use anyhow::{anyhow, bail, ensure, Context, Result};
|
||||||
use const_format::concatcp;
|
use const_format::concatcp;
|
||||||
use is_executable::is_executable;
|
use is_executable::is_executable;
|
||||||
use java_properties::PropertiesIter;
|
use java_properties::PropertiesIter;
|
||||||
@@ -18,7 +18,7 @@ use std::io;
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
env::var as env_var,
|
env::var as env_var,
|
||||||
fs::{File, Permissions, remove_dir_all, remove_file, set_permissions},
|
fs::{remove_dir_all, remove_file, set_permissions, File, Permissions},
|
||||||
io::Cursor,
|
io::Cursor,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{Ok, Result, anyhow, bail};
|
use anyhow::{anyhow, bail, Ok, Result};
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::path::Path;
|
|||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use anyhow::{Context, Ok};
|
use anyhow::{Context, Ok};
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use extattr::{Flags as XattrFlags, lsetxattr};
|
use extattr::{lsetxattr, Flags as XattrFlags};
|
||||||
|
|
||||||
pub const SYSTEM_CON: &str = "u:object_r:system_file:s0";
|
pub const SYSTEM_CON: &str = "u:object_r:system_file:s0";
|
||||||
pub const ADB_CON: &str = "u:object_r:adb_data_file:s0";
|
pub const ADB_CON: &str = "u:object_r:adb_data_file:s0";
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use anyhow::{Result, bail};
|
use anyhow::{bail, Result};
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use nom::{
|
use nom::{
|
||||||
AsChar, IResult, Parser,
|
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::{tag, take_while, take_while_m_n, take_while1},
|
bytes::complete::{tag, take_while, take_while1, take_while_m_n},
|
||||||
character::complete::{space0, space1},
|
character::complete::{space0, space1},
|
||||||
combinator::map,
|
combinator::map,
|
||||||
|
AsChar, IResult, Parser,
|
||||||
};
|
};
|
||||||
use std::{ffi, path::Path, vec};
|
use std::{ffi, path::Path, vec};
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use crate::{
|
|||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use rustix::{
|
use rustix::{
|
||||||
process::getuid,
|
process::getuid,
|
||||||
thread::{Gid, Uid, set_thread_res_gid, set_thread_res_uid},
|
thread::{set_thread_res_gid, set_thread_res_uid, Gid, Uid},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use anyhow::{Context, Error, Ok, Result, bail};
|
use anyhow::{bail, Context, Error, Ok, Result};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, File, OpenOptions, create_dir_all, remove_file, write},
|
fs::{self, create_dir_all, remove_file, write, File, OpenOptions},
|
||||||
io::{
|
io::{
|
||||||
ErrorKind::{AlreadyExists, NotFound},
|
ErrorKind::{AlreadyExists, NotFound},
|
||||||
Write,
|
Write,
|
||||||
@@ -13,7 +13,7 @@ use std::{
|
|||||||
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
|
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
|
||||||
use std::fs::metadata;
|
use std::fs::metadata;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use std::fs::{Permissions, set_permissions};
|
use std::fs::{set_permissions, Permissions};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::prelude::PermissionsExt;
|
use std::os::unix::prelude::PermissionsExt;
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ use std::path::PathBuf;
|
|||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use rustix::{
|
use rustix::{
|
||||||
process,
|
process,
|
||||||
thread::{LinkNameSpaceType, move_into_link_name_space},
|
thread::{move_into_link_name_space, LinkNameSpaceType},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn ensure_clean_dir(dir: impl AsRef<Path>) -> Result<()> {
|
pub fn ensure_clean_dir(dir: impl AsRef<Path>) -> Result<()> {
|
||||||
@@ -131,7 +131,7 @@ pub fn get_zip_uncompressed_size(zip_path: &str) -> Result<u64> {
|
|||||||
pub fn switch_mnt_ns(pid: i32) -> Result<()> {
|
pub fn switch_mnt_ns(pid: i32) -> Result<()> {
|
||||||
use rustix::{
|
use rustix::{
|
||||||
fd::AsFd,
|
fd::AsFd,
|
||||||
fs::{Mode, OFlags, open},
|
fs::{open, Mode, OFlags},
|
||||||
};
|
};
|
||||||
let path = format!("/proc/{pid}/ns/mnt");
|
let path = format!("/proc/{pid}/ns/mnt");
|
||||||
let fd = open(path, OFlags::RDONLY, Mode::from_raw_mode(0))?;
|
let fd = open(path, OFlags::RDONLY, Mode::from_raw_mode(0))?;
|
||||||
|
|||||||
Reference in New Issue
Block a user