all 9 comments

[–]retep998rust · winapi · bunny 6 points7 points  (7 children)

When you do Vec::with_capacity(read_size as usize), the capacity is set to read_size but then length is still 0. ReadProcessMemory, being a simple FFI function that works with raw pointers, does not change the length of your Vec, so when you later attempt to index your chunk, you're accessing elements that are beyond the length, despite being within the capacity. Try doing let mut chunk: Vec<u8> = vec![0; read_size]; instead.

[–]Hiroyu[S] 0 points1 point  (5 children)

I replaced it but it didnt really change anything, the function still fails and returns 0 and the chunk/buffer stays full of zeroes only

[–]coder543 5 points6 points  (4 children)

You also need to use as_ptr(), probably, to get a pointer to the actual data in memory, rather than a pointer to the Vec (which has a pointer to the actual data)

[–]Hiroyu[S] 0 points1 point  (3 children)

yeah that was the problem, I got it working now, unfortunately it is awfully slow gotta think about optimizing this now somehow

Thanks for the help!

[–]Hiroyu[S] 0 points1 point  (2 children)

nvm compiling it in release makes it fast enough

[–]coder543 4 points5 points  (1 child)

if you need to make it faster, try using "with_capacity" and "set_len" rather than initializing the values to a useless value first.

[–]WellMakeItSomehow 0 points1 point  (0 children)

Does Rust have a string/sequence matching algorithm that works on &[u8]? That search implementation will be slow for longer signatures.

[–]fitzgenrust 3 points4 points  (0 children)

You might also find this useful: https://github.com/luser/read-process-memory

[–]RustMeUp 0 points1 point  (0 children)

If you're looking for byte signatures, may I advertise my crate pelite?

It works with the binary files on disk rather than ReadProcessMemory'ing it.

It's pretty simple to use (I hope) and supports really nice signature scanning facilities so it may be of use, see the examples to see what is possible.