Skip to content

Commit

Permalink
feat: add configuration for YR_CONFIG_MAX_PROCESS_MEMORY_CHUNK
Browse files Browse the repository at this point in the history
  • Loading branch information
vthib committed Apr 4, 2023
1 parent 755d4e5 commit a984dfa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/internals/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ pub fn set_max_match_data(value: u32) -> Result<(), YaraError> {
}
}

/// Set the maximum size of chunks scanned from a process memory.
///
/// This is mapped to the YR_CONFIG_MAX_PROCESS_MEMORY_CHUNK property.
pub fn set_max_process_memory_chunk(value: u64) -> Result<(), YaraError> {
unsafe {
set_cfg(
yara_sys::_YR_CONFIG_NAME_YR_CONFIG_MAX_PROCESS_MEMORY_CHUNK,
&value as *const u64 as *mut c_void,
)
}
}

/// Get the stack size.
///
/// This is mapped to the YR_CONFIG_STACK_SIZE property.
Expand All @@ -59,6 +71,13 @@ pub fn get_max_match_data() -> Result<u32, YaraError> {
unsafe { get_cfg(yara_sys::_YR_CONFIG_NAME_YR_CONFIG_MAX_MATCH_DATA) }
}

/// Get the maximum size of chunks scanned from a process memory.
///
/// This is mapped to the YR_CONFIG_MAX_PROCESS_MEMORY_CHUNK property.
pub fn get_max_process_memory_chunk() -> Result<u64, YaraError> {
unsafe { get_cfg(yara_sys::_YR_CONFIG_NAME_YR_CONFIG_MAX_PROCESS_MEMORY_CHUNK) }
}

/// Safety:
///
/// The value pointer must point to a value of the right size for the given config.
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ impl Yara {
configuration::set_max_match_data(value)
}

/// Set the maximum size of chunks scanned from a process memory.
pub fn set_configuration_max_process_memory_chunk(&self, value: u64) -> Result<(), YaraError> {
configuration::set_max_process_memory_chunk(value)
}

/// Get the configured stack size.
pub fn get_configuration_stack_size(&self) -> Result<u32, YaraError> {
configuration::get_stack_size()
Expand All @@ -171,6 +176,11 @@ impl Yara {
configuration::get_max_match_data()
}

/// Get the maximum size of chunks scanned from a process memory.
pub fn get_configuration_max_process_memory_chunk(&self) -> Result<u64, YaraError> {
configuration::get_max_process_memory_chunk()
}

/// Create and initialize the library.
#[deprecated = "Use new"]
pub fn create() -> Result<Yara, YaraError> {
Expand Down
8 changes: 8 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ fn test_configuration() {
let yara = Yara::new().expect("Should be Ok");
assert_eq!(Ok(()), yara.set_configuration_stack_size(100));
assert_eq!(Ok(100), yara.get_configuration_stack_size());
assert_eq!(
Ok(()),
yara.set_configuration_max_process_memory_chunk(u64::MAX)
);
assert_eq!(
Ok(u64::MAX),
yara.get_configuration_max_process_memory_chunk()
);
}

#[test]
Expand Down

0 comments on commit a984dfa

Please sign in to comment.