#Can't return address from for_each_module loop

4 messages · Page 1 of 1 (latest)

gusty aurora
#

Hello! Noob here.

I am trying to find the base address of a module from the process id, but I have having trouble actually returning the address once it is found.

fn get_module_base_address(procid: u32) -> usize {
    let mut address_return: usize = 0x0;
    
    env_logger::init();
    for_each_module(procid, |(address, size), name| {
        println!("{}", name.display().to_string());
        if name.display().to_string().contains("ac_client.exe"){
            println!("address found = {}", address);
            let mut address_return= address;
        }
    })
    
    .unwrap();
    return address_return;
}

I am trying to make a function that finds the process ac_client.exe, then return the address of it in address_return. If no module is found, it returns the address, 0x0.

It won't let me return in the loop becuase it says "expected (), found usize". If I set address_return to the address, it says that variable is unused and returns 0x0, even though the address prints fine inside the loop.

crude basin
#

the closure you have there ```rust
|(address, size), name| {
println!("{}", name.display().to_string());
if name.display().to_string().contains("ac_client.exe"){
println!("address found = {}", address);
let mut address_return= address;
}
}


Is it's own scope effectively
#

I don't know what the traits are for for_each_module so cannot say for certain but you can try just doing address_return = address