mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-04-27 16:09:58 -07:00
fix(lib/util): use better names for runtime metadata
- document RuntimeMetadata fields - rename RayhunterMetadata to RuntimeMetadata - rename RuntimeMetadata.os to RuntimeMetadata.system_os - remove unpopulated hardware field - remove unnecessary duplication of datastructure in analyzer harness
This commit is contained in:
committed by
Will Greenberg
parent
188e9f436b
commit
0b3c0de481
@@ -1,34 +1,36 @@
|
||||
use nix::sys::utsname::uname;
|
||||
use serde::Serialize;
|
||||
|
||||
/// Expose binary and system information.
|
||||
pub struct RayhunterMetadata {
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub os: String,
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct RuntimeMetadata {
|
||||
/// The cargo package version from this library's cargo.toml, e.g., "1.2.3".
|
||||
pub rayhunter_version: String,
|
||||
/// The operating system `sysname` and optionally `release`. e.g., "Linux 3.18.48" or "linux".
|
||||
pub system_os: String,
|
||||
/// The CPU architecture in use. e.g., "armv7l" or "arm".
|
||||
pub arch: String,
|
||||
pub hardware: String,
|
||||
}
|
||||
|
||||
impl RayhunterMetadata {
|
||||
impl RuntimeMetadata {
|
||||
/// Return the binary and system information, attempting to retrieve
|
||||
/// attributes from `uname(2)` and falling back to values from
|
||||
/// `std::env::consts`.
|
||||
pub fn new() -> Self {
|
||||
match uname() {
|
||||
Ok(utsname) => RayhunterMetadata {
|
||||
name: env!("CARGO_PKG_NAME").to_owned(),
|
||||
version: env!("CARGO_PKG_VERSION").to_owned(),
|
||||
Ok(utsname) => RuntimeMetadata {
|
||||
rayhunter_version: env!("CARGO_PKG_VERSION").to_owned(),
|
||||
arch: format!("{}", utsname.machine().to_string_lossy()),
|
||||
os: format!(
|
||||
system_os: format!(
|
||||
"{} {}",
|
||||
utsname.sysname().to_string_lossy(),
|
||||
utsname.release().to_string_lossy(),
|
||||
),
|
||||
hardware: String::from("unknown"),
|
||||
},
|
||||
Err(_) => RayhunterMetadata {
|
||||
name: env!("CARGO_PKG_NAME").to_owned(),
|
||||
version: env!("CARGO_PKG_VERSION").to_owned(),
|
||||
Err(_) => RuntimeMetadata {
|
||||
rayhunter_version: env!("CARGO_PKG_VERSION").to_owned(),
|
||||
arch: std::env::consts::ARCH.to_string(),
|
||||
os: std::env::consts::OS.to_string(),
|
||||
hardware: String::from("unknown"),
|
||||
system_os: std::env::consts::OS.to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user