Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The immediate problem in this code is that you're storing pointers to the string parameters in your record. Those pointers are addresses in your <em>main</em> process; they are not valid in the target process. You should store those values in fixed-size arrays in your record, just like you're already doing with the module and function names. Then initialize the pointer fields inside the remote function.</p> <p>But you're really making it more complicated than it needs to be. You don't need to use <code>GetProcAddress</code> in the remote function at all. Put you <em>entire function</em> in a DLL. There you can call whatever functions you want, and the Delphi linker and the OS loader will ensure that they're all available to call at run time. You also don't need to allocate all your variables with <code>VirtualAllocEx</code>; you can use ordinary local variables in your DLL function.</p> <p>You'll use <code>CreateRemoteThread</code> three times over the course of your program. The first time is to inject a call to <code>LoadLibrary</code> to get your DLL into the target process's address space. The second time is to invoke your injected function, and the third time is to call <code>FreeLibrary</code> after you're finished. The tricky part is finding the address of your injected function in the target process. <a href="http://www.codeproject.com/Articles/90271/Remote-threads-basics-Part-2.aspx" rel="nofollow noreferrer">Alexey Kurakin's article on Code Project</a> demonstrates how to do that by finding the <em>relative</em> address of the function in your own process, and the applying that offset to the remote process to determine the argument to pass to your second call to <code>CreateRemoteThread</code>.</p> <p>Finally, there's no need to declare the support records for <code>ShFileOperation</code> yourself. Delphi already declares them for you in the <em>ShellAPI</em> unit. There you'll also find the named constants for the various flags you need, like <code>fo_Copy</code> instead of <code>$0002</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload