2

朋友们

我有一个小问题。我试图在 RAD Studio 中创建一个带有表单的 delphi Dll,但我不知道如何使用 DllMain 加载它。我想在运行时将此 Dll 注入到第三方进程中

我用没有问题的表单创建了 Dll 项目,但是我找不到与“如何使用 DllMain 加载它”相关的任何好东西,或者至少我发现的教程/东西对我没有帮助(或者我只是哑的)。有人能帮我吗?给我一些提示或我可以学习的网站/视频?

我真的很感谢你们的时间!=)

4

1 回答 1

2

您可以使用程序集将基于 ebp 的堆栈注入到一些变量中。这是一个例子:

library Project1;

uses
  System.SysUtils,
  Windows,
  System.Classes;

var
  hInstDLL: THandle;
  fdwReason: DWORD;
  lpReserved: DWORD;
begin
  asm
    push eax; // Save the current eax
    mov eax, [ebp+$8] // Put into eax the first argument of the current function (DLLMain)
    mov [hInstDLL], eax; // Put into hInstDLL this argument
    mov eax, [ebp+$c] // Load into eax the second argument
    mov [fdwReason], eax; // Save to fdwReason
    mov eax, [ebp+$10] // Put into eax the last argument
    mov [lpReserved], eax; // Put into lpReserved (unnecessery)
    pop eax; // Restore the original eax value
  end;

  if fdwReason = 1 {DLL_PROCESS_ATTACH} then
  begin
    // Do your stuff;
  end;
end.
于 2021-02-17T03:41:10.883 回答