1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
use crate::cache::container::cached_containers;
use crate::container::{
ContainerSearchItem, ContainerSearchItemKind, ContainerSearchQuery, SourcePath, SourceTag,
};
use crate::convert::{from_bn_type, to_bn_type};
use crate::plugin::ffi::{
BNWARPContainer, BNWARPFunction, BNWARPFunctionGUID, BNWARPSource, BNWARPTarget, 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::ffi::{c_char, CStr};
use std::mem::ManuallyDrop;
use std::ops::Deref;
use std::sync::Arc;
use warp::r#type::guid::TypeGUID;
pub type BNWARPContainerSearchQuery = ContainerSearchQuery;
pub type BNWARPContainerSearchItem = ContainerSearchItem;
#[repr(C)]
pub enum BNWARPContainerSearchItemKind {
Source = 0,
Function = 1,
Type = 2,
Symbol = 3,
}
#[repr(C)]
pub struct BNWARPContainerSearchResponse {
pub count: usize,
pub items: *mut *mut BNWARPContainerSearchItem,
pub offset: usize,
pub total: usize,
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPNewContainerSearchQuery(
query: *mut c_char,
offset: *const usize,
limit: *const usize,
source: *const BNWARPSource,
source_tags: *mut *mut c_char,
source_tags_count: usize,
) -> *mut BNWARPContainerSearchQuery {
let query_cstr = unsafe { CStr::from_ptr(query) };
let Ok(query) = query_cstr.to_str() else {
return std::ptr::null_mut();
};
let mut search_query = ContainerSearchQuery::new(query.to_string());
if !offset.is_null() {
search_query.offset = Some(*offset);
}
if !limit.is_null() {
search_query.limit = Some(*limit);
}
if !source.is_null() {
search_query.source = Some(*source);
}
if !source_tags.is_null() {
let source_tags_raw = unsafe { std::slice::from_raw_parts(source_tags, source_tags_count) };
let source_tags: Vec<SourceTag> = source_tags_raw
.iter()
.filter_map(|&ptr| CStr::from_ptr(ptr).to_str().ok())
.map(|s| s.into())
.collect();
search_query.tags = source_tags;
}
Box::into_raw(Box::new(search_query))
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerSearchItemGetKind(
item: *mut BNWARPContainerSearchItem,
) -> BNWARPContainerSearchItemKind {
let item = ManuallyDrop::new(Arc::from_raw(item));
match &item.kind {
ContainerSearchItemKind::Source { .. } => BNWARPContainerSearchItemKind::Source,
ContainerSearchItemKind::Function(_) => BNWARPContainerSearchItemKind::Function,
ContainerSearchItemKind::Type(_) => BNWARPContainerSearchItemKind::Type,
ContainerSearchItemKind::Symbol(_) => BNWARPContainerSearchItemKind::Symbol,
}
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerSearchItemGetSource(
item: *mut BNWARPContainerSearchItem,
) -> BNWARPSource {
let item = ManuallyDrop::new(Arc::from_raw(item));
item.source
}
#[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,
};
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
}
}
}
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
}
ContainerSearchItemKind::Symbol(_) => std::ptr::null_mut(),
}
}
// NOTE: In the future we should allow for the possibility of this returning a null pointer.
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerSearchItemGetName(
item: *mut BNWARPContainerSearchItem,
) -> *mut c_char {
let item = ManuallyDrop::new(Arc::from_raw(item));
match &item.kind {
ContainerSearchItemKind::Source { path, .. } => {
let bn_name = BnString::new(path.to_string());
BnString::into_raw(bn_name)
}
ContainerSearchItemKind::Function(func) => {
let bn_name = BnString::new(func.symbol.name.clone());
BnString::into_raw(bn_name)
}
ContainerSearchItemKind::Type(ty) => {
// TODO: Maybe un-named types should return std::ptr::null_mut()?
let ty_name = ty
.name
.clone()
.unwrap_or_else(|| TypeGUID::from(ty).to_string());
let bn_name = BnString::new(ty_name);
BnString::into_raw(bn_name)
}
ContainerSearchItemKind::Symbol(sym) => {
let bn_name = BnString::new(sym.name.clone());
BnString::into_raw(bn_name)
}
}
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerSearchItemGetFunction(
item: *mut BNWARPContainerSearchItem,
) -> *mut BNWARPFunction {
let item = ManuallyDrop::new(Arc::from_raw(item));
match &item.kind {
ContainerSearchItemKind::Source { .. } => std::ptr::null_mut(),
ContainerSearchItemKind::Function(func) => {
Arc::into_raw(Arc::new(func.clone())) as *mut BNWARPFunction
}
ContainerSearchItemKind::Type(_) => std::ptr::null_mut(),
ContainerSearchItemKind::Symbol(_) => 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
let boxed_raw_containers: Box<[_]> =
cached_containers().into_iter().map(Arc::into_raw).collect();
*count = boxed_raw_containers.len();
let leaked_raw_containers = Box::into_raw(boxed_raw_containers);
leaked_raw_containers as *mut *mut BNWARPContainer
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerGetName(container: *mut BNWARPContainer) -> *const c_char {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return std::ptr::null();
};
let name = container.to_string();
// NOTE: Leak the container name to be freed by BNFreeString
BnString::into_raw(name.into())
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerFetchFunctions(
container: *mut BNWARPContainer,
target: *mut BNWARPTarget,
source_tags: *mut *mut c_char,
source_tags_count: usize,
guids: *const BNWARPFunctionGUID,
count: usize,
) {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(mut container) = arc_container.write() else {
return;
};
let target = unsafe { ManuallyDrop::new(Arc::from_raw(target)) };
let source_tags_raw = unsafe { std::slice::from_raw_parts(source_tags, source_tags_count) };
let source_tags: Vec<SourceTag> = source_tags_raw
.iter()
.filter_map(|&ptr| CStr::from_ptr(ptr).to_str().ok())
.map(|s| s.into())
.collect();
let guids = unsafe { std::slice::from_raw_parts(guids, count) };
if let Err(e) = container.fetch_functions(&target, &source_tags, guids) {
tracing::error!("Failed to fetch functions: {}", e);
}
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerGetSources(
container: *mut BNWARPContainer,
count: *mut usize,
) -> *mut BNWARPSource {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.write() else {
return std::ptr::null_mut();
};
// NOTE: Leak the sources to be freed by BNWARPFreeSourceList
let boxed_sources: Box<[_]> = container.sources().unwrap_or_default().into_boxed_slice();
*count = boxed_sources.len();
Box::into_raw(boxed_sources) as *mut BNWARPSource
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerAddSource(
container: *mut BNWARPContainer,
source_path: *const c_char,
result: *mut BNWARPSource,
) -> bool {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(mut container) = arc_container.write() else {
return false;
};
let source_path_cstr = unsafe { CStr::from_ptr(source_path) };
let source_path_str = source_path_cstr.to_str().unwrap();
let source_path = SourcePath::new_with_str(source_path_str);
match container.add_source(source_path) {
Ok(source) => {
// NOTE: Leak the source to be freed by BNFreeString
*result = source;
true
}
Err(_) => false,
}
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerCommitSource(
container: *mut BNWARPContainer,
source: *const BNWARPSource,
) -> bool {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(mut container) = arc_container.write() else {
return false;
};
let source = unsafe { *source };
container
.commit_source(&source)
.is_ok_and(|committed| committed)
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerIsSourceUncommitted(
container: *mut BNWARPContainer,
source: *const BNWARPSource,
) -> bool {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return false;
};
let source = unsafe { *source };
container
.is_source_uncommitted(&source)
.is_ok_and(|uncommitted| uncommitted)
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerIsSourceWritable(
container: *mut BNWARPContainer,
source: *const BNWARPSource,
) -> bool {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return false;
};
let source = unsafe { *source };
container
.is_source_writable(&source)
.is_ok_and(|writable| writable)
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerGetSourcePath(
container: *mut BNWARPContainer,
source: *const BNWARPSource,
) -> *const c_char {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return std::ptr::null();
};
let source = unsafe { *source };
match container.source_path(&source) {
Ok(path) => {
let path = path.to_string();
// NOTE: Leak the source path to be freed by BNFreeString
BnString::into_raw(path.into())
}
Err(_) => std::ptr::null(),
}
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerAddFunctions(
container: *mut BNWARPContainer,
target: *mut BNWARPTarget,
source: *const BNWARPSource,
functions: *mut *mut BNWARPFunction,
count: usize,
) -> bool {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(mut container) = arc_container.write() else {
return false;
};
let target = unsafe { ManuallyDrop::new(Arc::from_raw(target)) };
let source = unsafe { *source };
let functions_ptr = std::slice::from_raw_parts(functions, count);
// TODO: We have to clone the objects here to make the type checker happy.
// TODO: See about avoiding this later.
let functions: Vec<_> = functions_ptr
.iter()
.map(|&f| unsafe { ManuallyDrop::new(Arc::from_raw(f)).as_ref().clone() })
.collect();
container
.add_functions(&target, &source, &functions)
.is_ok()
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerAddTypes(
view: *mut BNBinaryView,
container: *mut BNWARPContainer,
source: *const BNWARPSource,
types: *mut *mut BNType,
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;
};
let source = unsafe { *source };
let types_ptr = std::slice::from_raw_parts(types, count);
let types: Vec<_> = types_ptr
.iter()
.map(|&t| Type::from_raw(t))
.map(|ty| from_bn_type(&view, &ty, 255))
.collect();
container.add_types(&source, &types).is_ok()
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerRemoveFunctions(
container: *mut BNWARPContainer,
target: *mut BNWARPTarget,
source: *const BNWARPSource,
functions: *mut *mut BNWARPFunction,
count: usize,
) -> bool {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(mut container) = arc_container.write() else {
return false;
};
let target = unsafe { ManuallyDrop::new(Arc::from_raw(target)) };
let source = unsafe { *source };
let functions_ptr = std::slice::from_raw_parts(functions, count);
// TODO: We have to clone the objects here to make the type checker happy.
// TODO: See about avoiding this later.
let functions: Vec<_> = functions_ptr
.iter()
.map(|&f| unsafe { ManuallyDrop::new(Arc::from_raw(f)).as_ref().clone() })
.collect();
container
.remove_functions(&target, &source, &functions)
.is_ok()
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerRemoveTypes(
container: *mut BNWARPContainer,
source: *const BNWARPSource,
guids: *mut BNWARPTypeGUID,
count: usize,
) -> bool {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(mut container) = arc_container.write() else {
return false;
};
let source = unsafe { *source };
let guids = std::slice::from_raw_parts(guids, count);
container.remove_types(&source, &guids).is_ok()
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerGetSourcesWithFunctionGUID(
container: *mut BNWARPContainer,
target: *mut BNWARPTarget,
guid: *const BNWARPFunctionGUID,
count: *mut usize,
) -> *mut BNWARPSource {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return std::ptr::null_mut();
};
let target = unsafe { ManuallyDrop::new(Arc::from_raw(target)) };
let guid = unsafe { *guid };
// NOTE: Leak the sources to be freed by BNWARPFreeSourceList
let boxed_sources: Box<[_]> = container
.sources_with_function_guid(&target, &guid)
.unwrap_or_default()
.into_boxed_slice();
*count = boxed_sources.len();
Box::into_raw(boxed_sources) as *mut BNWARPSource
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerGetSourcesWithTypeGUID(
container: *mut BNWARPContainer,
guid: *const BNWARPTypeGUID,
count: *mut usize,
) -> *mut BNWARPSource {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return std::ptr::null_mut();
};
let guid = unsafe { *guid };
// NOTE: Leak the sources to be freed by BNWARPFreeSourceList
let boxed_sources: Box<[_]> = container
.sources_with_type_guid(&guid)
.unwrap_or_default()
.into_boxed_slice();
*count = boxed_sources.len();
Box::into_raw(boxed_sources) as *mut BNWARPSource
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerGetFunctionsWithGUID(
container: *mut BNWARPContainer,
target: *mut BNWARPTarget,
source: *const BNWARPSource,
guid: *const BNWARPFunctionGUID,
count: *mut usize,
) -> *mut *mut BNWARPFunction {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return std::ptr::null_mut();
};
let source = unsafe { *source };
let target = unsafe { ManuallyDrop::new(Arc::from_raw(target)) };
let guid = unsafe { *guid };
// NOTE: Leak the functions to be freed by BNWARPFreeFunctionList
let raw_boxed_functions: Box<[_]> = container
.functions_with_guid(&target, &source, &guid)
.unwrap_or_default()
.into_iter()
.map(Arc::new)
.map(Arc::into_raw)
.collect();
*count = raw_boxed_functions.len();
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 {
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 };
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
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerGetTypeGUIDsWithName(
container: *mut BNWARPContainer,
source: *const BNWARPSource,
name: *const c_char,
count: *mut usize,
) -> *mut BNWARPTypeGUID {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return std::ptr::null_mut();
};
let source = unsafe { *source };
let name_cstr = unsafe { CStr::from_ptr(name) };
let name = name_cstr.to_str().unwrap();
// NOTE: Leak the guids to be freed by BNWARPFreeTypeGUIDList
let boxed_guids = container
.type_guids_with_name(&source, name)
.unwrap_or_default()
.into_boxed_slice();
*count = boxed_guids.len();
Box::into_raw(boxed_guids) as *mut BNWARPTypeGUID
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPContainerSearch(
container: *mut BNWARPContainer,
query: *mut BNWARPContainerSearchQuery,
) -> *mut BNWARPContainerSearchResponse {
let arc_container = ManuallyDrop::new(Arc::from_raw(container));
let Ok(container) = arc_container.read() else {
return std::ptr::null_mut();
};
let query = unsafe { ManuallyDrop::new(Arc::from_raw(query)) };
let result = match container.search(&query) {
Ok(result) => result,
Err(err) => {
tracing::error!("Failed to search container {:?}: {}", query.deref(), err);
return std::ptr::null_mut();
}
};
let boxed_raw_items: Box<[_]> = result
.items
.into_iter()
.map(Arc::new)
.map(Arc::into_raw)
.collect();
let count = boxed_raw_items.len();
// NOTE: Leak the functions to be freed by BNWARPFreeContainerSearchItemList
let leaked_raw_items = Box::into_raw(boxed_raw_items) as *mut *mut BNWARPContainerSearchItem;
let raw_result = BNWARPContainerSearchResponse {
count,
items: leaked_raw_items,
total: result.total,
offset: result.offset,
};
// NOTE: Leak the result to be freed by BNWARPFreeContainerSearchResult
Box::into_raw(Box::new(raw_result))
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPNewContainerReference(
container: *mut BNWARPContainer,
) -> *mut BNWARPContainer {
Arc::increment_strong_count(container);
container
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPFreeContainerReference(container: *mut BNWARPContainer) {
if container.is_null() {
return;
}
Arc::decrement_strong_count(container);
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPFreeContainerList(
containers: *mut *mut BNWARPContainer,
count: usize,
) {
let containers_ptr = std::ptr::slice_from_raw_parts_mut(containers, count);
let containers = unsafe { Box::from_raw(containers_ptr) };
for container in containers {
BNWARPFreeContainerReference(container);
}
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPNewContainerSearchQueryReference(
query: *mut BNWARPContainerSearchQuery,
) -> *mut BNWARPContainerSearchQuery {
Arc::increment_strong_count(query);
query
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPFreeContainerSearchQueryReference(
query: *mut BNWARPContainerSearchQuery,
) {
if query.is_null() {
return;
}
Arc::decrement_strong_count(query);
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPNewContainerSearchItemReference(
item: *mut BNWARPContainerSearchItem,
) -> *mut BNWARPContainerSearchItem {
Arc::increment_strong_count(item);
item
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPFreeContainerSearchItemReference(
item: *mut BNWARPContainerSearchItem,
) {
if item.is_null() {
return;
}
Arc::decrement_strong_count(item);
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPFreeContainerSearchItemList(
items: *mut *mut BNWARPContainerSearchItem,
count: usize,
) {
let items_ptr = std::ptr::slice_from_raw_parts_mut(items, count);
let items = unsafe { Box::from_raw(items_ptr) };
for item in items {
BNWARPFreeContainerSearchItemReference(item);
}
}
#[no_mangle]
pub unsafe extern "C" fn BNWARPFreeContainerSearchResponse(
response: *mut BNWARPContainerSearchResponse,
) {
if response.is_null() {
return;
}
let response = unsafe { Box::from_raw(response) };
BNWARPFreeContainerSearchItemList(response.items, response.count);
}
|