Skip to content

Commit

Permalink
Added read_utf8 and read_utf8_lossy helpers to Pointer type
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1N committed Apr 8, 2024
1 parent 27372dc commit 591da3d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions memflow/src/types/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,29 @@ impl<U: PrimitiveAddress, T: Pod + Sized> Pointer<U, T> {

/// Implement special phys/virt read/write for CReprStr
impl<U: PrimitiveAddress> Pointer<U, ReprCString> {
pub fn read_string<M: MemoryView>(self, mem: &mut M) -> PartialResult<ReprCString> {
match mem.read_char_string(self.inner.to_umem().into()) {
pub fn read_utf8<M: MemoryView>(
self,
mem: &mut M,
max_length: usize,
) -> PartialResult<ReprCString> {
match mem.read_utf8(self.inner.to_umem().into(), max_length) {
Ok(s) => Ok(s.into()),
Err(PartialError::Error(e)) => Err(PartialError::Error(e)),
Err(PartialError::PartialVirtualRead(s)) => {
Err(PartialError::PartialVirtualRead(s.into()))
}
Err(PartialError::PartialVirtualWrite(s)) => {
Err(PartialError::PartialVirtualWrite(s.into()))
}
}
}

pub fn read_utf8_lossy<M: MemoryView>(
self,
mem: &mut M,
max_length: usize,
) -> PartialResult<ReprCString> {
match mem.read_utf8_lossy(self.inner.to_umem().into(), max_length) {
Ok(s) => Ok(s.into()),
Err(PartialError::Error(e)) => Err(PartialError::Error(e)),
Err(PartialError::PartialVirtualRead(s)) => {
Expand Down

0 comments on commit 591da3d

Please sign in to comment.