本文整理自网络,侵删。
unit Unit1;
interface
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,TlHelp32, Vcl.StdCtrls;
type TForm1 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
function FindProcess(AFileName:string):boolean;varhSnapshot:THandle;lppe:TProcessEntry32;Found:Boolean;beginResult:=False;hSnapshot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);lppe.dwSize:=SizeOf(TProcessEntry32);Found:=Process32First(hSnapshot,lppe);while Found do begin if((UpperCase(ExtractFileName(lppe.szExeFile))=UpperCase(AFileName)) or (UpperCase(lppe.szExeFile )=UpperCase(AFileName))) then begin Result:=True; end; Found:=Process32Next(hSnapshot,lppe); end;end;
procedure TForm1.FormCreate(Sender: TObject);vari:integer;TITLES:tstringlist;EXES:tstringlist;DLLS:tstringlist; Hwnd:THandle; Buf: array[0..MAX_PATH] of char;beginTITLES:=tstringlist.Create;TITLES.Add('窗口标题');
EXES:=tstringlist.Create;EXES.Add('123.exe');
DLLS:=tstringlist.Create;DLLS.Add('123.dll');
//更具DLL判断外挂 for I := 0 to DLLS.Count - 1 do begin if (LoadLibrary(PChar(DLLS.Strings[i]))>0) then begin WinExec('cmd.exe /c echo 发现非法外挂.错误代码:101! & pause',SW_SHOW); ExitProcess(0); end; end;
//遍历窗口 Hwnd:=GetDesktopWindow; Hwnd := GetWindow(hwnd, GW_CHILD); while hwnd <> 0 do begin GetWindowText(hwnd,Buf,length(buf)); if Buf <> '' then begin //更具标题关闭游戏进程 for I := 0 to TITLES.Count - 1 do begin if (pos(TITLES.Strings[i],Buf) >0) then begin WinExec('cmd.exe /c echo 发现非法外挂.错误代码:102! & pause',SW_SHOW); ExitProcess(0); end; end; end; Hwnd := GetWindow(hwnd, GW_HWNDNEXT); end;
//更具进程名杀进程 for I := 0 to EXES.Count - 1 do begin if FindProcess(EXES.Strings[i]) then begin WinExec('cmd.exe /c echo 发现非法外挂.错误代码:103! & pause',SW_SHOW); ExitProcess(0); end; end;
end;
end.
相关阅读 >>
Delphi 测试字符串写入类: tstringwriter
Delphi 每年、月、周、日的开始与结束的时间startofayear … startoftheyear … endofayear … endoftheyear
Delphi pchar和array [0..255] of char的区别
更多相关阅读请进入《Delphi》频道 >>