Skip to content

Commit

Permalink
Revert "ksud: try parse kmi from gki modules if uname is modified"
Browse files Browse the repository at this point in the history
This reverts commit f41d73f.

Signed-off-by: xiangfeidexiaohuo <[email protected]>
  • Loading branch information
xiangfeidexiaohuo committed Aug 23, 2024
1 parent 93c8c0a commit 4133b90
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions userspace/ksud/src/boot_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,48 +51,21 @@ pub fn get_kernel_version() -> Result<(i32, i32, i32)> {
}

#[cfg(target_os = "android")]
fn parse_kmi(version: &str) -> Result<String> {

fn parse_kmi() -> Result<String> {
let uname = rustix::system::uname();
let version = uname.release().to_string_lossy();
let re = Regex::new(r"(.* )?(\d+\.\d+)(\S+)?(android\d+)(.*)")?;
let cap = re
.captures(version)
.captures(&version)
.ok_or_else(|| anyhow::anyhow!("Failed to get KMI from boot/modules"))?;
let android_version = cap.get(4).map_or("", |m| m.as_str());
let kernel_version = cap.get(2).map_or("", |m| m.as_str());
Ok(format!("{android_version}-{kernel_version}"))
}

#[cfg(target_os = "android")]
fn parse_kmi_from_uname() -> Result<String> {
let uname = rustix::system::uname();
let version = uname.release().to_string_lossy();
parse_kmi(&version)
}

#[cfg(target_os = "android")]
fn parse_kmi_from_modules() -> Result<String> {
use std::io::BufRead;
// find a *.ko in /vendor/lib/modules
let modfile = std::fs::read_dir("/vendor/lib/modules")?
.filter_map(Result::ok)
.find(|entry| entry.path().extension().map_or(false, |ext| ext == "ko"))
.map(|entry| entry.path())
.ok_or_else(|| anyhow!("No kernel module found"))?;
let output = Command::new("modinfo").arg(modfile).output()?;
for line in output.stdout.lines().map_while(Result::ok) {
if line.starts_with("vermagic") {
return parse_kmi(&line);
}
}
anyhow::bail!("Parse KMI from modules failed")
}

#[cfg(target_os = "android")]
pub fn get_current_kmi() -> Result<String> {
parse_kmi_from_uname().or_else(|_| parse_kmi_from_modules())
}

#[cfg(not(target_os = "android"))]
pub fn get_current_kmi() -> Result<String> {
pub fn parse_kmi() -> Result<String> {
bail!("Unsupported platform")
}

Expand Down

0 comments on commit 4133b90

Please sign in to comment.