我想用delphi的Timer控件写一个定时程序,用来查找不同进程中是否含有指定的模块。但是运行时会出进内存占用不断增加的情况,关闭程序后才释放。
代码写得很烂
procedure TForm1.Timer1Timer(Sender: TObject);
var
hProcessSnap,hModuleSnap,PHandle:THandle;
ProcessEntry32:tagProcessEntry32;
ModuleEntry32:tagModuleEntry32;
Process32,Module32,sucessful:boolean;
FileName,DLLname,exename:string;
BaseAdd2,tt:Cardinal;
url,url1,url2: array [0..42] of char;
RV:dword;
const
RVA1:dword= $4a350;
RvA2:dword= $589e8;
BaseAdd1:dword=$400000;
begin
url:='url';
url1:='url1';
DLLname:='dllname';
exename:='exename';
hProcessSnap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessEntry32.dwSize:=sizeof(ProcessEntry32);
Process32:=Process32First(hProcessSnap, ProcessEntry32);
while Process32 do
begin
hModuleSnap:=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, ProcessEntry32.th32ProcessID);
ModuleEntry32.dwSize:=sizeof(ModuleEntry32);
Module32:=Module32First(hModuleSnap, ModuleEntry32);
while Module32 do
begin
FileName:=ExtractFileName(ModuleEntry32.szExePath);
if FileName=exename then
begin
RV:=BaseAdd1+RVA1;
PHandle:= OpenProcess(PROCESS_ALL_ACCESS, false,ProcessEntry32.th32ProcessID );
ReadProcessMemory(PHandle,Pointer(RV),@url2,43,tt);
if url=url2 then
begin
sucessful:= WriteProcessMemory(PHandle, Pointer(RV), @url1, sizeof(url1), tt);
CloseHandle(PHandle);
if sucessful then Label2.Caption:='成功'
else
Label2.Caption:='失败';
end;
end;
if FileName=dllName then
begin
BaseAdd2:=Cardinal(ModuleEntry32.modBaseAddr);
RV:=BaseAdd2+RVA2;
PHandle:= OpenProcess(PROCESS_ALL_ACCESS, false,ProcessEntry32.th32ProcessID );
ReadProcessMemory(PHandle,Pointer(RV),@url2,43,tt);
if url=url2 then
begin
sucessful:= WriteProcessMemory(PHandle, Pointer(RV), @url1, sizeof(url1), tt);
CloseHandle(PHandle);
if sucessful then Label2.Caption:='成功'
else Label2.Caption:='失败';
end;
end;
Module32:=Module32Next(hModuleSnap, ModuleEntry32);
end;
Process32:=Process32Next(hProcessSnap, ProcessEntry32);
end;
end;
[课程]Linux pwn 探索篇!