⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fuckedup.cs

📁 Hide-Delete icon from ToolBar32 for specific process , from command line arguments. TBBUTTON CSha
💻 CS
字号:
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace LicenseManage.BaseClasses
{
    using System.Threading;
    using HideSteamIcon;
    using Microsoft.VisualBasic;

    class FuckedUP
    {
        public static void FindAndKillButtons(string ProcessName) //ArrayList badstuff
        {
            
            IntPtr handleToolBar = GetToolbarWindowHandle(); //get toolbar handle

            UInt32 count = User32.SendMessage(handleToolBar, TB.BUTTONCOUNT, 0, 0); //get the button count from the toolbar tray

            bool found = false;

                for (int i = 0; i <= count; i++) //foreach button icon in toolbar..
                {
                    var text = String.Empty;
                    var ipWindowHandle = IntPtr.Zero;
                    if (IntPtr.Size == 8)
                    {
                        {
                            var tbButton1 = new TBBUTTONx64(); // structure for TBBUTTONx64
                            bool b = GetTBButton(handleToolBar, i, ref tbButton1, ref text, ref ipWindowHandle);
                                                }
                    }
                    else
                    {
                        {
                            var tbButton2 = new TBBUTTON(); // structure for TBBUTTON
                            bool b = GetTBButton(handleToolBar, i, ref tbButton2, ref text, ref ipWindowHandle);
                            
                        }
                    }
                    //test.Add(text);

                    //IntPtr window = RemoveIconsHelper.GetNotifyWindow();
                    //int count1 = (int)RemoveIconsHelper.SendMessage(window, RemoveIconsHelper.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero);

                    //for (int i1 = 0; i1 < count1; i1++)
                    //{
                    //    RemoveIconsHelper.SendMessage(window, RemoveIconsHelper.TB_DELETEBUTTON, i1, 0);
                    //}

                    
                    uint pid;
                    //get the process id from the Button ToolBar, usually explorer.exe
                    User32.GetWindowThreadProcessId(ipWindowHandle, out pid);
                    var pid_ = (int) pid;
                    Process CheckProcess = Process.GetProcessById((int)pid);
                    
                    if (CheckProcess.ProcessName.IndexOf(ProcessName) >= 0)
                    {
                        IntPtr test2 = RemoveIconsHelper.SendMessage(handleToolBar, RemoveIconsHelper.TB_HIDEBUTTON, i, 0);
                        IntPtr test3 = RemoveIconsHelper.SendMessage(handleToolBar, RemoveIconsHelper.TB_DELETEBUTTON, i, 0);
                        found = true;
                        //Console.WriteLine("TB Deleted Button");
                        
                    }
                    if (found)
                    {
                        Environment.Exit(1);
                    }
                 }
                 
                
            }
        

        private static unsafe bool GetTBButton(IntPtr hToolbar, int i, ref TBBUTTONx64 tbButton1, ref string text, ref IntPtr ipWindowHandle)
        {
            // One page
            const int BUFFER_SIZE = 0x1000;

            var localBuffer = new byte[BUFFER_SIZE];


            UInt32 processId;
 
            User32.GetWindowThreadProcessId(hToolbar, out processId);

            IntPtr hProcess = Kernel32.OpenProcess(ProcessRights.ALL_ACCESS, false, processId);

            IntPtr ipRemoteBuffer = Kernel32.VirtualAllocEx(hProcess, IntPtr.Zero, new UIntPtr(BUFFER_SIZE),
                                    MemAllocationType.COMMIT, MemoryProtection.PAGE_READWRITE);


            fixed (TBBUTTONx64* pTBButton = &tbButton1)
            {
                var ipTBButton = new IntPtr(pTBButton);

               

                    var b = (int)User32.SendMessage(hToolbar, TB.GETBUTTON, (IntPtr)i, ipRemoteBuffer);
                    if (b == 1)
                    {
                        

                     Kernel32.ReadProcessMemory(hProcess, ipRemoteBuffer, ipTBButton,new UIntPtr((uint)sizeof(TBBUTTON)), IntPtr.Zero);

                    }
                }
            // button text
            fixed (byte* pLocalBuffer = localBuffer)
            {
                var ipLocalBuffer = new IntPtr(pLocalBuffer);

                var chars = (int)User32.SendMessage(hToolbar, TB.GETBUTTONTEXTW, (IntPtr)tbButton1.idCommand, ipRemoteBuffer);
                
                if (chars > 2)
                {
                   Kernel32.ReadProcessMemory(hProcess, ipRemoteBuffer, ipLocalBuffer,
                                                        new UIntPtr(BUFFER_SIZE), IntPtr.Zero);
                   text = Marshal.PtrToStringUni(ipLocalBuffer, chars);
                   if (text == " ")
                        text = String.Empty;
                }
            }
            if (text == String.Empty)
            {
                Kernel32.VirtualFreeEx(hProcess, ipRemoteBuffer, UIntPtr.Zero, MemAllocationType.RELEASE);

                Kernel32.CloseHandle(hProcess);
                
                return true;
            }
            // window handle
            fixed (byte* pLocalBuffer = localBuffer)
            {
                var ipLocalBuffer = new IntPtr(pLocalBuffer);

                // this is in the remote virtual memory space
                var ipRemoteData = new IntPtr((void*)tbButton1.dwData);

                // this is fixed
                Int32 dwBytesRead = 0;
                var ipBytesRead = new IntPtr(&dwBytesRead);

                Kernel32.ReadProcessMemory(hProcess,  ipRemoteData, ipLocalBuffer, new UIntPtr(4), ipBytesRead);
                
                Int32 iWindowHandle = BitConverter.ToInt32(localBuffer, 0);
              
                ipWindowHandle = new IntPtr(iWindowHandle);
            }

            Kernel32.VirtualFreeEx(hProcess,ipRemoteBuffer,UIntPtr.Zero,MemAllocationType.RELEASE);

            Kernel32.CloseHandle(hProcess);
            return true;
        }

        private static unsafe bool GetTBButton(IntPtr hToolbar, int i, ref TBBUTTON tbButton, ref string text, ref IntPtr ipWindowHandle)
        {
            // One page
            const int BUFFER_SIZE = 0x1000;

            var localBuffer = new byte[BUFFER_SIZE];

            UInt32 processId;
            //The return value is the identifier of the thread that created the window. 
            User32.GetWindowThreadProcessId(hToolbar, out processId);
            
            //If the function succeeds, the return value is an open handle to the specified process
            IntPtr hProcess = Kernel32.OpenProcess(ProcessRights.ALL_ACCESS, false, processId);
      
            IntPtr ipRemoteBuffer = Kernel32.VirtualAllocEx(hProcess, IntPtr.Zero, new UIntPtr(BUFFER_SIZE),
                                    MemAllocationType.COMMIT, MemoryProtection.PAGE_READWRITE);

            fixed (TBBUTTON* pTBButton = &tbButton)
            {
                var ipTBButton = new IntPtr(pTBButton);
               
                    //gets the text from tooltip , for 'i' , returns 0 if failed , 1 if succeeds.
                    var b = (int) User32.SendMessage(hToolbar, TB.GETBUTTON, (IntPtr) i, ipRemoteBuffer);
                    if (b == 1)
                    { 
                        //{   Debug.Assert(false); return false;}  // this is fixed
                        
                        
                         Kernel32.ReadProcessMemory(hProcess, ipRemoteBuffer, ipTBButton,
                                                             new UIntPtr((uint) sizeof (TBBUTTON)), IntPtr.Zero);

                        }
                    }
                
            


            // button text
            fixed (byte* pLocalBuffer = localBuffer)
            {
                var ipLocalBuffer = new IntPtr(pLocalBuffer);

                var chars = (int)User32.SendMessage(hToolbar, TB.GETBUTTONTEXTW, (IntPtr)tbButton.idCommand, ipRemoteBuffer);
                //if (chars == -1) { Debug.Assert(false); return false; }
                if (chars > 2)
                {
                    

                     Kernel32.ReadProcessMemory(hProcess, ipRemoteBuffer, ipLocalBuffer,
                                                         new UIntPtr(BUFFER_SIZE), IntPtr.Zero);

                   

                    text = Marshal.PtrToStringUni(ipLocalBuffer, chars);

                    if (text == " ") 
                        text = String.Empty;
                }
            }

            // window handle
            fixed (byte* pLocalBuffer = localBuffer)
            {
                var ipLocalBuffer = new IntPtr(pLocalBuffer);

                // this is in the remote virtual memory space
                var ipRemoteData = new IntPtr((void*) tbButton.dwData);

                // this is fixed
                Int32 dwBytesRead = 0;
                var ipBytesRead = new IntPtr(&dwBytesRead);

                Kernel32.ReadProcessMemory(hProcess,  ipRemoteData,ipLocalBuffer,new UIntPtr(4),ipBytesRead);

                //if (!b4) { Debug.Assert(false); return false; }

                //if (dwBytesRead != 4) { Debug.Assert(false); return false; }

                Int32 iWindowHandle = BitConverter.ToInt32(localBuffer, 0);
               // if (iWindowHandle == -1) { Debug.Assert(false); }//return false; }

                ipWindowHandle = new IntPtr(iWindowHandle);
            }

            Kernel32.VirtualFreeEx(
                hProcess,
                ipRemoteBuffer,
                UIntPtr.Zero,
                MemAllocationType.RELEASE);

            Kernel32.CloseHandle(hProcess);
            return true;
        }
        


        private static IntPtr GetToolbarWindowHandle()
        {
            IntPtr hDesktop = User32.GetDesktopWindow();

            IntPtr hTray = User32.FindWindowEx( hDesktop, IntPtr.Zero, "Shell_TrayWnd", null );

            IntPtr hReBar = User32.FindWindowEx(hTray, IntPtr.Zero, "TrayNotifyWnd", null);

            IntPtr hTask = User32.FindWindowEx(hReBar, IntPtr.Zero, "SysPager", null);

            IntPtr hToolbar = User32.FindWindowEx( hTask, IntPtr.Zero, "ToolbarWindow32", null );

            if (hToolbar == IntPtr.Zero)
                hToolbar = IntPtr.Zero;
               //WinAPI.ShowMessage(0, "Couldn't find TooLbar.", "Error : ", 0);
            return hToolbar;
        }
    }
}

⌨️ 快捷键说明

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