jettero has asked for the wisdom of the Perl Monks concerning the following question:
my $handle; my $thispid = Win32::Process::GetCurrentProcessID(); # differs from $$ + under cygwin Win32::Process::Open($handle, $thispid, 1);
That much works well. I can $handle->Kill(1) and it works correctly. Next, I've tried to import ReadProcessMemory using this ...
my $readmem = Win32::API->new( kernel32 => q| BOOL ReadProcessMemory( HANDLE hProcess, LPCVOID lpBaseAddress, LPVOID lpBuffer, SIZE_T nS +ize, SIZE_T* lpNumberOfBytesRead )|);
... it didn't work cause it doesn't know LPCVOID. I discovered that it's really a pointer to a character string, so I changed it to LPSTR. Is that incorrect? I then call the thing like so:
my $buf = " " x 40; my $read = " " x 10; my $addr = "0"; my $len = length $buf; if( $readmem->Call($handle, $addr, $buf, $len, $read) ) { print "The read worked I guess($read): $!\n\t", unpack("H*", $buf) +, "\n"; } else { print "The read failed I guess($read): $!\n\t", unpack("H*", $buf) +, "\n"; }
I don't know if you can pass a Win32::Process handle or not, but I suspect that's my biggest problem. I also don't know what to put for the base address, but I'm hoping something like a "0" means "the beginning." Depending on what thing I tweak, I end up from anything to $!="no such file or directory" to segfaults. Am I misunderstanding Win32::API completely? Am I close?
Perhaps I should use something like
my $openpid = Win32::API->new( kernel32 => q|HANDLE OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD + dwProcessId)| );
instead of Win32::Process?
My ultimate goal is to dump the memory of another pid from perl to a file.
-Paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::API->new( ReadProcessMemory ) not working how I'd expect
by BrowserUk (Patriarch) on Aug 14, 2007 at 20:18 UTC | |
by jettero (Monsignor) on Aug 14, 2007 at 20:33 UTC | |
by BrowserUk (Patriarch) on Aug 14, 2007 at 22:07 UTC | |
by jettero (Monsignor) on Aug 15, 2007 at 01:30 UTC | |
by BrowserUk (Patriarch) on Aug 15, 2007 at 06:50 UTC |