From c74a81d5600e3829fcd2b611a01f8d028db70263 Mon Sep 17 00:00:00 2001
From: "SND\\kernelnet_cp"
 <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Mon, 7 Feb 2011 07:59:22 +0000
Subject: [PATCH] [+] added : isValid() routine; it validates virtual address

git-svn-id: https://pykd.svn.codeplex.com/svn@61122 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/dbgext.cpp |  1 +
 pykd/dbgmem.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++
 pykd/dbgmem.h   |  3 +++
 3 files changed, 46 insertions(+)

diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp
index 16d6df4..4dca1b6 100644
--- a/pykd/dbgext.cpp
+++ b/pykd/dbgext.cpp
@@ -98,6 +98,7 @@ BOOST_PYTHON_MODULE( pykd )
     boost::python::def( "dprintln", &DbgPrint::dprintln, dprintln( boost::python::args( "str", "dml" ), ""  ) );
     boost::python::def( "loadDump", &dbgLoadDump );
     boost::python::def( "dbgCommand", &dbgCommand );
+    boost::python::def( "isValid", &isOffsetValid );
     boost::python::def( "is64bitSystem", &is64bitSystem );
     boost::python::def( "isKernelDebugging", &isKernelDebugging );
     boost::python::def( "ptrSize", ptrSize );
diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp
index 0bb911b..dde15a7 100644
--- a/pykd/dbgmem.cpp
+++ b/pykd/dbgmem.cpp
@@ -4,6 +4,7 @@
 #include "dbgexcept.h"
 #include "dbgmem.h"
 #include "dbgsystem.h"
+#include "dbgcallback.h"
 
 using namespace std;
 
@@ -525,4 +526,45 @@ loadLinkedList( ULONG64 address )
     return objList;
 }
 
+///////////////////////////////////////////////////////////////////////////////////
+
+bool
+isOffsetValid( ULONG64  addr )
+{
+    HRESULT     hres;
+
+    try {
+    
+        // ����� �������� ��������� ����� � ������� �� ������������� �������� ������
+        OutputReader outputReader( dbgExt->client );    
+    
+        ULONG       offsetInfo;
+        
+        hres = 
+            dbgExt->dataSpaces4->GetOffsetInformation(
+                DEBUG_DATA_SPACE_VIRTUAL,
+                DEBUG_OFFSINFO_VIRTUAL_SOURCE,
+                addr,
+                &offsetInfo,
+                sizeof( offsetInfo ),
+                NULL );
+                
+        if ( FAILED( hres ) )
+            throw DbgException( "IDebugDataSpace4::GetOffsetInformation  failed" );                    
+            
+        return  offsetInfo != DEBUG_VSOURCE_INVALID;       
+    
+    } 
+	catch( std::exception  &e )
+	{
+		dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
+	}
+	catch(...)
+	{
+		dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
+	}	            
+	
+	return false;
+}
+
 ///////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h
index 268d84f..04918ff 100644
--- a/pykd/dbgmem.h
+++ b/pykd/dbgmem.h
@@ -91,4 +91,7 @@ addr64( ULONG64  addr );
 boost::python::object
 loadLinkedList( ULONG64 address );
 
+bool
+isOffsetValid( ULONG64  addr );
+
 /////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file