(arch: &CoreArchitecture, name: S, func: F)
| 403 | } |
| 404 | |
| 405 | pub(crate) fn register_relocation_handler<S, R, F>(arch: &CoreArchitecture, name: S, func: F) |
| 406 | where |
| 407 | S: BnStrCompatible, |
| 408 | R: 'static + RelocationHandler<Handle = CustomRelocationHandlerHandle<R>> + Send + Sync + Sized, |
| 409 | F: FnOnce(CustomRelocationHandlerHandle<R>, CoreRelocationHandler) -> R, |
| 410 | { |
| 411 | #[repr(C)] |
| 412 | struct RelocationHandlerBuilder<R> |
| 413 | where |
| 414 | R: 'static + RelocationHandler<Handle = CustomRelocationHandlerHandle<R>> + Send + Sync, |
| 415 | { |
| 416 | handler: R, |
| 417 | } |
| 418 | |
| 419 | extern "C" fn cb_free<R>(ctxt: *mut c_void) |
| 420 | where |
| 421 | R: 'static + RelocationHandler<Handle = CustomRelocationHandlerHandle<R>> + Send + Sync, |
| 422 | { |
| 423 | unsafe { |
| 424 | let _handler = Box::from_raw(ctxt as *mut RelocationHandlerBuilder<R>); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | extern "C" fn cb_get_relocation_info<R>( |
| 429 | ctxt: *mut c_void, |
| 430 | bv: *mut BNBinaryView, |
| 431 | arch: *mut BNArchitecture, |
| 432 | result: *mut BNRelocationInfo, |
| 433 | count: usize, |
| 434 | ) -> bool |
| 435 | where |
| 436 | R: 'static + RelocationHandler<Handle = CustomRelocationHandlerHandle<R>> + Send + Sync, |
| 437 | { |
| 438 | let custom_handler = unsafe { &*(ctxt as *mut R) }; |
| 439 | let bv = unsafe { BinaryView::ref_from_raw(BNNewViewReference(bv)) }; |
| 440 | let arch = unsafe { CoreArchitecture::from_raw(arch) }; |
| 441 | let result = unsafe { core::slice::from_raw_parts_mut(result, count) }; |
| 442 | let mut info = result |
| 443 | .iter() |
| 444 | .map(RelocationInfo::from_raw) |
| 445 | .collect::<Vec<_>>(); |
| 446 | let ok = |
| 447 | custom_handler.get_relocation_info(bv.as_ref(), arch.as_ref(), info.as_mut_slice()); |
| 448 | for (result, info) in result.iter_mut().zip(info.iter()) { |
| 449 | *result = info.as_raw(); |
| 450 | } |
| 451 | ok |
| 452 | } |
| 453 | |
| 454 | extern "C" fn cb_apply_relocation<R>( |
| 455 | ctxt: *mut c_void, |
| 456 | bv: *mut BNBinaryView, |
| 457 | arch: *mut BNArchitecture, |
| 458 | reloc: *mut BNRelocation, |
| 459 | dest: *mut u8, |
| 460 | len: usize, |
| 461 | ) -> bool |
| 462 | where |
no test coverage detected