-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from vthib/set-module-data
feat: add ability to set module data in scan callback
- Loading branch information
Showing
10 changed files
with
314 additions
and
3 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
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,45 @@ | ||
use std::ffi::{c_void, CStr}; | ||
use std::fmt::Debug; | ||
|
||
/// Details about a module being imported. | ||
pub struct YrModuleImport<'a>(&'a mut yara_sys::YR_MODULE_IMPORT); | ||
|
||
impl Debug for YrModuleImport<'_> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
Debug::fmt("YrModuleImport", f) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a mut yara_sys::YR_MODULE_IMPORT> for YrModuleImport<'a> { | ||
fn from(value: &'a mut yara_sys::YR_MODULE_IMPORT) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl YrModuleImport<'_> { | ||
/// Get the name of the module. | ||
pub fn name(&self) -> Option<&[u8]> { | ||
let ptr = self.0.module_name; | ||
if ptr.is_null() { | ||
None | ||
} else { | ||
// Safety: | ||
// - ptr is not null, and is guaranteed by libyara to be nul-terminated | ||
// - returned slice is valid for as long as self, guaranteeing the ptr to stay valid. | ||
let cstr = unsafe { CStr::from_ptr(ptr) }; | ||
Some(cstr.to_bytes()) | ||
} | ||
} | ||
|
||
/// Set the module data to be used by the module. | ||
/// | ||
/// # Safety | ||
/// | ||
/// The caller must guarantee that: | ||
/// - `ptr` is valid for reads of `size` bytes. | ||
/// - `ptr` stays valid for the full duration of the scan. | ||
pub unsafe fn set_module_data(&mut self, ptr: *mut c_void, size: usize) { | ||
self.0.module_data = ptr; | ||
self.0.module_data_size = size as _; | ||
} | ||
} |
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
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