2015-01-20 16:45:25 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <kdlib/process.h>
|
|
|
|
|
|
|
|
#include "pythreadstate.h"
|
2015-01-23 04:10:08 +08:00
|
|
|
#include "pyeventhandler.h"
|
2017-10-04 01:41:17 +08:00
|
|
|
#include "dbgexcept.h"
|
2015-01-20 16:45:25 +08:00
|
|
|
|
|
|
|
namespace pykd {
|
|
|
|
|
2015-03-30 15:37:57 +08:00
|
|
|
struct TargetSystemAdapter {
|
|
|
|
|
|
|
|
static unsigned long getNumberSystems()
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetSystem::getNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TargetSystemPtr getCurrent()
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetSystem::getCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TargetSystemPtr getSystem(unsigned long index)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetSystem::getByIndex(index);
|
|
|
|
}
|
|
|
|
|
2015-04-06 06:17:31 +08:00
|
|
|
static kdlib::TargetSystemPtr getSystemById(kdlib::SYSTEM_DEBUG_ID id)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetSystem::getById(id);
|
|
|
|
}
|
|
|
|
|
2016-07-28 17:51:12 +08:00
|
|
|
static void setCurrent(kdlib::TargetSystem& system)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
system.setCurrent();
|
|
|
|
}
|
|
|
|
|
2015-03-30 15:37:57 +08:00
|
|
|
static std::wstring getDescription(kdlib::TargetSystem& system)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.getDescription();
|
|
|
|
}
|
|
|
|
|
2015-04-06 06:17:31 +08:00
|
|
|
static kdlib::SYSTEM_DEBUG_ID getId(kdlib::TargetSystem& system)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.getId();
|
|
|
|
}
|
|
|
|
|
2015-03-31 00:42:00 +08:00
|
|
|
static bool isDumpAnalyzing(kdlib::TargetSystem& system)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.isDumpAnalyzing();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isKernelDebugging(kdlib::TargetSystem& system)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.isKernelDebugging();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is64bitSystem(kdlib::TargetSystem& system)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.is64bitSystem();
|
|
|
|
}
|
|
|
|
|
2015-03-30 15:37:57 +08:00
|
|
|
static unsigned long getNumberProcesses(kdlib::TargetSystem& system)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.getNumberProcesses();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TargetProcessPtr getProcessByIndex(kdlib::TargetSystem& system, unsigned long index)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.getProcessByIndex(index);
|
|
|
|
}
|
|
|
|
|
2015-04-15 04:46:17 +08:00
|
|
|
static kdlib::TargetProcessPtr getProcessById(kdlib::TargetSystem& system, kdlib::PROCESS_DEBUG_ID id)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.getProcessById(id);
|
|
|
|
}
|
|
|
|
|
2016-07-18 17:35:18 +08:00
|
|
|
static kdlib::TargetProcessPtr getProcessBySystemId(kdlib::TargetSystem& system, kdlib::PROCESS_ID pid)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.getProcessBySystemId(pid);
|
|
|
|
}
|
|
|
|
|
2015-03-30 15:37:57 +08:00
|
|
|
static kdlib::TargetProcessPtr getCurrentProcess(kdlib::TargetSystem& system)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.getCurrentProcess();
|
|
|
|
}
|
2015-03-31 05:23:11 +08:00
|
|
|
|
|
|
|
static bool isCurrent(kdlib::TargetSystem& system)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return system.isCurrent();
|
|
|
|
}
|
2015-12-16 05:19:54 +08:00
|
|
|
|
|
|
|
static python::list getProcessesList(kdlib::TargetSystem& system);
|
2016-07-11 18:51:59 +08:00
|
|
|
|
|
|
|
static std::wstring print(kdlib::TargetSystem& system);
|
2015-03-30 15:37:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-20 16:45:25 +08:00
|
|
|
struct TargetProcessAdapter {
|
|
|
|
|
|
|
|
static kdlib::TargetProcessPtr getCurrent()
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetProcess::getCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TargetProcessPtr getProcess(unsigned long index)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetProcess::getByIndex(index);
|
|
|
|
}
|
|
|
|
|
2015-04-06 06:17:31 +08:00
|
|
|
static kdlib::TargetProcessPtr getProcessById(kdlib::PROCESS_DEBUG_ID id)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetProcess::getById(id);
|
|
|
|
}
|
|
|
|
|
2015-01-21 05:14:17 +08:00
|
|
|
static unsigned long getNumberProcesses()
|
2015-01-20 16:45:25 +08:00
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetProcess::getNumber();
|
|
|
|
}
|
|
|
|
|
2016-07-28 17:51:12 +08:00
|
|
|
static void setCurrent(kdlib::TargetProcess& process)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.setCurrent();
|
|
|
|
}
|
|
|
|
|
2015-01-21 05:14:17 +08:00
|
|
|
static kdlib::PROCESS_ID getSystemId(kdlib::TargetProcess& process)
|
2015-01-20 16:45:25 +08:00
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getSystemId();
|
|
|
|
}
|
|
|
|
|
2015-04-06 06:17:31 +08:00
|
|
|
static kdlib::PROCESS_DEBUG_ID getId(kdlib::TargetProcess& process)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getId();
|
|
|
|
}
|
|
|
|
|
2015-01-21 05:14:17 +08:00
|
|
|
static kdlib::MEMOFFSET_64 getPebOffset(kdlib::TargetProcess& process)
|
2015-01-20 16:45:25 +08:00
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getPebOffset();
|
|
|
|
}
|
|
|
|
|
2015-01-21 05:14:17 +08:00
|
|
|
static std::wstring getExeName(kdlib::TargetProcess& process)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getExecutableName();
|
|
|
|
}
|
|
|
|
|
2015-01-20 16:45:25 +08:00
|
|
|
static unsigned long getNumberThreads(kdlib::TargetProcess& process )
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getNumberThreads();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TargetThreadPtr getThreadByIndex(kdlib::TargetProcess& process, unsigned long index)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getThreadByIndex(index);
|
|
|
|
}
|
2015-01-21 05:14:17 +08:00
|
|
|
|
2015-04-15 04:46:17 +08:00
|
|
|
static kdlib::TargetThreadPtr getThreadById(kdlib::TargetProcess& process, kdlib::THREAD_DEBUG_ID id)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getThreadById(id);
|
|
|
|
}
|
|
|
|
|
2016-07-18 17:35:18 +08:00
|
|
|
static kdlib::TargetThreadPtr getThreadBySystemId(kdlib::TargetProcess& process, kdlib::THREAD_ID tid)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getThreadBySystemId(tid);
|
|
|
|
}
|
|
|
|
|
2015-01-21 05:14:17 +08:00
|
|
|
static kdlib::TargetThreadPtr getCurrentThread(kdlib::TargetProcess& process)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getCurrentThread();
|
|
|
|
}
|
2015-01-22 04:48:46 +08:00
|
|
|
|
|
|
|
static unsigned long getNumberBreakpoints(kdlib::TargetProcess& process)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getNumberBreakpoints();
|
|
|
|
}
|
|
|
|
|
2015-01-23 04:10:08 +08:00
|
|
|
static Breakpoint* getBreakpointByIndex(kdlib::TargetProcess& process, unsigned long index)
|
2015-01-22 04:48:46 +08:00
|
|
|
{
|
2015-01-23 04:10:08 +08:00
|
|
|
kdlib::BreakpointPtr bp;
|
|
|
|
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
bp = process.getBreakpoint(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Breakpoint(bp);
|
2015-01-22 04:48:46 +08:00
|
|
|
}
|
2015-03-31 05:23:11 +08:00
|
|
|
|
|
|
|
static bool isCurrent(kdlib::TargetProcess& process)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.isCurrent();
|
|
|
|
}
|
2015-05-19 05:51:52 +08:00
|
|
|
|
|
|
|
static unsigned long getNumberModules(kdlib::TargetProcess& process)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getNumberModules();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::ModulePtr getModuleByIndex(kdlib::TargetProcess& process, unsigned long index)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getModuleByIndex(index);
|
|
|
|
}
|
2015-12-16 05:19:54 +08:00
|
|
|
|
2016-07-28 17:51:12 +08:00
|
|
|
static kdlib::ModulePtr getModuleByOffset(kdlib::TargetProcess& process, kdlib::MEMOFFSET_64 offset)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getModuleByOffset(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::ModulePtr getModuleByName(kdlib::TargetProcess& process, const std::wstring& name)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getModuleByName(name);
|
|
|
|
}
|
|
|
|
|
2017-10-04 01:41:17 +08:00
|
|
|
static bool isManaged(kdlib::TargetProcess& process)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.isManaged();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TargetHeapPtr getManagedHeap(kdlib::TargetProcess& process)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getManagedHeap();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TypedVarPtr getManagedVar(kdlib::TargetProcess& process, kdlib::MEMOFFSET_64 address)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return process.getManagedVar(address);
|
|
|
|
}
|
|
|
|
|
2015-12-16 05:19:54 +08:00
|
|
|
static python::list getThreadList(kdlib::TargetProcess& process);
|
|
|
|
|
|
|
|
static python::list getBreakpointsList(kdlib::TargetProcess& process);
|
|
|
|
|
|
|
|
static python::list getModulesList(kdlib::TargetProcess& process);
|
2016-07-11 18:51:59 +08:00
|
|
|
|
|
|
|
static std::wstring print(kdlib::TargetProcess& process);
|
2015-01-20 16:45:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct TargetThreadAdapter {
|
|
|
|
|
2015-04-06 06:17:31 +08:00
|
|
|
static unsigned long getNumberThreads()
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetThread::getNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TargetThreadPtr getCurrent()
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetThread::getCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TargetThreadPtr getThread(unsigned long index)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetThread::getByIndex(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::TargetThreadPtr getThreadById(kdlib::THREAD_DEBUG_ID id)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return kdlib::TargetThread::getById(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::THREAD_DEBUG_ID getId(kdlib::TargetThread& thread)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return thread.getId();
|
|
|
|
}
|
|
|
|
|
2015-01-20 16:45:25 +08:00
|
|
|
static kdlib::THREAD_ID getSystemId(kdlib::TargetThread& thread )
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return thread.getSystemId();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::MEMOFFSET_64 getTebOffset(kdlib::TargetThread& thread )
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return thread.getTebOffset();
|
|
|
|
}
|
2015-01-21 05:14:17 +08:00
|
|
|
|
|
|
|
static void setCurrent(kdlib::TargetThread& thread)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return thread.setCurrent();
|
|
|
|
}
|
2015-01-22 04:48:46 +08:00
|
|
|
|
|
|
|
static bool isCurrent(kdlib::TargetThread& thread)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return thread.isCurrent();
|
|
|
|
}
|
2015-12-16 05:19:54 +08:00
|
|
|
|
|
|
|
static python::list getStack(kdlib::TargetThread& thread);
|
2015-12-25 06:00:09 +08:00
|
|
|
|
|
|
|
static kdlib::MEMOFFSET_64 getIP(kdlib::TargetThread& thread)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return thread.getInstructionOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::MEMOFFSET_64 getSP(kdlib::TargetThread& thread)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return thread.getStackOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
static kdlib::MEMOFFSET_64 getFP(kdlib::TargetThread& thread)
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return thread.getFrameOffset();
|
|
|
|
}
|
|
|
|
|
2016-07-11 18:51:59 +08:00
|
|
|
static std::wstring print(kdlib::TargetThread& thread);
|
2015-01-20 16:45:25 +08:00
|
|
|
};
|
|
|
|
|
2017-10-04 01:41:17 +08:00
|
|
|
|
|
|
|
class TargetHeapIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
explicit TargetHeapIterator(kdlib::TargetHeapEnumPtr& heapEnum) :
|
|
|
|
m_heapEnum(heapEnum)
|
|
|
|
{}
|
|
|
|
|
|
|
|
static python::object self(const python::object& obj)
|
|
|
|
{
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
python::tuple next()
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
|
|
|
|
kdlib::MEMOFFSET_64 addr;
|
|
|
|
std::wstring name;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (!m_heapEnum->next(addr, name, size))
|
|
|
|
throw StopIteration("No more data.");
|
|
|
|
|
|
|
|
return python::make_tuple(addr, name, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t length()
|
|
|
|
{
|
|
|
|
AutoRestorePyState pystate;
|
|
|
|
return m_heapEnum->getCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
kdlib::TargetHeapEnumPtr m_heapEnum;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TargetHeapAdapter {
|
|
|
|
|
|
|
|
static TargetHeapIterator* getEntries(kdlib::TargetHeap& heap, const std::wstring& typeName=L"", size_t minSize=0, size_t maxSize=-1)
|
|
|
|
{
|
|
|
|
return new TargetHeapIterator(heap.getEnum(typeName, minSize, maxSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-01-20 16:45:25 +08:00
|
|
|
} // pykd namespace
|
|
|
|
|