diff options
| author | rbran <git@rubens.io> | 2025-04-10 12:58:27 +0000 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | 4d8feb4921cde4b70bb6db4ccd525a69205dee7f (patch) | |
| tree | edbd6845590fef0b2813ee30c16607e1ae8d8e32 /rust/src/function.rs | |
| parent | 067148afd1a8f9153bb5bfe6b5361b83e9f89ab6 (diff) | |
[Rust] Implement `LanguageRepresentation` and `LineFormatter`
Diffstat (limited to 'rust/src/function.rs')
| -rw-r--r-- | rust/src/function.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/rust/src/function.rs b/rust/src/function.rs index c1c29873..edde15a7 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -40,6 +40,7 @@ pub use binaryninjacore_sys::BNHighlightStandardColor as HighlightStandardColor; use crate::architecture::RegisterId; use crate::confidence::Conf; use crate::high_level_il::HighLevelILFunction; +use crate::language_representation::CoreLanguageRepresentationFunction; use crate::low_level_il::{LiftedILFunction, RegularLowLevelILFunction}; use crate::medium_level_il::MediumLevelILFunction; use crate::variable::{ @@ -476,6 +477,42 @@ impl Function { } } + /// Get the language representation of the function. + /// + /// * `language` - The language representation, ex. "Pseudo C". + pub fn language_representation<S: BnStrCompatible>( + &self, + language: S, + ) -> Option<Ref<CoreLanguageRepresentationFunction>> { + let lang_name = language.into_bytes_with_nul(); + let repr = unsafe { + BNGetFunctionLanguageRepresentation( + self.handle, + lang_name.as_ref().as_ptr() as *const c_char, + ) + }; + NonNull::new(repr) + .map(|handle| unsafe { CoreLanguageRepresentationFunction::ref_from_raw(handle) }) + } + + /// Get the language representation of the function, if available. + /// + /// * `language` - The language representation, ex. "Pseudo C". + pub fn language_representation_if_available<S: BnStrCompatible>( + &self, + language: S, + ) -> Option<Ref<CoreLanguageRepresentationFunction>> { + let lang_name = language.into_bytes_with_nul(); + let repr = unsafe { + BNGetFunctionLanguageRepresentationIfAvailable( + self.handle, + lang_name.as_ref().as_ptr() as *const c_char, + ) + }; + NonNull::new(repr) + .map(|handle| unsafe { CoreLanguageRepresentationFunction::ref_from_raw(handle) }) + } + pub fn high_level_il(&self, full_ast: bool) -> Result<Ref<HighLevelILFunction>, ()> { unsafe { let hlil_ptr = BNGetFunctionHighLevelIL(self.handle); |
