2011-04-14 20:28:22 +08:00
|
|
|
#pragma once
|
|
|
|
|
2011-09-15 22:16:20 +08:00
|
|
|
#include <string>
|
|
|
|
#include <dbgeng.h>
|
|
|
|
#include <dbghelp.h>
|
|
|
|
|
2011-09-29 15:53:45 +08:00
|
|
|
#include <boost\smart_ptr\scoped_ptr.hpp>
|
|
|
|
|
2011-10-10 19:19:12 +08:00
|
|
|
#include "dbgobj.h"
|
2011-09-15 22:16:20 +08:00
|
|
|
#include "dbgexcept.h"
|
2011-09-19 15:05:22 +08:00
|
|
|
#include "module.h"
|
2011-10-07 14:30:09 +08:00
|
|
|
#include "dbgio.h"
|
2011-10-10 23:59:24 +08:00
|
|
|
#include "dbgcmd.h"
|
2011-10-20 14:33:44 +08:00
|
|
|
#include "pyaux.h"
|
2011-10-26 15:10:44 +08:00
|
|
|
#include "disasm.h"
|
2011-09-15 22:16:20 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace pykd {
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-29 15:53:45 +08:00
|
|
|
class DebugClient;
|
|
|
|
typedef boost::shared_ptr<DebugClient> DebugClientPtr;
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-10-10 19:19:12 +08:00
|
|
|
class DebugClient : private DbgObject {
|
2011-09-15 22:16:20 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~DebugClient() {}
|
|
|
|
|
2011-09-29 15:53:45 +08:00
|
|
|
static
|
2011-10-14 15:03:51 +08:00
|
|
|
DebugClientPtr createDbgClient() ;
|
2011-09-29 15:53:45 +08:00
|
|
|
|
2011-10-03 15:40:27 +08:00
|
|
|
static
|
2011-10-14 15:03:51 +08:00
|
|
|
DebugClientPtr createDbgClient( IDebugClient4 *client );
|
2011-10-03 15:40:27 +08:00
|
|
|
|
|
|
|
static
|
|
|
|
DebugClientPtr setDbgClientCurrent( DebugClientPtr newDbgClient );
|
2011-10-10 22:35:43 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2011-10-21 15:13:31 +08:00
|
|
|
ULONG64 addr64( ULONG64 addr );
|
|
|
|
|
|
|
|
DbgOut dout() {
|
|
|
|
return DbgOut( m_client );
|
|
|
|
}
|
|
|
|
|
|
|
|
DbgIn din() {
|
|
|
|
return DbgIn( m_client );
|
|
|
|
}
|
|
|
|
|
2011-10-10 22:35:43 +08:00
|
|
|
std::string dbgCommand( const std::wstring &command );
|
2011-09-15 22:16:20 +08:00
|
|
|
|
|
|
|
void startProcess( const std::wstring &processName );
|
|
|
|
|
|
|
|
void attachProcess( ULONG processId );
|
|
|
|
|
|
|
|
void attachKernel( const std::wstring ¶m );
|
|
|
|
|
2011-10-26 15:10:44 +08:00
|
|
|
Disasm disasm( ULONG offset = 0 ) {
|
|
|
|
return Disasm( m_client, offset );
|
|
|
|
}
|
|
|
|
|
|
|
|
void dprint( const std::wstring &str, bool dml = false );
|
|
|
|
|
|
|
|
void dprintln( const std::wstring &str, bool dml = false );
|
|
|
|
|
|
|
|
void eprint( const std::wstring &str );
|
|
|
|
|
|
|
|
void eprintln( const std::wstring &str );
|
|
|
|
|
2011-10-11 00:44:19 +08:00
|
|
|
ULONG64 evaluate( const std::wstring &expression );
|
|
|
|
|
2011-10-11 15:18:26 +08:00
|
|
|
python::tuple getDebuggeeType();
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
ULONG getExecutionStatus();
|
|
|
|
|
|
|
|
template<ULONG status>
|
|
|
|
void changeDebuggerStatus();
|
|
|
|
|
2011-10-11 15:18:26 +08:00
|
|
|
bool isKernelDebugging();
|
|
|
|
|
|
|
|
bool isDumpAnalyzing();
|
|
|
|
|
2011-10-21 15:13:31 +08:00
|
|
|
void loadDump( const std::wstring &fileName );
|
|
|
|
|
2011-09-19 15:05:22 +08:00
|
|
|
Module loadModule( const std::string &moduleName ) {
|
|
|
|
return Module( m_client, moduleName );
|
|
|
|
}
|
|
|
|
|
2011-09-21 23:53:02 +08:00
|
|
|
Module findModule( ULONG64 offset ) {
|
|
|
|
return Module( m_client, offset );
|
|
|
|
}
|
|
|
|
|
2011-10-10 23:59:24 +08:00
|
|
|
DbgExtensionPtr loadExtension( const std::wstring &extPath ) {
|
|
|
|
return DbgExtensionPtr( new DbgExtension( m_client, extPath ) );
|
|
|
|
}
|
|
|
|
|
2011-10-26 14:49:57 +08:00
|
|
|
python::list loadBytes( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
2011-09-19 15:05:22 +08:00
|
|
|
|
2011-10-26 14:49:57 +08:00
|
|
|
python::list loadWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
|
|
|
|
|
|
|
python::list loadDWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
|
|
|
|
|
|
|
python::list loadQWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
|
|
|
|
2011-11-07 17:13:22 +08:00
|
|
|
python::list loadSignBytes( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
|
|
|
|
|
|
|
python::list loadSignWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
|
|
|
|
|
|
|
python::list loadSignDWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
|
|
|
|
|
|
|
python::list loadSignQWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
|
|
|
|
2011-10-26 14:49:57 +08:00
|
|
|
std::string loadChars( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
|
|
|
|
|
|
|
std::wstring loadWChars( ULONG64 offset, ULONG count, bool phyAddr = FALSE );
|
2011-10-20 14:33:44 +08:00
|
|
|
|
2011-11-16 14:42:00 +08:00
|
|
|
ULONG ptrSize();
|
|
|
|
|
|
|
|
LONG64 ptrByte();
|
|
|
|
|
|
|
|
LONG64 ptrWord();
|
|
|
|
|
|
|
|
LONG64 ptrDWord();
|
|
|
|
|
|
|
|
LONG64 ptrQWord();
|
|
|
|
|
|
|
|
LONG64 ptrMWord();
|
|
|
|
|
|
|
|
ULONG64 ptrSignByte();
|
|
|
|
|
|
|
|
ULONG64 ptrSignWord();
|
|
|
|
|
|
|
|
ULONG64 ptrSignDWord();
|
|
|
|
|
|
|
|
ULONG64 ptrSignQWord();
|
|
|
|
|
|
|
|
ULONG64 ptrSignMWord();
|
|
|
|
|
2011-10-21 15:13:31 +08:00
|
|
|
void readMemory( ULONG64 address, PVOID buffer, ULONG length, bool phyAddr = FALSE );
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
void setExecutionStatus( ULONG status );
|
|
|
|
|
|
|
|
void waitForEvent();
|
2011-10-03 19:34:36 +08:00
|
|
|
|
2011-10-21 15:13:31 +08:00
|
|
|
void writeMemory( ULONG64 address, PVOID buffer, ULONG length, bool phyAddr = FALSE );
|
|
|
|
|
2011-10-10 19:19:12 +08:00
|
|
|
public:
|
2011-09-15 22:16:20 +08:00
|
|
|
|
2011-10-10 19:19:12 +08:00
|
|
|
CComPtr<IDebugClient4>&
|
|
|
|
client() {
|
|
|
|
return m_client;
|
|
|
|
}
|
2011-10-03 15:40:27 +08:00
|
|
|
|
2011-10-10 19:19:12 +08:00
|
|
|
CComPtr<IDebugClient5>&
|
|
|
|
client5() {
|
|
|
|
return m_client5;
|
|
|
|
}
|
|
|
|
|
|
|
|
CComPtr<IDebugControl4>&
|
|
|
|
control() {
|
|
|
|
return m_control;
|
|
|
|
}
|
|
|
|
|
2011-10-21 15:13:31 +08:00
|
|
|
|
|
|
|
PyThreadStateSaver&
|
|
|
|
getThreadState() {
|
|
|
|
return m_pyThreadState;
|
|
|
|
}
|
|
|
|
|
2011-10-10 19:19:12 +08:00
|
|
|
private:
|
2011-10-03 15:40:27 +08:00
|
|
|
|
2011-10-26 14:49:57 +08:00
|
|
|
template<typename T>
|
|
|
|
python::list
|
|
|
|
loadArray( ULONG64 offset, ULONG count, bool phyAddr );
|
|
|
|
|
2011-11-07 17:13:22 +08:00
|
|
|
//python::list
|
|
|
|
//loadArray( ULONG64 offset, ULONG count, bool phyAddr );
|
|
|
|
|
2011-10-10 19:19:12 +08:00
|
|
|
DebugClient( IDebugClient4 *client ) : DbgObject( client ) {}
|
2011-10-20 14:33:44 +08:00
|
|
|
|
|
|
|
PyThreadStateSaver m_pyThreadState;
|
2011-09-15 22:16:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-29 15:53:45 +08:00
|
|
|
extern DebugClientPtr g_dbgClient;
|
2011-09-21 23:53:02 +08:00
|
|
|
|
|
|
|
void loadDump( const std::wstring &fileName );
|
|
|
|
|
|
|
|
void startProcess( const std::wstring &processName );
|
|
|
|
|
|
|
|
void attachProcess( ULONG processId );
|
|
|
|
|
|
|
|
void attachKernel( const std::wstring ¶m );
|
|
|
|
|
2011-10-11 15:18:26 +08:00
|
|
|
python::tuple getDebuggeeType();
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
ULONG getExecutionStatus();
|
|
|
|
|
2011-10-11 15:18:26 +08:00
|
|
|
bool isKernelDebugging();
|
2011-09-21 23:53:02 +08:00
|
|
|
|
2011-10-11 15:18:26 +08:00
|
|
|
bool isDumpAnalyzing();
|
2011-09-21 23:53:02 +08:00
|
|
|
|
2011-11-16 14:42:00 +08:00
|
|
|
ULONG ptrSize();
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
void setExecutionStatus( ULONG status );
|
|
|
|
|
|
|
|
void waitForEvent();
|
|
|
|
|
2011-09-21 23:53:02 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
template<ULONG status>
|
|
|
|
void DebugClient::changeDebuggerStatus()
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = m_control->SetExecutionStatus( status );
|
|
|
|
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugControl::SetExecutionStatus failed" );
|
|
|
|
|
|
|
|
ULONG currentStatus;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
waitForEvent();
|
|
|
|
|
|
|
|
hres = m_control->GetExecutionStatus( ¤tStatus );
|
|
|
|
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugControl::GetExecutionStatus failed" );
|
|
|
|
|
|
|
|
} while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE );
|
|
|
|
}
|
|
|
|
|
|
|
|
template<ULONG status>
|
|
|
|
void changeDebuggerStatus()
|
|
|
|
{
|
|
|
|
g_dbgClient->changeDebuggerStatus<status>();
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2011-09-15 22:16:20 +08:00
|
|
|
}; // namespace pykd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-12 14:59:11 +08:00
|
|
|
//#include "dbgext.h"
|
|
|
|
//#include "dbgeventcb.h"
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
//class dbgClient {
|
|
|
|
//
|
|
|
|
//public:
|
|
|
|
//
|
|
|
|
// dbgClient()
|
|
|
|
// {
|
|
|
|
// m_callbacks = NULL;
|
|
|
|
//
|
|
|
|
// IDebugClient4 *client = NULL;
|
|
|
|
// DebugCreate( __uuidof(IDebugClient4), (void **)&client );
|
|
|
|
//
|
|
|
|
// m_ext = new DbgExt( client );
|
|
|
|
//
|
|
|
|
// client->Release();
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ~dbgClient()
|
|
|
|
// {
|
|
|
|
// removeEventsMgr();
|
|
|
|
//
|
|
|
|
// delete m_ext;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// void startEventsMgr() {
|
|
|
|
//
|
|
|
|
// m_callbacks = new DbgEventCallbacksManager( m_ext->client );
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// void removeEventsMgr() {
|
|
|
|
//
|
|
|
|
// if ( m_callbacks )
|
|
|
|
// {
|
|
|
|
// delete m_callbacks;
|
|
|
|
// m_callbacks = NULL;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//private:
|
|
|
|
//
|
|
|
|
// DbgExt *m_ext;
|
|
|
|
// DbgEventCallbacksManager *m_callbacks;
|
|
|
|
//};
|
|
|
|
//
|
|
|
|
//extern dbgClient g_dbgClient;
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|