in reply to How to access the contents of a specific memory address?
This is pretty much all of Perl's Perl Language pointer API. You can get a pointer to a scalar string (not a pointer to a scalar integers!!!, egh, actually you can, but if you need to do it, you know how to do it) and you can get a SV *and you can read an arbitrary memory location into a scalar string, null terminated or fixed length. pack wants pointers in packed binary "\x01\x02\x03\x04" format, not english/readable/perl scalar integers "1234567" format. Only major limitation is Perl language can't copy scalar strings to arbitrary memory address (but see this hack Pure Perl module(246 lines, Linux/Win32) that calls external libraries - no XS file., but its not pure Perl language (Dynaloader Module), so that doesn't meet the standard of pure Perl language, also there is syscall, I dont use unix, so I dont know if there is a way to call a C memcpy with syscall). My code is 32 bit only. Changes would have to be made for it to work on 64 bits.my $astring = "some string"; my $svptr = (\$astring)+0; #works on 32 bit ONLY my $packesvptr = pack('L', $svptr); my $svbinary = unpack('P[L4]', $packesvptr); my $packedPV = substr($svbinary, 4*3, 4); print "\"".unpack('p', $packedPV)."\"";#null terminated, use 'P[12345] +' for binary data print "\n\nExample 2\n\n"; $packedPV = pack('p', $astring ); print "\"".unpack('p', $packedPV)."\"";
pointer dereferencing with basic Perl commands (rather than any specially designed modules)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to access the contents of a specific memory address?
by pat_mc (Pilgrim) on Jul 29, 2012 at 19:48 UTC |