From 1bdfc6e278dd3d7fb2fba61bae01f244b15df42b Mon Sep 17 00:00:00 2001
From: "SND\\kernelnet_cp"
 <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Thu, 17 Nov 2011 15:32:28 +0000
Subject: [PATCH] [0.1.x] added : debuggerPath routine

git-svn-id: https://pykd.svn.codeplex.com/svn@71441 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/dbgext.cpp       | 22 +++++++++++++++++-----
 pykd/pykd_2008.vcproj |  8 ++++----
 pykd/stdafx.h         |  1 +
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp
index 1728682..210e29e 100644
--- a/pykd/dbgext.cpp
+++ b/pykd/dbgext.cpp
@@ -53,6 +53,16 @@ static python::dict genDict(const pyDia::Symbol::ValueNameEntry srcValues[], siz
 
 ////////////////////////////////////////////////////////////////////////////////
 
+std::string
+getDebuggerImage()
+{
+    std::vector<char>   buffer(MAX_PATH);
+    GetModuleFileNameExA( GetCurrentProcess(), NULL, &buffer[0], buffer.size() );
+    return std::string( &buffer[0] );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
 BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 );
 BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln_, dprintln, 1, 2 );
 
@@ -277,15 +287,17 @@ BOOST_PYTHON_MODULE( pykd )
         "Attach debugger to a kernel target" );
     python::def( "expr", &pykd::evaluate,
         "Evaluate windbg expression" );
-    python::def( "getDebuggeeType", &pykd::getDebuggeeType,
+    python::def( "getDebuggeeType", &getDebuggeeType,
         "Return type of the debuggee" );
-    python::def( "getExecutionStatus", &pykd::getExecutionStatus,
+    python::def( "debuggerPath", &getDebuggerImage,
+        "Return full path to the process image that uses pykd" );
+    python::def( "getExecutionStatus", &getExecutionStatus,
         "Return information about the execution status of the debugger" );
-    python::def( "go", &pykd::changeDebuggerStatus<DEBUG_STATUS_GO>,
+    python::def( "go", &changeDebuggerStatus<DEBUG_STATUS_GO>,
         "Change debugger status to DEBUG_STATUS_GO"  );
-    python::def( "isDumpAnalyzing", &pykd::isDumpAnalyzing,
+    python::def( "isDumpAnalyzing", &isDumpAnalyzing,
         "Check if it is a dump analyzing ( not living debuggee )" );
-    python::def( "isKernelDebugging", &pykd::isKernelDebugging,
+    python::def( "isKernelDebugging", &isKernelDebugging,
         "Check if kernel dubugging is running" );
     python::def( "loadBytes", &loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ),
         "Read the block of the target's memory and return it as liat of unsigned bytes" ) );
diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj
index 57caf37..e96db3d 100644
--- a/pykd/pykd_2008.vcproj
+++ b/pykd/pykd_2008.vcproj
@@ -70,7 +70,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="dbgeng.lib diaguids.lib"
+				AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib"
 				OutputFile="$(OutDir)\$(ProjectName).pyd"
 				LinkIncremental="2"
 				AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib&quot;;&quot;$(DBG_SDK_ROOT)\lib\i386&quot;;&quot;$(PYTHON_ROOT)\x86\libs&quot;;&quot;$(BOOST_ROOT)\stage\lib&quot;"
@@ -151,7 +151,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="dbgeng.lib diaguids.lib"
+				AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib"
 				OutputFile="$(OutDir)\$(ProjectName).pyd"
 				LinkIncremental="2"
 				AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib\amd64&quot;;&quot;$(DBG_SDK_ROOT)\lib\amd64&quot;;&quot;$(PYTHON_ROOT)\x64\libs&quot;;&quot;$(BOOST_ROOT)\stage64\lib&quot;"
@@ -227,7 +227,7 @@
 			<Tool
 				Name="VCLinkerTool"
 				AdditionalOptions="/pdbpath:none"
-				AdditionalDependencies="dbgeng.lib diaguids.lib"
+				AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib"
 				OutputFile="$(OutDir)\$(ProjectName).pyd"
 				LinkIncremental="1"
 				AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib&quot;;&quot;$(DBG_SDK_ROOT)\lib\i386&quot;;&quot;$(PYTHON_ROOT)\x86\libs&quot;;&quot;$(BOOST_ROOT)\stage\lib&quot;"
@@ -306,7 +306,7 @@
 			<Tool
 				Name="VCLinkerTool"
 				AdditionalOptions="/pdbpath:none"
-				AdditionalDependencies="dbgeng.lib diaguids.lib"
+				AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib"
 				OutputFile="$(OutDir)\$(ProjectName).pyd"
 				LinkIncremental="1"
 				AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib\amd64&quot;;&quot;$(DBG_SDK_ROOT)\lib\amd64&quot;;&quot;$(PYTHON_ROOT)\x64\libs&quot;;&quot;$(BOOST_ROOT)\stage64\lib&quot;"
diff --git a/pykd/stdafx.h b/pykd/stdafx.h
index d1655a4..09b1fcd 100644
--- a/pykd/stdafx.h
+++ b/pykd/stdafx.h
@@ -29,6 +29,7 @@
 #include <tchar.h>
 #include <windows.h>
 #include <atlbase.h>
+#include <psapi.h>
 
 #include <dia2.h>