我做了一个拦截MESSAGEBOX函数的程序,可是它只能拦截本进程的MESSAGEBOX函数,我想拦截其它进程的怎么办啊?如何把DLL注入到其它的进程?希望大家能给出源代码,我想好好学学。。谢谢
解决方案 »
- 【求解】将客户端摄像头抓图上传到服务器的方法。
- 想了解一下delphi的三层架构如何实现?
- 如何截取浏览器弹出的Java脚本的窗口?
- 我想在公共单元内申请一变量,如何在一个窗体中正确引用他!!!!
- *.vsd和*.mdl可用什么打开。这大约是一个建模工具.
- 高手必读!!!
- 谁用过TinyDB数据引擎,用它怎么才能得到一个记录集呢
- 惊世之作!Visual DBTOOLS 3.0!
- 在线急!急!急!(一个简单的小问题)
- 如何通过窗体的Controls属性来控制窗体中的控件?
- 惊天大秘密: (微软真无耻) 目前微软推广的ERP Attain 居然是用Delphi开发的,而且这套系统的二次开发语言是纯Pascal语法!
- 调用EXE程序??
library mousehook;uses
SysUtils,
Classes,
Windows,
messages,
shellapi,
dialogs;type
Tmousehook=record
isrun:boolean;
hook:hhook;
end;
TlmportCode =packed record
Jumplnstruction: Word; //是$25FF,JUMP指令
AddressOfPointerToFunction: PPointer;//真正开始的地址
end;
PlmportCode = ^TlmportCode;type
TmessageA = function(hwn: hwnd; Iptext: pchar; Ipcapion:pchar; utype: cardinal): integer;stdcall;
TmessageW = function(hwn: hwnd; Iptext: pchar; Ipcapion:pchar; utype: cardinal): integer;stdcall;
var
mymousehook:Tmousehook;
FuncMessageboxA,FuncMessageBoxw:PlmportCode;
OldMessageBoxA: TmessageA;
OldMessageBoxW: TmessageW;{$R *.res}
function TrueFunctionAddress(func: Pointer): Pointer;
var
Code: PlmportCode;
Begin
Result:= func;
if func = nil then exit;
try
Code := func;
if (Code.jumplnstruction = $25FF) then begin
Result := Code.AddressOfPointerToFunction^;
end;
except
Result :=nil;
end;
end;
//这样,只要用自己的函数的地址代替它就可以了。替换函数:
Procedure PermuteFunction(OldFunc:Ppointer; NewFunc:Pointer);
var
written: DWORD;
begin
WriteProcessMemory(GetCurrentProcess,OldFunc,@NewFunc,4,written);
end;
function MyBoxA (hwn: hwnd; Iptext: pchar; Ipcapion:pchar; utype: cardinal): integer;stdcall;
begin
PermuteFunction(FuncMessageboxA.AddressOfPointerToFunction,@OldMessageboxA);
result :=OldMessageBoxA(hwn,'Succes Hook A!', Ipcapion,utype);
PermuteFunction(FuncMessageboxA.AddressOfPointerToFunction,@MyBoxA);
end;function MyBoxW (hwn: hwnd; Iptext: pchar; Ipcapion:pchar; utype: cardinal): integer;stdcall;
begin
PermuteFunction(FuncMessageboxW.AddressOfPointerToFunction,@OldMessageboxW);
result :=OldMessageBoxW(hwn,'成功挂上W!',Ipcapion,utype);
PermuteFunction(FuncMessageboxW.AddressOfPointerToFunction,@MyBoxW);
end;procedure API_Hookup;
begin
if @OldMessageBoxA = nil then
@OldMessageBoxA := TrueFunctionAddress(@messageboxA);
if @OldMessageBoxW = nil then
@OldMessageBoxW := TrueFunctionAddress(@messageboxW);
PermuteFunction(FuncMessageboxA.AddressOfPointerToFunction,@MyBoxA);
PermuteFunction(FuncMessageboxW.AddressOfPointerToFunction,@MyBoxW);
end;procedure Un_API_Hook;
begin
if @OldMessageBoxA <> nil then begin
PermuteFunction(FuncMessageboxA.AddressOfPointerToFunction,@OldMessageboxA);
PermuteFunction(FuncMessageboxW.AddressOfPointerToFunction,@OldMessageboxW);
end;
end;
function gethookinfo(code:integer;wp:WPARAM;lp:LPARAM):LResult;stdcall; begin
result:= CallNextHookEx(mymousehook.hook,code,wp,lp);
end; procedure installmousehook();stdcall;
begin
if not mymousehook.isrun then
begin
mymousehook.hook:=setwindowshookex(WH_MOUSE,@gethookinfo,HInstance,0);
mymousehook.isrun:=not mymousehook.isrun;
end;
end; procedure uninstallmousehook(); stdcall;
begin
if mymousehook.isrun then
begin
UnHookWindowsHookEx(mymousehook.hook);
mymousehook.isrun:=not mymousehook.isrun;
end;
end; Procedure DLLEntryPoint(dwReason:DWord); begin
Case dwReason of
DLL_PROCESS_ATTACH:begin
mymousehook.isrun:=false;
FuncMessageboxA := @MessageboxA;
FuncMessageBoxw := @MessageboxW;
API_Hookup;end;
DLL_PROCESS_DETACH:
begin
Un_API_Hook;
end;
DLL_THREAD_ATTACH:;
DLL_THREAD_DETACH:;
End;
end; exports
installmousehook,
uninstallmousehook;
begin
DLLProc := @DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end. 我的工程文件是这样写的:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
procedure installmousehook();stdcall;external 'mousehook.dll';
procedure uninstallmousehook();stdcall;external 'mousehook.dll'; {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
installmousehook();
end;procedure TForm1.Button2Click(Sender: TObject);
begin
uninstallmousehook();
end;procedure TForm1.Button3Click(Sender: TObject);
begin
MessageBoxA(Form1.Handle,'NO HOOK UP A','MessageBoxA',MB_OK);
MessageBoxW(Form1.Handle,'NO HOOK UP W','MessageBoxW',MB_OK);
MessageBox (Form1.Handle,'NO HOOK UP BOX','MessageBox',MB_OK);
end;end.
结果居然拦截不到MESSAGEBOX,包括本进程的都拦截不到,请大家帮忙分析一下。。
不胜感激~~~~~
找钩子及其应用,相信一定能帮你。