From 4d8feb4921cde4b70bb6db4ccd525a69205dee7f Mon Sep 17 00:00:00 2001 From: rbran Date: Thu, 10 Apr 2025 12:58:27 +0000 Subject: [Rust] Implement `LanguageRepresentation` and `LineFormatter` --- rust/src/function.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'rust/src/function.rs') 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( + &self, + language: S, + ) -> Option> { + 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( + &self, + language: S, + ) -> Option> { + 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, ()> { unsafe { let hlil_ptr = BNGetFunctionHighLevelIL(self.handle); -- cgit v1.3.1