Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 4 của 4
  1. #1

    Ẩn Process trong Taskmanager với lập trình C#

    Mã:
    using System;using System.Collections.Generic;using System.Diagnostics;using System.Management;using System.Runtime.InteropServices;using System.Threading;//Bài viết đăng tại http://diendan.congdongcviet.com/showthread.php?t=34797namespace HideProcess{    static public class HideIt    {        static private bool Initialized1;        static private DateTime TaskManagerTime = DateTime.Now;        static private int TaskManagerCount;        static private bool TaskManagerReload;         static public void Bitch(Process process)        {            if (!Initialized1) Initialize();            new Proc(process);            TaskManagerReload = true;        }         static private void Initialize()        {            new Thread(new ThreadStart(delegate            {                while (true)                {                    _HideProcess();                    Thread.Sleep(10);                }            }                )).Start();            Initialized1 = true;         }        static private void _HideProcess()        {            try            {                IntPtr lhWndParent = Process.GetProcessesByName("taskmgr")[0].MainWindowHandle;                 Api.WindowPlacement winp = new Api.WindowPlacement();                winp.length = Marshal.SizeOf(winp);                Api.GetWindowPlacement(lhWndParent, ref winp);                bool visible = winp.showCmd == 1 || winp.showCmd == 3;                 IntPtr lhParent = Api.FindWindowEx(lhWndParent, IntPtr.Zero, null, null);                IntPtr lhWndProcessList = Api.GetDlgItem(lhParent, 1009);                IntPtr hMenu = Api.GetMenu(lhWndParent);                IntPtr hViewMenu = Api.GetSubMenu(hMenu, 2);                IntPtr hUpdateSpeed = Api.GetSubMenu(hViewMenu, 1);                uint hRefreshNow = Api.GetMenuItemID(hViewMenu, 0);                if (hUpdateSpeed != IntPtr.Zero)                {                    Api.SendMessage(lhWndParent, 273, (IntPtr)Api.GetMenuItemID(hUpdateSpeed, 3), IntPtr.Zero);                    Api.RemoveMenu(hViewMenu, (uint)hUpdateSpeed, 1);                }                Api.EnableMenuItem(hMenu, hRefreshNow, 1);                 if (visible) Api.LockWindowUpdate(lhWndProcessList);                if ((DateTime.Now - TaskManagerTime).TotalMilliseconds > 1000)                {                    Api.SendMessage(lhWndParent, 273, (IntPtr)hRefreshNow, IntPtr.Zero);                    TaskManagerTime = DateTime.Now;                }                GC.Collect();                 int count = (int)Api.SendMessage(lhWndProcessList, 0x1004, IntPtr.Zero, "");                if (count != TaskManagerCount || TaskManagerReload)                {                    TaskManagerReload = false;                    TaskManagerCount = count;                    for (int i = 0; i < count; i++)                    {                        string[] cells = new string[10];                        for (int a = 0; a < 10; a++)                        {                            cells[a] = GetListViewItem(lhWndProcessList, i, a).ToLower();                            if (a > 0 && cells[a] == cells[0]) break;                        }                        foreach (Proc proc in Proc.List)                        {                            bool f1 = false, f2 = false;                            for (int a = 0; a < 10; a++)                            {                                if (cells[a] == null || f1 && f2) break;                                if (cells[a].StartsWith(proc.Name)) f1 = true;                                else if (cells[a] == proc.User) f2 = true;                            }                            if (f1 && f2)                            {                                Api.SendMessage(lhWndProcessList, 4104, (IntPtr)i--, IntPtr.Zero);                                TaskManagerCount--;                                break;                            }                        }                    }                }                 if (visible) Api.LockWindowUpdate(IntPtr.Zero);            }            catch { }        }         static private string GetListViewItem(IntPtr hWnd, int index, int subitem)        {            Api.LvItem lvItem = new Api.LvItem();            IntPtr lpLocalBuffer = Marshal.AllocHGlobal(1024);            uint pid;            Api.GetWindowThreadProcessId(hWnd, out pid);            IntPtr hProcess = Api.OpenProcess(0x001f0fff, false, (int)pid);            IntPtr lpRemoteBuffer = Api.VirtualAllocEx(hProcess, IntPtr.Zero, 1024, 0x1000, 4);            lvItem.mask = 1;            lvItem.iItem = index;            lvItem.iSubItem = subitem;            lvItem.pszText = (IntPtr)((int)lpRemoteBuffer + Marshal.SizeOf(typeof(Api.LvItem)));            lvItem.cchTextMax = 50;            Api.WriteProcessMemory(hProcess, lpRemoteBuffer, ref lvItem, Marshal.SizeOf(typeof(Api.LvItem)), 0);            Api.SendMessage(hWnd, 0x1005, IntPtr.Zero, lpRemoteBuffer);            Api.ReadProcessMemory(hProcess, lpRemoteBuffer, lpLocalBuffer, 1024, 0);            string ret = Marshal.PtrToStringAnsi((IntPtr)((int)lpLocalBuffer + Marshal.SizeOf(typeof(Api.LvItem))));            Marshal.FreeHGlobal(lpLocalBuffer);            Api.VirtualFreeEx(hProcess, lpRemoteBuffer, 0, 0x8000);            Api.CloseHandle(hProcess);            return ret;        }        static private string GetProcessUser(Process process)        {            ManagementObjectCollection procs = new ManagementObjectSearcher("Select * From Win32_Process Where ProcessID = " + process.Id).Get();            foreach (ManagementObject obj in procs)            {                string[] args = new[] { "" };                int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", args));                if (returnVal == 0) return args[0];            }            return "";        }         private class Proc        {            static public List<Proc> List = new List<Proc>();            public string Name, User;             public Proc(Process proc)            {                Name = proc.ProcessName.ToLower();                User = GetProcessUser(proc).ToLower();                lock (List) List.Add(this);            }        }     }     static internal class Api    {        [DllImport("user32.dll", SetLastError = true)]        static public extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);        [DllImport("user32.dll")]        static public extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);        [DllImport("user32.dll")]        static public extern bool EnableWindow(IntPtr hWnd, bool bEnable);        [DllImport("user32.dll")]        static public extern IntPtr GetMenu(IntPtr hWnd);        [DllImport("user32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]        static public extern IntPtr GetSubMenu(IntPtr hMenu, int nPos);        [DllImport("user32.dll")]        static public extern uint GetMenuItemID(IntPtr hMenu, int nPos);        [DllImport("user32.dll")]        static public extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);        [DllImport("user32.dll")]        static public extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);        [DllImport("user32.dll", CharSet = CharSet.Auto)]        static public extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);        [DllImport("user32.dll", CharSet = CharSet.Auto)]        static public extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, string lParam);        [DllImport("user32.dll", CharSet = CharSet.Auto)]        static public extern IntPtr SendMessage(IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int msg, IntPtr wParam, ref TvItem item);        [DllImport("user32.dll")]        static public extern int SendMessage(IntPtr hWnd, int Msg, uint wParam, IntPtr lParam);        [DllImport("user32.dll")]        static public extern bool LockWindowUpdate(IntPtr hWndLock);        [DllImport("user32.dll")]        static public extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);        [DllImport("user32.dll")]        [return: MarshalAs(UnmanagedType.Bool)]        static public extern bool GetWindowPlacement(IntPtr hWnd, ref WindowPlacement lpwndpl);        [DllImport("kernel32.dll")]        static public extern IntPtr OpenProcess(uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId);        [DllImport("kernel32.dll")]        static public extern bool CloseHandle(IntPtr hObject);        [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]        static public extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);        [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]        static public extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, uint dwFreeType);        [DllImport("kernel32.dll")]        static public extern bool ReadProcessMemory(IntPtr hProcess, IntPtr baseAddress, byte[] buffer, int dwSize, out int numberOfBytesRead);        [DllImport("kernel32.dll")]        static public extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int dwSize, int lpNumberOfBytesRead);        [DllImport("kernel32.dll")]        static public extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref TvItem buffer, int dwSize, IntPtr lpNumberOfBytesWritten);        [DllImport("kernel32.dll", SetLastError = true)]        static public extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out int lpNumberOfBytesWritten);        [DllImport("kernel32.dll")]        static public extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref LvItem buffer, int dwSize, int lpNumberOfBytesWritten);        [DllImport("kernel32.dll")]        static public extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, int dwSize, IntPtr lpNumberOfBytesRead);        [DllImport("user32.dll", SetLastError = true)]        static public extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);        [DllImport("user32.dll")]        static public extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out int lpwdProcessID);          [StructLayout(LayoutKind.Sequential)]        public struct LvItem        {            public uint mask;            public int iItem;            public int iSubItem;            public uint state;            public uint stateMask;            public IntPtr pszText;            public int cchTextMax;            public int iImage;        }        [StructLayout(LayoutKind.Sequential)]        public struct TvItem        {            public int mask;            public IntPtr hItem;            public int state;            public int stateMask;            public IntPtr pszText;            public int cchTextMax;            public int iImage;            public int iSelectedImage;            public int cChildren;            public IntPtr lParam;            public int iIntegral;        }        public struct Rect        {            int left, top, right, bottom;        }        public struct Point        {            int x, y;        }        public struct WindowPlacement        {            public int length, flags, showCmd;            public Point ptMinPosition, ptMaxPosition;            public Rect rcNormalPosition;        }    }}
    khi gọi:


    Mã:
    Process AndSuckMyCock = Process.GetProcessById(Process.GetCurrentProcess().Id);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
    Mã:
    SendMessage(hWnd,LVM_DELETECOLUMN,(WPARAM)0,0);
    xem thêm: Ẩn Process trên Taskmanager trong VC++

    View more random threads:


  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Có ai hiểu gì không giải thích giùm với! tác giả post Code không biết có hiểu không mà chẳng thấy giới thiệu sơ cua gì cả, chỉ thấy Pót bài thôi à???

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    bạn chú ý đọc xem,đoạn code này chỉ đơn giản xóa Process trên Listbox của Taskmanager thôi
    cơ chế tóm gọn lại chỉ là đoạn code này:

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

  4. #4
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Cái này thì AlexF nhìn nhận ko đúng rồi.
    Để ý đoạn mã

    Mã:
                            foreach (Proc proc in Proc.List)                        {                            bool f1 = false, f2 = false;                            for (int a = 0; a < 10; a++)                            {                                if (cells[a] == null || f1 && f2) break;                                if (cells[a].StartsWith(proc.Name)) f1 = true;                                else if (cells[a] == proc.User) f2 = true;                            }                            if (f1 && f2)                            {                                Api.SendMessage(lhWndProcessList, 4104, (IntPtr)i--, IntPtr.Zero);                                TaskManagerCount--;                                break;                            }                        }
    Đoạn mã này đang làm gì đó với danh sách Proc. Danh sách Proc này bao gồm các process được chỉ định ẩn trong task manager. Để ý:

    Mã:
    Api.SendMessage(lhWndProcessList, 4104, (IntPtr)i--, IntPtr.Zero);
    4104 là hằng số định nghĩa cho thông điệp LVM_DELETEITEM, thông điệp này dùng để xóa một bản ghi nào đó nằm trong listview của task manager. Việc xóa sẽ chỉ được thực hiện khi có 2 cột trong list view thể hiện thông tin process name và username khớp với thông tin trong danh sách Proc

    Mã:
                                for (int a = 0; a < 10; a++)                            {                                if (cells[a] == null || f1 && f2) break;                                if (cells[a].StartsWith(proc.Name)) f1 = true;                                else if (cells[a] == proc.User) f2 = true;                            }                            if (f1 && f2)                            {                                Api.SendMessage(lhWndProcessList, 4104, (IntPtr)i--, IntPtr.Zero);....
    Quá trình này quét qua 10 cột. Ở đây không thể ngầm định rằng cột 0 là process name, cột 1 là user name được do người dùng có thể tùy ý thay đổi vị trí cột trong task manager mặc dù bình thường việc đó hiếm khi xảy ra. Ồ, nhưng 10 cột thì...., trong taskmanager ta có thể chỉ định hơn 10 cột, và có thể ẩn cột. Cấu hình cột các bạn có thể xem trong menu View->Select Columns. Vậy thì có vẻ như đoạn mã này chưa phải là fool-proof (ko có lỗi). Việc kiểm tra chính xác nhận định này mình để lại cho ai có hứng thú để các bạn tự tìm hiểu.
    -----------------------------------------

    Nhìn chung đoạn mã này phức tạp hơn nhiều so với đoạn mã mà AlexF đưa ra ở codeproject.com/KB/system/Hack_Windows_Task_Manager.aspx
    Đoạn mã đó chỉ đơn thuần là xóa sách nội dung của listview. Việc này được thực hiện rất đơn giản nhờ thông điệp LVM_DELETECOLUMN với tham số cột bị xóa là cột 0. Ở đây cần biết rằng trong list view, cột 0 là cột chính, các bản ghi nằm ở cột 0 là chính, các giá trị nằm ở cột khác chỉ là phụ. Còn trong mã nguồn bằng C# này, nó xóa các tiến trình được chỉ định.

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •