Add support for specifying memflow OS name

This commit is contained in:
a2x 2024-03-29 23:11:34 +10:00
parent 4bf54462ac
commit ce25283e79
2 changed files with 29 additions and 16 deletions

View File

@ -31,7 +31,8 @@ E.g. `cs2-dumper.exe -c pcileech -a device=fpga -vvv`
- `-v...`: Increase logging verbosity. Can be specified multiple times. - `-v...`: Increase logging verbosity. Can be specified multiple times.
- `-c, --connector <connector>`: The name of the memflow connector to use. - `-c, --connector <connector>`: The name of the memflow connector to use.
- `-a, --connector-args <connector-args>`: Additional arguments to supply to the connector. - `-a, --connector-args <connector-args>`: Additional arguments to supply to the connector.
- `-o, --output <output>`: The output directory to write the generated files to. Default: `output`. - `-o, --os <os>`: The name of the target operating system.
- `-d, --directory <directory>`: The output directory to write the generated files to. Default: `output`.
- `-i, --indent-size <indent-size>`: The number of spaces to use per indentation level. Default: `4`. - `-i, --indent-size <indent-size>`: The number of spaces to use per indentation level. Default: `4`.
- `-h, --help`: Print help. - `-h, --help`: Print help.
- `-V, --version`: Print version. - `-V, --version`: Print version.

View File

@ -26,7 +26,7 @@ fn main() -> Result<()> {
let start_time = Instant::now(); let start_time = Instant::now();
let matches = parse_args(); let matches = parse_args();
let (conn_name, conn_args, indent_size, out_dir) = extract_args(&matches)?; let (conn_name, conn_args, os_name, indent_size, out_dir) = extract_args(&matches)?;
// Create the output directory if it doesn't exist. // Create the output directory if it doesn't exist.
fs::create_dir_all(&out_dir)?; fs::create_dir_all(&out_dir)?;
@ -34,17 +34,11 @@ fn main() -> Result<()> {
let os = if let Some(conn_name) = conn_name { let os = if let Some(conn_name) = conn_name {
let inventory = Inventory::scan(); let inventory = Inventory::scan();
let os_name = match env::consts::OS {
"linux" => "linux",
"windows" => "win32",
_ => panic!("unsupported os"),
};
inventory inventory
.builder() .builder()
.connector(&conn_name) .connector(&conn_name)
.args(conn_args) .args(conn_args)
.os(os_name) .os(&os_name)
.build()? .build()?
} else { } else {
// Fallback to the native OS layer if no connector name was provided. // Fallback to the native OS layer if no connector name was provided.
@ -92,10 +86,17 @@ fn parse_args() -> ArgMatches {
.required(false), .required(false),
) )
.arg( .arg(
Arg::new("output") Arg::new("os")
.help("The output directory to write the generated files to.") .help("The name of the target operating system.")
.long("output") .long("os")
.short('o') .short('o')
.required(false),
)
.arg(
Arg::new("directory")
.help("The output directory to write the generated files to.")
.long("directory")
.short('d')
.default_value("output") .default_value("output")
.value_parser(value_parser!(PathBuf)) .value_parser(value_parser!(PathBuf))
.required(false), .required(false),
@ -112,7 +113,9 @@ fn parse_args() -> ArgMatches {
.get_matches() .get_matches()
} }
fn extract_args(matches: &ArgMatches) -> Result<(Option<String>, ConnectorArgs, usize, &PathBuf)> { fn extract_args(
matches: &ArgMatches,
) -> Result<(Option<String>, ConnectorArgs, String, usize, &PathBuf)> {
use std::str::FromStr; use std::str::FromStr;
let log_level = match matches.get_count("verbose") { let log_level = match matches.get_count("verbose") {
@ -141,8 +144,17 @@ fn extract_args(matches: &ArgMatches) -> Result<(Option<String>, ConnectorArgs,
.map(|s| ConnectorArgs::from_str(&s).expect("unable to parse connector arguments")) .map(|s| ConnectorArgs::from_str(&s).expect("unable to parse connector arguments"))
.unwrap_or_default(); .unwrap_or_default();
let indent_size = *matches.get_one::<usize>("indent-size").unwrap(); let os_name = matches
let out_dir = matches.get_one::<PathBuf>("output").unwrap(); .get_one::<String>("os")
.map(|s| s.to_string())
.unwrap_or_else(|| match env::consts::OS {
"linux" => "linux".to_string(),
"windows" => "win32".to_string(),
_ => panic!("unsupported os"),
});
Ok((conn_name, conn_args, indent_size, out_dir)) let indent_size = *matches.get_one::<usize>("indent-size").unwrap();
let out_dir = matches.get_one::<PathBuf>("directory").unwrap();
Ok((conn_name, conn_args, os_name, indent_size, out_dir))
} }