From: Erik Terpstra Date: 2008-08-15T00:15:46+09:00 Subject: Re: Is it possible to extract data out of memory using Ruby? So if you would like to look at the 'in memory' representation of a Ruby String how would that work? require "dl" ptr = DL::PtrData.new 0 ptr.struct! "L", "val" size = ptr.size str = 'Hello world!' address = str.object_id * 2 value = ptr[ address, size ] puts [address, value].inspect TIA, Erik. Pit Capitain wrote: > 2008/8/14 Erik Terpstra : >> 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 -- Posted via http://www.ruby-forum.com/.