Add a helper method for reading/writing memory#123
Merged
tenderlove merged 3 commits intomasterfrom Mar 16, 2023
Merged
Conversation
kou
reviewed
Mar 16, 2023
Member
kou
left a comment
There was a problem hiding this comment.
Hmm. Fiddle::Pointer[value] and Fiddle::Pointer[address, length] may be confused.
How about Fiddle::Pointer.read/Fiddle::Pointer.write (like IO.read/IO.write) instead?
Member
Author
That sounds good to me. I wish we could use |
This commit adds two new methods, `Fiddle::Pointer.read` and `Fiddle::Pointer.write`. Both methods take an address, and will read or write bytes at that address respectively. For example we can read from an address without making a Pointer object: ```ruby Fiddle::Pointer.read(address, 5) # read 5 bytes ``` We can also write to an address without allocating a Pointer object: ```ruby Fiddle::Pointer.write(address, "bytes") # write 5 bytes ``` This allows us to read / write memory at arbitrary addresses without instantiating a new `Fiddle::Pointer` object. Co-Authored-By: Sutou Kouhei <kou@clear-code.com>
e66658c to
687f214
Compare
kou
reviewed
Mar 16, 2023
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Jun 28, 2023
(ruby/fiddle#123) This commit adds two new methods, `Fiddle::Pointer.read` and `Fiddle::Pointer.write`. Both methods take an address, and will read or write bytes at that address respectively. For example we can read from an address without making a Pointer object: ```ruby Fiddle::Pointer.read(address, 5) # read 5 bytes ``` We can also write to an address without allocating a Pointer object: ```ruby Fiddle::Pointer.write(address, "bytes") # write 5 bytes ``` This allows us to read / write memory at arbitrary addresses without instantiating a new `Fiddle::Pointer` object. Examples where this API would be useful [1](https://github.com/tenderlove/tenderjit/blob/f03481d28bff4d248746e596929b0841de65f181/lib/tenderjit/fiddle_hacks.rb#L26-L28) [2](https://github.com/tenderlove/ruby/blob/77c8daa2d40dd58eeb3785ce17dea2ee38f308d1/lib/ruby_vm/rjit/c_pointer.rb#L193) [3](https://github.com/tenderlove/ruby/blob/77c8daa2d40dd58eeb3785ce17dea2ee38f308d1/lib/ruby_vm/rjit/c_pointer.rb#L284) I also added a writer method for the same reasons as the reader. --------- ruby/fiddle@04238cefed Co-authored-by: Sutou Kouhei <kou@clear-code.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit adds two new methods,
Fiddle::Pointer.readandFiddle::Pointer.write. Both methods take an address, and will read or write bytes at that address respectively.For example we can read from an address without making a Pointer object:
We can also write to an address without allocating a Pointer object:
This allows us to read / write memory at arbitrary addresses without instantiating a new
Fiddle::Pointerobject.Examples where this API would be useful 1 2 3
I also added a writer method for the same reasons as the reader.