From 6d267ec0604ef5036f173761d67d0fb4adc8a8fa Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Thu, 13 Feb 2025 16:03:31 -0500 Subject: Fix base detection in rust API failing on auto arch detection Also added actual test for base address detection --- rust/src/base_detection.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'rust/src') diff --git a/rust/src/base_detection.rs b/rust/src/base_detection.rs index 46a56842..1fd45ef6 100644 --- a/rust/src/base_detection.rs +++ b/rust/src/base_detection.rs @@ -1,9 +1,8 @@ use binaryninjacore_sys::*; -use std::ffi::CStr; +use std::ffi::{c_char, CStr}; use crate::architecture::CoreArchitecture; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner}; -use crate::string::BnString; use std::num::NonZeroU32; use std::ptr::NonNull; @@ -11,6 +10,9 @@ pub type BaseAddressDetectionPOISetting = BNBaseAddressDetectionPOISetting; pub type BaseAddressDetectionConfidence = BNBaseAddressDetectionConfidence; pub type BaseAddressDetectionPOIType = BNBaseAddressDetectionPOIType; +/// This is the architecture name used to use the architecture auto-detection feature. +const BASE_ADDRESS_AUTO_DETECTION_ARCH: &CStr = c"auto detect"; + pub enum BaseAddressDetectionAnalysis { Basic, ControlFlow, @@ -169,9 +171,12 @@ pub struct BaseAddressDetectionSettings { impl BaseAddressDetectionSettings { pub(crate) fn into_raw(value: &Self) -> BNBaseAddressDetectionSettings { - let arch_name = value.arch.map(|a| a.name()).unwrap_or(BnString::new("")); + let arch_name = value + .arch + .map(|a| a.name().as_ptr()) + .unwrap_or(BASE_ADDRESS_AUTO_DETECTION_ARCH.as_ptr() as *const c_char); BNBaseAddressDetectionSettings { - Architecture: arch_name.as_ptr(), + Architecture: arch_name, Analysis: value.analysis.as_raw().as_ptr(), MinStrlen: value.min_string_len, Alignment: value.alignment.get(), -- cgit v1.3.1