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
Beispiel #2
0
 def getMultipleValues(self, hwnd, CountMessg, ValMessg, selected = None):
     buf_size = 512
     buf = create_string_buffer(pack_int(buf_size), buf_size)
     indexes = selected if selected else range(win32guiSendMessage(hwnd, CountMessg, 0, 0))
     val = []
     for ix in indexes:
         valLngth = win32guiSendMessage(hwnd, ValMessg, ix, addressof(buf))
         val.append(buf.value[:valLngth].decode(eg.systemEncoding))
     return val
Beispiel #3
0
 def getMultipleValues(self, hwnd, CountMessg, ValMessg, selected = None):
     buf_size = 512
     buf = create_string_buffer(pack_int(buf_size), buf_size)
     indexes = selected if selected else range(win32guiSendMessage(hwnd, CountMessg, 0, 0))
     val = []
     for ix in indexes:
         valLngth = win32guiSendMessage(hwnd, ValMessg, ix, addressof(buf))
         val.append(buf.value[:valLngth].decode(eg.systemEncoding))
     return 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
Beispiel #5
0
 def getListboxItems(self, hwnd):
     if self.only_sel:
         num_selected = win32guiSendMessage(hwnd, LB_GETSELCOUNT, 0, 0)
         if num_selected == LB_ERR:  # if we got LB_ERR then it is a single selection list box
             items = (win32guiSendMessage(hwnd, LB_GETCURSEL, 0, 0), )
         else:  # otherwise it is a multiselection list box
             items = (c_int * num_selected)()
             win32guiSendMessage(hwnd, LB_GETSELITEMS, num_selected, addressof(items))
             items = tuple(items)  # Convert from Ctypes array to a python tuple
     else:
         items = None
     return self.getMultipleValues(hwnd, LB_GETCOUNT, LB_GETTEXT, items)
Beispiel #6
0
 def getListboxItems(self, hwnd):
     if self.only_sel:
         num_selected = win32guiSendMessage(hwnd, LB_GETSELCOUNT, 0, 0)
         if num_selected == LB_ERR:  # if we got LB_ERR then it is a single selection list box
             items = (win32guiSendMessage(hwnd, LB_GETCURSEL, 0, 0), )
         else:  # otherwise it is a multiselection list box
             items = (c_int * num_selected)()
             win32guiSendMessage(hwnd, LB_GETSELITEMS, num_selected, addressof(items))
             items = tuple(items)  # Convert from Ctypes array to a python tuple
     else:
         items = None
     return self.getMultipleValues(hwnd, LB_GETCOUNT, LB_GETTEXT, items)
Beispiel #7
0
 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
Beispiel #8
0
 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 getComboboxItems(self, hwnd):
     if self.only_sel:
         items = (win32guiSendMessage(hwnd, CB_GETCURSEL, 0, 0), )
     else:
         items = None
     return self.getMultipleValues(hwnd, CB_GETCOUNT, CB_GETLBTEXT, items)
Beispiel #10
0
 def getComboboxItems(self, hwnd):
     if self.only_sel:
         items = (win32guiSendMessage(hwnd, CB_GETCURSEL, 0, 0), )
     else:
         items = None
     return self.getMultipleValues(hwnd, CB_GETCOUNT, CB_GETLBTEXT, items)