def getStatusBarItems(self, hwnd, buf_len=512): """If success, return statusbar texts like list of strings. Otherwise return either '>>> No process ! <<<' or '>>> No parts ! <<<'. Mandatory argument: handle of statusbar. Option argument: length of text buffer.""" pid = GetWindowThreadProcessId(hwnd)[1] process = _kernel32.OpenProcess( PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, False, pid) res_val = ['>>> No process ! <<<'] if process: parts = win32guiSendMessage(hwnd, SB_GETPARTS, 0, 0) partList = [] res_val = ['>>> No parts ! <<<'] if parts > 0: remBuf = _kernel32.VirtualAllocEx(process, None, buf_len, MEM_COMMIT, PAGE_READWRITE) locBuf = create_unicode_buffer(buf_len) for item in range(parts): win32guiSendMessage(hwnd, SB_GETTEXTW, item, remBuf) _kernel32.ReadProcessMemory(process, remBuf, locBuf, buf_len, None) #copy remBuf to locBuf partList.append(locBuf.value) res_val = partList _kernel32.VirtualFreeEx(process, remBuf, 0, MEM_RELEASE) CloseHandle(process) return res_val
def getListViewItems(self, hwnd): col = LVCOLUMN() col.mask = LVCF_FMT | LVCF_IMAGE | LVCF_ORDER | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH pid = GetWindowThreadProcessId(hwnd)[1] hProcHnd = _kernel32.OpenProcess(PROCESS_ALL_ACCESS, False, pid) pLVI = _kernel32.VirtualAllocEx(hProcHnd, 0, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) col.cchTextMax = 2000 col.pszText = pLVI + sizeof(col) + 1 ret = _kernel32.WriteProcessMemory(hProcHnd, pLVI, addressof(col), sizeof(col), 0) if not ret: raise WinError() retval = 1 col_count = 0 while retval: # Columns enumeration try: retval = win32guiSendMessage(hwnd, LVM_GETCOLUMN, col_count, pLVI) except: retval = 0 raise col_count += 1 pBuffer = _kernel32.VirtualAllocEx(hProcHnd, 0, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) lvitem_str = 20 * "\x00" + pack_int(pBuffer) + pack_int( 4096) + 8 * "\x00" lvitem_buffer = create_string_buffer(lvitem_str) num_items = win32guiSendMessage(hwnd, LVM_GETITEMCOUNT) res = [] for column_index in range(col_count): lvitem_buffer.__setslice__( 8, 12, pack_int(column_index)) #column index increment _kernel32.WriteProcessMemory(hProcHnd, pLVI, addressof(lvitem_buffer), sizeof(lvitem_buffer), 0) target_buff = create_string_buffer(4096) item_texts = [] for item_index in range(num_items): if self.only_sel: if not win32guiSendMessage(hwnd, LVM_GETITEMSTATE, item_index, LVIS_SELECTED): continue win32guiSendMessage(hwnd, LVM_GETITEMTEXT, item_index, pLVI) _kernel32.ReadProcessMemory(hProcHnd, pBuffer, addressof(target_buff), 4096, 0) item_texts.append(target_buff.value) res.append(item_texts) _kernel32.VirtualFreeEx(hProcHnd, pBuffer, 0, MEM_RELEASE) _kernel32.VirtualFreeEx(hProcHnd, pLVI, 0, MEM_RELEASE) CloseHandle(hProcHnd) return map( list, zip(*res)) #Transposing Two-Dimensional Arrays by Steve Holden