ksud: migrate to Rust 2024 edition
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ksud"
|
name = "ksud"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{ensure, Result};
|
use anyhow::{Result, ensure};
|
||||||
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::{copy, File};
|
use std::fs::{File, copy};
|
||||||
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")?;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{ensure, Context, Ok, Result};
|
use anyhow::{Context, Ok, Result, ensure};
|
||||||
use std::{
|
use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{Context, Result, bail};
|
||||||
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::{anyhow, bail, ensure, Context, Result};
|
use anyhow::{Context, Result, anyhow, bail, ensure};
|
||||||
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::OpenOptions;
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
env::var as env_var,
|
env::var as env_var,
|
||||||
fs::{remove_dir_all, remove_file, set_permissions, File, Permissions},
|
fs::{File, Permissions, remove_dir_all, remove_file, set_permissions},
|
||||||
io::Cursor,
|
io::Cursor,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
@@ -672,12 +672,15 @@ fn _list_modules(path: &str) -> Vec<HashMap<String, String>> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if !module_prop_map.contains_key("id") || module_prop_map["id"].is_empty() {
|
if !module_prop_map.contains_key("id") || module_prop_map["id"].is_empty() {
|
||||||
if let Some(id) = entry.file_name().to_str() {
|
match entry.file_name().to_str() {
|
||||||
info!("Use dir name as module id: {}", id);
|
Some(id) => {
|
||||||
module_prop_map.insert("id".to_owned(), id.to_owned());
|
info!("Use dir name as module id: {}", id);
|
||||||
} else {
|
module_prop_map.insert("id".to_owned(), id.to_owned());
|
||||||
info!("Failed to get module id: {:?}", module_prop);
|
}
|
||||||
continue;
|
_ => {
|
||||||
|
info!("Failed to get module id: {:?}", module_prop);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{anyhow, bail, Ok, Result};
|
use anyhow::{Ok, Result, anyhow, bail};
|
||||||
|
|
||||||
#[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::{lsetxattr, Flags as XattrFlags};
|
use extattr::{Flags as XattrFlags, lsetxattr};
|
||||||
|
|
||||||
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::{bail, Result};
|
use anyhow::{Result, bail};
|
||||||
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_while1, take_while_m_n},
|
bytes::complete::{tag, take_while, take_while_m_n, take_while1},
|
||||||
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::{set_thread_res_gid, set_thread_res_uid, Gid, Uid},
|
thread::{Gid, Uid, set_thread_res_gid, set_thread_res_uid},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
@@ -280,6 +280,6 @@ fn add_path_to_env(path: &str) -> Result<()> {
|
|||||||
let new_path = PathBuf::from(path.trim_end_matches('/'));
|
let new_path = PathBuf::from(path.trim_end_matches('/'));
|
||||||
paths.push(new_path);
|
paths.push(new_path);
|
||||||
let new_path_env = env::join_paths(paths)?;
|
let new_path_env = env::join_paths(paths)?;
|
||||||
env::set_var("PATH", new_path_env);
|
unsafe { env::set_var("PATH", new_path_env) };
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use anyhow::{bail, Context, Error, Ok, Result};
|
use anyhow::{Context, Error, Ok, Result, bail};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{create_dir_all, remove_file, write, File, OpenOptions},
|
fs::{File, OpenOptions, create_dir_all, remove_file, write},
|
||||||
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::{set_permissions, Permissions};
|
use std::fs::{Permissions, set_permissions};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::prelude::PermissionsExt;
|
use std::os::unix::prelude::PermissionsExt;
|
||||||
|
|
||||||
@@ -24,7 +24,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::{move_into_link_name_space, LinkNameSpaceType},
|
thread::{LinkNameSpaceType, move_into_link_name_space},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn ensure_clean_dir(dir: impl AsRef<Path>) -> Result<()> {
|
pub fn ensure_clean_dir(dir: impl AsRef<Path>) -> Result<()> {
|
||||||
@@ -129,7 +129,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::{open, Mode, OFlags},
|
fs::{Mode, OFlags, open},
|
||||||
};
|
};
|
||||||
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