theorbtwo has asked for the wisdom of the Perl Monks concerning the following question:
Allo, all.
I'm attempting to do some pointer work, in pure perl, under win32 (winxp, with AS perl 5.8.2, build 808). In particular, at this point, I want to get a long out of memory at a given address. I've tried using Pointer, but found it to give mildly odd results, possibly because I don't really understand it's API.
My current incarnation looks like this:
This does not have the expected effect. In particular... I get printed out get_long_at(0x6761c) (the address is as expected.) Then, I get a nice dialog box:sub get_long_at { my $addr=shift; printf "get_long_at(0x%x)\n", $addr; my $data=unpack("P4", $addr); printf "Got it\n"; return unpack("L", $data); }
Note that 0x34333234 is the ASCII representation of 4324. What does this mean? I have no idea. It seems to be a constant, though. The backtrace, once I say debug, looks like this.The instruction at "0x77c4337c" referenced memory at "0x34333234". The memory could not be "read".
Click on OK to terminate the program
Click on CANCEL to debug the program
MSVCRT! 77c4337c() PERL58! Perl_sv_setpvn + 149 bytes PERL58! Perl_unpackstring + 2264 bytes PERL58! Perl_unpackstring + 58 bytes PERL58! Perl_unpackstring + 10147 bytes PERL58! Perl_runops_standard + 12 bytes PERL58! RunPerl + 134 bytes PERL! 00401012() KERNEL32! GetCurrentDirectoryW + 68 bytes
Note that the segfault is in Perl_sv_setpvn, and not directly in the upack code, which suggests to me that $data=unpack("P4", $addr); is doing something different then what I thought it did, and not that perl itself is buggy. Of course, it's always possible that I'm wrong.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: unpack "P" and a horrible death (packed)
by tye (Sage) on Mar 21, 2004 at 16:24 UTC | |
by Anonymous Monk on Mar 21, 2004 at 16:49 UTC | |
|
Re: unpack "P" and a horrible death
by bart (Canon) on Mar 21, 2004 at 17:28 UTC | |
|
Re: unpack "P" and a horrible death
by matija (Priest) on Mar 21, 2004 at 16:50 UTC |