From a29618e0063f71ac6ae9c5ba20e21e792dea778b Mon Sep 17 00:00:00 2001 From: ConnorBP Date: Thu, 10 Apr 2025 10:28:13 -0400 Subject: [PATCH 1/4] 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 From ae3cad91f8d9401b14c88ff0fab32d533320a8c9 Mon Sep 17 00:00:00 2001 From: ConnorBP Date: Wed, 16 Apr 2025 17:41:30 -0400 Subject: [PATCH 2/4] additional verbose debugging info on pcileech error for testing --- memflow-pcileech/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/memflow-pcileech/src/lib.rs b/memflow-pcileech/src/lib.rs index 37d9018..5306b8c 100644 --- a/memflow-pcileech/src/lib.rs +++ b/memflow-pcileech/src/lib.rs @@ -128,6 +128,7 @@ impl PciLeech { 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() { + error!("Unable to create leechcore context: {conf:?} ppErr: {pp_lc_config_error_info:?} pErr: {p_lc_config_error_info:?}"); // TODO: handle version error // TODO: handle special case of fUserInputRequest let err = if p_lc_config_error_info.is_null() { From 9e4b41a267b24dad25d7096c3802880d6d398f72 Mon Sep 17 00:00:00 2001 From: ConnorBP Date: Wed, 16 Apr 2025 17:47:04 -0400 Subject: [PATCH 3/4] Update leechcore --- leechcore-sys/src/leechcore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leechcore-sys/src/leechcore b/leechcore-sys/src/leechcore index 258c958..0efa866 160000 --- a/leechcore-sys/src/leechcore +++ b/leechcore-sys/src/leechcore @@ -1 +1 @@ -Subproject commit 258c95894deb1a5d0cdeb0838152ac2312cb8bb8 +Subproject commit 0efa866043743ef010dc7f90f8ac95f83fe6dfd6 From e8251ec5ebbafa5a02a9a1fa5da503830504abae Mon Sep 17 00:00:00 2001 From: ConnorBP Date: Wed, 16 Apr 2025 18:19:53 -0400 Subject: [PATCH 4/4] more useful failure messages on build.rs --- leechcore-sys/build.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/leechcore-sys/build.rs b/leechcore-sys/build.rs index 1e609f8..54a7e15 100644 --- a/leechcore-sys/build.rs +++ b/leechcore-sys/build.rs @@ -56,6 +56,7 @@ fn build_leechcore(target: &str) { .map(|o| "src/leechcore/leechcore/".to_string() + o) .collect::>(), ) + .include("src/leechcore/includes/") .flag(&format!("-D{}", os_define())) .flag("-D_GNU_SOURCE"); // EXPORTED_FUNCTION= to not export any symbols @@ -96,8 +97,8 @@ fn build_leechcore(target: &str) { } } else { // copy pre-compiled idl file into the leechcore folder - std::fs::copy("gen/leechrpc_c.c", "src/leechcore/leechcore/leechrpc_c.c").unwrap(); - std::fs::copy("gen/leechrpc_h.h", "src/leechcore/leechcore/leechrpc_h.h").unwrap(); + std::fs::copy("gen/leechrpc_c.c", "src/leechcore/leechcore/leechrpc_c.c").expect("Failed to copy leechrpc_c.c"); + std::fs::copy("gen/leechrpc_h.h", "src/leechcore/leechcore/leechrpc_h.h").expect("Failed to copy leechrpc_h.h"); // link against required libraries println!("cargo:rustc-link-lib=rpcrt4"); @@ -113,8 +114,8 @@ fn build_leechcore(target: &str) { if target.contains("windows") { // remove temporary generated files - std::fs::remove_file("src/leechcore/leechcore/leechrpc_c.c").unwrap(); - std::fs::remove_file("src/leechcore/leechcore/leechrpc_h.h").unwrap(); + std::fs::remove_file("src/leechcore/leechcore/leechrpc_c.c").expect("Failed to remove leechrpc_c.c"); + std::fs::remove_file("src/leechcore/leechcore/leechrpc_h.h").expect("Failed to remove leechrpc_h.h"); } println!("cargo:rustc-link-lib=static=leechcore");