rdbo / libmem

Advanced Game Hacking Library for C, Modern C++, Rust and Python (Windows/Linux/FreeBSD) (Process/Memory Hacking) (Hooking/Detouring) (Cross Platform) (x86/x64/ARM/ARM64) (DLL/SO Injection) (Internal/External) (Assembler/Disassembler)
GNU Affero General Public License v3.0
738 stars 90 forks source link

Rust: no access to `lm_inst_t` properties. #217

Closed MeguminSama closed 1 month ago

MeguminSama commented 1 month ago

I'm using LM_Assemble and LM_Disassemble to automatically update jmp instruction operands, but there's no way to access the internal properties of lm_inst_t.

At the moment, to get the assembly string, I'm having to to_string the result of LM_Disassemble, split by " ->", and grab the first item in the array.

Would it be reasonable to make the properties of lm_inst_t public, or to provide functions to get access to the mnemonic, op_str, etc?

using libmem = { git = "https://github.com/rdbo/libmem.git", rev = "70745c82453e9ea38d289ff02c4dfc324df5c1ec" }

rdbo commented 1 month ago

The fields in the structs are not public because the Rust wrapper needs to do convertions between C strings and Rust strings, for example. I probably just forgot to do it at the time. The newer bindings will separate further the C API from the Rust API, where there will be a crate called libmem-sys (raw C bindings) and just libmem which will be more rusty Those bindings are not complete yet, but when 5.0.0 releases, you should expect to be able to access them normally. For the time being, best option might be to do functions like this in a fork:

impl lm_inst_t {
    pub fn get_mnemonic() -> String {
        string_from_cstring(&self.mnemonic)
    }

    pub fn get_op_str() -> String {
        string_from_cstring(&self.op_str)
    }
}
MeguminSama commented 1 month ago

Thanks for the quick response!

I was just looking into it and noticed the big move to libmem-sys (and that the properties are public on there).

I've switched over to libmem-sys for the time being, rather than making a fork - since the changes on my end were fairly minimal :)

Thanks!