I'm trying to get Win32::API to work with Win32::Process. I don't know if that's even possible. I'm trying to do a memory dump of a process for hex-editor-like activities.
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


In reply to dumping the memory of a foreign win32 pid from perl by jettero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.