improve resolve_pointer_chain implementation
This commit is contained in:
@@ -15,6 +15,9 @@ pub enum Error {
|
|||||||
/// there was a failure in building the Process or Module struct
|
/// there was a failure in building the Process or Module struct
|
||||||
#[error("failed to get process/module")]
|
#[error("failed to get process/module")]
|
||||||
ProcessError(String),
|
ProcessError(String),
|
||||||
|
/// there was a failure in resolving a pointer chain
|
||||||
|
#[error("failed to resolve pointer chain")]
|
||||||
|
ResolvePointerChainError(String),
|
||||||
/// there was a failure in conversion between integers
|
/// there was a failure in conversion between integers
|
||||||
#[error("failed to convert integer")]
|
#[error("failed to convert integer")]
|
||||||
ConvertIntegerError(#[from] std::num::TryFromIntError),
|
ConvertIntegerError(#[from] std::num::TryFromIntError),
|
||||||
|
|||||||
+7
-5
@@ -101,13 +101,15 @@ impl Process {
|
|||||||
|
|
||||||
/// follow a pointer chain to the end and return an address
|
/// follow a pointer chain to the end and return an address
|
||||||
pub fn resolve_pointer_chain(&self, chain: &[usize]) -> Result<usize, Error> {
|
pub fn resolve_pointer_chain(&self, chain: &[usize]) -> Result<usize, Error> {
|
||||||
let mut chain = chain.to_vec();
|
if chain.is_empty() {
|
||||||
let mut address = chain.remove(0);
|
return Err(Error::ResolvePointerChainError("chain was empty".into()));
|
||||||
while chain.len() > 1 {
|
}
|
||||||
address += chain.remove(0);
|
let mut address = chain[0];
|
||||||
|
for &offset in &chain[1..(chain.len() - 1)] {
|
||||||
|
address += offset;
|
||||||
address = self.read_mem(address)?;
|
address = self.read_mem(address)?;
|
||||||
}
|
}
|
||||||
Ok(address + chain.remove(0))
|
Ok(address + chain.last().expect("chain should have a last element"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// read a given `address` of process's memory
|
/// read a given `address` of process's memory
|
||||||
|
|||||||
Reference in New Issue
Block a user