Esempio n. 1
0
        public static unsafe string GetListViewItem(IntPtr hwnd, uint processId, int item, int subItem = 0)
        {
            int    num1 = 0;
            IntPtr num2 = IntPtr.Zero;
            IntPtr num3 = IntPtr.Zero;
            IntPtr num4 = IntPtr.Zero;

            try
            {
                LV_ITEM lpBuffer = new LV_ITEM();
                num4 = Marshal.AllocHGlobal(2048);
                num2 = ListViewItem1.OpenProcess(Win32ProcessAccessType.AllAccess, false, processId);
                if (num2 == IntPtr.Zero)
                {
                    throw new ApplicationException("Failed to access process!");
                }
                num3 = ListViewItem1.VirtualAllocEx(num2, IntPtr.Zero, 2048U, Win32AllocationTypes.MEM_COMMIT, Win32MemoryProtection.PAGE_READWRITE);
                if (num3 == IntPtr.Zero)
                {
                    throw new SystemException("Failed to allocate memory in remote process");
                }
                lpBuffer.mask       = 1;
                lpBuffer.iItem      = item;
                lpBuffer.iSubItem   = subItem;
                lpBuffer.pszText    = (char *)(num3.ToInt32() + Marshal.SizeOf(typeof(LV_ITEM)));
                lpBuffer.cchTextMax = 500;
                if (!ListViewItem1.WriteProcessMemory(num2, num3, ref lpBuffer, (uint)Marshal.SizeOf(typeof(LV_ITEM)), out num1))
                {
                    throw new SystemException("Failed to write to process memory");
                }
                ListViewItem1.SendMessageTimeout(hwnd, 4171, IntPtr.Zero, num3, 2, 5000, IntPtr.Zero);
                if (!ListViewItem1.ReadProcessMemory(num2, num3, num4, 2048, out num1))
                {
                    throw new SystemException("Failed to read from process memory");
                }
                return(Marshal.PtrToStringUni((IntPtr)(num4.ToInt32() + Marshal.SizeOf(typeof(LV_ITEM)))));
            }
            finally
            {
                if (num4 != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(num4);
                }
                if (num3 != IntPtr.Zero)
                {
                    ListViewItem1.VirtualFreeEx(num2, num3, 0, Win32AllocationTypes.MEM_RELEASE);
                }
                if (num2 != IntPtr.Zero)
                {
                    ListViewItem1.CloseHandle(num2);
                }
            }
        }
Esempio n. 2
0
        public static void SelectListViewItem(IntPtr hwnd, uint processId, int item)
        {
            IntPtr  zero1    = IntPtr.Zero;
            IntPtr  zero2    = IntPtr.Zero;
            IntPtr  num1     = IntPtr.Zero;
            LV_ITEM lpBuffer = new LV_ITEM();

            num1 = Marshal.AllocHGlobal(2048);
            IntPtr num2 = ListViewItem1.OpenProcess(Win32ProcessAccessType.AllAccess, false, processId);
            IntPtr num3 = ListViewItem1.VirtualAllocEx(num2, IntPtr.Zero, 2048U, Win32AllocationTypes.MEM_COMMIT, Win32MemoryProtection.PAGE_READWRITE);

            lpBuffer.state     = 3;
            lpBuffer.stateMask = 3;
            IntPtr zero3 = IntPtr.Zero;
            int    lpNumberOfBytesWritten = 0;

            ListViewItem1.WriteProcessMemory(num2, num3, ref lpBuffer, (uint)Marshal.SizeOf(typeof(LV_ITEM)), out lpNumberOfBytesWritten);
            ListViewItem1.SendMessageTimeout(hwnd, 4139, (IntPtr)item, num3, 2, 5000, IntPtr.Zero);
            ListViewItem1.VirtualFreeEx(num2, num3, 0, Win32AllocationTypes.MEM_RELEASE);
            ListViewItem1.CloseHandle(num2);
        }
Esempio n. 3
0
 internal static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, ref LV_ITEM lpBuffer, uint nSize, out int lpNumberOfBytesWritten);