summaryrefslogtreecommitdiff
path: root/plugins/warp/src/plugin/ffi/container.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2026-03-13 12:24:18 -0700
committerMason Reed <35282038+emesare@users.noreply.github.com>2026-03-24 18:46:48 -0700
commit3c88b11e5df33116580ac008e36092775df66135 (patch)
treecd64fbe149f05683ddabcccd0db7b87356f1f8cf /plugins/warp/src/plugin/ffi/container.rs
parentf325aa7b6026a1daef84931baeb1f50d7da10c10 (diff)
[WARP] Improved UX and API
- Exposes WARP type objects directly - Adds processor API (for generating warp files directly) - Adds file and chunk API - Misc cleanup - Simplified the amount of commands - Replaced the "Create" commands with a purpose built processor dialog - Added a native QT viewer for WARP files - Simplified committing to a remote with a purpose built commit dialog
Diffstat (limited to 'plugins/warp/src/plugin/ffi/container.rs')
-rw-r--r--plugins/warp/src/plugin/ffi/container.rs61
1 files changed, 21 insertions, 40 deletions
diff --git a/plugins/warp/src/plugin/ffi/container.rs b/plugins/warp/src/plugin/ffi/container.rs
index aa0c37d3..09f15d99 100644
--- a/plugins/warp/src/plugin/ffi/container.rs
+++ b/plugins/warp/src/plugin/ffi/container.rs
@@ -3,17 +3,11 @@ use crate::container::disk::DiskContainer;
use crate::container::{
ContainerSearchItem, ContainerSearchItemKind, ContainerSearchQuery, SourcePath, SourceTag,
};
-use crate::convert::{from_bn_type, to_bn_type};
use crate::plugin::ffi::{
BNWARPConstraintGUID, BNWARPContainer, BNWARPFunction, BNWARPFunctionGUID, BNWARPSource,
- BNWARPTarget, BNWARPTypeGUID,
+ BNWARPTarget, BNWARPType, BNWARPTypeGUID,
};
-use binaryninja::architecture::CoreArchitecture;
-use binaryninja::binary_view::BinaryView;
-use binaryninja::rc::Ref;
use binaryninja::string::BnString;
-use binaryninja::types::Type;
-use binaryninjacore_sys::{BNArchitecture, BNBinaryView, BNType};
use std::collections::HashMap;
use std::ffi::{c_char, CStr};
use std::mem::ManuallyDrop;
@@ -98,32 +92,25 @@ pub unsafe extern "C" fn BNWARPContainerSearchItemGetSource(
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerSearchItemGetType(
- arch: *mut BNArchitecture,
item: *mut BNWARPContainerSearchItem,
-) -> *mut BNType {
- // NOTE: to convert the type, we must have an architecture.
- let arch = match !arch.is_null() {
- true => Some(CoreArchitecture::from_raw(arch)),
- false => None,
- };
-
+) -> *mut BNWARPType {
let item = ManuallyDrop::new(Arc::from_raw(item));
match &item.kind {
ContainerSearchItemKind::Source { .. } => std::ptr::null_mut(),
ContainerSearchItemKind::Function(func) => {
match &func.ty {
None => std::ptr::null_mut(),
- Some(ty) => {
- let bn_ty = to_bn_type(arch, &ty);
- // NOTE: The type ref has been pre-incremented for the caller.
- unsafe { Ref::into_raw(bn_ty) }.handle
+ Some(func_ty) => {
+ let arc_func_ty = Arc::new(func_ty.clone());
+ // NOTE: Freed by BNWARPFreeTypeReference
+ Arc::into_raw(arc_func_ty) as *mut BNWARPType
}
}
}
ContainerSearchItemKind::Type(ty) => {
- let bn_ty = to_bn_type(arch, &ty);
- // NOTE: The type ref has been pre-incremented for the caller.
- unsafe { Ref::into_raw(bn_ty) }.handle
+ let arc_ty = Arc::new(ty.clone());
+ // NOTE: Freed by BNWARPFreeTypeReference
+ Arc::into_raw(arc_ty) as *mut BNWARPType
}
ContainerSearchItemKind::Symbol(_) => std::ptr::null_mut(),
}
@@ -254,7 +241,7 @@ pub unsafe extern "C" fn BNWARPContainerGetSources(
return std::ptr::null_mut();
};
- // NOTE: Leak the sources to be freed by BNWARPFreeSourceList
+ // NOTE: Leak the sources to be freed by BNWARPFreeUUIDList
let boxed_sources: Box<[_]> = container.sources().unwrap_or_default().into_boxed_slice();
*count = boxed_sources.len();
Box::into_raw(boxed_sources) as *mut BNWARPSource
@@ -389,14 +376,11 @@ pub unsafe extern "C" fn BNWARPContainerAddFunctions(
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerAddTypes(
- view: *mut BNBinaryView,
container: *mut BNWARPContainer,
source: *const BNWARPSource,
- types: *mut *mut BNType,
+ types: *mut *mut BNWARPType,
count: usize,
) -> bool {
- let view = unsafe { BinaryView::from_raw(view) };
-
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(mut container) = arc_container.write() else {
return false;
@@ -405,10 +389,11 @@ pub unsafe extern "C" fn BNWARPContainerAddTypes(
let source = unsafe { *source };
let types_ptr = std::slice::from_raw_parts(types, count);
+ // TODO: We have to clone the objects here to make the type checker happy.
+ // TODO: See about avoiding this later.
let types: Vec<_> = types_ptr
.iter()
- .map(|&t| Type::from_raw(t))
- .map(|ty| from_bn_type(&view, &ty, 255))
+ .map(|&t| unsafe { ManuallyDrop::new(Arc::from_raw(t)).as_ref().clone() })
.collect();
container.add_types(&source, &types).is_ok()
}
@@ -476,7 +461,7 @@ pub unsafe extern "C" fn BNWARPContainerGetSourcesWithFunctionGUID(
let guid = unsafe { *guid };
- // NOTE: Leak the sources to be freed by BNWARPFreeSourceList
+ // NOTE: Leak the sources to be freed by BNWARPFreeUUIDList
let boxed_sources: Box<[_]> = container
.sources_with_function_guid(&target, &guid)
.unwrap_or_default()
@@ -498,7 +483,7 @@ pub unsafe extern "C" fn BNWARPContainerGetSourcesWithTypeGUID(
let guid = unsafe { *guid };
- // NOTE: Leak the sources to be freed by BNWARPFreeSourceList
+ // NOTE: Leak the sources to be freed by BNWARPFreeUUIDList
let boxed_sources: Box<[_]> = container
.sources_with_type_guid(&guid)
.unwrap_or_default()
@@ -538,22 +523,17 @@ pub unsafe extern "C" fn BNWARPContainerGetFunctionsWithGUID(
Box::into_raw(raw_boxed_functions) as *mut *mut BNWARPFunction
}
-// TODO: Swap arch to Target?
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerGetTypeWithGUID(
- arch: *mut BNArchitecture,
container: *mut BNWARPContainer,
source: *const BNWARPSource,
guid: *const BNWARPTypeGUID,
-) -> *mut BNType {
+) -> *mut BNWARPType {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return std::ptr::null_mut();
};
- // NOTE: to convert the type, we must have an architecture.
- let arch = CoreArchitecture::from_raw(arch);
-
let source = unsafe { *source };
let guid = unsafe { *guid };
@@ -561,9 +541,10 @@ pub unsafe extern "C" fn BNWARPContainerGetTypeWithGUID(
let Some(ty) = container.type_with_guid(&source, &guid).unwrap_or_default() else {
return std::ptr::null_mut();
};
- let function_type = to_bn_type(Some(arch), &ty);
- // NOTE: The type ref has been pre-incremented for the caller.
- unsafe { Ref::into_raw(function_type) }.handle
+
+ let arc_ty = Arc::new(ty);
+ // NOTE: Freed by BNWARPFreeTypeReference
+ Arc::into_raw(arc_ty) as *mut BNWARPType
}
#[no_mangle]