mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[+] added: !pythonpath windbg command - print enviroment var $pythonpath
[+] added: !py windbg command uses $pythonpath var for search scripts git-svn-id: https://pykd.svn.codeplex.com/svn@56329 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
f8341a1a6d
commit
477da2e29f
@ -25,6 +25,7 @@
|
|||||||
#include "dbgsession.h"
|
#include "dbgsession.h"
|
||||||
#include "dbgcallback.h"
|
#include "dbgcallback.h"
|
||||||
#include "dbgstack.h"
|
#include "dbgstack.h"
|
||||||
|
#include "dbgpath.h"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -188,7 +189,6 @@ HRESULT
|
|||||||
CALLBACK
|
CALLBACK
|
||||||
py( PDEBUG_CLIENT4 client, PCSTR args)
|
py( PDEBUG_CLIENT4 client, PCSTR args)
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DbgExt ext = { 0 };
|
DbgExt ext = { 0 };
|
||||||
@ -201,7 +201,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args)
|
|||||||
boost::python::object global(main.attr("__dict__"));
|
boost::python::object global(main.attr("__dict__"));
|
||||||
|
|
||||||
boost::python::object result;
|
boost::python::object result;
|
||||||
|
|
||||||
// ðàçáîð ïàðàìåòðîâ
|
// ðàçáîð ïàðàìåòðîâ
|
||||||
typedef boost::escaped_list_separator<char> char_separator_t;
|
typedef boost::escaped_list_separator<char> char_separator_t;
|
||||||
typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
|
typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
|
||||||
@ -236,31 +236,59 @@ py( PDEBUG_CLIENT4 client, PCSTR args)
|
|||||||
char *emptyParam = "";
|
char *emptyParam = "";
|
||||||
|
|
||||||
PySys_SetArgv( 1, &emptyParam );
|
PySys_SetArgv( 1, &emptyParam );
|
||||||
}
|
}
|
||||||
|
|
||||||
result = boost::python::exec_file( argsList[0].c_str(), global, global );
|
// íàéòè ïóòü ê ôàéëó
|
||||||
|
std::string fullFileName;
|
||||||
}
|
std::string filePath;
|
||||||
catch( boost::python::error_already_set const & )
|
|
||||||
{
|
|
||||||
// îøèáêà â ñêðèïòå
|
|
||||||
PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL;
|
|
||||||
|
|
||||||
PyErr_Fetch( &errtype, &errvalue, &traceback );
|
if ( dbgPythonPath.findPath( argsList[0], fullFileName, filePath ) )
|
||||||
|
|
||||||
if(errvalue != NULL)
|
|
||||||
{
|
{
|
||||||
PyObject *s = PyObject_Str(errvalue);
|
DWORD oldCurDirLen = GetCurrentDirectoryA( 0, NULL );
|
||||||
|
|
||||||
|
char *oldCurDirCstr = new char[ oldCurDirLen ];
|
||||||
|
|
||||||
DbgPrint::dprintln( PyString_AS_STRING( s ) );
|
GetCurrentDirectoryA( oldCurDirLen, oldCurDirCstr );
|
||||||
|
|
||||||
|
SetCurrentDirectoryA( filePath.c_str() );
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
result = boost::python::exec_file( fullFileName.c_str(), global, global );
|
||||||
|
|
||||||
|
}
|
||||||
|
catch( boost::python::error_already_set const & )
|
||||||
|
{
|
||||||
|
// îøèáêà â ñêðèïòå
|
||||||
|
PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL;
|
||||||
|
|
||||||
|
PyErr_Fetch( &errtype, &errvalue, &traceback );
|
||||||
|
|
||||||
|
if(errvalue != NULL)
|
||||||
|
{
|
||||||
|
PyObject *s = PyObject_Str(errvalue);
|
||||||
|
|
||||||
|
DbgPrint::dprintln( PyString_AS_STRING( s ) );
|
||||||
|
|
||||||
Py_DECREF(s);
|
Py_DECREF(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_XDECREF(errvalue);
|
||||||
|
Py_XDECREF(errtype);
|
||||||
|
Py_XDECREF(traceback);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetCurrentDirectoryA( oldCurDirCstr );
|
||||||
|
|
||||||
|
delete[] oldCurDirCstr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
Py_XDECREF(errvalue);
|
{
|
||||||
Py_XDECREF(errtype);
|
DbgPrint::dprintln( "script file not found" );
|
||||||
Py_XDECREF(traceback);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -370,4 +398,20 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
HRESULT
|
||||||
|
CALLBACK
|
||||||
|
pythonpath( PDEBUG_CLIENT4 client, PCSTR args )
|
||||||
|
{
|
||||||
|
DbgExt ext = { 0 };
|
||||||
|
|
||||||
|
SetupDebugEngine( client, &ext );
|
||||||
|
dbgExt = &ext;
|
||||||
|
|
||||||
|
DbgPrint::dprintln( dbgPythonPath.getStr() );
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
118
pykd/dbgpath.cpp
Normal file
118
pykd/dbgpath.cpp
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
#include "dbgpath.h"
|
||||||
|
|
||||||
|
#include <boost/tokenizer.hpp>
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
DbgPythonPath &dbgPythonPath = DbgPythonPath();
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
DbgPythonPath::DbgPythonPath()
|
||||||
|
{
|
||||||
|
DWORD enviromentSize = 0;
|
||||||
|
|
||||||
|
enviromentSize = GetEnvironmentVariableA( "PYTHONPATH", NULL, enviromentSize );
|
||||||
|
|
||||||
|
char *enviromentBuffer = new char[ enviromentSize ];
|
||||||
|
|
||||||
|
GetEnvironmentVariableA( "PYTHONPATH", enviromentBuffer, enviromentSize );
|
||||||
|
|
||||||
|
typedef boost::escaped_list_separator<char> char_separator_t;
|
||||||
|
typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
|
||||||
|
|
||||||
|
std::string pytonPath( enviromentBuffer );
|
||||||
|
|
||||||
|
char_tokenizer_t token( pytonPath, char_separator_t( "", "; \t", "\"" ) );
|
||||||
|
|
||||||
|
for ( char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it )
|
||||||
|
{
|
||||||
|
if ( *it != "" )
|
||||||
|
m_pathList.push_back( *it );
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] enviromentBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
std::string
|
||||||
|
DbgPythonPath::getStr() const
|
||||||
|
{
|
||||||
|
std::string str;
|
||||||
|
std::vector<std::string>::const_iterator it = m_pathList.begin();
|
||||||
|
|
||||||
|
for ( ; it != m_pathList.end(); ++it )
|
||||||
|
{
|
||||||
|
str += *it;
|
||||||
|
str += ";";
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool
|
||||||
|
DbgPythonPath::findPath(
|
||||||
|
const std::string &fileName,
|
||||||
|
std::string &fullFileName,
|
||||||
|
std::string &filePath ) const
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
std::vector<std::string>::const_iterator it = m_pathList.begin();
|
||||||
|
|
||||||
|
for ( ; it != m_pathList.end(); ++it )
|
||||||
|
{
|
||||||
|
DWORD bufSize =
|
||||||
|
SearchPathA(
|
||||||
|
(*it).c_str(),
|
||||||
|
fileName.c_str(),
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
if ( bufSize > 0 )
|
||||||
|
{
|
||||||
|
char *fullFileNameCStr = new char[ bufSize ];
|
||||||
|
char *partFileNameCStr = NULL;
|
||||||
|
|
||||||
|
SearchPathA(
|
||||||
|
(*it).c_str(),
|
||||||
|
fileName.c_str(),
|
||||||
|
NULL,
|
||||||
|
bufSize,
|
||||||
|
fullFileNameCStr,
|
||||||
|
&partFileNameCStr );
|
||||||
|
|
||||||
|
fullFileName = std::string( fullFileNameCStr );
|
||||||
|
filePath = std::string( fullFileNameCStr, partFileNameCStr );
|
||||||
|
|
||||||
|
delete[] fullFileNameCStr;
|
||||||
|
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// DWORD SearchPath(
|
||||||
|
// LPCTSTR lpPath,
|
||||||
|
// LPCTSTR lpFileName,
|
||||||
|
// LPCTSTR lpExtension,
|
||||||
|
// DWORD nBufferLength,
|
||||||
|
// LPTSTR lpBuffer,
|
||||||
|
// LPTSTR* lpFilePart
|
||||||
|
//);
|
33
pykd/dbgpath.h
Normal file
33
pykd/dbgpath.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class DbgPythonPath
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
DbgPythonPath();
|
||||||
|
|
||||||
|
std::string
|
||||||
|
getStr() const;
|
||||||
|
|
||||||
|
bool
|
||||||
|
findPath(
|
||||||
|
const std::string &fileName,
|
||||||
|
std::string &fullFileName,
|
||||||
|
std::string &filePath ) const;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector< std::string > m_pathList;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
extern DbgPythonPath& dbgPythonPath;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
@ -4,4 +4,5 @@ EXPORTS
|
|||||||
|
|
||||||
info
|
info
|
||||||
py
|
py
|
||||||
pycmd
|
pycmd
|
||||||
|
pythonpath
|
@ -375,6 +375,10 @@
|
|||||||
RelativePath=".\dbgmodule.cpp"
|
RelativePath=".\dbgmodule.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\dbgpath.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\dbgprint.cpp"
|
RelativePath=".\dbgprint.cpp"
|
||||||
>
|
>
|
||||||
@ -477,6 +481,10 @@
|
|||||||
RelativePath=".\dbgmodule.h"
|
RelativePath=".\dbgmodule.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\dbgpath.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\dbgprint.h"
|
RelativePath=".\dbgprint.h"
|
||||||
>
|
>
|
||||||
|
@ -10,12 +10,12 @@ def loadSymbols():
|
|||||||
nt.PsActiveProcessHead = getOffset( "nt", "PsActiveProcessHead" )
|
nt.PsActiveProcessHead = getOffset( "nt", "PsActiveProcessHead" )
|
||||||
|
|
||||||
|
|
||||||
def printStacks():
|
def processInfo():
|
||||||
|
|
||||||
processList = typedVarList( nt.PsActiveProcessHead, "nt", "_EPROCESS", "ActiveProcessLinks" )
|
processList = typedVarList( nt.PsActiveProcessHead, "nt", "_EPROCESS", "ActiveProcessLinks" )
|
||||||
|
|
||||||
for process in processList:
|
for process in processList:
|
||||||
dprintln( "".join( [ chr(i) for k, i in process.ImageFileName.items() ] ) )
|
dprintln( "".join( [ chr(i) for i in process.ImageFileName.values() ] ) )
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -29,4 +29,4 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
loadSymbols()
|
loadSymbols()
|
||||||
|
|
||||||
printStacks()
|
processInfo()
|
||||||
|
Loading…
Reference in New Issue
Block a user