[0.3.x] added: memory test

git-svn-id: https://pykd.svn.codeplex.com/svn@83746 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2013-05-21 06:16:04 +00:00 committed by Mikhail I. Izmestev
parent 238ead9227
commit e079fc98eb
9 changed files with 382 additions and 311 deletions

30
pykd/module.h Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include "kdlib/module.h"
namespace pykd {
struct Module : public kdlib::Module
{
static kdlib::ModulePtr loadModuleByName( const std::wstring &name )
{
return kdlib::loadModule( name );
}
static kdlib::ModulePtr loadModuleByOffset( kdlib::MEMOFFSET_64 offset )
{
return kdlib::loadModule( offset);
}
static std::wstring print( kdlib::Module& module ) {
return L"PYKD MODULE";
}
//static kdlib::MEMOFFSET_64 convertToLong( kdlib::Module& module ) {
// return module.getBase();
//}
};
} // end namespace pykd

View File

@ -123,7 +123,9 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="module.h" />
<ClInclude Include="stdafx.h" /> <ClInclude Include="stdafx.h" />
<ClInclude Include="target.h" />
<ClInclude Include="targetver.h" /> <ClInclude Include="targetver.h" />
<ClInclude Include="variant.h" /> <ClInclude Include="variant.h" />
<ClInclude Include="windbgext.h" /> <ClInclude Include="windbgext.h" />
@ -146,6 +148,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug_2.7|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug_2.7|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile> </ClCompile>
<ClCompile Include="target.cpp" />
<ClCompile Include="windbgext.cpp" /> <ClCompile Include="windbgext.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -27,6 +27,12 @@
<ClInclude Include="variant.h"> <ClInclude Include="variant.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="module.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="target.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">
@ -41,6 +47,9 @@
<ClCompile Include="pymod.cpp"> <ClCompile Include="pymod.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="target.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="pykd.def"> <None Include="pykd.def">

View File

@ -4,9 +4,9 @@
#include "kdlib/kdlib.h" #include "kdlib/kdlib.h"
using namespace kdlib;
#include "variant.h" #include "variant.h"
#include "module.h"
#include "target.h"
using namespace pykd; using namespace pykd;
@ -44,30 +44,27 @@ static const std::string pykdVersion = PYKD_VERSION_BUILD_STR
#endif // _DEBUG #endif // _DEBUG
; ;
//////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// //
//BOOST_PYTHON_FUNCTION_OVERLOADS( detachProcess_, detachProcess, 0, 1 ); //BOOST_PYTHON_FUNCTION_OVERLOADS( detachProcess_, detachProcess, 0, 1 );
// //
BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, kdlib::dprint, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln_, dprintln, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln_, kdlib::dprintln, 1, 2 );
//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( Module_findSymbol, Module::getSymbolNameByVa, 1, 2 ); //BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( Module_findSymbol, Module::getSymbolNameByVa, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadChars_, kdlib::loadChars, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadWChars_, kdlib::loadWChars, 2, 3 );
// BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes_, kdlib::loadBytes, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadChars_, loadChars, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords_, kdlib::loadWords, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadWChars_, loadWChars, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadDWords_, kdlib::loadDWords, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes_, loadBytes, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadQWords_, kdlib::loadQWords, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords_, loadWords, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignBytes_, kdlib::loadSignBytes, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadDWords_, loadDWords, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignWords_, kdlib::loadSignWords, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadQWords_, loadQWords, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignDWords_, kdlib::loadSignDWords, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignBytes_, loadSignBytes, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignQWords_, kdlib::loadSignQWords, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignWords_, loadSignWords, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadFloats_, kdlib::loadFloats, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignDWords_, loadSignDWords, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadDoubles_, kdlib::loadDoubles, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignQWords_, loadSignQWords, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadFloats_, loadFloats, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( loadDoubles_, loadDoubles, 2, 3 );
//BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemory_, compareMemory, 3, 4 ); //BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemory_, compareMemory, 3, 4 );
// //
//BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceLine_, getSourceLine, 0, 1 ); //BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceLine_, getSourceLine, 0, 1 );
@ -101,23 +98,23 @@ BOOST_PYTHON_MODULE( pykd )
// Manage debug target // Manage debug target
python::def( "startProcess", &startProcess, python::def( "startProcess", &kdlib::startProcess,
"Start process for debugging" ); "Start process for debugging" );
python::def( "attachProcess", &attachProcess, python::def( "attachProcess", &kdlib::attachProcess,
"Attach debugger to a exsisting process" ); "Attach debugger to a exsisting process" );
// python::def( "detachProcess", &detachProcess, detachProcess_( boost::python::args( "pid" ), // python::def( "detachProcess", &detachProcess, detachProcess_( boost::python::args( "pid" ),
// "Stop process debugging") ); // "Stop process debugging") );
python::def( "killProcess", &terminateProcess, python::def( "killProcess", &kdlib::terminateProcess,
"Stop debugging and terminate current process" ); "Stop debugging and terminate current process" );
python::def( "loadDump", &loadDump, python::def( "loadDump", &kdlib::loadDump,
"Load crash dump"); "Load crash dump");
python::def( "isDumpAnalyzing", &isDumpAnalyzing, python::def( "isDumpAnalyzing", &kdlib::isDumpAnalyzing,
"Check if it is a dump analyzing ( not living debuggee )" ); "Check if it is a dump analyzing ( not living debuggee )" );
python::def( "isKernelDebugging", &isKernelDebugging, python::def( "isKernelDebugging", &kdlib::isKernelDebugging,
"Check if kernel dubugging is running" ); "Check if kernel dubugging is running" );
//python::def( "isWindbgExt", &WindbgGlobalSession::isInit, //python::def( "isWindbgExt", &WindbgGlobalSession::isInit,
// "Check if script works in windbg context" ); // "Check if script works in windbg context" );
python::def( "writeDump", &writeDump, python::def( "writeDump", &kdlib::writeDump,
"Create memory dump file" ); "Create memory dump file" );
// python::def( "breakin", &debugBreak, // python::def( "breakin", &debugBreak,
@ -126,24 +123,24 @@ BOOST_PYTHON_MODULE( pykd )
// "Evaluate windbg expression" ); // "Evaluate windbg expression" );
// python::def( "dbgCommand", &debugCommand, // python::def( "dbgCommand", &debugCommand,
// "Run a debugger's command and return it's result as a string" ); // "Run a debugger's command and return it's result as a string" );
// python::def( "go", &debugGo, python::def( "go", &targetGo,
// "Go debugging" ); "Go debugging" );
// python::def( "step", &debugStep, // python::def( "step", &debugStep,
// "The target is executing a single instruction or--if that instruction is a subroutine call--subroutine" ); // "The target is executing a single instruction or--if that instruction is a subroutine call--subroutine" );
// python::def( "trace", &debugStepIn, // python::def( "trace", &debugStepIn,
// "The target is executing a single instruction" ); // "The target is executing a single instruction" );
// Debug output // Debug output
python::def( "dprint", &dprint, dprint_( python::args( "str", "dml" ), python::def( "dprint", &kdlib::dprint, dprint_( python::args( "str", "dml" ),
"Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" ) ); "Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" ) );
python::def( "dprintln", &dprintln, dprintln_( python::args( "str", "dml" ), python::def( "dprintln", &kdlib::dprintln, dprintln_( python::args( "str", "dml" ),
"Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) ); "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) );
// Python debug output console helper classes // Python debug output console helper classes
python::class_<DbgOut, boost::noncopyable >( "dout", "dout", python::no_init ) python::class_<kdlib::DbgOut, boost::noncopyable >( "dout", "dout", python::no_init )
.def( "write", &DbgOut::write ); .def( "write", &kdlib::DbgOut::write );
python::class_<DbgIn, boost::noncopyable>( "din", "din", python::no_init ) python::class_<kdlib::DbgIn, boost::noncopyable>( "din", "din", python::no_init )
.def( "readline", &DbgIn::readline ); .def( "readline", &kdlib::DbgIn::readline );
// // system properties // // system properties
// python::def( "ptrSize", &ptrSize, // python::def( "ptrSize", &ptrSize,
@ -172,57 +169,57 @@ BOOST_PYTHON_MODULE( pykd )
// python::def( "getVaProtect", &getVaProtect, // python::def( "getVaProtect", &getVaProtect,
// "Return memory attributes" ); // "Return memory attributes" );
// python::def( "ptrByte", &ptrByte, python::def( "ptrByte", &kdlib::ptrByte,
// "Read an unsigned 1-byte integer from the target memory" ); "Read an unsigned 1-byte integer from the target memory" );
// python::def( "ptrWord", &ptrWord, python::def( "ptrWord", &kdlib::ptrWord,
// "Read an unsigned 2-byte integer from the target memory" ); "Read an unsigned 2-byte integer from the target memory" );
// python::def( "ptrDWord", (ULONG64(*)(ULONG64))&ptrDWord, python::def( "ptrDWord", &kdlib::ptrDWord,
// "Read an unsigned 4-byte integer from the target memory" ); "Read an unsigned 4-byte integer from the target memory" );
// python::def( "ptrQWord", (ULONG64(*)(ULONG64))&ptrQWord, python::def( "ptrQWord", &kdlib::ptrQWord,
// "Read an unsigned 8-byte integer from the target memory" ); "Read an unsigned 8-byte integer from the target memory" );
// python::def( "ptrMWord", (ULONG64(*)(ULONG64))&ptrMWord, python::def( "ptrMWord", &kdlib::ptrMWord,
// "Read an unsigned mashine's word wide integer from the target memory" ); "Read an unsigned mashine's word wide integer from the target memory" );
// python::def( "ptrSignByte", &ptrSignByte, python::def( "ptrSignByte", &kdlib::ptrSignByte,
// "Read an signed 1-byte integer from the target memory" ); "Read an signed 1-byte integer from the target memory" );
// python::def( "ptrSignWord", &ptrSignWord, python::def( "ptrSignWord", &kdlib::ptrSignWord,
// "Read an signed 2-byte integer from the target memory" ); "Read an signed 2-byte integer from the target memory" );
// python::def( "ptrSignDWord", &ptrSignDWord, python::def( "ptrSignDWord", &kdlib::ptrSignDWord,
// "Read an signed 4-byte integer from the target memory" ); "Read an signed 4-byte integer from the target memory" );
// python::def( "ptrSignQWord", &ptrSignQWord, python::def( "ptrSignQWord", &kdlib::ptrSignQWord,
// "Read an signed 8-byte integer from the target memory" ); "Read an signed 8-byte integer from the target memory" );
// python::def( "ptrSignMWord", &ptrSignMWord, python::def( "ptrSignMWord", &kdlib::ptrSignMWord,
// "Read an signed mashine's word wide integer from the target memory" ); "Read an signed mashine's word wide integer from the target memory" );
// python::def( "ptrPtr", (ULONG64(*)(ULONG64))&ptrPtr, python::def( "ptrPtr", &kdlib::ptrPtr,
// "Read an pointer value from the target memory" ); "Read an pointer value from the target memory" );
// python::def( "ptrFloat", &ptrSingleFloat, python::def( "ptrFloat", &kdlib::ptrSingleFloat,
// "Read a float with single precision from the target memory" ); "Read a float with single precision from the target memory" );
//python::def( "ptrDouble", &ptrDoubleFloat, python::def( "ptrDouble", &kdlib::ptrDoubleFloat,
// "Read a float with single precision from the target memory" ); "Read a float with single precision from the target memory" );
// python::def( "loadBytes", &loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ), python::def( "loadBytes", &kdlib::loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of unsigned bytes" ) ); "Read the block of the target's memory and return it as list of unsigned bytes" ) );
// python::def( "loadWords", &loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ), python::def( "loadWords", &kdlib::loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of unsigned shorts" ) ); "Read the block of the target's memory and return it as list of unsigned shorts" ) );
// python::def( "loadDWords", &loadDWords, loadDWords_( python::args( "offset", "count", "phyAddr" ), python::def( "loadDWords", &kdlib::loadDWords, loadDWords_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) ); "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) );
// python::def( "loadQWords", &loadQWords, loadQWords_( python::args( "offset", "count", "phyAddr" ), python::def( "loadQWords", &kdlib::loadQWords, loadQWords_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of unsigned long long ( quad word )" ) ); "Read the block of the target's memory and return it as list of unsigned long long ( quad word )" ) );
// python::def( "loadSignBytes", &loadSignBytes, loadSignBytes_( python::args( "offset", "count", "phyAddr" ), python::def( "loadSignBytes", &kdlib::loadSignBytes, loadSignBytes_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of signed bytes" ) ); "Read the block of the target's memory and return it as list of signed bytes" ) );
// python::def( "loadSignWords", &loadSignWords, loadSignWords_( python::args( "offset", "count", "phyAddr" ), python::def( "loadSignWords", &kdlib::loadSignWords, loadSignWords_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of signed words" ) ); "Read the block of the target's memory and return it as list of signed words" ) );
// python::def( "loadSignDWords", &loadSignDWords, loadSignDWords_( python::args( "offset", "count", "phyAddr" ), python::def( "loadSignDWords", &kdlib::loadSignDWords, loadSignDWords_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of signed longs" ) ); "Read the block of the target's memory and return it as list of signed longs" ) );
// python::def( "loadSignQWords", &loadSignQWords, loadSignQWords_( python::args( "offset", "count", "phyAddr" ), python::def( "loadSignQWords", &kdlib::loadSignQWords, loadSignQWords_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of signed long longs" ) ); "Read the block of the target's memory and return it as list of signed long longs" ) );
// python::def( "loadChars", &loadChars, loadChars_( python::args( "address", "count", "phyAddr" ), python::def( "loadChars", &kdlib::loadChars, loadChars_( python::args( "address", "count", "phyAddr" ),
// "Load string from target memory" ) ); "Load string from target memory" ) );
// python::def( "loadWChars", &loadWChars, loadWChars_( python::args( "address", "count", "phyAddr" ), python::def( "loadWChars", &kdlib::loadWChars, loadWChars_( python::args( "address", "count", "phyAddr" ),
// "Load string from target memory" ) ); "Load string from target memory" ) );
// python::def( "loadCStr", &loadCStr, python::def( "loadCStr", &kdlib::loadCStr,
// "Load string from the target buffer containing 0-terminated ansi-string" ); "Load string from the target buffer containing 0-terminated ansi-string" );
// python::def( "loadWStr", &loadWStr, python::def( "loadWStr", &kdlib::loadWStr,
// "Load string from the target buffer containing 0-terminated unicode-string" ); "Load string from the target buffer containing 0-terminated unicode-string" );
//python::def( "loadUnicodeString", &loadUnicodeStr, //python::def( "loadUnicodeString", &loadUnicodeStr,
// "Return string represention of windows UNICODE_STRING type" ); // "Return string represention of windows UNICODE_STRING type" );
//python::def( "loadAnsiString", &loadAnsiStr, //python::def( "loadAnsiString", &loadAnsiStr,
@ -231,10 +228,10 @@ BOOST_PYTHON_MODULE( pykd )
// "Return list of pointers, each points to next" ); // "Return list of pointers, each points to next" );
//python::def( "loadPtrs", &loadPtrArray, //python::def( "loadPtrs", &loadPtrArray,
// "Read the block of the target's memory and return it as a list of pointers" ); // "Read the block of the target's memory and return it as a list of pointers" );
// python::def( "loadFloats", &loadFloats, loadFloats_( python::args( "offset", "count", "phyAddr" ), python::def( "loadFloats", &kdlib::loadFloats, loadFloats_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of floats" ) ); "Read the block of the target's memory and return it as list of floats" ) );
// python::def( "loadDoubles", &loadDoubles, loadDoubles_( python::args( "offset", "count", "phyAddr" ), python::def( "loadDoubles", &kdlib::loadDoubles, loadDoubles_( python::args( "offset", "count", "phyAddr" ),
// "Read the block of the target's memory and return it as list of doubles" ) ); "Read the block of the target's memory and return it as list of doubles" ) );
// // types and vaiables // // types and vaiables
// python::def( "getSourceFile", &getSourceFile, getSourceFile_( python::args( "offset"), // python::def( "getSourceFile", &getSourceFile, getSourceFile_( python::args( "offset"),
@ -325,63 +322,64 @@ BOOST_PYTHON_MODULE( pykd )
// python::def( "setSymbolPath", &setSymbolPath, "Set current symbol path"); // python::def( "setSymbolPath", &setSymbolPath, "Set current symbol path");
// python::def( "appendSymbolPath", &appendSymbolPath, "Append current symbol path"); // python::def( "appendSymbolPath", &appendSymbolPath, "Append current symbol path");
python::class_<pykd::NumVariant>( "numVariant", "numVariant", python::no_init ) python::class_<kdlib::NumVariantGetter, boost::noncopyable>( "numVariant", "numVariant", python::no_init )
.def( python::init<python::object&>() ) .def("__init__", python::make_constructor(&NumVariant::getVariant) )
.def( "__eq__", &pykd::NumVariant::eq ) .def( "__eq__", &NumVariant::eq )
.def( "__ne__", &pykd::NumVariant::ne) .def( "__ne__", &NumVariant::ne)
.def( "__lt__", &pykd::NumVariant::lt) .def( "__lt__", &NumVariant::lt)
.def( "__gt__", &pykd::NumVariant::gt ) .def( "__gt__", &NumVariant::gt )
.def( "__le__", &pykd::NumVariant::le ) .def( "__le__", &NumVariant::le )
.def( "__ge__", &pykd::NumVariant::ge ) .def( "__ge__", &NumVariant::ge )
.def( "__add__", &pykd::NumVariant::add ) .def( "__add__", &NumVariant::add )
.def( "__radd__", &pykd::NumVariant::add ) .def( "__radd__", &NumVariant::add )
.def( "__sub__", &pykd::NumVariant::sub ) .def( "__sub__", &NumVariant::sub )
.def( "__rsub__", &pykd::NumVariant::rsub ) .def( "__rsub__", &NumVariant::rsub )
.def( "__mul__", &pykd::NumVariant::mul ) .def( "__mul__", &NumVariant::mul )
.def( "__rmul__", &pykd::NumVariant::mul ) .def( "__rmul__", &NumVariant::mul )
.def( "__div__", &pykd::NumVariant::div ) .def( "__div__", &NumVariant::div )
.def( "__rdiv__", &pykd::NumVariant::rdiv ) .def( "__rdiv__", &NumVariant::rdiv )
.def( "__mod__", &pykd::NumVariant::mod ) .def( "__mod__", &NumVariant::mod )
.def( "__rmod__", &pykd::NumVariant::rmod ) .def( "__rmod__", &NumVariant::rmod )
.def( "__rshift__", &pykd::NumVariant::rshift ) .def( "__rshift__", &NumVariant::rshift )
.def( "__rrshift__", &pykd::NumVariant::rrshift ) .def( "__rrshift__", &NumVariant::rrshift )
.def( "__lshift__", &pykd::NumVariant::lshift ) .def( "__lshift__", &NumVariant::lshift )
.def( "__rlshift__", &pykd::NumVariant::rlshift ) .def( "__rlshift__", &NumVariant::rlshift )
.def( "__and__", &pykd::NumVariant::and ) .def( "__and__", &NumVariant::and )
.def( "__rand__", &pykd::NumVariant::and ) .def( "__rand__", &NumVariant::and )
.def( "__or__", &pykd::NumVariant::or ) .def( "__or__", &NumVariant::or )
.def( "__ror__", &pykd::NumVariant::or ) .def( "__ror__", &NumVariant::or )
.def( "__xor__", &pykd::NumVariant::xor ) .def( "__xor__", &NumVariant::xor )
.def( "__rxor__", &pykd::NumVariant::xor ) .def( "__rxor__", &NumVariant::xor )
.def( "__neg__", &pykd::NumVariant::neg ) .def( "__neg__", &NumVariant::neg )
.def( "__pos__", &pykd::NumVariant::pos ) .def( "__pos__", &NumVariant::pos )
.def( "__invert__", &pykd::NumVariant::invert ) .def( "__invert__", &NumVariant::invert )
.def( "__nonzero__", &pykd::NumVariant::nonzero ) .def( "__nonzero__", &NumVariant::nonzero )
//.def( "__str__", &pykd::NumVariant::str ) //.def( "__str__", &pykd::NumVariant::str )
// .def( "__hex__", &pykd::NumVariant::hex ) // .def( "__hex__", &pykd::NumVariant::hex )
.def( "__long__", &pykd::NumVariant::long_ ) .def( "__long__", &NumVariant::long_ )
.def( "__int__", &pykd::NumVariant::int_ ) .def( "__int__", &NumVariant::int_ )
.def( "__index__", &pykd::NumVariant::long_ ) .def( "__index__", &NumVariant::long_ )
.def( "__hash__", &pykd::NumVariant::long_ ); .def( "__hash__", &NumVariant::long_ )
;
python::implicitly_convertible<pykd::NumVariant, unsigned long long>(); //python::implicitly_convertible<kdlib::NumVariantGetter, unsigned long long>();
python::implicitly_convertible<pykd::NumVariant, long long>(); //python::implicitly_convertible<kdlib::NumVariantGetter, long long>();
python::implicitly_convertible<pykd::NumVariant, unsigned long>(); //python::implicitly_convertible<kdlib::NumVariantGetter, unsigned long>();
python::implicitly_convertible<pykd::NumVariant, long>(); //python::implicitly_convertible<kdlib::NumVariantGetter, long>();
// python::class_<Module, ModulePtr, python::bases<intBase> >("module", "Class representing executable module", python::no_init ) python::class_<kdlib::Module, kdlib::ModulePtr, python::bases<kdlib::NumVariantGetter>, boost::noncopyable>("module", "Class representing executable module", python::no_init )
// .def("__init__", python::make_constructor(Module::loadModuleByName) ) .def("__init__", python::make_constructor(&Module::loadModuleByName ) )
// .def("__init__", python::make_constructor(Module::loadModuleByOffset) ) .def("__init__", python::make_constructor(&Module::loadModuleByOffset) )
// .def("begin", &Module::getBase, .def("begin", &kdlib::Module::getBase,
// "Return start address of the module" ) "Return start address of the module" )
// .def("end", &Module::getEnd, .def("end", &kdlib::Module::getEnd,
// "Return end address of the module" ) "Return end address of the module" )
// .def("size", &Module::getSize, .def("size", &kdlib::Module::getSize,
// "Return size of the module" ) "Return size of the module" )
// .def("name", &Module::getName, .def("name", &kdlib::Module::getName,
// "Return name of the module" ) "Return name of the module" )
// .def("reload", &Module::reloadSymbols, .def("reload", &kdlib::Module::reloadSymbols,
// "(Re)load symbols for the module" ) "(Re)load symbols for the module" )
//.def("image", &Module::getImageName, //.def("image", &Module::getImageName,
// "Return name of the image of the module" ) // "Return name of the image of the module" )
//.def("symfile", &Module::getSymFile, //.def("symfile", &Module::getSymFile,
@ -429,9 +427,11 @@ python::class_<pykd::NumVariant>( "numVariant", "numVariant", python::no_init )
// "Return string from the module's version resources" ) // "Return string from the module's version resources" )
//.def("getVersion", &Module::getVersion, //.def("getVersion", &Module::getVersion,
// "Return tuple of the module's file version" ) // "Return tuple of the module's file version" )
// .def("__getattr__", &Module::getSymbolOffset, .def("__getattr__", &kdlib::Module::getSymbolVa,
// "Return address of the symbol" ) "Return address of the symbol" )
// .def( "__str__", &Module::print ); .def( "__str__", &Module::print );
// python::class_<TypeInfo, TypeInfoPtr, python::bases<intBase>, boost::noncopyable >("typeInfo", "Class representing typeInfo", python::no_init ) // python::class_<TypeInfo, TypeInfoPtr, python::bases<intBase>, boost::noncopyable >("typeInfo", "Class representing typeInfo", python::no_init )
// .def("__init__", python::make_constructor(TypeInfo::getTypeInfoByName ) ) // .def("__init__", python::make_constructor(TypeInfo::getTypeInfoByName ) )

22
pykd/target.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "stdafx.h"
#include "kdlib/dbgengine.h"
#include "target.h"
namespace pykd {
///////////////////////////////////////////////////////////////////////////////
void targetGo()
{
PyThreadState* state = PyEval_SaveThread();
kdlib::targetGo();
PyEval_RestoreThread( state );
}
///////////////////////////////////////////////////////////////////////////////
} //end namespace pykd

11
pykd/target.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
namespace pykd {
///////////////////////////////////////////////////////////////////////////////
void targetGo();
///////////////////////////////////////////////////////////////////////////////
} //end namespace pykd

View File

@ -4,203 +4,199 @@
namespace pykd { namespace pykd {
class NumVariant : public kdlib::NumVariant class NumVariant : public kdlib::NumVariantGetter
{ {
public: public:
NumVariant( const python::object &obj ) static kdlib::NumVariantGetter* getVariant( const python::object &obj )
{ {
NumVariant* var = new NumVariant();
if ( PyBool_Check( obj.ptr() ) ) if ( PyBool_Check( obj.ptr() ) )
{ {
if ( obj.ptr() == Py_True ) if ( obj.ptr() == Py_True )
setBool(true); var->m_variant.setBool(true);
else else
setBool(false); var->m_variant.setBool(false);
return; return var;
} }
if ( PyInt_CheckExact( obj.ptr() ) ) if ( PyInt_CheckExact( obj.ptr() ) )
{ {
setLong( PyLong_AsLong( obj.ptr() ) ); var->m_variant.setLong( PyLong_AsLong( obj.ptr() ) );
return; return var;
} }
if ( _PyLong_Sign( obj.ptr() ) >= 0 ) if ( _PyLong_Sign( obj.ptr() ) >= 0 )
setULongLong( PyLong_AsUnsignedLongLong( obj.ptr() ) ); var->m_variant.setULongLong( PyLong_AsUnsignedLongLong( obj.ptr() ) );
else else
setLongLong( PyLong_AsLongLong( obj.ptr() ) ); var->m_variant.setLongLong( PyLong_AsLongLong( obj.ptr() ) );
return var;
} }
python::object convertToPython() static python::object convertToPython( kdlib::NumVariantGetter& v )
{ {
if ( isChar() ) kdlib::NumVariant var = v;
return python::object( asInt() );
if ( isUChar() ) if ( var.isChar() )
return python::object( asInt() ); return python::object( var.asInt() );
if (isShort() ) if ( var.isUChar() )
return python::object( asInt() ); return python::object( var.asInt() );
if ( isUShort() ) if ( var.isShort() )
return python::object( asInt() ); return python::object( var.asInt() );
if ( isLong() ) if ( var.isUShort() )
return python::object( asLong() ); return python::object( var.asInt() );
if ( isULong() ) if ( var.isLong() )
return python::object( asULong() ); return python::object( var.asLong() );
if ( isLongLong() ) if ( var.isULong() )
return python::object( asLongLong() ); return python::object( var.asULong() );
if ( isULongLong() ) if ( var.isLongLong() )
return python::object( asULongLong() ); return python::object( var.asLongLong() );
if ( isInt() ) if ( var.isULongLong() )
return python::object( asInt() ); return python::object( var.asULongLong() );
if ( isUInt() ) if ( var.isInt() )
return python::object( asUInt() ); return python::object( var.asInt() );
if ( isFloat() ) if ( var.isUInt() )
return python::object( asFloat() ); return python::object( var.asUInt() );
if ( isDouble() ) if ( var.isFloat() )
return python::object( asDouble() ); return python::object( var.asFloat() );
}
if ( var.isDouble() )
return python::object( var.asDouble() );
public: return python::object( var.asInt() );
python::object eq( python::object& obj ) {
return convertToPython() == obj;
}
python::object ne( python::object& obj ) {
return convertToPython() != obj;
}
python::object lt( python::object& obj ) {
return convertToPython() < obj;
}
python::object gt( python::object& obj ) {
return convertToPython() > obj;
}
python::object le( python::object& obj ) {
return convertToPython() <= obj;
}
python::object ge( python::object& obj ) {
return convertToPython() >= obj;
}
python::object add( python::object& obj ) {
return convertToPython() + obj;
}
python::object sub( python::object& obj ) {
return convertToPython() - obj;
}
python::object rsub( python::object& obj ) {
return obj - convertToPython();
}
python::object mul( python::object& obj ) {
return convertToPython() * obj;
}
python::object div( python::object& obj ) {
return convertToPython() / obj;
}
python::object rdiv( python::object& obj ) {
return obj / convertToPython();
}
python::object mod( python::object& obj ) {
return convertToPython() % obj;
}
python::object rmod( python::object& obj ) {
return obj % convertToPython();
}
python::object rshift( python::object& obj ) {
return convertToPython() >> obj;
}
python::object rrshift( python::object& obj ) {
return obj >> convertToPython();
}
python::object lshift( python::object& obj ) {
return convertToPython() << obj;
}
python::object rlshift( python::object& obj ) {
return obj << convertToPython();
}
python::object and( python::object& obj ) {
return convertToPython() & obj;
}
python::object or( python::object& obj ) {
return convertToPython() | obj;
}
python::object xor( python::object& obj ) {
return convertToPython() ^ obj;
}
python::object neg() {
return 0 - convertToPython();
}
python::object pos() {
return 0 + convertToPython();
}
python::object invert() {
return convertToPython() ^ convertToPython();
}
python::object nonzero() {
return convertToPython() != 0;
} }
public: public:
python::object long_() { static python::object eq( kdlib::NumVariantGetter& var, python::object& obj ) {
return python::long_( asLongLong() ); return convertToPython(var) == obj;
} }
python::object int_() { static python::object ne( kdlib::NumVariantGetter& var, python::object& obj ) {
return python::long_( asLongLong() ); return convertToPython(var) != obj;
} }
operator unsigned long long() { static python::object lt( kdlib::NumVariantGetter& var, python::object& obj ) {
return asULongLong(); return convertToPython(var) < obj;
} }
operator unsigned long() { static python::object gt( kdlib::NumVariantGetter& var, python::object& obj ) {
return asULong(); return convertToPython(var) > obj;
} }
operator long long() { static python::object le( kdlib::NumVariantGetter& var, python::object& obj ) {
return asLongLong(); return convertToPython(var) <= obj;
} }
operator long() { static python::object ge( kdlib::NumVariantGetter& var, python::object& obj ) {
return asLong(); return convertToPython(var) >= obj;
} }
static python::object add( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) + obj;
}
static python::object sub( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) - obj;
}
static python::object rsub( kdlib::NumVariantGetter& var, python::object& obj ) {
return obj - convertToPython(var);
}
static python::object mul( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) * obj;
}
static python::object div( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) / obj;
}
static python::object rdiv( kdlib::NumVariantGetter& var, python::object& obj ) {
return obj / convertToPython(var);
}
static python::object mod( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) % obj;
}
static python::object rmod( kdlib::NumVariantGetter& var, python::object& obj ) {
return obj % convertToPython(var);
}
static python::object rshift( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) >> obj;
}
static python::object rrshift( kdlib::NumVariantGetter& var, python::object& obj ) {
return obj >> convertToPython(var);
}
static python::object lshift( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) << obj;
}
static python::object rlshift( kdlib::NumVariantGetter& var, python::object& obj ) {
return obj << convertToPython(var);
}
static python::object and( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) & obj;
}
static python::object or( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) | obj;
}
static python::object xor( kdlib::NumVariantGetter& var, python::object& obj ) {
return convertToPython(var) ^ obj;
}
static python::object neg(kdlib::NumVariantGetter& var) {
return 0 - convertToPython(var);
}
static python::object pos(kdlib::NumVariantGetter& var) {
return 0 + convertToPython(var);
}
static python::object invert(kdlib::NumVariantGetter& var) {
return convertToPython(var) ^ convertToPython(var);
}
static python::object nonzero(kdlib::NumVariantGetter& var) {
return convertToPython(var) != 0;
}
static python::object long_(kdlib::NumVariantGetter& var ) {
return convertToPython(var);
}
static python::object int_(kdlib::NumVariantGetter& var) {
return convertToPython(var);
}
private:
virtual kdlib::NumVariant getValue() const{
return m_variant;
}
kdlib::NumVariant m_variant;
}; };
} // end pykf namespace } // end pykf namespace

View File

@ -84,8 +84,8 @@ class MemoryTest( unittest.TestCase ):
self.assertEqual( u'Hello', pykd.loadWStr( target.module.helloWStr ) ) self.assertEqual( u'Hello', pykd.loadWStr( target.module.helloWStr ) )
def testBigCStr( self ): def testBigCStr( self ):
self.assertEqual( 0x2000, len( pykd.loadCStr( pykd.ptrPtr( target.module.bigCStr ) ) ) ) self.assertEqual( 0x2000, len( pykd.loadCStr( target.module.bigCStr ) ) )
self.assertEqual( 0x2000, len( pykd.loadWStr( pykd.ptrPtr( target.module.bigWStr ) ) ) ) self.assertEqual( 0x2000, len( pykd.loadWStr( target.module.bigWStr ) ) )
def testVaValid( self ): def testVaValid( self ):
self.assertTrue( pykd.isValid( target.module.begin() ) ) self.assertTrue( pykd.isValid( target.module.begin() ) )

View File

@ -14,7 +14,7 @@ import pykd
import target import target
import intbase import intbase
#import memtest import memtest
#import moduletest #import moduletest
#import typeinfo #import typeinfo
#import typedvar #import typedvar
@ -48,7 +48,7 @@ def getTestSuite( singleName = "" ):
unittest.TestLoader().loadTestsFromTestCase( StartProcessWithoutParamsTest ), unittest.TestLoader().loadTestsFromTestCase( StartProcessWithoutParamsTest ),
# *** Test without start/kill new processes # *** Test without start/kill new processes
#unittest.TestLoader().loadTestsFromTestCase( moduletest.ModuleTest ), #unittest.TestLoader().loadTestsFromTestCase( moduletest.ModuleTest ),
#unittest.TestLoader().loadTestsFromTestCase( memtest.MemoryTest ), unittest.TestLoader().loadTestsFromTestCase( memtest.MemoryTest ),
#unittest.TestLoader().loadTestsFromTestCase( typeinfo.TypeInfoTest ), #unittest.TestLoader().loadTestsFromTestCase( typeinfo.TypeInfoTest ),
#unittest.TestLoader().loadTestsFromTestCase( typedvar.TypedVarTest ), #unittest.TestLoader().loadTestsFromTestCase( typedvar.TypedVarTest ),
#unittest.TestLoader().loadTestsFromTestCase( regtest.CpuRegTest ), #unittest.TestLoader().loadTestsFromTestCase( regtest.CpuRegTest ),