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
|
||||
#[error("failed to get process/module")]
|
||||
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
|
||||
#[error("failed to convert integer")]
|
||||
ConvertIntegerError(#[from] std::num::TryFromIntError),
|
||||
|
||||
+7
-5
@@ -101,13 +101,15 @@ impl Process {
|
||||
|
||||
/// follow a pointer chain to the end and return an address
|
||||
pub fn resolve_pointer_chain(&self, chain: &[usize]) -> Result<usize, Error> {
|
||||
let mut chain = chain.to_vec();
|
||||
let mut address = chain.remove(0);
|
||||
while chain.len() > 1 {
|
||||
address += chain.remove(0);
|
||||
if chain.is_empty() {
|
||||
return Err(Error::ResolvePointerChainError("chain was empty".into()));
|
||||
}
|
||||
let mut address = chain[0];
|
||||
for &offset in &chain[1..(chain.len() - 1)] {
|
||||
address += offset;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user