summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2026-01-20 14:33:01 -0800
committerMason Reed <35282038+emesare@users.noreply.github.com>2026-03-23 21:50:02 -0700
commit1f98e7ca7cce35ae4c2b4741f33e9892dd695534 (patch)
tree7d848669f9f4d1473349d1eda0bbd6ff0ef48437 /rust/src
parentbc5e0b8ba9520d560bb07ee298047c7880b879ff (diff)
[Rust] Add `TypeBuilder::function` and `TypeBuilder::function_with_opts`
Temporary, we will likely deprecate in favor of a separate function builder later
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/types.rs122
1 files changed, 121 insertions, 1 deletions
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 2528237f..65e50040 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -437,7 +437,127 @@ impl TypeBuilder {
result
}
- // TODO : BNCreateFunctionTypeBuilder
+ // TODO: Deprecate this for a FunctionBuilder (along with the Type variant?)
+ /// NOTE: This is likely to be deprecated and removed in favor of a function type builder, please
+ /// use [`Type::function`] where possible.
+ pub fn function<'a, T: Into<Conf<&'a Type>>>(
+ return_type: T,
+ parameters: Vec<FunctionParameter>,
+ variable_arguments: bool,
+ ) -> Self {
+ let mut owned_raw_return_type = Conf::<&Type>::into_raw(return_type.into());
+ let mut variable_arguments = Conf::new(variable_arguments, MAX_CONFIDENCE).into();
+ let mut can_return = Conf::new(true, MIN_CONFIDENCE).into();
+ let mut pure = Conf::new(false, MIN_CONFIDENCE).into();
+
+ let mut raw_calling_convention: BNCallingConventionWithConfidence =
+ BNCallingConventionWithConfidence {
+ convention: std::ptr::null_mut(),
+ confidence: MIN_CONFIDENCE,
+ };
+
+ let mut stack_adjust = Conf::new(0, MIN_CONFIDENCE).into();
+ let mut raw_parameters = parameters
+ .into_iter()
+ .map(FunctionParameter::into_raw)
+ .collect::<Vec<_>>();
+ let reg_stack_adjust_regs = std::ptr::null_mut();
+ let reg_stack_adjust_values = std::ptr::null_mut();
+
+ let mut return_regs: BNRegisterSetWithConfidence = BNRegisterSetWithConfidence {
+ regs: std::ptr::null_mut(),
+ count: 0,
+ confidence: 0,
+ };
+
+ let result = unsafe {
+ Self::from_raw(BNCreateFunctionTypeBuilder(
+ &mut owned_raw_return_type,
+ &mut raw_calling_convention,
+ raw_parameters.as_mut_ptr(),
+ raw_parameters.len(),
+ &mut variable_arguments,
+ &mut can_return,
+ &mut stack_adjust,
+ reg_stack_adjust_regs,
+ reg_stack_adjust_values,
+ 0,
+ &mut return_regs,
+ BNNameType::NoNameType,
+ &mut pure,
+ ))
+ };
+
+ for raw_param in raw_parameters {
+ FunctionParameter::free_raw(raw_param);
+ }
+
+ result
+ }
+
+ // TODO: Deprecate this for a FunctionBuilder (along with the Type variant?)
+ /// NOTE: This is likely to be deprecated and removed in favor of a function type builder, please
+ /// use [`Type::function_with_opts`] where possible.
+ pub fn function_with_opts<
+ 'a,
+ T: Into<Conf<&'a Type>>,
+ C: Into<Conf<Ref<CoreCallingConvention>>>,
+ >(
+ return_type: T,
+ parameters: &[FunctionParameter],
+ variable_arguments: bool,
+ calling_convention: C,
+ stack_adjust: Conf<i64>,
+ ) -> Self {
+ let mut owned_raw_return_type = Conf::<&Type>::into_raw(return_type.into());
+ let mut variable_arguments = Conf::new(variable_arguments, MAX_CONFIDENCE).into();
+ let mut can_return = Conf::new(true, MIN_CONFIDENCE).into();
+ let mut pure = Conf::new(false, MIN_CONFIDENCE).into();
+
+ let mut owned_raw_calling_convention =
+ Conf::<Ref<CoreCallingConvention>>::into_owned_raw(&calling_convention.into());
+
+ let mut stack_adjust = stack_adjust.into();
+ let mut raw_parameters = parameters
+ .iter()
+ .cloned()
+ .map(FunctionParameter::into_raw)
+ .collect::<Vec<_>>();
+
+ // TODO: Update type signature and include these (will be a breaking change)
+ let reg_stack_adjust_regs = std::ptr::null_mut();
+ let reg_stack_adjust_values = std::ptr::null_mut();
+
+ let mut return_regs: BNRegisterSetWithConfidence = BNRegisterSetWithConfidence {
+ regs: std::ptr::null_mut(),
+ count: 0,
+ confidence: 0,
+ };
+
+ let result = unsafe {
+ Self::from_raw(BNCreateFunctionTypeBuilder(
+ &mut owned_raw_return_type,
+ &mut owned_raw_calling_convention,
+ raw_parameters.as_mut_ptr(),
+ raw_parameters.len(),
+ &mut variable_arguments,
+ &mut can_return,
+ &mut stack_adjust,
+ reg_stack_adjust_regs,
+ reg_stack_adjust_values,
+ 0,
+ &mut return_regs,
+ BNNameType::NoNameType,
+ &mut pure,
+ ))
+ };
+
+ for raw_param in raw_parameters {
+ FunctionParameter::free_raw(raw_param);
+ }
+
+ result
+ }
/// Create a pointer [`TypeBuilder`] with the given target type. Analogous to [`Type::pointer`].
pub fn pointer<'a, A: Architecture, T: Into<Conf<&'a Type>>>(arch: &A, ty: T) -> Self {