كود:
code en delphi
Here is Delphi example of hook dll. To install hook - call from .EXE SetHook function.
When DLL is injected into process - it is examine command line to find - "am i injected
onto taskmanager process?" If so -
seek "SysListView32" controls ( Task and Process listviews).
library HookLib;
uses
SysUtils,
Classes, Windows;
var hHook: integer;
hMod: THANDLE;
CurL: integer;
L: array[0..1] of integer;
EnabledIt: Boolean;
procedure DOUT(s:String);
begin
OutputDebugString(PChar(s+#10#13));
end;
function ResetWindowProc(hwnd:integer; NewProc:DWORD):DWORD;
begin
Result := SetWindowLong(hwnd,GWL_WNDPROC, NewProc);
end;
function FindListView(hwnd, prev: integer): boolean;
var wText: PChar;
begin
wText := AllocMem(250);
Result := FALSE;
if (CurL = 2) or (hwnd=0) then Exit;;
if(GetClassName(hwnd, wText, 250) <> 0) then
if wText = 'SysListView32' then
begin
L[CurL] := hwnd;
inc(CurL);
GetWindowText(hwnd, wText, 250);
DOUT(wText + ' ' + 'Found!');
end;
FindListView(GetWindow(hwnd, GW_CHILD), hwnd);
FindListView(GetWindow(hwnd, GW_HWNDNEXT), hwnd);
Result := TRUE;
end;
function HookProc(Code, wParam, lParam: integer): Integer; stdcall;
begin
if (Code = HSHELL_WINDOWCREATED) and (EnabledIt) then
begin
FindListView(wParam, 0);
end;
Result := CallNextHookEx(hHook, Code, wParam, lParam);
end;
function SetHook: DWORD;stdcall;
begin
hHook := SetWindowsHookEx(WH_SHELL, @HookProc, hMod, 0 );
Result := 0;
end;
function ResetHook: DWORD;stdcall;
begin
UnhookWindowsHookEx(hHook);
Result := 0;
end;
procedure InitDLL;
begin
EnabledIt := FALSE;
DOUT(GetCommandLine());
If Pos('taskmgr', GetCommandLine()) <> 0 Then EnabledIt := TRUE;
hMod := GetModuleHandle('HookLib.dll');
end;
exports SetHook, ResetHook;
begin
InitDLL;
end.