From 1f778420866eb5a3da8a16808edb4bf79a173076 Mon Sep 17 00:00:00 2001 From: ko1N Date: Mon, 22 Nov 2021 21:29:49 +0000 Subject: [PATCH] Fixed gap write handling when additional reads are required --- memflow-pcileech/src/lib.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/memflow-pcileech/src/lib.rs b/memflow-pcileech/src/lib.rs index f951cae..e3e17ea 100644 --- a/memflow-pcileech/src/lib.rs +++ b/memflow-pcileech/src/lib.rs @@ -308,17 +308,25 @@ impl PhysicalMemory for PciLeech { // dispatch necessary reads to fill the gaps if !gaps.is_empty() { - let iter = gaps.iter().map(|g| { - MemData( - g.gap_addr, - unsafe { slice::from_raw_parts_mut(g.gap_buffer, g.gap_buffer_len) }.into(), - ) - }); + let mut vec = gaps + .iter() + .map(|g| { + MemData( + g.gap_addr, + unsafe { slice::from_raw_parts_mut(g.gap_buffer, g.gap_buffer_len) }.into(), + ) + }) + .collect::>(); + + let mut iter = vec + .iter_mut() + .map(|MemData(a, d): &mut PhysicalReadData| MemData(*a, d.into())); let out_fail = &mut |_| true; - self.phys_read_raw_iter((&mut iter.clone()).into(), &mut out_fail.into())?; - for (gap, mut read) in gaps.iter().zip(iter) { + self.phys_read_raw_iter((&mut iter).into(), &mut out_fail.into())?; + + for (gap, mut read) in gaps.iter().zip(vec) { let in_buffer = unsafe { slice::from_raw_parts(gap.in_buffer, gap.in_end - gap.in_start) }; read.1[gap.in_start..gap.in_end].copy_from_slice(in_buffer);