-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support reading from 32-bit processes on 64-bit hosts and vice versa #1
Conversation
For reference I haven't touched the code that Clippy is complaining about, but I can remove it if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for the pull request!
I wouldn't worry too much about the clippy warnings, they didn't exist at the time I last committed code, so that's on me to clean up.
I have a good number of nitpicks to improve the code. You can see the comments in the review.
src/data_member.rs
Outdated
@@ -53,6 +54,7 @@ impl<T: Sized + Copy> DataMember<T> { | |||
Self { | |||
offsets: Vec::new(), | |||
process: handle, | |||
arch: std::mem::size_of::<usize>() * 8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only place where arch
is used, you divide it by 8. I'd recommend not multiplying by 8 here so that you don't have an extra divide every time you try to call get_offset()
.
Thanks for checking out the PR and the constructive feedback, looking at what I can do to fix the issues. |
I've added another commit with most of the changes requested. The main thing I didn't do was the masking because when I try to take that approach I get
when trying to use I'm not super happy with |
The error you're talking about will be coming from https://github.com/Tommoa/rs-process-memory/blob/master/src/windows.rs#L72 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, you just need to run rustfmt
on architecture.rs
!
If possible, would you be able to put documentation examples of set_arch()
? I think that you might be able to get it working on x64 with 32-bit pointers as the stack usually grows from the bottom of the address space (unless ASLR messes with that, but I'm not sure).
Updated, thanks for all your comments. Hope the example is ok. |
Ah, I didn't realise that it would actually try to compile the examples. I'm not sure of a sensible way to demonstrate the feature within the same process. |
Read up on how the documentation examples worked and I've added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just one final thing that I missed in the last review.
Looking at the code examples has actually got me wondering about whether it'd be better to move the architecture stuff from DataMember<>
to ProcessHandle
. At the moment, ProcessHandle
is just an alias to a type, which is a pid_t
on Linux, a mach_port_name_t
and a HANDLE
on Windows. Perhaps by changing it to a struct that contains the handle and the architecture it'd make the API a little easier to work with, allowing you to define the architecture on the process handle itself (after all, you won't have different sized pointers within the same program unless someone is using relative pointers). Perhaps I'll work on that after this PR is merged!
src/architecture.rs
Outdated
|
||
/// Convert bytes read from memory into a pointer in the | ||
/// current architecture. | ||
pub fn pointer_from_ne_bytes(self, bytes: &Vec<u8>) -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be a slice (&[u8]
). You'd just need to remove all the as_slice()
s down the bottom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorted. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I'll do a rustfmt
after merging.
Thanks! |
Support setting the architecture of a DataMember to either 32 or 64 bit, defaulting to the pointer size of the host program.
Currently this setting only affects the traversal via
get_offset()
, but I had to make modifications tocopy_address()
due to rust-lang/rust#50824I'm new to rust so let me know if I can improve anything.