From a29618e0063f71ac6ae9c5ba20e21e792dea778b Mon Sep 17 00:00:00 2001 From: ConnorBP Date: Thu, 10 Apr 2025 10:28:13 -0400 Subject: [PATCH] corrected handling of FFI pointer to pointer to error struct for error output from leechcore --- memflow-pcileech/src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/memflow-pcileech/src/lib.rs b/memflow-pcileech/src/lib.rs index 110e785..37d9018 100644 --- a/memflow-pcileech/src/lib.rs +++ b/memflow-pcileech/src/lib.rs @@ -124,13 +124,21 @@ impl PciLeech { ) -> Result { // open device let mut conf = build_lc_config(device, remote, mem_map.is_some()); - let err = std::ptr::null_mut::(); - let handle = unsafe { LcCreateEx(&mut conf, err) }; + let p_lc_config_error_info = std::ptr::null_mut::(); + let pp_lc_config_error_info = &raw const p_lc_config_error_info as *mut PLC_CONFIG_ERRORINFO; + let handle = unsafe { LcCreateEx(&mut conf, pp_lc_config_error_info) }; if handle.is_null() { // TODO: handle version error // TODO: handle special case of fUserInputRequest + let err = if p_lc_config_error_info.is_null() { + None + } else { + // read the data at the error + Some(unsafe { p_lc_config_error_info.read() }) + }; + return Err(Error(ErrorOrigin::Connector, ErrorKind::Configuration) - .log_error(format!("unable to create leechcore context: {err:?}"))); + .log_error(format!("unable to create leechcore context: {err:?}", ))); } // TODO: allow handling these errors properly