Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions plugins/warp/api/python/warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ def all() -> List['WarpContainer']:
warpcore.BNWARPFreeContainerList(containers, count.value)
return result

@staticmethod
def add(name: str) -> 'WarpContainer':
container = warpcore.BNWARPAddContainer(name)
if container is None:
raise ValueError(f"Failed to add container: {name}")
return WarpContainer(container)

@staticmethod
def by_name(name: str) -> Optional['WarpContainer']:
for container in WarpContainer:
Expand Down
8 changes: 8 additions & 0 deletions plugins/warp/api/warp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ std::vector<Ref<Container> > Container::All()
return result;
}

Ref<Container> Container::Add(const std::string &name)
{
BNWARPContainer *result = BNWARPAddContainer(name.c_str());
if (!result)
return nullptr;
return new Container(result);
}

std::string Container::GetName() const
{
char *rawName = BNWARPContainerGetName(m_object);
Expand Down
3 changes: 3 additions & 0 deletions plugins/warp/api/warp.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ namespace Warp {
/// Retrieve all available containers.
static std::vector<Ref<Container> > All();

/// Add a new container with the given name.
static Ref<Container> Add(const std::string &name);

std::string GetName() const;

std::vector<Source> GetSources() const;
Expand Down
1 change: 1 addition & 0 deletions plugins/warp/api/warpcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ extern "C"
WARP_FFI_API BNWARPFunction* BNWARPGetFunction(BNFunction* analysisFunction);
WARP_FFI_API BNWARPFunction* BNWARPGetMatchedFunction(BNFunction* analysisFunction);
WARP_FFI_API BNWARPContainer** BNWARPGetContainers(size_t* count);
WARP_FFI_API BNWARPContainer* BNWARPAddContainer(const char* name);

WARP_FFI_API char* BNWARPContainerGetName(BNWARPContainer* container);

Expand Down
5 changes: 5 additions & 0 deletions plugins/warp/src/cache/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ pub fn cached_containers() -> Vec<Arc<RwLock<Box<dyn Container>>>> {
let containers_cache = CONTAINER_CACHE.get_or_init(Default::default);
containers_cache.iter().map(|c| c.clone()).collect()
}

pub fn cached_container_by_name(name: &str) -> Option<Arc<RwLock<Box<dyn Container>>>> {
let containers_cache = CONTAINER_CACHE.get_or_init(Default::default);
containers_cache.get(name).map(|c| c.clone())
}
19 changes: 18 additions & 1 deletion plugins/warp/src/plugin/ffi/container.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::cache::container::cached_containers;
use crate::cache::container::{add_cached_container, cached_container_by_name, cached_containers};
use crate::container::disk::DiskContainer;
use crate::container::{
ContainerSearchItem, ContainerSearchItemKind, ContainerSearchQuery, SourcePath, SourceTag,
};
Expand All @@ -12,6 +13,7 @@ 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;
use std::ops::Deref;
Expand Down Expand Up @@ -172,6 +174,21 @@ pub unsafe extern "C" fn BNWARPContainerSearchItemGetFunction(
}
}

#[no_mangle]
pub unsafe extern "C" fn BNWARPAddContainer(name: *const c_char) -> *mut BNWARPContainer {
let name_cstr = unsafe { CStr::from_ptr(name) };
let name_str = name_cstr.to_str().unwrap();
// TODO: Using this generic API name for disk container, I think anything like the network container
// TODO: should probably be a second class name so something like BNWARPAddNetworkContainer.
let disk_container = DiskContainer::new(name_str.to_string(), HashMap::new());
let container_name = disk_container.to_string();
add_cached_container(disk_container);
match cached_container_by_name(&container_name) {
Some(container) => Arc::into_raw(container) as *mut BNWARPContainer,
None => std::ptr::null_mut(),
}
}

#[no_mangle]
pub unsafe extern "C" fn BNWARPGetContainers(count: *mut usize) -> *mut *mut BNWARPContainer {
// NOTE: Leak the arc pointers to be freed by BNWARPFreeContainerList
Expand Down
Loading