读书人

为何远程注入后宿主程序会进入假死状

发布时间: 2012-03-04 11:13:33 作者: rapoo

【求助】为何远程注入后,宿主程序会进入假死状态?
各位朋友好,我用网上找的代码,把我写的一个dll注入到记事本中,但是一旦注入,就会发现记事本进入假死状态,后来换成注入explorer.exe,就会发现系统不能正常使用了,只能强行结束explorer,请教各位朋友,如果才能使宿主程序不进入假死状态。

PS:附上dll里面的入口和所调用的函数:

library HookLib;

uses
Forms,
Windows,
SysUtils,
Classes,
UnitMouseHook in 'UnitMouseHook.pas',
Hooker in 'Hooker.pas' {frmBase},
Tasklist in 'Tasklist.pas' {frmTasklist},
UnitKeyHook in 'UnitKeyHook.pas';

{$R *.res}


procedure DllEntryPoint(dwReason: DWORD);
begin
case dwReason of
DLL_PROCESS_ATTACH:
begin
StartApp;
end;

DLL_PROCESS_DETACH:
begin

end;

DLL_THREAD_ATTACH:
begin
end;

DLL_THREAD_DETACH:
begin
end;
end;
end;

exports
StartApp;


begin
DllProc := @DllEntryPoint;
DllEntryPoint(DLL_PROCESS_ATTACH);
end.


function StartApp: BOOL; stdcall;
begin
Result := True;
try
try
Application.Initialize;
Application.CreateForm(TfrmBase, frmBase);
frmBase.FormStyle := fsStayOnTop;
Application.Run;
except
on e: Exception do
begin
Result := False;
end;
end;
finally
FreeAndNil(frmBase);
end;
end;

麻烦各位朋友帮忙想想办法,谢谢了。

[解决办法]
LZ这个程序里,dll代码不全吧,没有消息处理函数么?
[解决办法]

Delphi(Pascal) code
  Application.Initialize;  Application.CreateForm(TfrmBase, frmBase);  frmBase.FormStyle := fsStayOnTop;  Application.Run;
[解决办法]
探讨

DllEntryPoint(DLL_PROCESS_ATTACH);
这一句是多余的,删除掉,DllEntryPoint的指针已经赋值给了DllProc,这个是系统调用的,当其它应该程序加载你的DLL的时候就会调用DllEntryPoint过程,你可以在DLL_PROCESS_ATTACH里面加了MessageBox输出信息看一下就知道了。

[解决办法]
不好意思,果真是不会解发DLL_PROCESS_ATTACH,不过会自动触发DLL_PROCESS_DETACH,有点奇怪,在用VC写的DLL这些事件是自动触发的。可以用下面的试一下的,
Delphi(Pascal) code
var  frmBase: TfrmBase;procedure DllEntryPoint(dwReason: DWORD);begin  case dwReason of    DLL_PROCESS_ATTACH:    begin      frmBase:= TfrmBase.create(nil);      frmBase.FormStyle := fsStayOnTop;      frmBase.show;    end;    DLL_PROCESS_DETACH:    begin      if Assigned(frmBase) then        FreeAndNil(frmBase);    end;  end;end;begin  DllProc := @DllEntryPoint;  DllEntryPoint(DLL_PROCESS_ATTACH);end; 

读书人网 >.NET

热点推荐