По просьбе трудящихся накатал самоудаление через CreateRemoteThread:
| Код | uses TlHelp32;
function GetExplorerID : DWORD; var hSnap : THandle; pe32 : TProcessEntry32;
begin Result := DWORD(-1); hSnap := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0); pe32.dwSize := SizeOf(pe32); if Process32First(hSnap, pe32) then repeat if LowerCase(pe32.szExeFile) = 'explorer.exe' then begin Result := pe32.th32ProcessID; Break; end; until not Process32Next(hSnap, pe32);
CloseHandle (hSnap); end;
type TInjectCode = packed record PushOpcode : byte; // push FileName PushOperand : DWORD; CallOpcode : word; // call [DeleteFileA] CallOperand : DWORD; JzOpcode : byte; // jz @InjectCode JzOperand : byte; RetOpcode : byte; // ret AdrDeleteFile : DWORD; // адрес DeleteFileA FileName : array [0..4095] of char; // имя файла для удаления end;
var InjectCode : TInjectCode = (PushOpcode : $68; CallOpcode : $15FF; JzOpcode : $74; RetOpcode : $C3; );
procedure TForm1.Button1Click(Sender: TObject); var hExplorer, hThread : THandle; adrThread : pointer; Delta, tmp : DWORD;
begin hExplorer := OpenProcess (PROCESS_ALL_ACCESS, False, GetExplorerID);
adrThread := VirtualAllocEx (hExplorer, nil, SizeOf(InjectCode), MEM_COMMIT, PAGE_EXECUTE_READWRITE); Delta := DWORD(adrThread) - DWORD(@InjectCode); InjectCode.PushOperand := Delta + DWORD(@InjectCode.FileName); InjectCode.CallOperand := Delta + DWORD(@InjectCode.AdrDeleteFile); InjectCode.JzOperand := DWORD(@InjectCode) - DWORD(@InjectCode.RetOpcode); InjectCode.AdrDeleteFile := DWORD(GetProcAddress(LoadLibrary('kernel32.dll'), 'DeleteFileA')); CopyMemory (@InjectCode.FileName, PChar(Application.ExeName), Length(Application.ExeName)); WriteProcessMemory (hExplorer, adrThread, @InjectCode, SizeOf(InjectCode), tmp);
hThread := CreateRemoteThread (hExplorer, nil, 0, adrThread, nil, 0, tmp); CloseHandle (hThread); CloseHandle (hExplorer); end;
| Добавлено @ 20:30 Теперь, при выполнении этой процедурины в explorer'е создастся поток, который будет всё время пытаться удалить наш .exe-шник. Это ему удастся после того, как будет завершена наша прога... |