def parse_stream_header(h, ctxt, data): stream_type, stream_attributes, stream_size, stream_name_size = struct.unpack( win32_stream_id_format, data) print( "\nType:", stream_type, stream_types[stream_type], "Attributes:", stream_attributes, "Size:", stream_size, "Name len:", stream_name_size, ) if stream_name_size > 0: ## ??? sdk says this size is in characters, but it appears to be number of bytes ??? bytes_read, stream_name_buf, ctxt = win32file.BackupRead( h, stream_name_size, None, False, True, ctxt) stream_name = pywintypes.UnicodeFromRaw(stream_name_buf[:]) else: stream_name = "Unnamed" print("Name:" + stream_name) return ( ctxt, stream_type, stream_attributes, stream_size, stream_name_size, stream_name, )
def parseUString(data, start, limit): i = start while i < limit: if data[i:i + 2] == '\000\000': break i = i + 2 szKey = pywintypes.UnicodeFromRaw(data[start:i]) i = i + 2 #print "szKey:", '"'+str(szKey)+'"', "(consumed", i-start, "bytes - to", i, ")" return i, szKey
def get_item_text(hwnd, max_len=4): while True: # 创建char[] buf = ctypes.create_string_buffer(max_len) # 获取内容 if win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, max_len // 2, buf) == 0: return None # 如果以0,0,0,0结尾,说明缓冲区够大 if (buf.raw[-4], buf.raw[-3], buf.raw[-2], buf.raw[-1]) == (0, 0, 0, 0): # 转成utf-8 text = pywintypes.UnicodeFromRaw(buf.raw) # 去掉末尾的0就能返回 return text.strip('\00') # 否则把缓冲区扩大一倍重试 else: max_len *= 2