Skip to content

Commit

Permalink
Merge pull request #5 from a2x/main
Browse files Browse the repository at this point in the history
Handle partial memory reads gracefully in ReadProcessMemory
  • Loading branch information
ko1N authored Apr 7, 2024
2 parents 1fa5f56 + d157b7d commit ebc9a25
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/windows/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::sync::Arc;

use super::{conv_err, Handle};

use windows::core::HRESULT;
use windows::Win32::System::Diagnostics::Debug::{ReadProcessMemory, WriteProcessMemory};
use windows::Win32::System::Threading::{
OpenProcess, PROCESS_QUERY_INFORMATION, PROCESS_VM_READ, PROCESS_VM_WRITE,
Expand Down Expand Up @@ -80,9 +81,12 @@ impl<'a> RWSlice for CSliceMut<'a, u8> {
size: usize,
) -> Result<usize> {
let mut written = 0;
ReadProcessMemory(**handle, remote, local as _, size, Some(&mut written))
.map_err(conv_err)?;
Ok(written)

match ReadProcessMemory(**handle, remote, local as _, size, Some(&mut written)) {
Ok(_) => Ok(written),
Err(err) if err.code() == HRESULT::from_win32(299) => Ok(written), // ERROR_PARTIAL_COPY
Err(err) => Err(conv_err(err)),
}
}
}

Expand Down

0 comments on commit ebc9a25

Please sign in to comment.