taskkill: Disallow process self-termination.
This commit is contained in:
parent
76e7fcc9d8
commit
fbcf44aa23
|
@ -38,4 +38,5 @@ STRINGTABLE
|
|||
STRING_SEARCH_FAILED, "Error: Could not find process \"%s\".\n"
|
||||
STRING_ENUM_FAILED, "Error: Unable to enumerate the process list.\n"
|
||||
STRING_TERMINATE_FAILED, "Error: Unable to terminate process \"%s\".\n"
|
||||
STRING_SELF_TERMINATION, "Error: Process self-termination is not permitted.\n"
|
||||
}
|
||||
|
|
|
@ -204,6 +204,7 @@ static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
|
|||
static int send_close_messages(void)
|
||||
{
|
||||
DWORD *pid_list, pid_list_size;
|
||||
DWORD self_pid = GetCurrentProcessId();
|
||||
unsigned int i;
|
||||
int status_code = 0;
|
||||
|
||||
|
@ -234,6 +235,13 @@ static int send_close_messages(void)
|
|||
DWORD pid = atoiW(task_list[i]);
|
||||
struct pid_close_info info = { pid };
|
||||
|
||||
if (pid == self_pid)
|
||||
{
|
||||
taskkill_message(STRING_SELF_TERMINATION);
|
||||
status_code = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
EnumWindows(pid_enum_proc, (LPARAM)&info);
|
||||
if (info.found)
|
||||
taskkill_message_printfW(STRING_CLOSE_PID_SEARCH, pid);
|
||||
|
@ -258,6 +266,13 @@ static int send_close_messages(void)
|
|||
struct pid_close_info info = { pid_list[index] };
|
||||
|
||||
found_process = TRUE;
|
||||
if (pid_list[index] == self_pid)
|
||||
{
|
||||
taskkill_message(STRING_SELF_TERMINATION);
|
||||
status_code = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
EnumWindows(pid_enum_proc, (LPARAM)&info);
|
||||
taskkill_message_printfW(STRING_CLOSE_PROC_SRCH, process_name, pid_list[index]);
|
||||
}
|
||||
|
@ -278,6 +293,7 @@ static int send_close_messages(void)
|
|||
static int terminate_processes(void)
|
||||
{
|
||||
DWORD *pid_list, pid_list_size;
|
||||
DWORD self_pid = GetCurrentProcessId();
|
||||
unsigned int i;
|
||||
int status_code = 0;
|
||||
|
||||
|
@ -308,6 +324,13 @@ static int terminate_processes(void)
|
|||
DWORD pid = atoiW(task_list[i]);
|
||||
HANDLE process;
|
||||
|
||||
if (pid == self_pid)
|
||||
{
|
||||
taskkill_message(STRING_SELF_TERMINATION);
|
||||
status_code = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||
if (!process)
|
||||
{
|
||||
|
@ -341,6 +364,13 @@ static int terminate_processes(void)
|
|||
{
|
||||
HANDLE process;
|
||||
|
||||
if (pid_list[index] == self_pid)
|
||||
{
|
||||
taskkill_message(STRING_SELF_TERMINATION);
|
||||
status_code = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
process = OpenProcess(PROCESS_TERMINATE, FALSE, pid_list[index]);
|
||||
if (!process)
|
||||
{
|
||||
|
|
|
@ -34,3 +34,4 @@
|
|||
#define STRING_SEARCH_FAILED 111
|
||||
#define STRING_ENUM_FAILED 112
|
||||
#define STRING_TERMINATE_FAILED 113
|
||||
#define STRING_SELF_TERMINATION 114
|
||||
|
|
Loading…
Reference in New Issue