I need to redirect a function from the application by its pointer to my function from rust. Detors also crashes.
It's definitely not the function's memory address, because in C ++ this code works
I understand how it works in C ++, but I still do not fully understand how it should work in rust. I translated many other functions related to memory, but I still could not find a solution to this problem on the Internet
Are you sure you have declared the rust function properly in C++? In rust extern implicitly means extern "C". I'm not very acquainted with the winapi, nor am I in a position to do research (I'm on mobile).
ok, I need to set the value 0xE9 in the zero offset of the address, from offset 1 set the value, for example 0x1337 in the amount of 4 characters "/ x1 / x3 / x3 / x7"
One byte is two hexadecimal digits. I believe you mean to write \x00\x00\x13\x37. And even then, that's big endianâ âwhich, frankly, is uncommon! On little endian machines you probably want to write \x37\x13\x00\x00. The last one is what the C2Rust output would write on little endian machines (it's still not clear what issue you had with that code specifically).
There is one remaining issue of alignment. Either the input pointer must not be aligned to 4-byte boundaries (it needs to be aligned to a dword boundary minus 1), or the original C code invoked UB (in which case you can fix it by changing the last line of the C2Rust output to use ptr.write_unaligned instead of *ptr = ).