From 3a39aa8f50a5c86bdeaa157d228d3bbef17565bc Mon Sep 17 00:00:00 2001 From: "SND\\ussrhero_cp" Date: Tue, 15 Dec 2015 21:19:54 +0000 Subject: [PATCH] [0.3.x] added : targetSystem.processes() (return list of processes for the target system) [0.3.x] added : targetProcess.threads() (return list of threads for the target process) [0.3.x] added : targetProcess.modules() (return list of modules for the target process) [0.3.x] added : targetProcess.breakpoints() (return list of breakpoints for the target process) [0.3.x] added : targetProcess.stack() (return the thread's stack trace) git-svn-id: https://pykd.svn.codeplex.com/svn@90885 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/pykd_vc120.vcxproj | 1 + pykd/pykd_vc120.vcxproj.filters | 3 ++ pykd/pymod.cpp | 18 +++++-- pykd/pyprocess.cpp | 89 +++++++++++++++++++++++++++++++++ pykd/pyprocess.h | 10 ++++ 5 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 pykd/pyprocess.cpp diff --git a/pykd/pykd_vc120.vcxproj b/pykd/pykd_vc120.vcxproj index f542c56..412d088 100644 --- a/pykd/pykd_vc120.vcxproj +++ b/pykd/pykd_vc120.vcxproj @@ -236,6 +236,7 @@ + diff --git a/pykd/pykd_vc120.vcxproj.filters b/pykd/pykd_vc120.vcxproj.filters index 682f2ca..ffa05a7 100644 --- a/pykd/pykd_vc120.vcxproj.filters +++ b/pykd/pykd_vc120.vcxproj.filters @@ -242,6 +242,9 @@ Source Files + + Source Files + diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index c121dcc..ea5ade0 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -534,7 +534,7 @@ BOOST_PYTHON_MODULE( pykd ) .def("__init__", python::make_constructor(&kdlib::TargetSystem::getCurrent)) .def("__init__", python::make_constructor(&kdlib::TargetSystem::getByIndex)) .def("getNumber", TargetSystemAdapter::getNumberSystems, - "Retunr number of systems").staticmethod("getNumber") + "Return number of systems").staticmethod("getNumber") .def("getCurrent", TargetSystemAdapter::getCurrent, "Return current target system").staticmethod("getCurrent") .def("getSystemById", TargetSystemAdapter::getSystemById, @@ -559,6 +559,8 @@ BOOST_PYTHON_MODULE( pykd ) "Return process by id") .def("currentProcess", TargetSystemAdapter::getCurrentProcess, "Return current process") + .def("processes", TargetSystemAdapter::getProcessesList, + "get list of processes for the target system") ; python::class_("targetProcess", "Class representing process in the target system", python::no_init ) @@ -577,7 +579,7 @@ BOOST_PYTHON_MODULE( pykd ) .add_property("peb", TargetProcessAdapter::getPebOffset, "Return PEB address" ) .add_property("exeName", TargetProcessAdapter::getExeName, - "Return the process executbakle file name") + "Return the process executable file name") .def("isCurrent", TargetProcessAdapter::isCurrent, "Check if the target is current") .def("getNumberThreads", TargetProcessAdapter::getNumberThreads, @@ -596,6 +598,12 @@ BOOST_PYTHON_MODULE( pykd ) "Return number of modules for this process" ) .def("getModule", TargetProcessAdapter::getModuleByIndex, "Return a module object by it's index" ) + .def("threads", TargetProcessAdapter::getThreadList, + "Return list of threads for the target process") + .def("breakpoints", TargetProcessAdapter::getBreakpointsList, + "Return list of breakpoints for the target process") + .def("modules", TargetProcessAdapter::getModulesList, + "Return list of modules for the target process") ; python::class_("targetThread", "Class representing process in the target system", python::no_init ) @@ -606,9 +614,9 @@ BOOST_PYTHON_MODULE( pykd ) .def("getCurrent", TargetThreadAdapter::getCurrent, "Return a current thread").staticmethod("getCurrent") .def("getThreadById", TargetThreadAdapter::getThreadById, - "Return process by id").staticmethod("getThreadById") + "Return thread by id").staticmethod("getThreadById") .add_property("id", TargetThreadAdapter::getId, - "Return thread id") + "Return thread's id") .add_property("systemID", TargetThreadAdapter::getSystemId, "Retrun system thread ID ( TID )" ) .add_property("teb", TargetThreadAdapter::getTebOffset, @@ -617,6 +625,8 @@ BOOST_PYTHON_MODULE( pykd ) "Set this thread current") .def("isCurrent", TargetThreadAdapter::isCurrent, "Check if this thread is current") + .def("stack", TargetThreadAdapter::getStack, + "Get thread's stack tarce") ; python::class_, boost::noncopyable>("module", "Class representing executable module", python::no_init ) diff --git a/pykd/pyprocess.cpp b/pykd/pyprocess.cpp new file mode 100644 index 0000000..14434ad --- /dev/null +++ b/pykd/pyprocess.cpp @@ -0,0 +1,89 @@ +#include "stdafx.h" + +#include "pyprocess.h" +#include "stladaptor.h" + +namespace pykd { + +/////////////////////////////////////////////////////////////////////////////// + +python::list TargetSystemAdapter::getProcessesList(kdlib::TargetSystem& system) +{ + std::vector processLst; + + do { + AutoRestorePyState pystate; + for ( unsigned long i = 0; i < system.getNumberProcesses(); ++i) + processLst.push_back(system.getProcessByIndex(i)); + } while(false); + + return vectorToList(processLst); +} + +/////////////////////////////////////////////////////////////////////////////// + +python::list TargetProcessAdapter::getThreadList(kdlib::TargetProcess& process) +{ + std::vector threadLst; + + do { + AutoRestorePyState pystate; + for ( unsigned long i = 0; i < process.getNumberThreads(); ++i) + threadLst.push_back(process.getThreadByIndex(i)); + } while(false); + + return vectorToList(threadLst); +} + +/////////////////////////////////////////////////////////////////////////////// + +python::list TargetProcessAdapter::getBreakpointsList(kdlib::TargetProcess& process) +{ + std::vector bpLst; + + do { + AutoRestorePyState pystate; + for ( unsigned long i = 0; i < process.getNumberBreakpoints(); ++i) + bpLst.push_back(new Breakpoint(process.getBreakpoint(i))); + } while(false); + + return vectorToList(bpLst); +} + +/////////////////////////////////////////////////////////////////////////////// + +python::list TargetProcessAdapter::getModulesList(kdlib::TargetProcess& process) +{ + std::vector moduleLst; + + do { + AutoRestorePyState pystate; + for ( unsigned long i = 0; i < process.getNumberModules(); ++i) + moduleLst.push_back(process.getModuleByIndex(i)); + } while(false); + + return vectorToList(moduleLst); +} + +/////////////////////////////////////////////////////////////////////////////// + +python::list TargetThreadAdapter::getStack(kdlib::TargetThread& thread) +{ + + std::vector frameLst; + + do { + AutoRestorePyState pystate; + kdlib::StackPtr stack = thread.getStack(); + + for (unsigned long i = 0; i < stack->getFrameCount(); ++i) + frameLst.push_back(stack->getFrame(i)); + } while(false); + + return vectorToList(frameLst); +} + +/////////////////////////////////////////////////////////////////////////////// + +} + diff --git a/pykd/pyprocess.h b/pykd/pyprocess.h index aad4a57..fe9b4bf 100644 --- a/pykd/pyprocess.h +++ b/pykd/pyprocess.h @@ -92,6 +92,8 @@ struct TargetSystemAdapter { AutoRestorePyState pystate; return system.isCurrent(); } + + static python::list getProcessesList(kdlib::TargetSystem& system); }; @@ -204,6 +206,12 @@ struct TargetProcessAdapter { AutoRestorePyState pystate; return process.getModuleByIndex(index); } + + static python::list getThreadList(kdlib::TargetProcess& process); + + static python::list getBreakpointsList(kdlib::TargetProcess& process); + + static python::list getModulesList(kdlib::TargetProcess& process); }; @@ -262,6 +270,8 @@ struct TargetThreadAdapter { AutoRestorePyState pystate; return thread.isCurrent(); } + + static python::list getStack(kdlib::TargetThread& thread); }; } // pykd namespace