def Receive(self): # Receive data from server bufObject = win32file.AllocateReadBuffer(ReadClient.BUFFER_SIZE) while True: try: (readRtn, data) = win32file.ReadFile(self.hPipe, bufObject) if readRtn != 0 and readRtn != winerror.ERROR_MORE_DATA: showFormat = 'ReadFile failed, w/err: {0} {1}: {2}' showInfo = showFormat.format( win32api.FormatMessage(win32api.GetLastError()), *get_file_line()) win32api.OutputDebugString(showInfo) break data_list = data.split(ReadClient.MSG_HEAD_FLAG) if self.receiver: for item in data_list: if len(item) > 0: self.receiver(item) except pywintypes.error as e: showFormat = '{0} failed, w/err: {1} {2}: {3}' showInfo = showFormat.format(e.args[1], e.args[2], *get_file_line()) win32api.OutputDebugString(showInfo) break
def debug(*arg, **karg): 'prints out TExdebug information to Win32 Debug Stream' if __debug__: tempstr = "" for a in arg: tempstr += "%s " % (a) win32api.OutputDebugString(tempstr) for k in karg: win32api.OutputDebugString("%s : %s" % (k, karg[k]))
def Connect(self): isFirstConnect = True while True: try: self.hPipe = win32file.CreateFile(self.pipePath, win32file.GENERIC_READ, 0, None, win32file.OPEN_EXISTING, 0, None) infoFormat = 'The named pipe {0} is connected.' info = infoFormat.format(self.pipePath) win32api.OutputDebugString(info) return self.hPipe except pywintypes.error as e: infoFormat = 'Unable to open named pipe {0}, w/err: {1}' info = infoFormat.format(self.pipePath, e.args[2]) win32api.OutputDebugString(info) if isFirstConnect: isFirstConnect = False # 如果提示没有找到文件,则等待一定时间之后再尝试打开 if e.args[0] == winerror.ERROR_FILE_NOT_FOUND: time.sleep(ReadClient.WAIT_TIMEOUT * ReadClient.MS_TO_SEC) continue elif e.args[0] == winerror.ERROR_PIPE_BUSY: # All pipes instances are busy, so wait for some seconds try: win32pipe.WaitNamedPipe(self.pipePath, ReadClient.WAIT_TIMEOUT) continue except pywintypes.error as waitError: # if waitError.args[0] == winerror.ERROR_SEM_TIMEOUT: infoFormat = '{0} {1} failed, w/err: {2}' info = infoFormat.format(waitError.args[1], self.pipePath, waitError.args[2]) win32api.OutputDebugString(info) return None else: # Exit if an error other than ERROR_FILE_NOT_FOUND or ERROR_PIPE_BUSY occurs return None else: return None
def HandleOutput(self, message): # debug("QueueOutput on thread %d, flags %d with '%s'...\n" % (win32api.GetCurrentThreadId(), self.writeQueueing, message )) self.outputQueue.put(message) if win32api.GetCurrentThreadId() != self.mainThreadId: pass # debug("not my thread - ignoring queue options!\n") elif self.writeQueueing == flags.WQ_LINE: pos = string.rfind(message, '\n') if pos >= 0: # debug("Line queueing - forcing flush\n") self.QueueFlush() return elif self.writeQueueing == flags.WQ_NONE: # debug("WQ_NONE - flushing!\n") self.QueueFlush() return # Let our idle handler get it - wake it up try: win32ui.GetMainFrame().PostMessage( win32con.WM_USER) # Kick main thread off. except win32ui.error: # This can happen as the app is shutting down, so we send it to the C++ debugger win32api.OutputDebugString(message)
def _ShowDebugInfo(self, item): try: msgType = Consumer.TYPE_MAP[item[Consumer.TYPE_FLAG]] except KeyError as e: win32api.OutputDebugString(str(e)) return showFormat = 'Receives Message: "{0}"' if msgType == Consumer.TYPE_HEARTBEAT: self.heartbeatCnt += 1 if self.heartbeatCnt % Consumer.HEARTBEAT_SHOW_INTERVAL == 0: showInfo = showFormat.format(item) else: showInfo = None else: showInfo = showFormat.format(item) if showInfo: win32api.OutputDebugString(showInfo)
def immunityANDollydbg(): win32api.OutputDebugString("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s") #[email protected] name = "Immunity Debugger - %s - [CPU - main thread, module %s]" % (os.path.basename(__file__).split(".py")[0]+".exe",os.path.basename(__file__).split(".py")[0]) name2 = "OllyDbg - %s - [CPU - main thread, module %s]" % (os.path.basename(__file__).split(".py")[0]+".exe",os.path.basename(__file__).split(".py")[0]) print name for x in [name,name2]: handle = win32gui.FindWindow(None, x) win32gui.PostMessage(handle,win32con.WM_CLOSE,0,0) if handle != 0: return True return False
def HandleOutput(self, message): debug("QueueOutput on thread %d, flags %d with '%s'..." % (win32api.GetCurrentThreadId(), self.writeQueueing, message)) self.outputQueue.put(message) if win32api.GetCurrentThreadId() != self.mainThreadId: debug("not my thread - ignoring queue options!\n") elif self.writeQueueing == flags.WQ_LINE: pos = string.rfind(message, '\n') if pos > 0: debug("Line queueing - forcing flush\n") return self.QueueFlush() elif self.writeQueueing == flags.WQ_NONE: debug("WQ_NONE - flushing!\n") return self.QueueFlush() # Let our idle handler get it - wake it up try: win32ui.GetMainFrame().PostMessage( win32con.WM_USER) # Kick main thread off. except win32ui.error: # This can happen as the app is shutting down, and possibly # if the event queue is full - either way, we ignore! win32api.OutputDebugString(message)
def Process(self, item): infoDict = {} infos = item.split(',') for subItem in infos: if len(subItem) > 0: infoItems = subItem.split(':') key = self._replace_seperator_alias_in_data( infoItems[0].strip()) val = self._replace_seperator_alias_in_data( infoItems[1].strip()) infoDict[key] = val self._ShowDebugInfo(infoDict) try: msgType = Consumer.TYPE_MAP[infoDict[Consumer.TYPE_FLAG]] if msgType != Consumer.TYPE_HEARTBEAT: if self.receiver: self.receiver(infoDict) except KeyError as e: win32api.OutputDebugString(str(e)) return
def write(self, message): try: self.redir.write(message) except: win32api.OutputDebugString(message)
def _trace_(self, *args): for arg in args[:-1]: win32api.OutputDebugString(str(arg) + " ") win32api.OutputDebugString(str(args[-1]) + "\n")
def DebugOutput(x): win32api.OutputDebugString(x)