vxcall/toy-arms

Writing memory in an internal dll

Closed this issue · 6 comments

How does one do this? There are no example's for this specific thing, only for reading and writing patterns. In C++ it would go like this:

namespace mem {
    template<typename T>
    void write(DWORD64 addr, T value) {
        *((T*)addr) = value;
    }
}

mem::write<int>(localPlayer + offsets::playerHealth, 1337);

but it doesnt work the same way in Rust or well, i dont know how to.

To note, i have tried the following:

use toy_arms::GameObject;
use toy_arms_derive::GameObject;

#[derive(GameObject)]
struct LocalPlayer {
    pointer: *mut usize, // Denote the base address of LocalPlayer to use it later in get_health() function.
}

impl LocalPlayer {
    // snip

    unsafe fn set_health(&self, value: usize) {
        // *((T*)addr) = value;
        let base = self.pointer as *mut *mut usize;
        base.read().offset(0xEC).write(value);
    }
}

and many more attempts but they have all failed.

Hi, sorry for the inconvenience.
I haven't got to maintain this crate for a while, and Im working on performance tuning this weekend.
Some part of syntax slightly changed in middle of the process, so I'll done it first and answer your question when im ready to say anything definitive.
bear with me plz.

No worries, take your time.

Found out how to write memory after horrible seconds of figuring it out.

#[derive(GameObject)]
struct LocalPlayer {
    pointer: *mut usize, // Denote the base address of LocalPlayer to use it later in get_health() function.
}

impl LocalPlayer {
    // snip

    unsafe fn set_health(&self, value: usize) {
        let health_lmao = cast!(mut self.pointer as usize + offsets::player::HEALTH, usize);
        *health_lmao = value;
    }
}

Oh ya 💯 , u can use read:: instead of cast! macro which is not an intuitive to use.(same thing tho)
I didn't even know that cast! macro is exposed publicly...
I need to fix things up really

The cast macro was used in most of the internal examples, I'll check out the read macro.