-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the config structures and loading to a separate module, so that it can be used by each command. Pass the "fmt" section of the config to the "fmt" command. As we add support for other commands to use the config file we can easily pass their sub-structure into the command. Load the config file from %{HOME}/.yara-x.toml - or whatever the corresponding location is on Windows. The exact format of the config is still to be documented, but now that it is generic and not specific to formatting I've moved the docs to a new file that is more appropriately named.
- Loading branch information
Showing
11 changed files
with
119 additions
and
71 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 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
File renamed without changes.
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
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,75 @@ | ||
use figment::{ | ||
providers::{Format, Serialized, Toml}, | ||
Figment, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::path::PathBuf; | ||
|
||
/// Configuration structure for "yr" commands. | ||
#[derive(Deserialize, Serialize, Debug)] | ||
pub struct Config { | ||
/// Format specific configuration information. | ||
pub fmt: FormatConfig, | ||
} | ||
|
||
/// Format specific configuration information. | ||
#[derive(Deserialize, Serialize, Debug)] | ||
pub struct FormatConfig { | ||
/// Rule specific formatting information. | ||
pub rule: Rule, | ||
/// Meta specific formatting information. | ||
pub meta: Meta, | ||
/// Pattern specific formatting information. | ||
pub patterns: Patterns, | ||
} | ||
|
||
/// Rule specific formatting information. | ||
#[derive(Deserialize, Serialize, Debug)] | ||
pub struct Rule { | ||
/// Indent section headers (meta, strings, condition). | ||
pub indent_section_headers: bool, | ||
/// Indent section contents one level past section headers. | ||
pub indent_section_contents: bool, | ||
} | ||
|
||
/// Meta specific formatting information. | ||
#[derive(Deserialize, Serialize, Debug)] | ||
pub struct Meta { | ||
/// Align values to longest key. | ||
pub align_values: bool, | ||
} | ||
|
||
/// Pattern specific formatting information. | ||
#[derive(Deserialize, Serialize, Debug)] | ||
pub struct Patterns { | ||
/// Align patterns to longest name. | ||
pub align_values: bool, | ||
} | ||
|
||
impl Default for Config { | ||
fn default() -> Config { | ||
Config { | ||
fmt: FormatConfig { | ||
rule: Rule { | ||
indent_section_headers: true, | ||
indent_section_contents: true, | ||
}, | ||
meta: Meta { align_values: true }, | ||
patterns: Patterns { align_values: true }, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
/// Load config file from a given path. Path must contain a valid TOML file or | ||
/// this function will propagate the error. For structure of the config file | ||
/// see "YARA-X Config Guide.md". | ||
pub fn load_config_from_file( | ||
config_file: &PathBuf, | ||
) -> Result<Config, figment::Error> { | ||
let config: Config = | ||
Figment::from(Serialized::defaults(Config::default())) | ||
.merge(Toml::file_exact(config_file.as_path())) | ||
.extract()?; | ||
Ok(config) | ||
} |
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