From 90f0dc0044695dcc7d6512b04c5c0f01dafd275b Mon Sep 17 00:00:00 2001
From: "SND\\kernelnet_cp"
 <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Mon, 3 Oct 2011 10:51:11 +0000
Subject: [PATCH] git-svn-id: https://pykd.svn.codeplex.com/svn@70177
 9b283d60-5439-405e-af05-b73fd8c4d996

---
 pykd/dbgio.h | 224 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 224 insertions(+)
 create mode 100644 pykd/dbgio.h

diff --git a/pykd/dbgio.h b/pykd/dbgio.h
new file mode 100644
index 0000000..5294afb
--- /dev/null
+++ b/pykd/dbgio.h
@@ -0,0 +1,224 @@
+#pragma once
+
+#include <string>
+#include <dbgeng.h>
+
+#include "dbgext.h"
+
+/////////////////////////////////////////////////////////////////////////////////
+
+class dbgPrint {
+
+public:
+
+	static void dprint( const boost::python::object& obj, bool dml = false );
+	
+	static void dprintln( const boost::python::object& obj, bool dml = false );
+
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+// ����� ��� ��������� ������ � ��������
+
+class OutputReader : public IDebugOutputCallbacks {
+
+public:
+
+	OutputReader( IDebugClient  *debugClient ) 
+	{
+		HRESULT   hres;
+
+		try {
+
+			m_debugClient = debugClient;
+			m_debugClient->AddRef();
+
+			hres = m_debugClient->GetOutputCallbacks( &m_previousCallback );
+			if ( FAILED( hres ) )
+			{
+				throw hres;
+			}
+
+			hres = m_debugClient->SetOutputCallbacks( this );
+			if ( FAILED( hres ) )
+			{
+				throw hres;
+			}
+
+		} catch( ... )
+		{
+			m_debugClient->Release();
+			m_debugClient = NULL;
+		}
+	}
+
+	~OutputReader() 
+	{
+		if ( m_debugClient )
+		{
+			m_debugClient->SetOutputCallbacks( m_previousCallback );
+			m_debugClient->Release();
+		}
+	}
+
+	const std::string&
+	Line() const {
+		return  m_readLine;
+	}
+
+private:
+
+	 // IUnknown.
+    STDMETHOD(QueryInterface)(
+        __in REFIID InterfaceId,
+		__out PVOID* Interface ) {
+			return E_NOINTERFACE;
+	}
+
+	STDMETHOD_(ULONG, AddRef)() {
+		return 1L;
+	}
+
+
+	STDMETHOD_(ULONG, Release)() {
+		return 0L;
+	}
+
+   STDMETHOD(Output)(
+        __in ULONG Mask,
+        __in PCSTR Text )
+   {
+		if ( Mask == DEBUG_OUTPUT_NORMAL )
+		{
+			m_readLine += std::string( Text );
+		}
+
+	   return S_OK;
+   }
+
+private:
+
+	std::string               m_readLine;
+
+	IDebugClient             *m_debugClient;
+
+	IDebugOutputCallbacks    *m_previousCallback;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class InputReader : public IDebugInputCallbacks {
+
+public:
+
+    InputReader( IDebugClient  *debugClient ) 
+    {
+    	HRESULT   hres;
+
+		try {
+
+			m_debugClient = debugClient;
+			m_debugClient->AddRef();
+
+			hres = m_debugClient->GetInputCallbacks( &m_previousCallback );
+			if ( FAILED( hres ) )
+			{
+				throw hres;
+			}
+
+			hres = m_debugClient->SetInputCallbacks( this );
+			if ( FAILED( hres ) )
+			{
+				throw hres;
+			}
+
+		} catch( ... )
+		{
+			m_debugClient->Release();
+			m_debugClient = NULL;
+		}    
+    }
+    
+	~InputReader() 
+	{
+		if ( m_debugClient )
+		{
+			m_debugClient->SetInputCallbacks( m_previousCallback );
+			m_debugClient->Release();
+		}
+	}
+    
+
+private:
+
+	 // IUnknown.
+    STDMETHOD(QueryInterface)(
+        __in REFIID InterfaceId,
+		__out PVOID* Interface ) {
+			return E_NOINTERFACE;
+	}
+
+	STDMETHOD_(ULONG, AddRef)() {
+		return 1L;
+	}
+
+
+	STDMETHOD_(ULONG, Release)() {
+		return 0L;
+	}
+
+    STDMETHOD( EndInput )() {
+        return S_OK;
+    }        
+    
+    STDMETHOD( StartInput )(
+        IN ULONG  BufferSize ) {
+            return S_OK;
+    }        
+        
+private:
+
+	IDebugClient            *m_debugClient;
+
+    IDebugInputCallbacks    *m_previousCallback;           
+
+};
+
+
+/////////////////////////////////////////////////////////////////////////////////
+
+class dbgOut {
+
+public:
+
+    void
+    write( const boost::python::object  &str ) {
+        dbgPrint::dprint( str );
+    }         
+    
+};
+
+/////////////////////////////////////////////////////////////////////////////////
+
+class dbgIn {
+
+public:
+
+    std::string
+    readline() {
+    
+        char        str[100];
+        ULONG       inputSize;
+        
+        OutputReader        outputReader( dbgExt->client );
+    
+        dbgExt->control->Input( str, sizeof(str), &inputSize );
+    
+        return std::string( str );
+    }    
+
+};
+
+/////////////////////////////////////////////////////////////////////////////////
+