Pit Capitain
8/14/2008 7:42:00 AM
2008/8/14 Erik Terpstra <erik@ruby-lang.nl>:
> Is it possible to extract data out of memory using Ruby?
Erik, to read and write longs (4 bytes) I use the DL standard library
with the following code:
require "dl"
ptr = DL::PtrData.new 0
ptr.struct! "L", "val"
size = ptr.size
# read
ptr[ address, size ].unpack( "L" )[ 0 ]
# write
ptr[ address, size ] = [ val ].pack( "L" )
For reading and writing bytes you have to change the "L" to something
else. See the docs for the DL standard library.
Regards,
Pit