Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add set and get configuration Co-authored-by: Ivan Krivosheev <ikrivosheev@ptsecurity.com>
- Loading branch information
1 parent
6d40365
commit 967b23a
Showing
9 changed files
with
280 additions
and
49 deletions.
There are no files selected for viewing
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,52 @@ | ||
use std::ffi::c_void; | ||
|
||
use yara_sys; | ||
|
||
use crate::errors::*; | ||
|
||
/// A `ConfigName` is enum of available configuration options | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
pub enum ConfigName { | ||
/// Stack size to use for YR_CONFIG_STACK_SIZE | ||
StackSize, | ||
/// Maximum number of strings to allow per yara rule. Will be mapped to YR_CONFIG_MAX_STRINGS_PER_RULE | ||
MaxStringsPerRule, | ||
/// Maximum number of bytes to allow per yara match. Will be mapped to YR_CONFIG_MAX_MATCH_DATA | ||
MaxMatchData, | ||
} | ||
|
||
#[cfg(unix)] | ||
type EnumType = u32; | ||
#[cfg(windows)] | ||
type EnumType = i32; | ||
|
||
impl ConfigName { | ||
pub fn to_yara(&self) -> EnumType { | ||
use self::ConfigName::*; | ||
let res = match self { | ||
StackSize => yara_sys::_YR_CONFIG_NAME_YR_CONFIG_STACK_SIZE, | ||
MaxStringsPerRule => yara_sys::_YR_CONFIG_NAME_YR_CONFIG_MAX_STRINGS_PER_RULE, | ||
MaxMatchData => yara_sys::_YR_CONFIG_NAME_YR_CONFIG_MAX_MATCH_DATA, | ||
}; | ||
res as EnumType | ||
} | ||
} | ||
|
||
pub fn set_configuration(name: ConfigName, value: u32) -> Result<(), YaraError> { | ||
let result = unsafe { | ||
yara_sys::yr_set_configuration(name.to_yara(), &value as *const u32 as *mut c_void) | ||
}; | ||
|
||
yara_sys::Error::from_code(result).map_err(Into::into) | ||
} | ||
|
||
pub fn get_configuration(name: ConfigName) -> Result<u32, YaraError> { | ||
let value: u32 = 0; | ||
let result = unsafe { | ||
yara_sys::yr_get_configuration(name.to_yara(), &value as *const u32 as *mut c_void) | ||
}; | ||
|
||
yara_sys::Error::from_code(result) | ||
.map_err(Into::into) | ||
.map(|_| value) | ||
} |
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
Oops, something went wrong.