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-11-25 21:07:28 +08:00
|
|
|
#include "cpureg.h"
|
2011-12-01 02:40:57 +08:00
|
|
|
#include "inteventhandler.h"
|
|
|
|
#include "synsymbol.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 );
|
|
|
|
|
2011-11-16 17:20:41 +08:00
|
|
|
void breakin();
|
|
|
|
|
2011-11-16 18:30:50 +08:00
|
|
|
bool compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, bool phyAddr = FALSE );
|
|
|
|
|
2011-12-23 19:51:16 +08:00
|
|
|
void detachProcess();
|
|
|
|
|
2011-10-21 15:13:31 +08:00
|
|
|
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-11-30 00:05:46 +08:00
|
|
|
std::string findSymbol( ULONG64 offset );
|
|
|
|
|
2011-12-09 22:01:49 +08:00
|
|
|
ULONG64 getCurrentProcess();
|
|
|
|
|
2011-12-13 15:52:04 +08:00
|
|
|
python::list getCurrentStack();
|
|
|
|
|
2011-10-11 15:18:26 +08:00
|
|
|
python::tuple getDebuggeeType();
|
|
|
|
|
2011-12-09 22:01:49 +08:00
|
|
|
ULONG64 getImplicitThread();
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
ULONG getExecutionStatus();
|
|
|
|
|
2011-12-13 15:52:04 +08:00
|
|
|
ULONG64 getOffset( const std::wstring symbolname );
|
|
|
|
|
2011-12-13 22:49:11 +08:00
|
|
|
std::string getPdbFile( ULONG64 moduleBase );
|
|
|
|
|
2011-12-15 14:28:13 +08:00
|
|
|
std::string getProcessorMode();
|
|
|
|
|
|
|
|
std::string getProcessorType();
|
|
|
|
|
2011-12-15 21:29:54 +08:00
|
|
|
python::list getThreadList();
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
template<ULONG status>
|
|
|
|
void changeDebuggerStatus();
|
|
|
|
|
2011-11-28 14:37:23 +08:00
|
|
|
bool is64bitSystem();
|
|
|
|
|
2011-10-11 15:18:26 +08:00
|
|
|
bool isKernelDebugging();
|
|
|
|
|
|
|
|
bool isDumpAnalyzing();
|
|
|
|
|
2011-12-15 21:29:54 +08:00
|
|
|
bool isVaValid( ULONG64 addr );
|
|
|
|
|
2011-10-21 15:13:31 +08:00
|
|
|
void loadDump( const std::wstring &fileName );
|
|
|
|
|
2011-11-25 20:19:24 +08:00
|
|
|
Module loadModuleByName( const std::string &moduleName ) {
|
2011-12-01 02:40:57 +08:00
|
|
|
return Module( m_client, m_symSymbols, moduleName );
|
2011-09-19 15:05:22 +08:00
|
|
|
}
|
|
|
|
|
2011-11-25 20:19:24 +08:00
|
|
|
Module loadModuleByOffset( ULONG64 offset ) {
|
2011-12-01 02:40:57 +08:00
|
|
|
return Module( m_client, m_symSymbols, offset );
|
2011-09-21 23:53:02 +08:00
|
|
|
}
|
|
|
|
|
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-30 00:28:23 +08:00
|
|
|
std::string loadCStr( ULONG64 offset );
|
|
|
|
|
|
|
|
std::wstring loadWStr( ULONG64 offset );
|
|
|
|
|
2011-12-15 22:20:28 +08:00
|
|
|
std::string loadAnsiStr( ULONG64 address );
|
|
|
|
|
|
|
|
std::wstring loadUnicodeStr( ULONG64 address );
|
|
|
|
|
2011-12-22 16:17:27 +08:00
|
|
|
python::list loadPtrList( ULONG64 address );
|
|
|
|
|
|
|
|
python::list loadPtrArray( ULONG64 address, ULONG number );
|
|
|
|
|
2011-11-16 14:42:00 +08:00
|
|
|
ULONG ptrSize();
|
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
ULONG64 ptrByte( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
ULONG64 ptrWord( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
ULONG64 ptrDWord( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
ULONG64 ptrQWord( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
ULONG64 ptrMWord( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
LONG64 ptrSignByte( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
LONG64 ptrSignWord( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
LONG64 ptrSignDWord( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
LONG64 ptrSignQWord( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
LONG64 ptrSignMWord( ULONG64 offset );
|
2011-11-16 14:42:00 +08:00
|
|
|
|
2011-11-16 15:36:21 +08:00
|
|
|
ULONG64 ptrPtr( ULONG64 offset );
|
|
|
|
|
2011-11-25 21:07:28 +08:00
|
|
|
python::object getRegByName( const std::wstring ®Name );
|
|
|
|
|
|
|
|
python::object getRegByIndex( ULONG index );
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
void setExecutionStatus( ULONG status );
|
2011-12-23 19:51:16 +08:00
|
|
|
|
|
|
|
void terminateProcess();
|
2011-10-20 14:33:44 +08:00
|
|
|
|
|
|
|
void waitForEvent();
|
2011-10-03 19:34:36 +08:00
|
|
|
|
2011-10-21 15:13:31 +08:00
|
|
|
|
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-12-01 02:40:57 +08:00
|
|
|
void addSyntheticSymbol(
|
|
|
|
ULONG64 addr,
|
|
|
|
ULONG size,
|
|
|
|
const std::string &symName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return m_symSymbols->add(addr, size, symName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void delAllSyntheticSymbols()
|
|
|
|
{
|
|
|
|
return m_symSymbols->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG delSyntheticSymbol(
|
|
|
|
ULONG64 addr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return m_symSymbols->remove(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG delSyntheticSymbolsMask(
|
|
|
|
const std::string &moduleName,
|
|
|
|
const std::string &symName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return m_symSymbols->removeByMask(moduleName, symName);
|
|
|
|
}
|
|
|
|
|
2011-12-06 17:26:58 +08:00
|
|
|
SynSymbolsPtr getSynSymbols() {
|
|
|
|
return m_symSymbols;
|
|
|
|
}
|
|
|
|
|
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-12-01 02:40:57 +08:00
|
|
|
SynSymbolsPtr m_symSymbols; // DebugClient is creator
|
|
|
|
InternalDbgEventHandler m_internalDbgEventHandler;
|
|
|
|
|
|
|
|
DebugClient( IDebugClient4 *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-12-23 19:51:16 +08:00
|
|
|
void detachProcess();
|
|
|
|
|
2011-11-30 00:05:46 +08:00
|
|
|
std::string findSymbol( ULONG64 offset );
|
|
|
|
|
2011-10-11 15:18:26 +08:00
|
|
|
python::tuple getDebuggeeType();
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
ULONG getExecutionStatus();
|
|
|
|
|
2011-12-13 15:52:04 +08:00
|
|
|
ULONG64 getOffset( const std::wstring symbolname );
|
|
|
|
|
2011-12-13 22:49:11 +08:00
|
|
|
std::string getPdbFile( ULONG64 moduleBase );
|
|
|
|
|
2011-11-28 14:37:23 +08:00
|
|
|
bool is64bitSystem();
|
|
|
|
|
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 );
|
|
|
|
|
2011-12-23 19:51:16 +08:00
|
|
|
void terminateProcess();
|
|
|
|
|
2011-10-20 14:33:44 +08:00
|
|
|
void waitForEvent();
|
|
|
|
|
2011-12-01 02:40:57 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Synthetic symbols global finctions:
|
|
|
|
|
|
|
|
inline void addSyntheticSymbol(
|
|
|
|
ULONG64 addr,
|
|
|
|
ULONG size,
|
|
|
|
const std::string &symName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return g_dbgClient->addSyntheticSymbol(addr, size, symName);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void delAllSyntheticSymbols()
|
|
|
|
{
|
|
|
|
return g_dbgClient->delAllSyntheticSymbols();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ULONG delSyntheticSymbol(
|
|
|
|
ULONG64 addr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return g_dbgClient->delSyntheticSymbol(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ULONG delSyntheticSymbolsMask(
|
|
|
|
const std::string &moduleName,
|
|
|
|
const std::string &symName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return g_dbgClient->delSyntheticSymbolsMask(moduleName, symName);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|