-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update-deps
- Loading branch information
Showing
11 changed files
with
133 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-FileCopyrightText: 2023 The MalwareTracesGenerator development team | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pub mod generate; | ||
pub mod traces; | ||
|
||
use crate::commands::{generate::Generate, traces::Traces}; | ||
use clap::{Parser, Subcommand}; | ||
use std::error::Error; | ||
|
||
#[derive(Parser)] | ||
#[clap(author, version)] | ||
#[clap(arg_required_else_help = true)] | ||
pub struct Arguments { | ||
#[clap(subcommand)] | ||
pub command: Command, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
pub enum Command { | ||
Traces(Traces), | ||
Generate(Generate), | ||
} | ||
|
||
pub trait Runnable { | ||
fn run(&self) -> Result<(), Box<dyn Error>>; | ||
} | ||
|
||
impl Runnable for Arguments { | ||
fn run(&self) -> Result<(), Box<dyn Error>> { | ||
match &self.command { | ||
Command::Traces(traces) => traces as &dyn Runnable, | ||
Command::Generate(generate) => generate, | ||
} | ||
.run() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-FileCopyrightText: 2023 The MalwareTracesGenerator development team | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
use crate::commands::{traces::Traces, Runnable}; | ||
use clap::Parser; | ||
use serde::Deserialize; | ||
use std::{error::Error, fs::read_to_string, path::PathBuf}; | ||
use toml::from_str; | ||
|
||
#[derive(Deserialize)] | ||
struct Configuration { | ||
metadata: Metadata, | ||
traces: Vec<Traces>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct Metadata { | ||
name: String, | ||
version: String, | ||
references: Vec<String>, | ||
authors: Option<Vec<Author>>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct Author { | ||
name: String, | ||
email: Option<String>, | ||
} | ||
|
||
#[derive(Parser)] | ||
pub struct Generate { | ||
#[clap(required = true, help = "Path to the configuration file")] | ||
path: PathBuf, | ||
} | ||
|
||
impl Runnable for Generate { | ||
fn run(&self) -> Result<(), Box<dyn Error>> { | ||
if !self.path.try_exists()? || !self.path.is_file() { | ||
return Ok(()); | ||
} | ||
|
||
let configuration: Configuration = from_str(read_to_string(self.path.clone())?.as_str())?; | ||
|
||
for trace in configuration.traces { | ||
trace.run()?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters