From 0d0648873bbb8cd0d30ff459795d1ed6919af812 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 18 Jul 2016 09:35:18 +0000 Subject: [PATCH] [0.3.x] added : targetSystem.getProcessBySystemId method ( return process by PID ) [0.3.x] added : targetProcess.getThreadBySystemId method ( return thread by tid ) git-svn-id: https://pykd.svn.codeplex.com/svn@91010 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/pymod.cpp | 4 ++++ pykd/pyprocess.h | 12 ++++++++++++ snippets/wfp.py | 14 +++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 7185908..d3fcac1 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -575,6 +575,8 @@ BOOST_PYTHON_MODULE( pykd ) "Return process by index") .def("getProcessById", TargetSystemAdapter::getProcessById, "Return process by id") + .def("getProcessBySystemId", TargetSystemAdapter::getProcessBySystemId, + "Return process by PID") .def("currentProcess", TargetSystemAdapter::getCurrentProcess, "Return current process") .def("processes", TargetSystemAdapter::getProcessesList, @@ -607,6 +609,8 @@ BOOST_PYTHON_MODULE( pykd ) "Return thread by its index" ) .def("getThreadById", TargetProcessAdapter::getThreadById, "Return thread by its index") + .def("getThreadBySystemId", TargetProcessAdapter::getThreadBySystemId, + "Return thread by tid") .def("currentThread", TargetProcessAdapter::getCurrentThread, "Return current thread" ) .def("getNumberBreakpoints", TargetProcessAdapter::getNumberBreakpoints, diff --git a/pykd/pyprocess.h b/pykd/pyprocess.h index 8473315..d11a660 100644 --- a/pykd/pyprocess.h +++ b/pykd/pyprocess.h @@ -81,6 +81,12 @@ struct TargetSystemAdapter { return system.getProcessById(id); } + static kdlib::TargetProcessPtr getProcessBySystemId(kdlib::TargetSystem& system, kdlib::PROCESS_ID pid) + { + AutoRestorePyState pystate; + return system.getProcessBySystemId(pid); + } + static kdlib::TargetProcessPtr getCurrentProcess(kdlib::TargetSystem& system) { AutoRestorePyState pystate; @@ -167,6 +173,12 @@ struct TargetProcessAdapter { return process.getThreadById(id); } + static kdlib::TargetThreadPtr getThreadBySystemId(kdlib::TargetProcess& process, kdlib::THREAD_ID tid) + { + AutoRestorePyState pystate; + return process.getThreadBySystemId(tid); + } + static kdlib::TargetThreadPtr getCurrentThread(kdlib::TargetProcess& process) { AutoRestorePyState pystate; diff --git a/snippets/wfp.py b/snippets/wfp.py index d1b4d3a..a73cfdf 100644 --- a/snippets/wfp.py +++ b/snippets/wfp.py @@ -4,9 +4,9 @@ import re from pykd import * -fwpsLayer = typeInfo( "FWPS_BUILTIN_LAYERS_" ).asMap() -fwpsDataType = typeInfo( "FWP_DATA_TYPE_" ).asMap() -fwpDirection = typeInfo( "FWP_DIRECTION_" ).asMap() +fwpsLayer = dict( [ (long(val), key) for key, val in typeInfo( "FWPS_BUILTIN_LAYERS_" ).fields() ] ) +fwpsDataType = dict( [ (long(val), key) for key, val in typeInfo( "FWP_DATA_TYPE_" ).fields() ] ) +fwpDirection = dict( [ (long(val), key) for key, val in typeInfo( "FWP_DIRECTION_" ).fields() ] ) def printBlob( blob ): bb = loadBytes( blob.data, blob.size ) @@ -47,7 +47,7 @@ def wfpFixedValues( addr ): dprintln( "FWPS_INCOMING_VALUES0:" ) inFixedValue = typedVar( "FWPS_INCOMING_VALUES0_", addr ) - + dprintln( " Layer: " + fwpsLayer[ inFixedValue.layerId ] ) dprintln( " Value: %d" % inFixedValue.valueCount ) @@ -59,10 +59,10 @@ def wfpFixedValues( addr ): layerName = discardRe.sub( '', layerName, 1 ) layerRe = re.compile( 'LAYER' ) - fwpsFields = typeInfo( layerRe.sub( 'FIELDS', layerName, 1 ) + '_' ).asMap() + fwpsFields = typeInfo( layerRe.sub( 'FIELDS', layerName, 1 ) + '_' ).fields() - for i in range( 0, len(values) ): - dprintln( " " + fwpsFields[ i ] ) + for i in xrange( min(len(fwpsFields),len(values)) ): + dprintln( " " + fwpsFields[i][0] ) dprintln( " Type: " + fwpsDataType[ values[i].field("type") ] ) dprintln( " Value: " + printFwpsValue( values[i] ) )